From 92a3fef06bfe66cd1c29359ef2af0244ce9f0898 Mon Sep 17 00:00:00 2001 From: svtk Date: Thu, 3 Nov 2011 18:29:34 +0400 Subject: [PATCH] Added 'sink' instruction to pseudocode --- .../jet/lang/cfg/pseudocode/Instruction.java | 2 + .../cfg/pseudocode/InstructionVisitor.java | 8 +- .../JetControlFlowInstructionsGenerator.java | 4 + .../LocalDeclarationInstruction.java | 23 +++++- .../jet/lang/cfg/pseudocode/Pseudocode.java | 28 ++++++- .../pseudocode/SubroutineExitInstruction.java | 8 ++ .../pseudocode/SubroutineSinkInstruction.java | 40 +++++++++ .../cfg/AnonymousInitializers.instructions | 30 ++++--- .../testData/cfg/ArrayAccess.instructions | 4 +- .../testData/cfg/Assignments.instructions | 12 ++- compiler/testData/cfg/Basic.instructions | 38 ++++++--- .../testData/cfg/EmptyFunction.instructions | 4 +- .../testData/cfg/FailFunction.instructions | 4 +- compiler/testData/cfg/Finally.instructions | 82 +++++++++++++------ compiler/testData/cfg/For.instructions | 8 +- compiler/testData/cfg/If.instructions | 12 ++- .../testData/cfg/LazyBooleans.instructions | 4 +- .../cfg/OnlyWhileInFunctionBody.instructions | 8 +- .../cfg/ReturnFromExpression.instructions | 4 +- .../testData/cfg/ShortFunction.instructions | 10 ++- .../jetbrains/jet/cfg/JetControlFlowTest.java | 6 +- 21 files changed, 255 insertions(+), 84 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineSinkInstruction.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Instruction.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Instruction.java index 4a2cf3832e6..63f759c81d1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Instruction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Instruction.java @@ -20,4 +20,6 @@ public interface Instruction { Collection getNextInstructions(); void accept(InstructionVisitor visitor); + + boolean isDead(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionVisitor.java index 29c047bf731..bbe46cf75af 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionVisitor.java @@ -8,8 +8,8 @@ public class InstructionVisitor { visitInstructionWithNext(instruction); } - public void visitFunctionLiteralValue(LocalDeclarationInstruction instruction) { - visitReadValue(instruction); + public void visitLocalDeclarationInstruction(LocalDeclarationInstruction instruction) { + visitInstructionWithNext(instruction); } public void visitUnconditionalJump(UnconditionalJumpInstruction instruction) { @@ -40,6 +40,10 @@ public class InstructionVisitor { visitInstruction(instruction); } + public void visitSubroutineSink(SubroutineSinkInstruction instruction) { + visitInstruction(instruction); + } + public void visitJump(AbstractJumpInstruction instruction) { visitInstruction(instruction); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java index f6edfb38f22..ad12a39d3cd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java @@ -70,11 +70,13 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd private final Pseudocode pseudocode; private final Label error; + private final Label sink; private final JetElement currentSubroutine; private JetControlFlowInstructionsGeneratorWorker(@NotNull JetElement scopingElement, @NotNull JetElement currentSubroutine) { this.pseudocode = new Pseudocode(scopingElement); this.error = pseudocode.createLabel("error"); + this.sink = pseudocode.createLabel("sink"); this.currentSubroutine = currentSubroutine; } @@ -183,6 +185,8 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd pseudocode.addExitInstruction(new SubroutineExitInstruction(subroutine, "")); bindLabel(error); add(new SubroutineExitInstruction(subroutine, "")); + bindLabel(sink); + pseudocode.addSinkInstruction(new SubroutineSinkInstruction(subroutine, "")); elementToBlockInfo.remove(subroutine); allBlocks.pop(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java index c7753272360..52cb0c2ca5c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/LocalDeclarationInstruction.java @@ -1,17 +1,22 @@ package org.jetbrains.jet.lang.cfg.pseudocode; +import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetClass; import org.jetbrains.jet.lang.psi.JetDeclaration; import org.jetbrains.jet.lang.psi.JetFunction; import org.jetbrains.jet.lang.psi.JetObjectDeclaration; +import java.util.ArrayList; +import java.util.Collection; + /** * @author abreslav */ -public class LocalDeclarationInstruction extends ReadValueInstruction { +public class LocalDeclarationInstruction extends InstructionWithNext { - private Pseudocode body; + private final Pseudocode body; + private Instruction sink; public LocalDeclarationInstruction(@NotNull JetDeclaration element, Pseudocode body) { super(element); @@ -22,9 +27,21 @@ public class LocalDeclarationInstruction extends ReadValueInstruction { return body; } + @NotNull + @Override + public Collection getNextInstructions() { + ArrayList instructions = Lists.newArrayList(sink); + instructions.addAll(super.getNextInstructions()); + return instructions; + } + + public void setSink(SubroutineSinkInstruction sink) { + this.sink = outgoingEdgeTo(sink); + } + @Override public void accept(InstructionVisitor visitor) { - visitor.visitFunctionLiteralValue(this); + visitor.visitLocalDeclarationInstruction(this); } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java index 630199c91e8..9854a5a00e0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/Pseudocode.java @@ -59,6 +59,7 @@ public class Pseudocode { private final JetElement correspondingElement; private SubroutineExitInstruction exitInstruction; + private SubroutineSinkInstruction sinkInstruction; private boolean postPrecessed = false; public Pseudocode(JetElement correspondingElement) { @@ -84,7 +85,7 @@ public class Pseudocode { public List getDeadInstructions() { List deadInstructions = Lists.newArrayList(); for (Instruction instruction : instructions) { - if (((InstructionImpl)instruction).isDead()) { + if (instruction.isDead()) { deadInstructions.add(instruction); } } @@ -101,6 +102,12 @@ public class Pseudocode { assert this.exitInstruction == null; this.exitInstruction = exitInstruction; } + + public void addSinkInstruction(SubroutineSinkInstruction sinkInstruction) { + addInstruction(sinkInstruction); + assert this.sinkInstruction == null; + this.sinkInstruction = sinkInstruction; + } public void addInstruction(Instruction instruction) { instructions.add(instruction); @@ -112,6 +119,12 @@ public class Pseudocode { return exitInstruction; } + @NotNull + public SubroutineSinkInstruction getSinkInstruction() { + return sinkInstruction; + } + + @NotNull public SubroutineEnterInstruction getEnterInstruction() { return (SubroutineEnterInstruction) instructions.get(0); @@ -163,9 +176,10 @@ public class Pseudocode { } @Override - public void visitFunctionLiteralValue(LocalDeclarationInstruction instruction) { + public void visitLocalDeclarationInstruction(LocalDeclarationInstruction instruction) { instruction.getBody().postProcess(); - super.visitFunctionLiteralValue(instruction); + instruction.setSink(getSinkInstruction()); + super.visitLocalDeclarationInstruction(instruction); } @Override @@ -173,12 +187,18 @@ public class Pseudocode { // Nothing } + @Override + public void visitSubroutineSink(SubroutineSinkInstruction instruction) { + // Nothing + } + @Override public void visitInstruction(Instruction instruction) { throw new UnsupportedOperationException(instruction.toString()); } }); } + getExitInstruction().setSink(getSinkInstruction()); removeDeadInstructions(); } @@ -188,7 +208,7 @@ public class Pseudocode { while (hasRemovedInstruction) { hasRemovedInstruction = false; for (Instruction instruction : instructions) { - if (!(instruction instanceof SubroutineEnterInstruction || instruction instanceof SubroutineExitInstruction) && + if (!(instruction instanceof SubroutineEnterInstruction || instruction instanceof SubroutineExitInstruction || instruction instanceof SubroutineSinkInstruction) && instruction.getPreviousInstructions().isEmpty() && !processedInstructions.contains(instruction)) { hasRemovedInstruction = true; for (Instruction nextInstruction : instruction.getNextInstructions()) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineExitInstruction.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineExitInstruction.java index 0a6e5621aa0..5c1c61997ea 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineExitInstruction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineExitInstruction.java @@ -12,6 +12,7 @@ import java.util.Collections; public class SubroutineExitInstruction extends InstructionImpl { private final JetElement subroutine; private final String debugLabel; + private SubroutineSinkInstruction sinkInstruction; public SubroutineExitInstruction(@NotNull JetElement subroutine, @NotNull String debugLabel) { this.subroutine = subroutine; @@ -22,9 +23,16 @@ public class SubroutineExitInstruction extends InstructionImpl { return subroutine; } + public void setSink(SubroutineSinkInstruction instruction) { + sinkInstruction = (SubroutineSinkInstruction) outgoingEdgeTo(instruction); + } + @NotNull @Override public Collection getNextInstructions() { + if (sinkInstruction != null) { + return Collections.singleton(sinkInstruction); + } return Collections.emptyList(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineSinkInstruction.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineSinkInstruction.java new file mode 100644 index 00000000000..10d420f5549 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/SubroutineSinkInstruction.java @@ -0,0 +1,40 @@ +package org.jetbrains.jet.lang.cfg.pseudocode; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetElement; + +import java.util.Collection; +import java.util.Collections; + +/** + * @author svtk + */ +public class SubroutineSinkInstruction extends InstructionImpl { + private final JetElement subroutine; + private final String debugLabel; + + public SubroutineSinkInstruction(@NotNull JetElement subroutine, @NotNull String debugLabel) { + this.subroutine = subroutine; + this.debugLabel = debugLabel; + } + + public JetElement getSubroutine() { + return subroutine; + } + + @NotNull + @Override + public Collection getNextInstructions() { + return Collections.emptyList(); + } + + @Override + public void accept(InstructionVisitor visitor) { + visitor.visitSubroutineSink(this); + } + + @Override + public String toString() { + return debugLabel; + } +} diff --git a/compiler/testData/cfg/AnonymousInitializers.instructions b/compiler/testData/cfg/AnonymousInitializers.instructions index 218e35049b6..9b932ef3926 100644 --- a/compiler/testData/cfg/AnonymousInitializers.instructions +++ b/compiler/testData/cfg/AnonymousInitializers.instructions @@ -16,26 +16,30 @@ class AnonymousInitializers() { } --------------------- l0: - NEXT:[r(34)] PREV:[] - r(34) NEXT:[w(k)] PREV:[] - w(k) NEXT:[r(12)] PREV:[r(34)] - r(12) NEXT:[w($i)] PREV:[w(k)] - w($i) NEXT:[r(13)] PREV:[r(12)] - r(13) NEXT:[w($i)] PREV:[w($i)] - w($i) NEXT:[] PREV:[r(13)] + NEXT:[r(34)] PREV:[] + r(34) NEXT:[w(k)] PREV:[] + w(k) NEXT:[r(12)] PREV:[r(34)] + r(12) NEXT:[w($i)] PREV:[w(k)] + w($i) NEXT:[r(13)] PREV:[r(12)] + r(13) NEXT:[w($i)] PREV:[w($i)] + w($i) NEXT:[] PREV:[r(13)] l1: - NEXT:[] PREV:[w($i)] + NEXT:[] PREV:[w($i)] error: - NEXT:[] PREV:[] + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == k == val k = 34 --------------------- l0: - NEXT:[r(34)] PREV:[] - r(34) NEXT:[] PREV:[] + NEXT:[r(34)] PREV:[] + r(34) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[r(34)] + NEXT:[] PREV:[r(34)] error: - NEXT:[] PREV:[] + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/ArrayAccess.instructions b/compiler/testData/cfg/ArrayAccess.instructions index 877a122fb43..d6fbbcd6b6d 100644 --- a/compiler/testData/cfg/ArrayAccess.instructions +++ b/compiler/testData/cfg/ArrayAccess.instructions @@ -32,7 +32,9 @@ l0: r(+=) NEXT:[w(a[10])] PREV:[r(1)] w(a[10]) NEXT:[] PREV:[r(+=)] l1: - NEXT:[] PREV:[w(a[10])] + NEXT:[] PREV:[w(a[10])] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/Assignments.instructions b/compiler/testData/cfg/Assignments.instructions index a0adbac1a3c..974d10e915b 100644 --- a/compiler/testData/cfg/Assignments.instructions +++ b/compiler/testData/cfg/Assignments.instructions @@ -4,11 +4,13 @@ class Test { } --------------------- l0: - NEXT:[] PREV:[] + NEXT:[] PREV:[] l1: - NEXT:[] PREV:[] + NEXT:[] PREV:[] error: - NEXT:[] PREV:[] + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == assignments == fun assignments() : Unit { @@ -63,7 +65,9 @@ l5: r(=) NEXT:[w(t.x)] PREV:[r(t)] w(t.x) NEXT:[] PREV:[r(=)] l1: - NEXT:[] PREV:[w(t.x)] + NEXT:[] PREV:[w(t.x)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/Basic.instructions b/compiler/testData/cfg/Basic.instructions index e03b4382450..385770a89e5 100644 --- a/compiler/testData/cfg/Basic.instructions +++ b/compiler/testData/cfg/Basic.instructions @@ -2,12 +2,14 @@ {1} --------------------- l2: - NEXT:[r(1)] PREV:[] - r(1) NEXT:[] PREV:[] + NEXT:[r(1)] PREV:[] + r(1) NEXT:[] PREV:[] l3: - NEXT:[] PREV:[r(1)] + NEXT:[] PREV:[r(1)] error: - NEXT:[] PREV:[] + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == f == fun f(a : Boolean) : Unit { @@ -41,7 +43,7 @@ l0: r(foo(a, 3)) NEXT:[r(genfun)] PREV:[r(foo)] r(genfun) NEXT:[r(genfun())] PREV:[r(foo(a, 3))] r(genfun()) NEXT:[df({1})] PREV:[r(genfun)] - df({1}) NEXT:[r({1})] PREV:[r(genfun())] + df({1}) NEXT:[, r({1})] PREV:[r(genfun())] r({1}) NEXT:[r(flfun)] PREV:[df({1})] r(flfun) NEXT:[r(flfun {1})] PREV:[r({1})] r(flfun {1}) NEXT:[r(3)] PREV:[r(flfun)] @@ -69,16 +71,20 @@ l4: l5: r(a || false) NEXT:[] PREV:[jt(l5), r(false)] l1: - NEXT:[] PREV:[r(a || false)] + NEXT:[] PREV:[r(a || false)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[df({1}), ] l2: - NEXT:[r(1)] PREV:[] - r(1) NEXT:[] PREV:[] + NEXT:[r(1)] PREV:[] + r(1) NEXT:[] PREV:[] l3: - NEXT:[] PREV:[r(1)] + NEXT:[] PREV:[r(1)] error: - NEXT:[] PREV:[] + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == foo == fun foo(a : Boolean, b : Int) : Unit {} @@ -87,9 +93,11 @@ l0: NEXT:[read (Unit)] PREV:[] read (Unit) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == genfun == fun genfun() : Unit {} @@ -98,9 +106,11 @@ l0: NEXT:[read (Unit)] PREV:[] read (Unit) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == flfun == fun flfun(f : fun () : Any) : Unit {} @@ -109,7 +119,9 @@ l0: NEXT:[read (Unit)] PREV:[] read (Unit) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/EmptyFunction.instructions b/compiler/testData/cfg/EmptyFunction.instructions index 36b5c7f0fc2..b7afe8758e2 100644 --- a/compiler/testData/cfg/EmptyFunction.instructions +++ b/compiler/testData/cfg/EmptyFunction.instructions @@ -5,7 +5,9 @@ l0: NEXT:[read (Unit)] PREV:[] read (Unit) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/FailFunction.instructions b/compiler/testData/cfg/FailFunction.instructions index be079a574d4..be84d56dee9 100644 --- a/compiler/testData/cfg/FailFunction.instructions +++ b/compiler/testData/cfg/FailFunction.instructions @@ -13,7 +13,9 @@ l0: r(java.lang.RuntimeException()) NEXT:[jmp(error)] PREV:[r(RuntimeException())] jmp(error) NEXT:[] PREV:[r(java.lang.RuntimeException())] l1: - NEXT:[] PREV:[] + NEXT:[] PREV:[] error: NEXT:[] PREV:[jmp(error)] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/Finally.instructions b/compiler/testData/cfg/Finally.instructions index 32e5c6c9b3a..a908fe99130 100644 --- a/compiler/testData/cfg/Finally.instructions +++ b/compiler/testData/cfg/Finally.instructions @@ -14,9 +14,11 @@ l0: l2: r(2) NEXT:[] PREV:[jmp?(l2), r(1)] l1: - NEXT:[] PREV:[r(2)] + NEXT:[] PREV:[r(2)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3() { @@ -48,9 +50,11 @@ l2: l4: r(2) NEXT:[] PREV:[jmp?(l2), read (Unit)] l1: - NEXT:[] PREV:[ret l1, r(2)] + NEXT:[] PREV:[ret l1, r(2)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == anonymous_0 == { () => @@ -72,9 +76,11 @@ l5: read (Unit) NEXT:[] PREV:[jf(l5)] l4: l6: - NEXT:[] PREV:[ret l4, read (Unit)] + NEXT:[] PREV:[ret l4, read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3() { @@ -91,25 +97,27 @@ fun t3() { } --------------------- l0: - NEXT:[jmp?(l2)] PREV:[] - jmp?(l2) NEXT:[r(2), r(1)] PREV:[] - r(1) NEXT:[df({ () => if (2 > 3) { retu..)] PREV:[jmp?(l2)] + NEXT:[jmp?(l2)] PREV:[] + jmp?(l2) NEXT:[r(2), r(1)] PREV:[] + r(1) NEXT:[df({ () => if (2 > 3) { retu..)] PREV:[jmp?(l2)] df({ () => if (2 > 3) { return@ } - }) NEXT:[r({ () => if (2 > 3) { retur..)] PREV:[r(1)] + }) NEXT:[, r({ () => if (2 > 3) { retur..)] PREV:[r(1)] r({ () => if (2 > 3) { return@ } - }) NEXT:[r(2)] PREV:[df({ () => if (2 > 3) { retu..)] + }) NEXT:[r(2)] PREV:[df({ () => if (2 > 3) { retu..)] l2: - r(2) NEXT:[] PREV:[jmp?(l2), r({ () => if (2 > 3) { retur..)] + r(2) NEXT:[] PREV:[jmp?(l2), r({ () => if (2 > 3) { retur..)] l1: - NEXT:[] PREV:[r(2)] + NEXT:[] PREV:[r(2)] error: - NEXT:[] PREV:[] + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[df({ () => if (2 > 3) { retu..), ] l3: NEXT:[r(2)] PREV:[] r(2) NEXT:[r(3)] PREV:[] @@ -123,9 +131,11 @@ l5: read (Unit) NEXT:[] PREV:[jf(l5)] l4: l6: - NEXT:[] PREV:[ret l4, read (Unit)] + NEXT:[] PREV:[ret l4, read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == anonymous_1 == { () => @@ -157,9 +167,11 @@ l4: l6: r(2) NEXT:[] PREV:[jmp?(l4), read (Unit)] l3: - NEXT:[] PREV:[ret l3, r(2)] + NEXT:[] PREV:[ret l3, r(2)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3() { @@ -176,7 +188,7 @@ fun t3() { } --------------------- l0: - NEXT:[df({ () => try { 1 if (2 > 3..)] PREV:[] + NEXT:[df({ () => try { 1 if (2 > 3..)] PREV:[] df({ () => try { 1 @@ -186,7 +198,7 @@ l0: } finally { 2 } - }) NEXT:[r({ () => try { 1 if (2 > 3)..)] PREV:[] + }) NEXT:[, r({ () => try { 1 if (2 > 3)..)] PREV:[] r({ () => try { 1 @@ -196,11 +208,13 @@ l0: } finally { 2 } - }) NEXT:[] PREV:[df({ () => try { 1 if (2 > 3..)] + }) NEXT:[] PREV:[df({ () => try { 1 if (2 > 3..)] l1: - NEXT:[] PREV:[r({ () => try { 1 if (2 > 3)..)] + NEXT:[] PREV:[r({ () => try { 1 if (2 > 3)..)] error: - NEXT:[] PREV:[] + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[df({ () => try { 1 if (2 > 3..), ] l2: NEXT:[jmp?(l4)] PREV:[] jmp?(l4) NEXT:[r(2), r(1)] PREV:[] @@ -219,9 +233,11 @@ l4: l6: r(2) NEXT:[] PREV:[jmp?(l4), read (Unit)] l3: - NEXT:[] PREV:[ret l3, r(2)] + NEXT:[] PREV:[ret l3, r(2)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3() { @@ -263,9 +279,11 @@ l8: l3: read (Unit) NEXT:[] PREV:[jf(l3), jmp(l3)] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3() { @@ -308,9 +326,11 @@ l4: l2: r(2) NEXT:[] PREV:[jmp?(l2), r(5)] l1: - NEXT:[] PREV:[r(2)] + NEXT:[] PREV:[r(2)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3() { @@ -351,9 +371,11 @@ l4: l2: r(2) NEXT:[] PREV:[jmp?(l2), read (Unit)] l1: - NEXT:[] PREV:[r(2)] + NEXT:[] PREV:[r(2)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3(a : Int) { @@ -399,9 +421,11 @@ l8: l2: read (Unit) NEXT:[] PREV:[jmp?(l2), jmp?(l4)] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3(a : Int) { @@ -448,9 +472,11 @@ l3: l2: r(2) NEXT:[] PREV:[jmp?(l2), r(5)] l1: - NEXT:[] PREV:[r(2)] + NEXT:[] PREV:[r(2)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t3 == fun t3(a : Int) { @@ -495,9 +521,11 @@ l3: l2: r(2) NEXT:[] PREV:[jmp?(l2), read (Unit)] l1: - NEXT:[] PREV:[r(2)] + NEXT:[] PREV:[r(2)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == tf == fun tf() { @@ -520,7 +548,9 @@ l2: r(2) NEXT:[ret(*) l1] PREV:[jmp?(l2)] ret(*) l1 NEXT:[] PREV:[r(2)] l1: - NEXT:[] PREV:[ret(*) l1, ret(*) l1] + NEXT:[] PREV:[ret(*) l1, ret(*) l1] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/For.instructions b/compiler/testData/cfg/For.instructions index 4e19aac83c9..8343194883d 100644 --- a/compiler/testData/cfg/For.instructions +++ b/compiler/testData/cfg/For.instructions @@ -23,9 +23,11 @@ l5: l2: read (Unit) NEXT:[] PREV:[jmp?(l2), jmp?(l4)] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == doSmth == fun doSmth(i: Int) {} @@ -34,7 +36,9 @@ l0: NEXT:[read (Unit)] PREV:[] read (Unit) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/If.instructions b/compiler/testData/cfg/If.instructions index d075477d559..e1d4dc25f3d 100644 --- a/compiler/testData/cfg/If.instructions +++ b/compiler/testData/cfg/If.instructions @@ -42,9 +42,11 @@ l5: r(doSmth) NEXT:[r(doSmth(r))] PREV:[r(r)] r(doSmth(r)) NEXT:[] PREV:[r(doSmth)] l1: - NEXT:[] PREV:[r(doSmth(r))] + NEXT:[] PREV:[r(doSmth(r))] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == t2 == fun t2(b: Boolean) { @@ -81,9 +83,11 @@ l4: read (Unit) NEXT:[] PREV:[jf(l4)] l1: l5: - NEXT:[] PREV:[ret l1, ret l1, read (Unit)] + NEXT:[] PREV:[ret l1, ret l1, read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == doSmth == fun doSmth(s: String) {} @@ -92,7 +96,9 @@ l0: NEXT:[read (Unit)] PREV:[] read (Unit) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/LazyBooleans.instructions b/compiler/testData/cfg/LazyBooleans.instructions index 8c477e17313..080a7519745 100644 --- a/compiler/testData/cfg/LazyBooleans.instructions +++ b/compiler/testData/cfg/LazyBooleans.instructions @@ -66,7 +66,9 @@ l12: l13: r(14) NEXT:[] PREV:[jmp(l13), r(13)] l1: - NEXT:[] PREV:[r(14)] + NEXT:[] PREV:[r(14)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/OnlyWhileInFunctionBody.instructions b/compiler/testData/cfg/OnlyWhileInFunctionBody.instructions index bdad7a8566b..b1d99d5eca1 100644 --- a/compiler/testData/cfg/OnlyWhileInFunctionBody.instructions +++ b/compiler/testData/cfg/OnlyWhileInFunctionBody.instructions @@ -20,9 +20,11 @@ l4: l3: read (Unit) NEXT:[] PREV:[jf(l3)] l1: - NEXT:[] PREV:[read (Unit)] + NEXT:[] PREV:[read (Unit)] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== == dowhile == fun dowhile() { @@ -44,7 +46,9 @@ l5: l3: * read (Unit) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[ret l1] + NEXT:[] PREV:[ret l1] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/ReturnFromExpression.instructions b/compiler/testData/cfg/ReturnFromExpression.instructions index c097530ba85..0fb6dc06df5 100644 --- a/compiler/testData/cfg/ReturnFromExpression.instructions +++ b/compiler/testData/cfg/ReturnFromExpression.instructions @@ -12,7 +12,9 @@ l0: l2: r(false || (return false)) NEXT:[] PREV:[jt(l2)] l1: - NEXT:[] PREV:[ret(*) l1, r(false || (return false))] + NEXT:[] PREV:[ret(*) l1, r(false || (return false))] error: NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/testData/cfg/ShortFunction.instructions b/compiler/testData/cfg/ShortFunction.instructions index e0e2b89781b..fa0b7bbd2fe 100644 --- a/compiler/testData/cfg/ShortFunction.instructions +++ b/compiler/testData/cfg/ShortFunction.instructions @@ -2,10 +2,12 @@ fun short() = 1 --------------------- l0: - NEXT:[r(1)] PREV:[] - r(1) NEXT:[] PREV:[] + NEXT:[r(1)] PREV:[] + r(1) NEXT:[] PREV:[] l1: - NEXT:[] PREV:[r(1)] + NEXT:[] PREV:[r(1)] error: - NEXT:[] PREV:[] + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[] ===================== diff --git a/compiler/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java b/compiler/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java index 9f67398d6ba..8063e47d0f9 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java +++ b/compiler/tests/org/jetbrains/jet/cfg/JetControlFlowTest.java @@ -123,7 +123,7 @@ public class JetControlFlowTest extends JetLiteFixture { //check edges directions Collection instructions = pseudocode.getInstructions(); for (Instruction instruction : instructions) { - if (!((InstructionImpl) instruction).isDead()) { + if (!instruction.isDead()) { for (Instruction nextInstruction : instruction.getNextInstructions()) { assertTrue("instruction '" + instruction + "' has '" + nextInstruction + "' among next instructions list, but not vice versa", nextInstruction.getPreviousInstructions().contains(instruction)); @@ -170,7 +170,7 @@ public class JetControlFlowTest extends JetLiteFixture { private static String formatInstruction(Instruction instruction, int maxLength) { String[] parts = instruction.toString().split("\n"); - String prefix = ((InstructionImpl)instruction).isDead() ? "* " : " "; + String prefix = instruction.isDead() ? "* " : " "; if (parts.length == 1) { return prefix + String.format("%1$-" + maxLength + "s", instruction); } @@ -266,7 +266,7 @@ public class JetControlFlowTest extends JetLiteFixture { for (final Instruction fromInst : instructions) { fromInst.accept(new InstructionVisitor() { @Override - public void visitFunctionLiteralValue(LocalDeclarationInstruction instruction) { + public void visitLocalDeclarationInstruction(LocalDeclarationInstruction instruction) { int index = count[0]; // instruction.getBody().dumpSubgraph(out, "subgraph cluster_" + index, count, "color=blue;\nlabel = \"f" + index + "\";", nodeToName); printEdge(out, nodeToName.get(instruction), nodeToName.get(instruction.getBody().getInstructions().get(0)), null);