andyarvanitis / purescript-native

A native compiler backend for PureScript (via C++ or Golang)
http://purescript.org
Other
632 stars 40 forks source link

Cannot find ls/ls.h and rs/rs.h #57

Closed mikesol closed 4 years ago

mikesol commented 4 years ago

Hi!

First off, thanks a lot for this great project.

I'm trying to compile something that uses Data.Set and hitting the following error:

Creating output/src/Data_Set/Data_Set.o (C++)
output/src/Data_Set/Data_Set.cpp:13:19: fatal error: ls/ls.h: No such file or directory
 #include "ls/ls.h"
                   ^
compilation terminated.
Makefile:100: recipe for target 'output/src/Data_Set/Data_Set.o' failed
make[1]: *** [output/src/Data_Set/Data_Set.o] Error 1
make[1]: Leaving directory '/home/mike/purescript-audio-behaviors'
Makefile:58: recipe for target 'debug' failed
make: *** [debug] Error 2

I can't find ls/ls.h anywhere in the generated source or ffi. Is this part of an external library? Thanks!

mikesol commented 4 years ago

Did a bit of digging - the issue is because the transpiler translates this line: https://github.com/purescript/purescript-ordered-collections/blob/54af8b281bf01acfc14e147debec76974901e93c/src/Data/Set.purs#L176:

      then case compare (ls `Array.unsafeIndex` l) (rs `Array.unsafeIndex` r) of

into

                                boxed v = Data_Ord::compare()(dictOrd)(ls::l())(rs::r());

whereas it should be something like

boxed v = Data_Ord::compare()(dictOrd)(Data_Array::unsafeIndex()(ls)(l))(Data_Array::unsafeIndex()(rs)(r));
andyarvanitis commented 4 years ago

Thanks for the report. The inliner is what is responsible for removing explicit calls to unsafeIndex. It looks like something is going wrong with it, though, and turning those local variables into module-level values.