diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index 36f3c3ac1f8..8bafae1e6a1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -276,7 +276,7 @@ public class JetFlowInformationProvider { if (!isJumpElement) continue; } - if (PseudocodeUtil.isDeadInAllCopies(instruction)) { + if (instruction.getDead()) { unreachableElements.add(element); } else { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java index 9613b7a0f40..7452157936e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java @@ -370,7 +370,7 @@ public class PseudocodeImpl implements Pseudocode { Set instructionSet = Sets.newHashSet(instructions); for (Instruction instruction : mutableInstructionList) { if (!instructionSet.contains(instruction)) { - ((InstructionImpl)instruction).die(); + ((InstructionImpl)instruction).setMarkedAsDead(true); for (Instruction nextInstruction : instruction.getNextInstructions()) { nextInstruction.getPreviousInstructions().remove(instruction); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeUtil.java index b6e5bdc5db8..8ad89af03b5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeUtil.java @@ -85,12 +85,4 @@ public class PseudocodeUtil { } return BindingContextUtils.extractVariableDescriptorIfAny(bindingContext, element, onlyReference); } - - public static boolean isDeadInAllCopies(@NotNull Instruction instruction) { - boolean allCopiesAreDead = instruction.getDead(); - for (Instruction copy : instruction.getCopies()) { - allCopiesAreDead = allCopiesAreDead && copy.getDead(); - } - return allCopiesAreDead; - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionImpl.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionImpl.kt index a57b75dd7c2..6cf1c37d22e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionImpl.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionImpl.kt @@ -27,7 +27,6 @@ public abstract class InstructionImpl(public override val lexicalScope: LexicalS private var _owner: Pseudocode? = null private val _copies = HashSet() private var original: Instruction? = null - protected var _dead: Boolean = false private fun setOriginalInstruction(value: Instruction?) { assert(original == null) { "Instruction can't have two originals: this.original = ${original}; new original = $this" } @@ -49,11 +48,9 @@ public abstract class InstructionImpl(public override val lexicalScope: LexicalS protected abstract fun createCopy(): InstructionImpl - public fun die() { - _dead = true - } + public var markedAsDead: Boolean = false - override val dead: Boolean get() = _dead + override val dead: Boolean get() = markedAsDead && getCopies().all { (it as InstructionImpl).markedAsDead } public fun copy(): Instruction { return updateCopyInfo(createCopy()) diff --git a/compiler/tests/org/jetbrains/jet/cfg/AbstractControlFlowTest.java b/compiler/tests/org/jetbrains/jet/cfg/AbstractControlFlowTest.java index cea52dc1fa4..569662b8224 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/AbstractControlFlowTest.java +++ b/compiler/tests/org/jetbrains/jet/cfg/AbstractControlFlowTest.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.cfg.pseudocode.PseudocodeImpl; import org.jetbrains.jet.lang.cfg.pseudocode.instructions.Instruction; +import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionImpl; import org.jetbrains.jet.lang.resolve.BindingContext; import java.util.*; @@ -108,7 +109,7 @@ public abstract class AbstractControlFlowTest extends AbstractPseudocodeTest { //check edges directions Collection instructions = pseudocode.getInstructionsIncludingDeadCode(); for (Instruction instruction : instructions) { - if (!instruction.getDead()) { + if (!((InstructionImpl)instruction).getMarkedAsDead()) { for (Instruction nextInstruction : instruction.getNextInstructions()) { assertTrue("instruction '" + instruction + "' has '" + nextInstruction + "' among next instructions list, but not vice versa", nextInstruction.getPreviousInstructions().contains(instruction)); diff --git a/compiler/tests/org/jetbrains/jet/cfg/AbstractPseudocodeTest.java b/compiler/tests/org/jetbrains/jet/cfg/AbstractPseudocodeTest.java index 1dc9d51d6d1..734e4c4d512 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/AbstractPseudocodeTest.java +++ b/compiler/tests/org/jetbrains/jet/cfg/AbstractPseudocodeTest.java @@ -140,7 +140,7 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironment { @NotNull Set remainedAfterPostProcessInstructions ) { boolean isRemovedThroughPostProcess = !remainedAfterPostProcessInstructions.contains(instruction); - assert isRemovedThroughPostProcess == ((InstructionImpl)instruction).getDead(); + assert isRemovedThroughPostProcess == ((InstructionImpl)instruction).getMarkedAsDead(); return isRemovedThroughPostProcess ? "-" : " "; }