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

Commit 76f3b21

Browse files
author
Dart CI
committed
Version 2.18.0-239.0.dev
Merge commit 'bd660d98472f01c57ece4dcf2a7a8810ea4e402d' into 'dev'
2 parents e47b915 + bd660d9 commit 76f3b21

30 files changed

+967
-343
lines changed

pkg/_fe_analyzer_shared/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ linter:
1818
- package_api_docs
1919
- lines_longer_than_80_chars
2020
# - always_specify_types
21+
- use_super_parameters

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

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,10 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
10321032
class FlowAnalysisDebug<Node extends Object, Statement extends Node,
10331033
Expression extends Object, Variable extends Object, Type extends Object>
10341034
implements FlowAnalysis<Node, Statement, Expression, Variable, Type> {
1035+
static int _nextCallbackId = 0;
1036+
1037+
static Expando<String> _description = new Expando<String>();
1038+
10351039
FlowAnalysis<Node, Statement, Expression, Variable, Type> _wrapped;
10361040

10371041
bool _exceptionOccurred = false;
@@ -1538,16 +1542,18 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
15381542

15391543
@override
15401544
Map<Type, NonPromotionReason> Function() whyNotPromoted(Expression target) {
1541-
return _wrap(
1542-
'whyNotPromoted($target)', () => _wrapped.whyNotPromoted(target),
1545+
return _wrap('whyNotPromoted($target)',
1546+
() => _trackWhyNotPromoted(_wrapped.whyNotPromoted(target)),
15431547
isQuery: true);
15441548
}
15451549

15461550
@override
15471551
Map<Type, NonPromotionReason> Function() whyNotPromotedImplicitThis(
15481552
Type staticType) {
1549-
return _wrap('whyNotPromotedImplicitThis($staticType)',
1550-
() => _wrapped.whyNotPromotedImplicitThis(staticType),
1553+
return _wrap(
1554+
'whyNotPromotedImplicitThis($staticType)',
1555+
() => _trackWhyNotPromoted(
1556+
_wrapped.whyNotPromotedImplicitThis(staticType)),
15511557
isQuery: true);
15521558
}
15531559

@@ -1561,6 +1567,19 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
15611567
@override
15621568
void _dumpState() => _wrapped._dumpState();
15631569

1570+
/// Wraps [callback] so that when it is called, the call (and its return
1571+
/// value) will be printed to the console. Also registers the wrapped
1572+
/// callback in [_description] so that it will be given a unique identifier
1573+
/// when printed to the console.
1574+
Map<Type, NonPromotionReason> Function() _trackWhyNotPromoted(
1575+
Map<Type, NonPromotionReason> Function() callback) {
1576+
String callbackToString = '#CALLBACK${_nextCallbackId++}';
1577+
Map<Type, NonPromotionReason> Function() wrappedCallback =
1578+
() => _wrap('$callbackToString()', callback, isQuery: true);
1579+
_description[wrappedCallback] = callbackToString;
1580+
return wrappedCallback;
1581+
}
1582+
15641583
T _wrap<T>(String description, T callback(),
15651584
{bool isQuery: false, bool? isPure}) {
15661585
isPure ??= isQuery;
@@ -1578,10 +1597,18 @@ class FlowAnalysisDebug<Node extends Object, Statement extends Node,
15781597
_wrapped._dumpState();
15791598
}
15801599
if (isQuery) {
1581-
print(' => $result');
1600+
print(' => ${_describe(result)}');
15821601
}
15831602
return result;
15841603
}
1604+
1605+
static String _describe(Object? value) {
1606+
if (value != null && value is! String && value is! num && value is! bool) {
1607+
String? description = _description[value];
1608+
if (description != null) return description;
1609+
}
1610+
return value.toString();
1611+
}
15851612
}
15861613

15871614
/// An instance of the [FlowModel] class represents the information gathered by
@@ -2613,6 +2640,9 @@ class ReferenceWithType<Variable extends Object, Type extends Object> {
26132640
final Type type;
26142641

26152642
ReferenceWithType(this.reference, this.type);
2643+
2644+
@override
2645+
String toString() => 'ReferenceWithType($reference, $type)';
26162646
}
26172647

26182648
/// Data structure representing a unique value that a variable might take on
@@ -2859,6 +2889,9 @@ class VariableModel<Variable extends Object, Type extends Object> {
28592889
if (nonPromotionHistory != null) {
28602890
parts.add('nonPromotionHistory: $nonPromotionHistory');
28612891
}
2892+
if (properties.isNotEmpty) {
2893+
parts.add('properties: $properties');
2894+
}
28622895
return 'VariableModel(${parts.join(', ')})';
28632896
}
28642897

@@ -3357,6 +3390,9 @@ class VariableReference<Variable extends Object, Type extends Object>
33573390
variableInfo[variable] = variableModel;
33583391
}
33593392

3393+
@override
3394+
String toString() => 'VariableReference($variable)';
3395+
33603396
@override
33613397
VariableModel<Variable, Type>? _getInfo(
33623398
Map<Variable?, VariableModel<Variable, Type>> variableInfo) =>
@@ -3371,7 +3407,7 @@ class _AssertContext<Variable extends Object, Type extends Object>
33713407
/// Flow models associated with the condition being asserted.
33723408
ExpressionInfo<Variable, Type>? _conditionInfo;
33733409

3374-
_AssertContext(FlowModel<Variable, Type> previous) : super(previous);
3410+
_AssertContext(super.previous);
33753411

33763412
@override
33773413
String toString() =>
@@ -3424,8 +3460,7 @@ class _ConditionalContext<Variable extends Object, Type extends Object>
34243460
/// circumstance where the "then" branch is taken.
34253461
ExpressionInfo<Variable, Type>? _thenInfo;
34263462

3427-
_ConditionalContext(ExpressionInfo<Variable, Type> conditionInfo)
3428-
: super(conditionInfo);
3463+
_ConditionalContext(ExpressionInfo<Variable, Type> super.conditionInfo);
34293464

34303465
@override
34313466
String toString() => '_ConditionalContext(conditionInfo: $_conditionInfo, '
@@ -4353,8 +4388,7 @@ abstract class _FlowContext {}
43534388
/// [_FlowContext] representing a function expression.
43544389
class _FunctionExpressionContext<Variable extends Object, Type extends Object>
43554390
extends _SimpleContext<Variable, Type> {
4356-
_FunctionExpressionContext(FlowModel<Variable, Type> previous)
4357-
: super(previous);
4391+
_FunctionExpressionContext(super.previous);
43584392

43594393
@override
43604394
String toString() => '_FunctionExpressionContext(previous: $_previous)';
@@ -4367,8 +4401,7 @@ class _IfContext<Variable extends Object, Type extends Object>
43674401
/// statement executes, in the circumstance where the "then" branch is taken.
43684402
FlowModel<Variable, Type>? _afterThen;
43694403

4370-
_IfContext(ExpressionInfo<Variable, Type> conditionInfo)
4371-
: super(conditionInfo);
4404+
_IfContext(ExpressionInfo<Variable, Type> super.conditionInfo);
43724405

43734406
@override
43744407
String toString() =>
@@ -4378,8 +4411,7 @@ class _IfContext<Variable extends Object, Type extends Object>
43784411
/// [_FlowContext] representing an "if-null" (`??`) expression.
43794412
class _IfNullExpressionContext<Variable extends Object, Type extends Object>
43804413
extends _SimpleContext<Variable, Type> {
4381-
_IfNullExpressionContext(FlowModel<Variable, Type> previous)
4382-
: super(previous);
4414+
_IfNullExpressionContext(super.previous);
43834415

43844416
@override
43854417
String toString() => '_IfNullExpressionContext(previous: $_previous)';
@@ -4396,9 +4428,8 @@ class _LegacyBinaryAndContext<Variable extends Object, Type extends Object>
43964428
/// expression.
43974429
final AssignedVariablesNodeInfo<Variable> _assignedVariablesInfoForRhs;
43984430

4399-
_LegacyBinaryAndContext(Map<Variable, Type> previousKnownTypes,
4400-
this._lhsShownTypes, this._assignedVariablesInfoForRhs)
4401-
: super(previousKnownTypes);
4431+
_LegacyBinaryAndContext(super.previousKnownTypes, this._lhsShownTypes,
4432+
this._assignedVariablesInfoForRhs);
44024433
}
44034434

44044435
/// Contextual information tracked by legacy type promotion about a statement or
@@ -4947,7 +4978,7 @@ class _LegacyVariableReadInfo<Variable, Type>
49474978
/// [_FlowContext] representing a null aware access (`?.`).
49484979
class _NullAwareAccessContext<Variable extends Object, Type extends Object>
49494980
extends _SimpleContext<Variable, Type> {
4950-
_NullAwareAccessContext(FlowModel<Variable, Type> previous) : super(previous);
4981+
_NullAwareAccessContext(super.previous);
49514982

49524983
@override
49534984
String toString() => '_NullAwareAccessContext(previous: $_previous)';
@@ -5030,6 +5061,10 @@ class _PropertyGetReference<Variable extends Object, Type extends Object>
50305061
target.storeInfo(variableInfo, targetInfo.setProperties(newProperties));
50315062
}
50325063

5064+
@override
5065+
String toString() =>
5066+
'_PropertyGetReference($target, $propertyName, $propertyMember)';
5067+
50335068
@override
50345069
VariableModel<Variable, Type>? _getInfo(
50355070
Map<Variable?, VariableModel<Variable, Type>> variableInfo) {
@@ -5064,8 +5099,7 @@ class _SimpleStatementContext<Variable extends Object, Type extends Object>
50645099
/// after evaluation of the switch expression.
50655100
final FlowModel<Variable, Type> _previous;
50665101

5067-
_SimpleStatementContext(Reachability checkpoint, this._previous)
5068-
: super(checkpoint);
5102+
_SimpleStatementContext(super.checkpoint, this._previous);
50695103

50705104
@override
50715105
String toString() => '_SimpleStatementContext(breakModel: $_breakModel, '
@@ -5146,7 +5180,7 @@ class _TryContext<Variable extends Object, Type extends Object>
51465180
/// has finished executing.
51475181
FlowModel<Variable, Type>? _afterBodyAndCatches;
51485182

5149-
_TryContext(FlowModel<Variable, Type> previous) : super(previous);
5183+
_TryContext(super.previous);
51505184

51515185
@override
51525186
String toString() =>
@@ -5160,7 +5194,7 @@ class _TryFinallyContext<Variable extends Object, Type extends Object>
51605194
/// block.
51615195
late final FlowModel<Variable, Type> _beforeFinally;
51625196

5163-
_TryFinallyContext(FlowModel<Variable, Type> previous) : super(previous);
5197+
_TryFinallyContext(super.previous);
51645198
}
51655199

51665200
/// [_FlowContext] representing a `while` loop (or a C-style `for` loop, which
@@ -5170,8 +5204,7 @@ class _WhileContext<Variable extends Object, Type extends Object>
51705204
/// Flow models associated with the loop condition.
51715205
final ExpressionInfo<Variable, Type> _conditionInfo;
51725206

5173-
_WhileContext(Reachability checkpoint, this._conditionInfo)
5174-
: super(checkpoint);
5207+
_WhileContext(super.checkpoint, this._conditionInfo);
51755208

51765209
@override
51775210
String toString() => '_WhileContext(breakModel: $_breakModel, '

pkg/_fe_analyzer_shared/lib/src/macros/api/code.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ class DeclarationCode extends Code {
2727
@override
2828
CodeKind get kind => CodeKind.declaration;
2929

30-
DeclarationCode.fromString(String code) : super.fromString(code);
30+
DeclarationCode.fromString(super.code) : super.fromString();
3131

32-
DeclarationCode.fromParts(List<Object> parts) : super.fromParts(parts);
32+
DeclarationCode.fromParts(super.parts) : super.fromParts();
3333
}
3434

3535
/// A piece of code representing a syntactically valid expression.
3636
class ExpressionCode extends Code {
3737
@override
3838
CodeKind get kind => CodeKind.expression;
3939

40-
ExpressionCode.fromString(String code) : super.fromString(code);
40+
ExpressionCode.fromString(super.code) : super.fromString();
4141

42-
ExpressionCode.fromParts(List<Object> parts) : super.fromParts(parts);
42+
ExpressionCode.fromParts(super.parts) : super.fromParts();
4343
}
4444

4545
/// A piece of code representing a syntactically valid function body.
@@ -52,9 +52,9 @@ class FunctionBodyCode extends Code {
5252
@override
5353
CodeKind get kind => CodeKind.functionBody;
5454

55-
FunctionBodyCode.fromString(String code) : super.fromString(code);
55+
FunctionBodyCode.fromString(super.code) : super.fromString();
5656

57-
FunctionBodyCode.fromParts(List<Object> parts) : super.fromParts(parts);
57+
FunctionBodyCode.fromParts(super.parts) : super.fromParts();
5858
}
5959

6060
/// A piece of code identifying a syntactically valid function or function type

pkg/_fe_analyzer_shared/lib/src/macros/executor/builder_impls.dart

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class TypeBuilderBase implements IdentifierResolver {
4343
}
4444

4545
class TypeBuilderImpl extends TypeBuilderBase implements TypeBuilder {
46-
TypeBuilderImpl(IdentifierResolver identifierResolver)
47-
: super(identifierResolver);
46+
TypeBuilderImpl(super.identifierResolver);
4847

4948
@override
5049
void declareType(String name, DeclarationCode typeDeclaration) {
@@ -60,13 +59,9 @@ class DeclarationBuilderBase extends TypeBuilderBase
6059
final TypeDeclarationResolver typeDeclarationResolver;
6160
final TypeResolver typeResolver;
6261

63-
DeclarationBuilderBase(IdentifierResolver identifierResolver,
64-
this.typeIntrospector, this.typeDeclarationResolver, this.typeResolver,
65-
{Map<String, List<DeclarationCode>>? parentClassAugmentations,
66-
List<DeclarationCode>? parentLibraryAugmentations})
67-
: super(identifierResolver,
68-
parentClassAugmentations: parentClassAugmentations,
69-
parentLibraryAugmentations: parentLibraryAugmentations);
62+
DeclarationBuilderBase(super.identifierResolver, this.typeIntrospector,
63+
this.typeDeclarationResolver, this.typeResolver,
64+
{super.parentClassAugmentations, super.parentLibraryAugmentations});
7065

7166
@override
7267
Future<TypeDeclaration> declarationOf(IdentifierImpl identifier) =>
@@ -94,13 +89,8 @@ class DeclarationBuilderBase extends TypeBuilderBase
9489

9590
class DeclarationBuilderImpl extends DeclarationBuilderBase
9691
implements DeclarationBuilder {
97-
DeclarationBuilderImpl(
98-
IdentifierResolver identifierResolver,
99-
TypeIntrospector typeIntrospector,
100-
TypeDeclarationResolver typeDeclarationResolver,
101-
TypeResolver typeResolver)
102-
: super(identifierResolver, typeIntrospector, typeDeclarationResolver,
103-
typeResolver);
92+
DeclarationBuilderImpl(super.identifierResolver, super.typeIntrospector,
93+
super.typeDeclarationResolver, super.typeResolver);
10494

10595
@override
10696
void declareInLibrary(DeclarationCode declaration) {
@@ -134,18 +124,9 @@ class DefinitionBuilderBase extends DeclarationBuilderBase
134124
implements TypeInferrer {
135125
final TypeInferrer typeInferrer;
136126

137-
DefinitionBuilderBase(
138-
IdentifierResolver identifierResolver,
139-
TypeIntrospector typeIntrospector,
140-
TypeDeclarationResolver typeDeclarationResolver,
141-
TypeResolver typeResolver,
142-
this.typeInferrer,
143-
{Map<String, List<DeclarationCode>>? parentClassAugmentations,
144-
List<DeclarationCode>? parentLibraryAugmentations})
145-
: super(identifierResolver, typeIntrospector, typeDeclarationResolver,
146-
typeResolver,
147-
parentClassAugmentations: parentClassAugmentations,
148-
parentLibraryAugmentations: parentLibraryAugmentations);
127+
DefinitionBuilderBase(super.identifierResolver, super.typeIntrospector,
128+
super.typeDeclarationResolver, super.typeResolver, this.typeInferrer,
129+
{super.parentClassAugmentations, super.parentLibraryAugmentations});
149130

150131
@override
151132
Future<TypeAnnotation> inferType(OmittedTypeAnnotationImpl omittedType) =>

0 commit comments

Comments
 (0)