Skip to content

Commit cf7587a

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Revert "Flow analysis: track property get targets."
This reverts commit bc6cdf5. Reason for revert: Broke Golem benchmarks - https://golem.corp.goog/PerformanceChanges?repository=dart&revision=91561 Original change's description: > Flow analysis: track property get targets. > > These targets are needed for "why not promoted" error messages, and > it's easier to have flow analysis keep track of them than to have the > analyzer and CFE try to reconstruct them at the time of reporting the > error. > > Bug: #44898 > Change-Id: Ia8ef4a7ce13cc30860e59b7369e6230d233e252d > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193832 > Commit-Queue: Paul Berry <[email protected]> > Reviewed-by: Johnni Winther <[email protected]> > Reviewed-by: Konstantin Shcheglov <[email protected]> [email protected],[email protected],[email protected] Change-Id: Ic2b66b1db621c0f4e4c5398acfe2ae61bd7625ca No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: #44898 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194104 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent fc349bd commit cf7587a

File tree

13 files changed

+121
-121
lines changed

13 files changed

+121
-121
lines changed

pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,8 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
736736
/// expression to the left hand side of the `.`, and [propertyName] should be
737737
/// the identifier to the right hand side of the `.`. [staticType] should be
738738
/// the static type of the value returned by the property get.
739-
///
740-
/// [propertyMember] should be whatever data structure the client uses to keep
741-
/// track of the field or property being accessed. In the event of
742-
/// non-promotion of a property get, this value can be retrieved from
743-
/// [PropertyNotPromoted.propertyMember].
744739
void propertyGet(Expression wholeExpression, Expression target,
745-
String propertyName, Object? propertyMember, Type staticType);
740+
String propertyName, Type staticType);
746741

747742
/// Retrieves the SSA node associated with [variable], or `null` if [variable]
748743
/// is not associated with an SSA node because it is write captured. For
@@ -793,13 +788,8 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
793788
/// the whole property get, and [propertyName] should be the name of the
794789
/// property being read. [staticType] should be the static type of the value
795790
/// returned by the property get.
796-
///
797-
/// [propertyMember] should be whatever data structure the client uses to keep
798-
/// track of the field or property being accessed. In the event of
799-
/// non-promotion of a property get, this value can be retrieved from
800-
/// [PropertyNotPromoted.propertyMember].
801-
void thisOrSuperPropertyGet(Expression expression, String propertyName,
802-
Object? propertyMember, Type staticType);
791+
void thisOrSuperPropertyGet(
792+
Expression expression, String propertyName, Type staticType);
803793

804794
/// Call this method just before visiting the body of a "try/catch" statement.
805795
///
@@ -1349,12 +1339,11 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
13491339

13501340
@override
13511341
void propertyGet(Expression wholeExpression, Expression target,
1352-
String propertyName, Object? propertyMember, Type staticType) {
1342+
String propertyName, Type staticType) {
13531343
_wrap(
1354-
'propertyGet($wholeExpression, $target, $propertyName, '
1355-
'$propertyMember, $staticType)',
1344+
'propertyGet($wholeExpression, $target, $propertyName, $staticType)',
13561345
() => _wrapped.propertyGet(
1357-
wholeExpression, target, propertyName, propertyMember, staticType));
1346+
wholeExpression, target, propertyName, staticType));
13581347
}
13591348

13601349
@override
@@ -1389,13 +1378,12 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
13891378
}
13901379

13911380
@override
1392-
void thisOrSuperPropertyGet(Expression expression, String propertyName,
1393-
Object? propertyMember, Type staticType) {
1381+
void thisOrSuperPropertyGet(
1382+
Expression expression, String propertyName, Type staticType) {
13941383
_wrap(
1395-
'thisOrSuperPropertyGet($expression, $propertyName, $propertyMember, '
1396-
'$staticType)',
1384+
'thisOrSuperPropertyGet($expression, $propertyName, $staticType)',
13971385
() => _wrapped.thisOrSuperPropertyGet(
1398-
expression, propertyName, propertyMember, staticType));
1386+
expression, propertyName, staticType));
13991387
}
14001388

14011389
@override
@@ -2346,17 +2334,12 @@ class PropertyNotPromoted<Type extends Object> extends NonPromotionReason {
23462334
/// The name of the property.
23472335
final String propertyName;
23482336

2349-
/// The field or property being accessed. This matches a `propertyMember`
2350-
/// value that was passed to either [FlowAnalysis.propertyGet] or
2351-
/// [FlowAnalysis.thisOrSuperPropertyGet].
2352-
final Object? propertyMember;
2353-
23542337
/// The static type of the property at the time of the access. This is the
23552338
/// type that was passed to [FlowAnalysis.whyNotPromoted]; it is provided to
23562339
/// the client as a convenience for ID testing.
23572340
final Type staticType;
23582341

2359-
PropertyNotPromoted(this.propertyName, this.propertyMember, this.staticType);
2342+
PropertyNotPromoted(this.propertyName, this.staticType);
23602343

23612344
@override
23622345
String get documentationLink => 'http://dart.dev/go/non-promo-property';
@@ -2534,10 +2517,8 @@ abstract class Reference<Variable extends Object, Type extends Object> {
25342517

25352518
/// Creates a reference representing a get of a property called [propertyName]
25362519
/// on the reference represented by `this`.
2537-
Reference<Variable, Type> propertyGet(
2538-
String propertyName, Object? propertyMember) =>
2539-
new _PropertyGetReference<Variable, Type>(
2540-
this, propertyName, propertyMember);
2520+
Reference<Variable, Type> propertyGet(String propertyName) =>
2521+
new _PropertyGetReference<Variable, Type>(this, propertyName);
25412522

25422523
/// Stores info for this reference in [variableInfo].
25432524
void storeInfo(Map<Variable?, VariableModel<Variable, Type>> variableInfo,
@@ -3971,14 +3952,14 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
39713952

39723953
@override
39733954
void propertyGet(Expression wholeExpression, Expression target,
3974-
String propertyName, Object? propertyMember, Type staticType) {
3955+
String propertyName, Type staticType) {
39753956
Reference<Variable, Type>? reference =
39763957
_getExpressionReference(target)?.reference;
39773958
if (reference != null) {
39783959
_storeExpressionReference(
39793960
wholeExpression,
39803961
new ReferenceWithType<Variable, Type>(
3981-
reference.propertyGet(propertyName, propertyMember), staticType));
3962+
reference.propertyGet(propertyName), staticType));
39823963
}
39833964
}
39843965

@@ -4035,13 +4016,12 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
40354016
}
40364017

40374018
@override
4038-
void thisOrSuperPropertyGet(Expression expression, String propertyName,
4039-
Object? propertyMember, Type staticType) {
4019+
void thisOrSuperPropertyGet(
4020+
Expression expression, String propertyName, Type staticType) {
40404021
_storeExpressionReference(
40414022
expression,
40424023
new ReferenceWithType<Variable, Type>(
4043-
new _ThisReference<Variable, Type>()
4044-
.propertyGet(propertyName, propertyMember),
4024+
new _ThisReference<Variable, Type>().propertyGet(propertyName),
40454025
staticType));
40464026
}
40474027

@@ -4706,7 +4686,7 @@ class _LegacyTypePromotion<Node extends Object, Statement extends Node,
47064686

47074687
@override
47084688
void propertyGet(Expression wholeExpression, Expression target,
4709-
String propertyName, Object? propertyMember, Type staticType) {}
4689+
String propertyName, Type staticType) {}
47104690

47114691
@override
47124692
SsaNode<Variable, Type>? ssaNodeForTesting(Variable variable) {
@@ -4726,8 +4706,8 @@ class _LegacyTypePromotion<Node extends Object, Statement extends Node,
47264706
void thisOrSuper(Expression expression, Type staticType) {}
47274707

47284708
@override
4729-
void thisOrSuperPropertyGet(Expression expression, String propertyName,
4730-
Object? propertyMember, Type staticType) {}
4709+
void thisOrSuperPropertyGet(
4710+
Expression expression, String propertyName, Type staticType) {}
47314711

47324712
@override
47334713
void tryCatchStatement_bodyBegin() {}
@@ -4928,12 +4908,7 @@ class _PropertyGetReference<Variable extends Object, Type extends Object>
49284908
/// The name of the property.
49294909
final String propertyName;
49304910

4931-
/// The field or property being accessed. This matches a `propertyMember`
4932-
/// value that was passed to either [FlowAnalysis.propertyGet] or
4933-
/// [FlowAnalysis.thisOrSuperPropertyGet].
4934-
final Object? propertyMember;
4935-
4936-
_PropertyGetReference(this.target, this.propertyName, this.propertyMember);
4911+
_PropertyGetReference(this.target, this.propertyName);
49374912

49384913
@override
49394914
Map<Type, NonPromotionReason> Function() getNonPromotionReasons(
@@ -4945,8 +4920,7 @@ class _PropertyGetReference<Variable extends Object, Type extends Object>
49454920
return () {
49464921
Map<Type, NonPromotionReason> result = <Type, NonPromotionReason>{};
49474922
for (Type type in promotedTypes) {
4948-
result[type] =
4949-
new PropertyNotPromoted(propertyName, propertyMember, staticType);
4923+
result[type] = new PropertyNotPromoted(propertyName, staticType);
49504924
}
49514925
return result;
49524926
};

pkg/_fe_analyzer_shared/test/mini_ast.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ class _Property extends LValue {
15101510
Harness h, FlowAnalysis<Node, Statement, Expression, Var, Type> flow) {
15111511
var targetType = target._visit(h, flow);
15121512
var propertyType = h.getMember(targetType, propertyName);
1513-
flow.propertyGet(this, target, propertyName, propertyName, propertyType);
1513+
flow.propertyGet(this, target, propertyName, propertyType);
15141514
return propertyType;
15151515
}
15161516

@@ -1614,7 +1614,7 @@ class _ThisOrSuperPropertyGet extends Expression {
16141614
@override
16151615
Type _visit(
16161616
Harness h, FlowAnalysis<Node, Statement, Expression, Var, Type> flow) {
1617-
flow.thisOrSuperPropertyGet(this, propertyName, propertyName, type);
1617+
flow.thisOrSuperPropertyGet(this, propertyName, type);
16181618
return type;
16191619
}
16201620
}

pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ class AssignmentExpressionResolver {
121121
CompileTimeErrorCode.INVALID_ASSIGNMENT,
122122
right,
123123
[rightType, writeType],
124-
_resolver.computeWhyNotPromotedMessages(right, whyNotPromoted?.call()),
124+
_resolver.computeWhyNotPromotedMessages(
125+
right, right, whyNotPromoted?.call()),
125126
);
126127
}
127128

pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,7 @@ class MethodInvocationResolver {
807807
);
808808
}
809809
_resolver.flowAnalysis?.flow?.propertyGet(
810-
functionExpression,
811-
target,
812-
node.methodName.name,
813-
node.methodName.staticElement,
814-
getterReturnType);
810+
functionExpression, target, node.methodName.name, getterReturnType);
815811
functionExpression.staticType = targetType;
816812
}
817813

pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ class PropertyElementResolver {
203203
readElementRequested = readLookup.requested;
204204
if (readElementRequested is PropertyAccessorElement &&
205205
!readElementRequested.isStatic) {
206-
_resolver.flowAnalysis?.flow?.thisOrSuperPropertyGet(node, node.name,
207-
readElementRequested, readElementRequested.returnType);
206+
_resolver.flowAnalysis?.flow?.thisOrSuperPropertyGet(
207+
node, node.name, readElementRequested.returnType);
208208
}
209209
_resolver.checkReadOfNotAssignedLocalVariable(node, readElementRequested);
210210
}
@@ -373,11 +373,7 @@ class PropertyElementResolver {
373373
nameErrorEntity: propertyName,
374374
);
375375

376-
_resolver.flowAnalysis?.flow?.propertyGet(
377-
node,
378-
target,
379-
propertyName.name,
380-
result.getter,
376+
_resolver.flowAnalysis?.flow?.propertyGet(node, target, propertyName.name,
381377
result.getter?.returnType ?? _typeSystem.typeProvider.dynamicType);
382378

383379
if (hasRead && result.needsGetterError) {
@@ -657,7 +653,6 @@ class PropertyElementResolver {
657653
node,
658654
target,
659655
propertyName.name,
660-
readElement,
661656
readElement?.returnType ?? _typeSystem.typeProvider.dynamicType);
662657
}
663658

pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ class TypePropertyResolver {
130130
if (flow != null) {
131131
if (receiver != null) {
132132
messages = _resolver.computeWhyNotPromotedMessages(
133-
nameErrorEntity, flow.whyNotPromoted(receiver)());
133+
receiver, nameErrorEntity, flow.whyNotPromoted(receiver)());
134134
} else {
135135
var thisType = _resolver.thisType;
136136
if (thisType != null) {
137-
messages = _resolver.computeWhyNotPromotedMessages(
137+
messages = _resolver.computeWhyNotPromotedMessages(receiver,
138138
nameErrorEntity, flow.whyNotPromotedImplicitThis(thisType)());
139139
}
140140
}

pkg/analyzer/lib/src/error/bool_expression_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class BoolExpressionVerifier {
5757
errorCode: CompileTimeErrorCode
5858
.UNCHECKED_USE_OF_NULLABLE_VALUE_AS_CONDITION,
5959
messages: _resolver.computeWhyNotPromotedMessages(
60-
expression, whyNotPromoted?.call()));
60+
expression, expression, whyNotPromoted?.call()));
6161
} else {
6262
_errorReporter.reportErrorForNode(errorCode, expression, arguments);
6363
}

pkg/analyzer/lib/src/error/nullable_dereference_verifier.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class NullableDereferenceVerifier {
7676

7777
List<DiagnosticMessage>? messages;
7878
if (errorNode is Expression) {
79-
messages = _resolver.computeWhyNotPromotedMessages(
80-
errorNode, _resolver.flowAnalysis?.flow?.whyNotPromoted(errorNode)());
79+
messages = _resolver.computeWhyNotPromotedMessages(errorNode, errorNode,
80+
_resolver.flowAnalysis?.flow?.whyNotPromoted(errorNode)());
8181
}
8282
report(errorNode, receiverType, errorCode: errorCode, messages: messages);
8383
return true;

pkg/analyzer/lib/src/generated/error_detection_helpers.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ mixin ErrorDetectionHelpers {
8585
}
8686
return;
8787
}
88-
var messages =
89-
computeWhyNotPromotedMessages(expression, whyNotPromoted?.call());
88+
var messages = computeWhyNotPromotedMessages(
89+
expression, expression, whyNotPromoted?.call());
9090
// report problem
9191
if (isConstConstructor) {
9292
// TODO(paulberry): this error should be based on the actual type of the
@@ -229,6 +229,7 @@ mixin ErrorDetectionHelpers {
229229
/// [whyNotPromoted] should be the non-promotion details returned by the flow
230230
/// analysis engine.
231231
List<DiagnosticMessage> computeWhyNotPromotedMessages(
232+
Expression? expression,
232233
SyntacticEntity errorEntity,
233234
Map<DartType, NonPromotionReason>? whyNotPromoted);
234235

@@ -312,7 +313,8 @@ mixin ErrorDetectionHelpers {
312313
errorCode,
313314
getErrorNode(expression),
314315
[actualStaticType, expectedStaticType],
315-
computeWhyNotPromotedMessages(expression, whyNotPromoted?.call()),
316+
computeWhyNotPromotedMessages(
317+
expression, expression, whyNotPromoted?.call()),
316318
);
317319
return false;
318320
}

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
312312

313313
@override
314314
List<DiagnosticMessage> computeWhyNotPromotedMessages(
315+
Expression? expression,
315316
SyntacticEntity errorEntity,
316317
Map<DartType, NonPromotionReason>? whyNotPromoted) {
317318
return [];

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,17 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
533533

534534
@override
535535
List<DiagnosticMessage> computeWhyNotPromotedMessages(
536+
Expression? expression,
536537
SyntacticEntity errorEntity,
537538
Map<DartType, NonPromotionReason>? whyNotPromoted) {
539+
if (expression is NamedExpression) {
540+
expression = expression.expression;
541+
}
538542
List<DiagnosticMessage> messages = [];
539543
if (whyNotPromoted != null) {
540544
for (var entry in whyNotPromoted.entries) {
541545
var whyNotPromotedVisitor = _WhyNotPromotedVisitor(
542-
source, errorEntity, flowAnalysis!.dataForTesting);
546+
source, expression, errorEntity, flowAnalysis!.dataForTesting);
543547
if (typeSystem.isPotentiallyNullable(entry.key)) continue;
544548
var message = entry.value.accept(whyNotPromotedVisitor);
545549
if (message != null) {
@@ -3443,6 +3447,10 @@ class _WhyNotPromotedVisitor
34433447
PromotableElement, DartType> {
34443448
final Source source;
34453449

3450+
/// The expression that was not promoted, or `null` if the thing that was not
3451+
/// promoted was an implicit `this`.
3452+
final Expression? _expression;
3453+
34463454
final SyntacticEntity _errorEntity;
34473455

34483456
final FlowAnalysisDataForTesting? _dataForTesting;
@@ -3451,7 +3459,8 @@ class _WhyNotPromotedVisitor
34513459

34523460
DartType? propertyType;
34533461

3454-
_WhyNotPromotedVisitor(this.source, this._errorEntity, this._dataForTesting);
3462+
_WhyNotPromotedVisitor(
3463+
this.source, this._expression, this._errorEntity, this._dataForTesting);
34553464

34563465
@override
34573466
DiagnosticMessage? visitDemoteViaExplicitWrite(
@@ -3471,7 +3480,18 @@ class _WhyNotPromotedVisitor
34713480
@override
34723481
DiagnosticMessage? visitPropertyNotPromoted(
34733482
PropertyNotPromoted<DartType> reason) {
3474-
var receiverElement = reason.propertyMember;
3483+
var expression = _expression;
3484+
Element? receiverElement;
3485+
if (expression is SimpleIdentifier) {
3486+
receiverElement = expression.staticElement;
3487+
} else if (expression is PropertyAccess) {
3488+
receiverElement = expression.propertyName.staticElement;
3489+
} else if (expression is PrefixedIdentifier) {
3490+
receiverElement = expression.identifier.staticElement;
3491+
} else {
3492+
assert(false,
3493+
'Unrecognized property access expression: ${expression.runtimeType}');
3494+
}
34753495
if (receiverElement is PropertyAccessorElement) {
34763496
propertyReference = receiverElement;
34773497
propertyType = reason.staticType;

0 commit comments

Comments
 (0)