[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH][4][5] Add arity checks for ##core#proc-class p

From: Evan Hanson
Subject: [Chicken-hackers] [PATCH][4][5] Add arity checks for ##core#proc-class platform rewrites
Date: Sun, 22 Mar 2015 18:36:59 +1300

Hi hackers,

Earlier today Peter came across an issue on the chicken-5 branch where
the program `(number->string)` would produce bad C and fail to compile
due to a C procedure being called with too few arguments.

I traced this back to the c-platform rewrite from `number->string` to
`C_number_to_string`, which happily produces such a call when no
arguments are provided. Attached is a patch that adds argument count
checking for this class of compiler rewrites, in the style of some of
the others.

Why did Peter hit this issue on chicken-5 but not on master? Well, on
master `number->string` is subject to constant folding, which in the
0-ary case the optimizer attempts and detects as erroneous, thereby
marking the call site "broken" and exempt from further optimizations
(including compiler rewrites). This broken-node tracking aspect of the
compiler effectively masks the fact that this class of rewrites doesn't
work for calls with a bad argument count. (Mostly; you can still trigger
the issue on master if you really try, for example with the program
`(apply number->string '())`. Note that a couple of other common
procedures have this problem, too, including `-` and `/`, which is why
I've included a patch against master as well as chicken-5.) On
chicken-5, where `number->string` is no longer foldable (per d701161),
the argument count mismatch isn't detected during optimization and thus
c-platform.scm is free to rewrite it (to an invalid C call).

Let me know if any of that was unclear. The patch against 5 is obviously
more important, but I'd like them both to go in, assuming they look OK.



Attachment: 0001-Add-arity-checks-for-core-proc-class-platform-rewrit.4.patch
Description: Text Data

Attachment: 0001-Add-arity-checks-for-core-proc-class-platform-rewrit.5.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]