iu-parfunc / gibbon

A compiler for functional programs on serialized data
http://iu-parfunc.github.io/gibbon/
157 stars 13 forks source link

Nested data constructors can lead to dropped functions/variables #203

Open jazullo opened 1 year ago

jazullo commented 1 year ago
import Gibbon.Prelude
import Gibbon.Maybe
import Gibbon.PList

print_empty :: () -> PList (Maybe RBT)
print_empty z = 
  let _ = printsym (quote ".") in
  Cons Nothing Nil

x :: PList (Maybe RBT)
x = print_empty ()

Produces error

~/gibbon$ cabal v2-exec gibbon -- --packed --no-gc --to-exe ../llrbt/print_test.hs
gibbon: Function not found: _copy_RBT while checking AppE "_copy_RBT" [] [VarE "x_254"]
at
CallStack (from HasCallStack):
  error, called at src/Gibbon/L1/Typecheck.hs:46:26 in gibbon-0.2-inplace:Gibbon.L1.Typecheck

on master

jazullo commented 1 year ago

I believe fixing this issue should allow the tree printer in the below code to work. This file currently produces a L2 typechecking variable for a dropped variable, which is both lower down and a different error, but I think they are related? https://gist.github.com/jazullo/7ac6c4db284b6498b18da3f4957d0c68

vidsinghal commented 1 year ago

@jazullo this error is there because you haven't included the date type definitions. Hence the compiler doesn't know what RBT, B, I is.

vidsinghal commented 1 year ago
import Gibbon.Prelude
import Gibbon.Maybe
import Gibbon.PList

data B = B Bool

data I = I Int

data RBT
  = Empty
  | Node B I RBT RBT

print_empty :: () -> PList (Maybe RBT)
print_empty z = 
  let _ = printsym (quote ".")
      xx :: Maybe RBT 
      xx = Nothing
   in Cons xx (Nil)

x :: PList (Maybe RBT)
x = print_empty ()