Skip to content

Commit 22c0137

Browse files
johnniwintherCommit Queue
authored and
Commit Queue
committed
[cfe] Inline set literal and collection transformations in inference visitor
Change-Id: Iaf3a3a9fd288757280071701461e40057ba7e79d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270000 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]>
1 parent 6ab608a commit 22c0137

11 files changed

+1214
-1408
lines changed

pkg/front_end/lib/src/fasta/builder/formal_parameter_builder.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,6 @@ class FormalParameterBuilder extends ModifierBuilderImpl
262262
initializer = bodyBuilder.typeInferrer.inferParameterInitializer(
263263
bodyBuilder, initializer, variable!.type, hasDeclaredInitializer);
264264
variable!.initializer = initializer..parent = variable;
265-
library.loader.transformPostInference(
266-
variable!,
267-
bodyBuilder.transformSetLiterals,
268-
bodyBuilder.transformCollections,
269-
library.library);
270265
initializerWasInferred = true;
271266
bodyBuilder.performBacklogComputations(
272267
delayedActionPerformers: delayedActionPerformers,

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,6 @@ class BodyBuilder extends StackListenerImpl
276276

277277
int functionNestingLevel = 0;
278278

279-
// Set when a spread element is encountered in a collection so the collection
280-
// needs to be desugared after type inference.
281-
bool transformCollections = false;
282-
283-
// Set by type inference when a set literal is encountered that needs to be
284-
// transformed because the backend target does not support set literals.
285-
bool transformSetLiterals = false;
286-
287279
Statement? problemInLoopOrSwitch;
288280

289281
Scope? switchScope;
@@ -806,8 +798,6 @@ class BodyBuilder extends StackListenerImpl
806798
void inferAnnotations(TreeNode? parent, List<Expression>? annotations) {
807799
if (annotations != null) {
808800
typeInferrer.inferMetadata(this, parent, annotations);
809-
libraryBuilder.loader.transformListPostInference(annotations,
810-
transformSetLiterals, transformCollections, libraryBuilder.library);
811801
}
812802
}
813803

@@ -1007,18 +997,6 @@ class BodyBuilder extends StackListenerImpl
1007997
initializer = typeInferrer
1008998
.inferFieldInitializer(this, fieldBuilder.builtType, initializer)
1009999
.expression;
1010-
1011-
if (transformCollections || transformSetLiterals) {
1012-
// Wrap the initializer in a temporary parent expression; the
1013-
// transformations need a parent relation.
1014-
Not wrapper = new Not(initializer);
1015-
libraryBuilder.loader.transformPostInference(
1016-
wrapper,
1017-
transformSetLiterals,
1018-
transformCollections,
1019-
libraryBuilder.library);
1020-
initializer = wrapper.operand;
1021-
}
10221000
fieldBuilder.buildBody(coreTypes, initializer);
10231001
}
10241002
} else if (!fieldBuilder.hasBodyBeenBuilt) {
@@ -1299,11 +1277,6 @@ class BodyBuilder extends StackListenerImpl
12991277
originParameter.type,
13001278
parameter.hasDeclaredInitializer);
13011279
originParameter.initializer = initializer..parent = originParameter;
1302-
libraryBuilder.loader.transformPostInference(
1303-
originParameter,
1304-
transformSetLiterals,
1305-
transformCollections,
1306-
libraryBuilder.library);
13071280
}
13081281

13091282
VariableDeclaration? tearOffParameter =
@@ -1313,11 +1286,6 @@ class BodyBuilder extends StackListenerImpl
13131286
_cloner.cloneInContext(initializer!);
13141287
tearOffParameter.initializer = tearOffInitializer
13151288
..parent = tearOffParameter;
1316-
libraryBuilder.loader.transformPostInference(
1317-
tearOffParameter,
1318-
transformSetLiterals,
1319-
transformCollections,
1320-
libraryBuilder.library);
13211289
}
13221290
}
13231291
}
@@ -1348,8 +1316,6 @@ class BodyBuilder extends StackListenerImpl
13481316
!(builder.function.asyncMarker == AsyncMarker.Async &&
13491317
builder.function.futureValueType == null),
13501318
"No future value type computed.");
1351-
libraryBuilder.loader.transformPostInference(body, transformSetLiterals,
1352-
transformCollections, libraryBuilder.library);
13531319
}
13541320

13551321
if (builder.returnType is! OmittedTypeBuilder) {
@@ -1846,8 +1812,6 @@ class BodyBuilder extends StackListenerImpl
18461812
"not returning anything different.");
18471813

18481814
performBacklogComputations(allowFurtherDelays: false);
1849-
libraryBuilder.loader.transformPostInference(fakeReturn,
1850-
transformSetLiterals, transformCollections, libraryBuilder.library);
18511815

18521816
return fakeReturn.expression!;
18531817
}
@@ -2164,8 +2128,6 @@ class BodyBuilder extends StackListenerImpl
21642128
}
21652129
}
21662130
setParents(constructor.initializers, constructor);
2167-
libraryBuilder.loader.transformListPostInference(constructor.initializers,
2168-
transformSetLiterals, transformCollections, libraryBuilder.library);
21692131
if (body == null) {
21702132
/// >If a generative constructor c is not a redirecting constructor
21712133
/// >and no body is provided, then c implicitly has an empty body {}.
@@ -3949,7 +3911,6 @@ class BodyBuilder extends StackListenerImpl
39493911
Object? variableOrExpression = pop();
39503912
exitLocalScope();
39513913

3952-
transformCollections = true;
39533914
List<VariableDeclaration> variables =
39543915
_buildForLoopVariableDeclarations(variableOrExpression)!;
39553916
typeInferrer.assignedVariables.pushNode(assignedVariablesNodeInfo);
@@ -6303,7 +6264,6 @@ class BodyBuilder extends StackListenerImpl
63036264
"Unexpected pattern in control flow if: ${condition.pattern}.");
63046265
Token ifToken = pop() as Token;
63056266

6306-
transformCollections = true;
63076267
TreeNode node;
63086268
if (entry is MapLiteralEntry) {
63096269
node = forest.createIfMapEntry(
@@ -6348,7 +6308,6 @@ class BodyBuilder extends StackListenerImpl
63486308
"Unexpected pattern in control flow if: ${condition.pattern}.");
63496309
Token ifToken = pop() as Token;
63506310

6351-
transformCollections = true;
63526311
TreeNode node;
63536312
if (thenEntry is MapLiteralEntry) {
63546313
if (elseEntry is MapLiteralEntry) {
@@ -6417,7 +6376,6 @@ class BodyBuilder extends StackListenerImpl
64176376
void handleSpreadExpression(Token spreadToken) {
64186377
debugEvent("SpreadExpression");
64196378
Object? expression = pop();
6420-
transformCollections = true;
64216379
push(forest.createSpreadElement(
64226380
offsetForToken(spreadToken), toValue(expression),
64236381
isNullAware: spreadToken.lexeme == '...?'));
@@ -6837,7 +6795,6 @@ class BodyBuilder extends StackListenerImpl
68376795
Object? lvalue = pop(); // lvalue
68386796
exitLocalScope();
68396797

6840-
transformCollections = true;
68416798
ForInElements elements =
68426799
_computeForInElements(forToken, inToken, lvalue, null);
68436800
typeInferrer.assignedVariables.pushNode(assignedVariablesNodeInfo);

pkg/front_end/lib/src/fasta/kernel/collections.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,6 @@ mixin ControlFlowMapEntry implements MapLiteralEntry {
463463

464464
@override
465465
String toStringInternal() => toText(defaultAstTextStrategy);
466-
467-
@override
468-
String toText(AstTextStrategy strategy) {
469-
AstPrinter state = new AstPrinter(strategy);
470-
toTextInternal(state);
471-
return state.getText();
472-
}
473466
}
474467

475468
/// A spread element in a map literal.
@@ -520,8 +513,9 @@ class SpreadMapEntry extends TreeNode with ControlFlowMapEntry {
520513
}
521514

522515
@override
523-
void toTextInternal(AstPrinter state) {
524-
// TODO(johnniwinther): Implement this.
516+
void toTextInternal(AstPrinter printer) {
517+
printer.write('...');
518+
expression.toTextInternal(printer);
525519
}
526520
}
527521

@@ -590,8 +584,15 @@ class IfMapEntry extends TreeNode with ControlFlowMapEntry {
590584
}
591585

592586
@override
593-
void toTextInternal(AstPrinter state) {
594-
// TODO(johnniwinther): Implement this.
587+
void toTextInternal(AstPrinter printer) {
588+
printer.write('if (');
589+
condition.toTextInternal(printer);
590+
printer.write(') ');
591+
then.toTextInternal(printer);
592+
if (otherwise != null) {
593+
printer.write(' else ');
594+
otherwise!.toTextInternal(printer);
595+
}
595596
}
596597
}
597598

0 commit comments

Comments
 (0)