Comments (11)
Ok, fixed in main branches now (commit in pure11 repo: pure11/pure11@f14293c). Thanks again for the report and examples!
from purescript-native.
Thanks! Would love to see it used in such a cool project/domain.
I've been tied up lately and haven't been able to get to 0.11, and it will probably be another week before I can finally do so. So please feel free to submit something now (I might be able to at least have a quick look). There's a good chance neither of those issues will be affected by 0.11 changes, but I can think of a couple of areas that might (TCO in particular, if that's involved in your segfault).
One thing that will help with any diagnosis/report will be to run your cases with a debug build (which isn't currently the default in the standard Makefile -- I should probably change that).
from purescript-native.
Here's the first example that leads to problems.
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
type Rec = {aa :: Int, bb :: Int, cc:: Int}
expand :: Int -> Int -> Rec
expand aa bb = {aa:aa, bb:bb, cc:(aa*bb)}
showRec :: Rec -> String
showRec jj@{aa, bb, cc} = show aa <> " " <> show bb <> " " <> show cc
main :: Eff (console :: CONSOLE) Unit
main = do
let
rr = expand 2 3
mycc = rr.cc
log $ "Rec: " <> showRec rr
log $ "Rec: " <> show rr.cc <> " vs. " <> show mycc
The output with psc 0.11.4 is, as expected,
Rec: 2 3 6
Rec: 6 vs. 6
The output with pcc 0.10.7 is
Rec: 2 3 6
Rec: 6 vs. 0
when I switch on debug, as you recommended, I get a crash
Assertion failed: (variant.tag == t), function extractPointer, file output-pcc/PureScript/PureScript.cc, line 96.
make: *** [run] Abort trap: 6
I'll send the second issue that I saw in a bit, when I understand it better.
Thanks again for looking into this!
from purescript-native.
Here the other examples. It looks a bit contrived, it was extracted from the package sharkdp/purescript-format
that I was trying to use, much reduced.
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Maybe (Maybe(..))
type PropertiesRecord = { precision :: Maybe Int }
default :: PropertiesRecord
default = { precision: Nothing }
data Properties = Properties PropertiesRecord
precision :: Int -> Properties
precision digits = Properties (default { precision = Just digits })
format :: Properties -> Number -> String
format (Properties rec) num' = show num where -- full version does some formatting here
num = case rec.precision of
Nothing -> num'
Just digits -> num' -- some formatting logic goes here
main :: Eff (console :: CONSOLE) Unit
main = do
log $ format (precision 1) 123.456
Works with psc, but compiling with pcc it dies with "signal 11" (without debug). Switching on debug it aborts with
Assertion failed: (variant.tag == t), function extractPointer, file output-pcc/PureScript/PureScript.cc, line 96.
make: *** [run] Abort trap: 6
Something bad happens with the num
variable. The full code doesn't even compile with pcc at all (although it does with psc) because of some name clash in the generated .cc file, involving num
(the full version has format
as a class member function, and num
is re-used in two instances, one for formatting Int
and the other for formatting Number
--- something must go wrong in the code generation).
Cheers, LatB
from purescript-native.
Ok, I found the problem. The same bug is affecting both examples. What's happening is that the codegen isn't getting the type information (from core) that tells it whether an accessor is for a record field (vs something like a typeclass dict). I still need to track down why this is happening --
I'm pretty sure it used to be fine, so maybe something changed upstream that I missed. It also doesn't seem to occur with the standard test cases. Thanks again for the report. I'll also let you know if I can find a workaround for now.
from purescript-native.
I've published the fix -- now in pure11 and purescript-native repositories. The latest pre-built binaries also have it: https://github.com/pure11/pure11/releases/tag/v0.10.7_2017-05-08 (if you're using a Mac)
Tests are passing, so I'll go ahead and close this, but please let me know if you see any problems (feel free to re-open this ticket if you think related).
from purescript-native.
Note: commit fix in pure11 repo: pure11/pure11@00b51f9
from purescript-native.
Thanks Andy, the fix works for me with the examples above, thank you!
However, my "main objective" of purscript-format still does not compile, and I'm assuming the problem is related to this one.
I prepared a much simplified example below, based on the previous one:
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Maybe (Maybe(..))
type PropertiesRecord = { precision :: Maybe Int }
default :: PropertiesRecord
default = { precision: Nothing }
data Properties = Properties PropertiesRecord
precision :: Int -> Properties
precision digits = Properties (default { precision = Just digits })
format :: Properties -> Number -> String
format prop@(Properties rec) num | rec.precision == Just 0 = "no precision"
format (Properties rec) num' = show num where
num = case rec.precision of
Nothing -> num'
Just digits -> num'
main :: Eff (console :: CONSOLE) Unit
main = do
log $ format (precision 1) 123.456
it does not compile, with the following error:
Creating output-pcc/Main/Main.o
output-pcc/Main/Main.cc:22:16: error: redefinition of 'num'
const auto num = ([=]() -> any {
^
output-pcc/Main/Main.cc:18:17: note: previous definition is here
const auto& num = v1;
^
1 error generated.
make[1]: *** [output-pcc/Main/Main.o] Error 1
make: *** [debug] Error 2
On the other hand:
$> pulp run
* Building project in <whatever>
* Build successful.
123.456
from purescript-native.
I think I know what's causing that one -- I'll try to have a look at it today.
You might have already spotted this, but you can change
format prop@(Properties rec) num | rec.precision == Just 0 = "no precision"
to
format prop@(Properties rec) num' | rec.precision == Just 0 = "no precision"
to work around it for now.
from purescript-native.
I'll close this again, but please let me know if you see any of these same issues again (I don't expect you will).
from purescript-native.
everything works for me -- thank you!
from purescript-native.
Related Issues (20)
- ObjectUpdate seems to need deep copy HOT 2
- Cannot find ls/ls.h and rs/rs.h HOT 2
- Incorrect equality check in Data_Interval_Duration_Iso HOT 3
- Returning a constant from the ffi HOT 7
- "attribute 'haskell-nix' missing" when building with nix HOT 3
- error building purescript-dotlang HOT 16
- Support spago alternate entry point option
- ffi array type interop with opaque types HOT 7
- zero-fill shift right operator doesn't exist HOT 11
- pass arguments to run HOT 2
- stack nix integration HOT 1
- Problems with nix toolchain HOT 9
- Consider combining executables (and specify backend with switch) HOT 5
- un-gitignore cabal files HOT 2
- cpp binary size HOT 4
- Update to PureScript 0.14 HOT 5
- Webassembly / Emscripten with C++ HOT 1
- Upgrade to Latest PureScript Version
- Backend "psgo" exited with error:1 HOT 2
- go module initialization HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-native.