[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-hackers] [PATCH] Don't silently truncate huge literals, and don
From: |
Peter Bex |
Subject: |
[Chicken-hackers] [PATCH] Don't silently truncate huge literals, and don't constant-fold if it would result in such a literal |
Date: |
Sat, 30 Jan 2016 15:07:37 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hello all,
As you can see in the "big prime" thread on chicken-users, CHICKEN will
silently truncate the length of a literal, which means it will generate
incorrect code which will still run but produce the wrong behaviour.
The attached patch detects such large literals and aborts the
compilation (there's not much we can do in such a situation).
Because the big-prime actually isn't an object literal occuring in the
source code, we can avoid this particular case by refusing to constant-
fold if the result would be too large to be encoded.
The attached patch does this. Only for CHICKEN 5, it adds a test case
because I didn't know how to get the compiler to generate a type of
object that's so large through constant-folding.
I'm not super happy with the fact that encodeable-literal? is in
support.scm (it really is an implementation detail of the
c-backend/runtime.c), but I didn't really know where else to put it,
because the constant folding itself is in support.scm. I could move
both to optimizer.scm because that's where constant folding happens,
but we'd have the same problem there.
PS: If constant folding of an expression with huge objects happens,
the compiler can take a very long time to generate the C comment at
the bottom that says "folded constant expression". This means, that
if we compile a program like this:
(print (string-length (number->string (- (expt 2 44207281) 1) 16)))
it will generate a comment like "folded constant expression (- X 1)",
where X is the bignum resulting from (expt 2 44207281). Because it
encodes the string as decimal, this takes a very long time. I'm not
sure how to easily fix this without removing the debugging message
entirely, which is not something we'd want.
Cheers,
Peter
0001-Don-t-silently-truncate-huge-literals.chicken-5.patch
Description: Text Data
0001-Don-t-silently-truncate-huge-literals.master.patch
Description: Text Data
signature.asc
Description: Digital signature
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Chicken-hackers] [PATCH] Don't silently truncate huge literals, and don't constant-fold if it would result in such a literal,
Peter Bex <=