Open stefan-hoeck opened 3 years ago
Actually, I don't think this is a bug of the chez backend: The problem is already there when the CExp
IR is being generated. The branch should be chosen from the data constructor used in the second argument, not from the one in the first argument, so there shouldn't be any decision making based on the first argument at all. Imagine the same function being called with a two-argument record, which will happen to have the same representation in the IRs as Prelude.Pair: Such a function call will always end up in the wrong branch.
For instance, when I look at the code generated by the JS backend, we were just lucky that it worked correctly in this case.
I may have hit this on javascript, here's what the error looks like:
/home/ssdd/dev/responsible/build/exec/hello:1225
const $4 = $1($3);
^
TypeError: $1 is not a function
at Control_App_bindApp (/home/ssdd/dev/responsible/build/exec/hello:1225:13)
at Control_App_x3ex3ex3d_Monad_x28Appx20x24esx29 (/home/ssdd/dev/responsible/build/exec/hello:1113:9)
at /home/ssdd/dev/responsible/build/exec/hello:363:407
at Control_App_bindApp (/home/ssdd/dev/responsible/build/exec/hello:1227:27)
at Control_App_x3ex3ex3d (/home/ssdd/dev/responsible/build/exec/hello:1237:9)
at Examples_HelloNode_hello (/home/ssdd/dev/responsible/build/exec/hello:445:9)
at /home/ssdd/dev/responsible/build/exec/hello:453:345
at Control_App_bindApp (/home/ssdd/dev/responsible/build/exec/hello:1227:27)
at Control_App_x3ex3ex3d (/home/ssdd/dev/responsible/build/exec/hello:1237:9)
at /home/ssdd/dev/responsible/build/exec/hello:1349:10
When compiling with chez backend, I get Invalid memory reference
as above. I can't reduce the code to a small example right now. If I remove a putStrLn
, the error goes away on both backends.
I hit this error in my program as well . Not a nice experience. What can be a workaround? In my case it is a recursive function with a LazyList.
The following code behaves correctly on the JS backend but not on the default Chez Scheme backend. This occurred in a larger code base of mine, and breaking it down to the example below took quite some time. It might still not be minimal, though:
Steps to Reproduce
Compile and run the following example:
Expected Behavior
Prints
(1, 1)
.Observed Behavior
Fails with:
Exception: invalid memory reference. Some debugging context lost
Now, I had a look at the generated Scheme code, and the culprit is the second pattern match in function
step
(I'll add a properly indented version of it below): Instead of matching against theMSF
constructor, the generated Scheme performs anull?
check against the pair argument. Pairs are treated asCONS
constructors internally, so the Chez codegen performs this check to distinguish theCONS
case from theNIL
case. However,null?
returns#f
for everything that is not an empty list (the number we pass as an argument in our case), and the wrong branch is entered, leading to the exception described below.Finally, if I change the implementation of
step
to the following version, the program runs correctly: