@@ -345,6 +345,13 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
345
345
*/
346
346
Map <int , int > _localClosureIndexMap;
347
347
348
+ /**
349
+ * Indicates whether closure function bodies should be serialized. This flag
350
+ * is set while visiting the bodies of initializer expressions that will be
351
+ * needed by type inference.
352
+ */
353
+ bool _serializeClosureBodyExprs = false ;
354
+
348
355
/**
349
356
* Create a slot id for storing a propagated or inferred type or const cycle
350
357
* info.
@@ -580,6 +587,9 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
580
587
/**
581
588
* Serialize a [FunctionDeclaration] or [MethodDeclaration] into an
582
589
* [UnlinkedExecutable] .
590
+ *
591
+ * If [serializeBodyExpr] is `true` , then the function definition is stored
592
+ * in [UnlinkedExecutableBuilder.bodyExpr] .
583
593
*/
584
594
UnlinkedExecutableBuilder serializeExecutable (
585
595
AstNode node,
@@ -595,7 +605,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
595
605
Comment documentationComment,
596
606
NodeList <Annotation > annotations,
597
607
TypeParameterList typeParameters,
598
- bool isExternal) {
608
+ bool isExternal,
609
+ bool serializeBodyExpr) {
599
610
int oldScopesLength = scopes.length;
600
611
_TypeParameterScope typeParameterScope = new _TypeParameterScope ();
601
612
scopes.add (typeParameterScope);
@@ -643,7 +654,7 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
643
654
}
644
655
b.visibleOffset = enclosingBlock? .offset;
645
656
b.visibleLength = enclosingBlock? .length;
646
- serializeFunctionBody (b, null , body, false );
657
+ serializeFunctionBody (b, null , body, serializeBodyExpr );
647
658
scopes.removeLast ();
648
659
assert (scopes.length == oldScopesLength);
649
660
return b;
@@ -658,7 +669,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
658
669
* are serialized first.
659
670
*
660
671
* If [serializeBodyExpr] is `true` , then the function definition is stored
661
- * in [UnlinkedExecutableBuilder.bodyExpr] .
672
+ * in [UnlinkedExecutableBuilder.bodyExpr] , and closures occurring inside
673
+ * [initializers] and [body] have their function bodies serialized as well.
662
674
*
663
675
* The return value is a map whose keys are the offsets of local function
664
676
* nodes representing closures inside [initializers] and [body] , and whose
@@ -679,10 +691,12 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
679
691
List <UnlinkedLabelBuilder > oldLabels = labels;
680
692
List <UnlinkedVariableBuilder > oldVariables = variables;
681
693
Map <int , int > oldLocalClosureIndexMap = _localClosureIndexMap;
694
+ bool oldSerializeClosureBodyExprs = _serializeClosureBodyExprs;
682
695
executables = < UnlinkedExecutableBuilder > [];
683
696
labels = < UnlinkedLabelBuilder > [];
684
697
variables = < UnlinkedVariableBuilder > [];
685
698
_localClosureIndexMap = < int , int > {};
699
+ _serializeClosureBodyExprs = serializeBodyExpr;
686
700
if (initializers != null ) {
687
701
for (ConstructorInitializer initializer in initializers) {
688
702
initializer.accept (this );
@@ -692,6 +706,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
692
706
if (serializeBodyExpr) {
693
707
if (body is Expression ) {
694
708
b.bodyExpr = serializeConstExpr (_localClosureIndexMap, body);
709
+ } else if (body is ExpressionFunctionBody ) {
710
+ b.bodyExpr = serializeConstExpr (_localClosureIndexMap, body.expression);
695
711
} else {
696
712
// TODO(paulberry): serialize other types of function bodies.
697
713
}
@@ -704,6 +720,7 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
704
720
labels = oldLabels;
705
721
variables = oldVariables;
706
722
_localClosureIndexMap = oldLocalClosureIndexMap;
723
+ _serializeClosureBodyExprs = oldSerializeClosureBodyExprs;
707
724
return localClosureIndexMap;
708
725
}
709
726
@@ -1158,7 +1175,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
1158
1175
node.documentationComment,
1159
1176
node.metadata,
1160
1177
node.functionExpression.typeParameters,
1161
- node.externalKeyword != null ));
1178
+ node.externalKeyword != null ,
1179
+ false ));
1162
1180
}
1163
1181
1164
1182
@override
@@ -1181,7 +1199,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
1181
1199
null ,
1182
1200
null ,
1183
1201
node.typeParameters,
1184
- false ));
1202
+ false ,
1203
+ _serializeClosureBodyExprs));
1185
1204
}
1186
1205
}
1187
1206
@@ -1280,7 +1299,8 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
1280
1299
node.documentationComment,
1281
1300
node.metadata,
1282
1301
node.typeParameters,
1283
- node.externalKeyword != null ));
1302
+ node.externalKeyword != null ,
1303
+ false ));
1284
1304
}
1285
1305
1286
1306
@override
0 commit comments