-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IAssassin code generation bug when a lambda expression closes over 31 free variables #688
Comments
Its quite possible that I made a mistake in my reading of: http://www.ccs.neu.edu/home/lth/larceny/notes/note13-malcode.html (Update: an earlier version of this comment had some mistakes its reasoning, namely a fencepost error in my thinking about what In particular, we have:
So, okay, there's a threshold value On further investigation, we find:
So, hmm, the value of But then what is
This makes it seem like (Second update: still more errors corrected.) Anyway, looking again at the documentation for the
IAssassin is not following the documented semantics; it appears to be assuming that when (Incidentally, is there are good reason to use (I would be curious to know if this same bug exhibits itself on the Petit/C or Petit/NASM backend, especially since the IAssassin backend was largely directly ported from the Petit/NASM backend, apart from a few opcodes that needed special treatment due to its non-Petit nature.) |
Fixed by changeset 9241f06 IAssassin was incorrect. Comparing the IAssassin code to the documentation is confusing because the documentation uses The bug does not show up in Petit Larceny (Standard-C) on Linux. I haven't checked the Petit/NASM backend, so I'll leave this ticket open until that's been checked. |
By the way, I ran across this bug while adding R7RS So I suspected a compiler bug, but my test case contained over 2000 lines of code (excluding comments). I found the bug by examining a 26416-line listing of the generated MacScheme machine assembly code. That was kinda fun. |
@WillClinger ah, I see where I went wrong in my analysis of the documentation above. |
Felix wrote:
The reason is simplicity of code generation. With the semantics Lars and I documented in 1999, there are only two cases: |
The Fence back-end gets this right, probably because it was forked off the SPARC back-end: src/asm/Fence/pass5p2.sch:emit-init-procedure-slots. (The ARM back-end, built on Fence, in any case only has hardware registers so the bug would have shown up in real code pretty quickly.) |
The IAssassin code generation bug has been fixed, so leaving this ticket open is misleading. If Petit/Nasm has a similar bug, we should open a new ticket for that. I'm afraid I'll forget to check, so I won't close this ticket right now. I am, however, downgrading it to minor and moving the milestone. |
The IAssassin bug has been fixed, and issue #758 has been created to remind us to check for this bug in the Petit/Nasm version in case we go back to using that version, so I'm closing this. |
In current IAssassin versions of Larceny:
evaluates to
When one more argument is added to both
foo
and to the lambda expression, theoutput is correct.
This is a bug in the code generator, but I'm not sure whether it's a bug in Twobit or in
the IAssassin back end. Twobit produces this MacScheme machine code:
Explanation:
With the current IAssassin (IA32) version of Larceny, the Twobit compiler generates
code for an abstract MacScheme machine with 32 registers, of which 31 are used for
arguments. The
lambda
instruction creates a procedure that closes over the valuesin some number of those registers. When closing over less than 31 values, the
semantics is straightforward. When closing over 32 or more,
reg31
holds a list ofall values to close over past the first 30 (not counting the contents of
reg0
). Whenclosing over exactly 31 registers, there are two reasonable semantics. Evidently
Twobit is using one of the two reasonable semantics, but the IAssassin assembler
is using the other.
I don't know which is right. I'll have to consult the MacScheme machine documentation.
The text was updated successfully, but these errors were encountered: