Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7c5b3dc

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
[vm/tfa] Pass receiver type into field initializer summaries.
This is required for tracking type arguments, since field initializers can reference type variables from the enclosing class. Also a few drive-by spelling fixes. Change-Id: I91e33f7d8c61e288ccb2d8e18b33f4e67ac22a1b Cq-Include-Trybots: luci.dart.try:vm-kernel-win-release-x64-try, vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-precomp-win-release-x64-try Reviewed-on: https://dart-review.googlesource.com/74666 Commit-Queue: Samir Jindel <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent cd26b88 commit 7c5b3dc

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

pkg/vm/lib/transformations/type_flow/analysis.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ class _DirectInvocation extends _Invocation {
163163
case CallKind.PropertyGet:
164164
assertx(args.values.length == firstParamIndex);
165165
assertx(args.names.isEmpty);
166-
return fieldValue.getValue(typeFlowAnalysis);
166+
return fieldValue.getValue(
167+
typeFlowAnalysis, field.isStatic ? null : args.values[0]);
167168

168169
case CallKind.PropertySet:
169170
assertx(args.values.length == firstParamIndex + 1);
@@ -176,7 +177,8 @@ class _DirectInvocation extends _Invocation {
176177
// Call via field.
177178
// TODO(alexmarkov): support function types and use inferred type
178179
// to get more precise return type.
179-
final receiver = fieldValue.getValue(typeFlowAnalysis);
180+
final receiver = fieldValue.getValue(
181+
typeFlowAnalysis, field.isStatic ? null : args.values[0]);
180182
if (receiver != const EmptyType()) {
181183
typeFlowAnalysis.applyCall(/* callSite = */ null,
182184
DynamicSelector.kCall, new Args.withReceiver(args, receiver),
@@ -185,7 +187,7 @@ class _DirectInvocation extends _Invocation {
185187
return new Type.nullableAny();
186188

187189
case CallKind.FieldInitializer:
188-
assertx(args.values.isEmpty);
190+
assertx(args.values.length == firstParamIndex);
189191
assertx(args.names.isEmpty);
190192
Type initializerResult = typeFlowAnalysis
191193
.getSummary(field)
@@ -685,7 +687,6 @@ class _FieldValue extends _DependencyTracker {
685687
final Field field;
686688
final Type staticType;
687689
Type value;
688-
_DirectInvocation _initializerInvocation;
689690

690691
_FieldValue(this.field) : staticType = new Type.fromStatic(field.type) {
691692
if (field.initializer == null && _isDefaultValueOfFieldObservable()) {
@@ -717,22 +718,22 @@ class _FieldValue extends _DependencyTracker {
717718
});
718719
}
719720

720-
void ensureInitialized(TypeFlowAnalysis typeFlowAnalysis) {
721+
void ensureInitialized(TypeFlowAnalysis typeFlowAnalysis, Type receiverType) {
721722
if (field.initializer != null) {
722-
if (_initializerInvocation == null) {
723-
_initializerInvocation = typeFlowAnalysis._invocationsCache
724-
.getInvocation(
725-
new DirectSelector(field, callKind: CallKind.FieldInitializer),
726-
new Args<Type>(const <Type>[]));
727-
}
723+
assertx(field.isStatic == (receiverType == null));
724+
final args = !field.isStatic ? <Type>[receiverType] : const <Type>[];
725+
final initializerInvocation = typeFlowAnalysis._invocationsCache
726+
.getInvocation(
727+
new DirectSelector(field, callKind: CallKind.FieldInitializer),
728+
new Args<Type>(args));
728729

729730
// It may update the field value.
730-
typeFlowAnalysis.workList.processInvocation(_initializerInvocation);
731+
typeFlowAnalysis.workList.processInvocation(initializerInvocation);
731732
}
732733
}
733734

734-
Type getValue(TypeFlowAnalysis typeFlowAnalysis) {
735-
ensureInitialized(typeFlowAnalysis);
735+
Type getValue(TypeFlowAnalysis typeFlowAnalysis, Type receiverType) {
736+
ensureInitialized(typeFlowAnalysis, receiverType);
736737
addDependentInvocation(typeFlowAnalysis.currentInvocation);
737738
return value;
738739
}

pkg/vm/lib/transformations/type_flow/summary_collector.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,24 @@ class SummaryCollector extends RecursiveVisitor<TypeExpr> {
268268
_returnValue = null;
269269
_receiver = null;
270270

271-
if (member is Field) {
272-
_summary = new Summary();
271+
final hasReceiver = hasReceiverArg(member);
273272

273+
if (member is Field) {
274+
if (hasReceiver) {
275+
_summary = new Summary(parameterCount: 1, positionalParameterCount: 1);
276+
// TODO(alexmarkov): subclass cone
277+
_receiver = _declareParameter(
278+
"this", member.enclosingClass.rawType, null,
279+
isReceiver: true);
280+
_environment.thisType = member.enclosingClass?.thisType;
281+
} else {
282+
_summary = new Summary();
283+
}
274284
assertx(member.initializer != null);
275285
_summary.result = _visit(member.initializer);
276286
} else {
277287
FunctionNode function = member.function;
278288

279-
final hasReceiver = hasReceiverArg(member);
280289
final firstParamIndex = hasReceiver ? 1 : 0;
281290

282291
_summary = new Summary(
@@ -366,8 +375,7 @@ class SummaryCollector extends RecursiveVisitor<TypeExpr> {
366375
final List<Type> args = <Type>[];
367376
final List<String> names = <String>[];
368377

369-
if (hasReceiverArg(member) &&
370-
(selector.callKind != CallKind.FieldInitializer)) {
378+
if (hasReceiverArg(member)) {
371379
assertx(member.enclosingClass != null);
372380
Type receiver = new Type.cone(member.enclosingClass.rawType);
373381
args.add(receiver);

pkg/vm/test/transformations/type_flow/summary_collector_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import '../../common_test_utils.dart';
1818
final String pkgVmDir = Platform.script.resolve('../../..').toFilePath();
1919

2020
class PrintSummaries extends RecursiveVisitor<Null> {
21-
final SummaryCollector _summaryColector;
21+
final SummaryCollector _summaryCollector;
2222
final StringBuffer _buf = new StringBuffer();
2323

2424
PrintSummaries(TypeEnvironment environment, CoreTypes coreTypes)
25-
: _summaryColector = new SummaryCollector(
25+
: _summaryCollector = new SummaryCollector(
2626
environment,
2727
new EmptyEntryPointsListener(),
2828
new NativeCodeOracle(
@@ -38,7 +38,7 @@ class PrintSummaries extends RecursiveVisitor<Null> {
3838
if (!member.isAbstract &&
3939
!((member is Field) && (member.initializer == null))) {
4040
_buf.writeln("------------ $member ------------");
41-
_buf.writeln(_summaryColector.createSummary(member));
41+
_buf.writeln(_summaryCollector.createSummary(member));
4242
}
4343
}
4444
}

pkg/vm/testcases/transformations/type_flow/summary_collector/calls.dart.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RESULT: _T {}?
2222
%y = _Parameter #1 [_T (dart.core::int)+?]
2323
RESULT: _T {}?
2424
------------ #lib::B::bar4 ------------
25-
25+
%this = _Parameter #0 [_T (#lib::B)+]
2626
RESULT: _T {}?
2727
------------ #lib::C:: ------------
2828
%this = _Parameter #0 [_T (#lib::C)+]

pkg/vm/testcases/transformations/type_flow/summary_collector/setter_result.dart.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RESULT: _T {}?
77
t1 = _Call direct [dart.core::Object::] (%this)
88
RESULT: _T {}?
99
------------ #lib::A::foo ------------
10-
10+
%this = _Parameter #0 [_T (#lib::A)+]
1111
RESULT: _T {}?
1212
------------ #lib::B:: ------------
1313
%this = _Parameter #0 [_T (#lib::B)+]

0 commit comments

Comments
 (0)