-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
semfold: fix conversion folding (#823)
## 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 that to-`char` conversions are now properly subjected to range checks during constant 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 sure that 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`).
- Loading branch information
Showing
3 changed files
with
27 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters