Skip to content

Commit

Permalink
Random-order variable sets are no more in use in CFG #KT-13990 Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mglukhikh committed Sep 22, 2016
1 parent 6609590 commit fc89385
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@
package org.jetbrains.kotlin.cfg

import com.google.common.collect.Maps
import com.google.common.collect.Sets
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeUtil
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.VariableDeclarationInstruction
import org.jetbrains.kotlin.cfg.pseudocodeTraverser.Edges
import org.jetbrains.kotlin.cfg.pseudocodeTraverser.TraversalOrder
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingContextUtils
import org.jetbrains.kotlin.resolve.BindingContextUtils.variableDescriptorForDeclaration
import org.jetbrains.kotlin.resolve.calls.tower.getFakeDescriptorForObject
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import java.util.Collections

class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingContext: BindingContext) {
Expand All @@ -56,7 +50,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon
if (!includeInsideLocalDeclarations) {
return getUpperLevelDeclaredVariables(pseudocode)
}
val declaredVariables = Sets.newHashSet<VariableDescriptor>()
val declaredVariables = linkedSetOf<VariableDescriptor>()
declaredVariables.addAll(getUpperLevelDeclaredVariables(pseudocode))

for (localFunctionDeclarationInstruction in pseudocode.localDeclarations) {
Expand All @@ -76,7 +70,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon
}

private fun computeDeclaredVariablesForPseudocode(pseudocode: Pseudocode): Set<VariableDescriptor> {
val declaredVariables = Sets.newHashSet<VariableDescriptor>()
val declaredVariables = linkedSetOf<VariableDescriptor>()
for (instruction in pseudocode.instructions) {
if (instruction is VariableDeclarationInstruction) {
val variableDeclarationElement = instruction.variableDeclarationElement
Expand Down Expand Up @@ -238,7 +232,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon
incomingEdgesData: Collection<InitControlFlowInfo>
): InitControlFlowInfo {
if (incomingEdgesData.size == 1) return incomingEdgesData.single()
val variablesInScope = Sets.newHashSet<VariableDescriptor>()
val variablesInScope = linkedSetOf<VariableDescriptor>()
for (edgeData in incomingEdgesData) {
variablesInScope.addAll(edgeData.keys)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER

interface Context
class Point

class Example {
constructor(context: Context?)
constructor(context: Context?, arg1: Int)
constructor(context: Context?, arg1: Int, arg2: Int)
constructor(context: Context?, arg1: Int, arg2: Int, arg3: Int)

var condition: Boolean = false
private var index = <!DEBUG_INFO_LEAKING_THIS!>newIndex<!>(condition)
private fun newIndex(zero: Boolean) = if (zero) 0 else 1

private lateinit var latePoint1: Point
private lateinit var latePoint2: Point

private val point1 = Point()
private val point2 = Point()
private val point3 = Point()
private val point4 = Point()
private var nullPoint: Point? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package

public interface Context {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

public final class Example {
public constructor Example(/*0*/ context: Context?)
public constructor Example(/*0*/ context: Context?, /*1*/ arg1: kotlin.Int)
public constructor Example(/*0*/ context: Context?, /*1*/ arg1: kotlin.Int, /*2*/ arg2: kotlin.Int)
public constructor Example(/*0*/ context: Context?, /*1*/ arg1: kotlin.Int, /*2*/ arg2: kotlin.Int, /*3*/ arg3: kotlin.Int)
public final var condition: kotlin.Boolean
private final var index: kotlin.Int
private final lateinit var latePoint1: Point
private final lateinit var latePoint2: Point
private final var nullPoint: Point?
private final val point1: Point
private final val point2: Point
private final val point3: Point
private final val point4: Point
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
private final fun newIndex(/*0*/ zero: kotlin.Boolean): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

public final class Point {
public constructor Point()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,12 @@ public void testLocalObject() throws Exception {
doTest(fileName);
}

@TestMetadata("multipleAreNull.kt")
public void testMultipleAreNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.kt");
doTest(fileName);
}

@TestMetadata("nobacking.kt")
public void testNobacking() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/constructorConsistency/nobacking.kt");
Expand Down

0 comments on commit fc89385

Please sign in to comment.