Skip to content

Commit 16d97ab

Browse files
committed
Get rid of MutableDataFlorInfoForArguments.setInitialDataFlowInfo
1 parent 5ceb973 commit 16d97ab

File tree

8 files changed

+33
-52
lines changed

8 files changed

+33
-52
lines changed

compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.ValueArgumentsToParametersMapper
4141
import org.jetbrains.kotlin.resolve.calls.callUtil.getCall
4242
import org.jetbrains.kotlin.resolve.calls.model.*
4343
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.getExplicitReceiverValue
44+
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
4445
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
4546
import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate
4647
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
@@ -112,7 +113,7 @@ fun getExpectedTypePredicate(
112113
resolutionCandidate,
113114
DelegatingBindingTrace(bindingContext, "Compute type predicates for unresolved call arguments"),
114115
TracingStrategy.EMPTY,
115-
DataFlowInfoForArgumentsImpl(call)
116+
DataFlowInfoForArgumentsImpl(DataFlowInfo.EMPTY, call)
116117
)
117118
val status = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters(call,
118119
TracingStrategy.EMPTY,

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/ArgumentTypeResolver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ public void analyzeArgumentsAndRecordTypes(
313313
) {
314314
MutableDataFlowInfoForArguments infoForArguments = context.dataFlowInfoForArguments;
315315
Call call = context.call;
316-
infoForArguments.setInitialDataFlowInfo(context.dataFlowInfo);
317316

318317
for (ValueArgument argument : call.getValueArguments()) {
319318
KtExpression expression = argument.getArgumentExpression();

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/CallResolutionContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ protected CallResolutionContext(
6060
this.dataFlowInfoForArguments = dataFlowInfoForArguments;
6161
}
6262
else if (checkArguments == CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS) {
63-
this.dataFlowInfoForArguments = new DataFlowInfoForArgumentsImpl(call);
63+
this.dataFlowInfoForArguments = new DataFlowInfoForArgumentsImpl(dataFlowInfo, call);
6464
}
6565
else {
66-
this.dataFlowInfoForArguments = new MutableDataFlowInfoForArguments.WithoutArgumentsCheck();
66+
this.dataFlowInfoForArguments = new MutableDataFlowInfoForArguments.WithoutArgumentsCheck(dataFlowInfo);
6767
}
6868
}
6969

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/DataFlowInfoForArgumentsImpl.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@
2727
import java.util.List;
2828
import java.util.Map;
2929

30-
public class DataFlowInfoForArgumentsImpl implements MutableDataFlowInfoForArguments {
31-
@NotNull private final Call call; //for better debug messages only
30+
public class DataFlowInfoForArgumentsImpl extends MutableDataFlowInfoForArguments {
3231
@Nullable private Map<ValueArgument, DataFlowInfo> infoMap = null;
3332
@Nullable private Map<ValueArgument, ValueArgument> nextArgument = null;
34-
@Nullable private DataFlowInfo initialInfo;
3533
@Nullable private DataFlowInfo resultInfo;
3634

37-
public DataFlowInfoForArgumentsImpl(@NotNull Call call) {
38-
this.call = call;
35+
public DataFlowInfoForArgumentsImpl(@NotNull DataFlowInfo initialInfo, @NotNull Call call) {
36+
super(initialInfo);
3937
initNextArgMap(call.getValueArguments());
4038
}
4139

@@ -54,21 +52,14 @@ private void initNextArgMap(@NotNull List<? extends ValueArgument> valueArgument
5452
}
5553
}
5654

57-
@Override
58-
public void setInitialDataFlowInfo(@NotNull DataFlowInfo dataFlowInfo) {
59-
//TODO assert initialInfo == null
60-
initialInfo = dataFlowInfo;
61-
}
62-
6355
@NotNull
6456
@Override
6557
public DataFlowInfo getInfo(@NotNull ValueArgument valueArgument) {
66-
assert initialInfo != null : "Initial data flow info was not set for call: " + call;
6758
DataFlowInfo infoForArgument = infoMap == null ? null : infoMap.get(valueArgument);
6859
if (infoForArgument == null) {
69-
return initialInfo;
60+
return initialDataFlowInfo;
7061
}
71-
return initialInfo.and(infoForArgument);
62+
return initialDataFlowInfo.and(infoForArgument);
7263
}
7364

7465
@Override
@@ -88,8 +79,7 @@ public void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowIn
8879
@NotNull
8980
@Override
9081
public DataFlowInfo getResultInfo() {
91-
assert initialInfo != null : "Initial data flow info was not set for call: " + call;
92-
if (resultInfo == null) return initialInfo;
93-
return initialInfo.and(resultInfo);
82+
if (resultInfo == null) return initialDataFlowInfo;
83+
return initialDataFlowInfo.and(resultInfo);
9484
}
9585
}

compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/MutableDataFlowInfoForArguments.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@
2020
import org.jetbrains.kotlin.psi.ValueArgument;
2121
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
2222

23-
public interface MutableDataFlowInfoForArguments extends DataFlowInfoForArguments {
23+
public abstract class MutableDataFlowInfoForArguments implements DataFlowInfoForArguments {
2424

25-
void setInitialDataFlowInfo(@NotNull DataFlowInfo dataFlowInfo);
25+
@NotNull protected final DataFlowInfo initialDataFlowInfo;
2626

27-
void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo dataFlowInfo);
27+
public MutableDataFlowInfoForArguments(@NotNull DataFlowInfo initialDataFlowInfo) {
28+
this.initialDataFlowInfo = initialDataFlowInfo;
29+
}
2830

29-
class WithoutArgumentsCheck implements MutableDataFlowInfoForArguments {
30-
private DataFlowInfo dataFlowInfo;
31+
public abstract void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo dataFlowInfo);
3132

32-
@Override
33-
public void setInitialDataFlowInfo(@NotNull DataFlowInfo dataFlowInfo) {
34-
this.dataFlowInfo = dataFlowInfo;
33+
@NotNull
34+
@Override
35+
public DataFlowInfo getResultInfo() {
36+
return initialDataFlowInfo;
37+
}
38+
39+
public static class WithoutArgumentsCheck extends MutableDataFlowInfoForArguments {
40+
41+
public WithoutArgumentsCheck(@NotNull DataFlowInfo dataFlowInfo) {
42+
super(dataFlowInfo);
3543
}
3644

3745
@Override
@@ -44,11 +52,5 @@ public void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowIn
4452
public DataFlowInfo getInfo(@NotNull ValueArgument valueArgument) {
4553
throw new IllegalStateException();
4654
}
47-
48-
@NotNull
49-
@Override
50-
public DataFlowInfo getResultInfo() {
51-
return dataFlowInfo;
52-
}
5355
};
5456
}

compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ private void recordThisOrSuperCallInTraceAndCallExtension(
564564
ResolvedCallImpl.create(resolutionCandidate,
565565
TemporaryBindingTrace.create(trace, "Fake trace for fake 'this' or 'super' resolved call"),
566566
TracingStrategy.EMPTY,
567-
new DataFlowInfoForArgumentsImpl(call));
567+
new DataFlowInfoForArgumentsImpl(context.dataFlowInfo, call));
568568
resolvedCall.markCallAsCompleted();
569569

570570
trace.record(RESOLVED_CALL, call, resolvedCall);

compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,10 @@ private SimpleFunctionDescriptorImpl createFunctionDescriptorForSpecialConstruct
157157
}
158158

159159
/*package*/ static MutableDataFlowInfoForArguments createIndependentDataFlowInfoForArgumentsForCall(
160+
@NotNull DataFlowInfo initialDataFlowInfo,
160161
final Map<ValueArgument, DataFlowInfo> dataFlowInfoForArgumentsMap
161162
) {
162-
return new MutableDataFlowInfoForArguments() {
163-
private DataFlowInfo initialDataFlowInfo;
164-
165-
@Override
166-
public void setInitialDataFlowInfo(@NotNull DataFlowInfo dataFlowInfo) {
167-
this.initialDataFlowInfo = dataFlowInfo;
168-
}
163+
return new MutableDataFlowInfoForArguments(initialDataFlowInfo) {
169164

170165
@Override
171166
public void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo dataFlowInfo) {
@@ -177,25 +172,19 @@ public void updateInfo(@NotNull ValueArgument valueArgument, @NotNull DataFlowIn
177172
public DataFlowInfo getInfo(@NotNull ValueArgument valueArgument) {
178173
return dataFlowInfoForArgumentsMap.get(valueArgument);
179174
}
180-
181-
@NotNull
182-
@Override
183-
public DataFlowInfo getResultInfo() {
184-
//todo merge and use
185-
return initialDataFlowInfo;
186-
}
187175
};
188176
}
189177

190178
public static MutableDataFlowInfoForArguments createDataFlowInfoForArgumentsForIfCall(
191179
@NotNull Call callForIf,
180+
@NotNull DataFlowInfo conditionInfo,
192181
@NotNull DataFlowInfo thenInfo,
193182
@NotNull DataFlowInfo elseInfo
194183
) {
195184
Map<ValueArgument, DataFlowInfo> dataFlowInfoForArgumentsMap = Maps.newHashMap();
196185
dataFlowInfoForArgumentsMap.put(callForIf.getValueArguments().get(0), thenInfo);
197186
dataFlowInfoForArgumentsMap.put(callForIf.getValueArguments().get(1), elseInfo);
198-
return createIndependentDataFlowInfoForArgumentsForCall(dataFlowInfoForArgumentsMap);
187+
return createIndependentDataFlowInfoForArgumentsForCall(conditionInfo, dataFlowInfoForArgumentsMap);
199188
}
200189

201190
/*package*/ static Call createCallForSpecialConstruction(

compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public KotlinTypeInfo visitIfExpression(KtIfExpression ifExpression, ExpressionT
125125
KtBlockExpression elseBlock = psiFactory.wrapInABlockWrapper(elseBranch);
126126
Call callForIf = createCallForSpecialConstruction(ifExpression, ifExpression, Lists.newArrayList(thenBlock, elseBlock));
127127
MutableDataFlowInfoForArguments dataFlowInfoForArguments =
128-
createDataFlowInfoForArgumentsForIfCall(callForIf, thenInfo, elseInfo);
128+
createDataFlowInfoForArgumentsForIfCall(callForIf, conditionDataFlowInfo, thenInfo, elseInfo);
129129
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils.resolveSpecialConstructionAsCall(
130130
callForIf, ResolveConstruct.IF, Lists.newArrayList("thenBranch", "elseBranch"),
131131
Lists.newArrayList(false, false),

0 commit comments

Comments
 (0)