@@ -1032,6 +1032,10 @@ abstract class FlowAnalysis<Node extends Object, Statement extends Node,
10321032class 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.
43544389class _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.
43794412class _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 (`?.` ).
49484979class _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 , '
0 commit comments