-
Notifications
You must be signed in to change notification settings - Fork 39
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
semfold: fix conversion folding #823
semfold: fix conversion folding #823
Conversation
The logic for to-integer and to-float conversions now uses exhaustive case statements, which fixes both an internal issue with unexpected literal-node types and conversions-to-char not having range checks.
Perform the range check in a single place. In addition, don't transition unsigned-valued nodes to `nkUIntLit` -- there's no reason to.
One of the issues encountered in the tests is now fixed. The test case for `1.23456789012345'f32` was already working previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try a regular build that tomorrow, IIRC these were one of the issues. 👍🏽
I've reverted the unrelated change to the test such that there are no merge conflicts with #824. |
/merge |
Merge requested by: @saem Contents after the first section break of the PR description has been removed and preserved below:
|
Summary
Make the logic handling folding of integer- and float-like conversion
more exhaustive and slightly simplify it. This fixes the internal issue
of literal-nodes having unexpected types, and it also fixes no range
error being reported at compile-time for some to-
char
conversion.Details
Folding conversions to integer, float, and bool types now considers all
valid source types, with unexpected types now being treated as a defect
instead of silently ignoring them. Named set constants are used for
this, with
tyChar
being included in the integer-like set, meaning thatto-
char
conversions are now properly subjected to range checks duringconstant folding.
For the integer-like branch handling, the logic is simplified to only
perform the range check in a single place, and the unnecessary
transition-to-
nkUIntLit
removed (newIntNodeType
already makes surethat the node has the correct kind based on the type).
In general, this is a step towards the type of a literal-node matching
its kind. Both the C and VM code generator use the node kind for
deciding whether a float literal is a 32-bit or 64-bit one, so the
float-literal-nodes produced by constant folding now having the correct
kind fixes a bug where the emitted float literals had the wrong target-
language type (see the fixed test
tfloats.nim
).