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
Properly translate local definitions from the MIR to the
CgNode
IR.While the previous implementation didn't produce the wrong results (so
far), it was based on incorrect assumptions.
Details
tbBody
and use it for translating the body of control-flowconstructs (
mnkIf
,mnkBlock
, etc.)inArgBlock
counter with theinUnscoped
flagtbStmt
overload that's now only used in a single placecnkDef
nodes in thedefs
list, store theinformation required to produce the nodes; this is more efficient, as
it means less work during clean-up (the contents of the
defs
seqdon't require destruction)
Translation of
def
sA
def
for a local/global in the MIR means "locations starts to existand is accessible from all connected basic blocks within the same scope
(
mnkScope
) to which the only control-flow path also visits the def".The
CgNode
IR doesn't have an explicit notion of "scope" as the MIRdoes, and placing a
cnkDef
in some control-flow- related construct(e.g.,
cnkIf
) can produce the wrong code when the construct doesn'topen a new scope itself (i.e., its body is not wrapped in an
mnkScope
).Previously, translating a
mnkDef
to an assignment, with thecnkDef
placed at the start of the enclosing scope (this is also referred to as
lifting the def), was performed for all defs within an argument block.
However, argument blocks are wholly unrelated to the problem described
above, and the associated comment was also wrong: a
cnkStmtList
doesn't open a scope.
Due to a lot of code being located in some argument block, this
incorrect implementation still produced the correct results so far, but
changes to how MIR code is generated or how some of the MIR passes
operate could break this at any time.
The correct thing to look for is whether a definition is inside a
control-flow constructs (
if
,block
, etc.). If it is, and there's nomnkScope
in-between, the definition needs to be lifted into theclosest surrounding scope.
An alternative approach would be introducing a
cnkScope
node for theCgNode
IR and then leaving the work to the code generators. Thereason
for not going that route is that keeping the lifting logic in
cgirgen
for now makes it easier to change later on.
Future work
construct need to be lifted; an analysis pass could detect whether
this is the case
the destructor injection pass can be removed