-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IncrementalCompact: Don't corrupt CFG when finishing early
Finishing an IncrementalComapact before iterating the whole underlying IRCode is not something that we really do in base, or at least not in places other than a basic block boundary. However, it can be useful for downstream consumers, so make it work anyway. Also create a separate test file for IncrementalCompact tests (of which we really should have more) and move one existing test.
- Loading branch information
Showing
4 changed files
with
44 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Core.Compiler: IncrementalCompact, insert_node_here!, finish, | ||
NewInstruction, verify_ir, ReturnNode, SSAValue | ||
|
||
foo_test_function(i) = i == 1 ? 1 : 2 | ||
|
||
@testset "IncrementalCompact statefulness" begin | ||
ir = only(Base.code_ircode(foo_test_function, (Int,)))[1] | ||
compact = IncrementalCompact(ir) | ||
|
||
# set up first iterator | ||
x = Core.Compiler.iterate(compact) | ||
x = Core.Compiler.iterate(compact, x[2]) | ||
|
||
# set up second iterator | ||
x = Core.Compiler.iterate(compact) | ||
|
||
# consume remainder | ||
while x !== nothing | ||
x = Core.Compiler.iterate(compact, x[2]) | ||
end | ||
|
||
ir = finish(compact) | ||
@test Core.Compiler.verify_ir(ir) === nothing | ||
end | ||
|
||
# Test early finish of IncrementalCompact | ||
@testset "IncrementalCompact early finish" begin | ||
ir = only(Base.code_ircode(foo_test_function, (Int,)))[1] | ||
compact = IncrementalCompact(ir) | ||
|
||
insert_node_here!(compact, NewInstruction(ReturnNode(1), Union{}, ir[SSAValue(1)][:line])) | ||
new_ir = finish(compact) | ||
# TODO: Should IncrementalCompact be doing this internally? | ||
empty!(new_ir.cfg.blocks[1].succs) | ||
verify_ir(new_ir) | ||
@test length(new_ir.cfg.blocks) == 1 | ||
end |
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