Giter VIP home page Giter VIP logo

Comments (11)

andyarvanitis avatar andyarvanitis commented on July 23, 2024 1

Ok, fixed in main branches now (commit in pure11 repo: pure11/pure11@f14293c). Thanks again for the report and examples!

from purescript-native.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

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.

LATBauerdick avatar LATBauerdick commented on July 23, 2024

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.

LATBauerdick avatar LATBauerdick commented on July 23, 2024

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.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

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.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

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.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

Note: commit fix in pure11 repo: pure11/pure11@00b51f9

from purescript-native.

LATBauerdick avatar LATBauerdick commented on July 23, 2024

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.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

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.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

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.

LATBauerdick avatar LATBauerdick commented on July 23, 2024

everything works for me -- thank you!

from purescript-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.