codegen: remove the cnkChckRange
node kinds
#842
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Replace the
cnkChckRange
node kinds with a magic call that is alreadyinserted during MIR synthesis (
mirgen
) and remove all decision makingregarding range-checks from the code generators.
This is a step towards moving decision making regarding run-time checks
fully into late semantic analysis. In addition, this fixes destructors
not being run for scopes where the only escaping unstructured control-
flow is due to range checks.
Details
A new internal magic is added for representing conversions-with-range-
checks during the MIR and code generation phase:
mChckRange
.mirgen
translates
nkChckRange
,nkChckRange64
, andnkChckRangeF
to thenew magic, but only if its not a to-unsigned conversion and range checks
are enabled for the current owner.
For now, these guards mirror those previously used in the code
generators, but the direction is to move to a correct-by-construction
approach and only inject
nkChckRange
nodes where range checks shouldbe performed.
The
mChckRange
magic is included in themagicsThatCanRaise
set, andthe duplicate set of the same name is removed from
mirexec
. As aconsequence, the exceptional control-flow arising from failed range
checks is now picked up on by MIR-based data- and control-flow analysis.
However, since the set is constant, this also means that range-check
calls will be treated as raising even when panics are enabled. This is a
known problem with magics that needs to be solved at one point.
Multiple things are now obsolete and thus removed:
cnkChckRange
node kindscgirgen
logic for producingcnkChckRange
nodes (which wasoriginally duplicated from the logic in
transf.transformConv
)cnkChckRange
. Parts of it arere-used for implementing
mChckRange
supportTwo additional problems are fixed as a side-effect of the changes:
rangeChecks
option inthe same way as the other code generator
rangeChecks
option orbecause the target type is unsigned) are not treated as no-op
by the JS code generator, but instead use unchecked conversions
(the
tdollars.nim
test is adjusted accordingly), in line withthe other code generators