larcenists / larceny

Larceny Scheme implementation
Other
202 stars 32 forks source link

strange error with expression in function position #743

Closed jordanblack closed 7 years ago

jordanblack commented 8 years ago

((if #t + -) 1 2 3) ERROR detected by compiler: Wrong number of arguments to integrable procedure (+ '1 '2 '3)

WillClinger commented 8 years ago

This is a compiler bug that must have been present from the earliest days of Larceny. It's a phase-ordering problem: Twobit's pass 1 is responsible for rewriting calls to variable-arity integrable procedures into the preferred number of arguments, which is 2 for +, but the (if #t + -) isn't simplified to + until Pass 2. What's worse, pass 2 doesn't know anything about integrable procedures, so it can't repeat the rewriting done by pass 1 whenever its own rewriting produces a seemingly obvious call to an integrable procedure.

The error message is generated by pass 4 as it tries to generate code for the call. It should be easy to disable that error message and generate code for a closed call, but that would disable the error message for all integrable procedures, and I'm not the only programmer who finds those messages to be helpful.

Trying to fix the phase-ordering problem would probably create several bugs more serious than this one. Disabling the error message for all procedures is also unattractive. One possible compromise is to add a new table for variable-arity integrable procedures so pass 4 can tell whether it should generate a closed call or generate an error message.

WillClinger commented 7 years ago

Fixed by changeset 0812c6e283d65920e48bd20535e4c418d770c0cc

This is not a robust fix, and should be reconsidered as part of the GreatPrimOpCleanUp.