Skip to content

Commit aa00d48

Browse files
stereotype441Commit Queue
authored andcommitted
[flow analysis] Remove skipDuplicateCheck hack.
In https://dart-review.googlesource.com/c/sdk/+/278649, I added assertions to flow analysis to make sure that `FlowAnalysis.declare` wasn't called more times than necessary. To work around a few instance in which it _was_ being called more than necessary, I added a parameter `skipDuplicateCheck` that caused the assertion to be skipped. This change fixes the one remaining case in which skipping the check was necessary, by moving the CFE logic that calls `FlowAnalysis.declare` for formal parameters. Previously, this logic was in both `BodyBuilder.finishFunction` and `BodyBuilder.finishConstructor`, resulting in some duplication because `BodyBuilder.finishFunction` sometimes calls `BodyBuilder.finishConstructor`. I've moved the logic into a new method, `BodyBuilder._declareFormals`, which is called from `BodyBuilder.finishFunction` and `BodyBuilder.parseInitializers`, ensuring that the calls to `FlowAnalysis.declare` only occur once. Fixing this case allows the `skipDuplicateCheck` hack to be removed entirely. Note that there was also one place where the analyzer was also using `skipDuplicateCheck`, but it was doing so unnecessarily. Change-Id: Ic34d1b7120f05d94c53774d52eb90e4ada67415f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434261 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 758ff3a commit aa00d48

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,10 @@ class FlowAnalysisHelper {
245245
// a `FormalParameterListImpl`
246246
var declaredElement =
247247
parameter.declaredFragment!.element as PromotableElementImpl2;
248-
// TODO(paulberry): `skipDuplicateCheck` is currently needed to work
249-
// around a failure in duplicate_definition_test.dart; fix this.
250248
flow!.declare(
251249
declaredElement,
252250
SharedTypeView(declaredElement.type),
253251
initialized: true,
254-
skipDuplicateCheck: true,
255252
);
256253
}
257254
}

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

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,20 +1201,9 @@ class BodyBuilder extends StackListenerImpl
12011201
typeInferrer.assignedVariables.finish();
12021202

12031203
FunctionNode function = _context.function;
1204-
if (thisVariable != null) {
1205-
typeInferrer.flowAnalysis.declare(
1206-
thisVariable!, new SharedTypeView(thisVariable!.type),
1207-
initialized: true);
1208-
}
1204+
_declareFormals();
12091205
if (formals?.parameters != null) {
12101206
for (int i = 0; i < formals!.parameters!.length; i++) {
1211-
FormalParameterBuilder parameter = formals.parameters![i];
1212-
VariableDeclaration variable = parameter.variable!;
1213-
typeInferrer.flowAnalysis.declare(
1214-
variable, new SharedTypeView(variable.type),
1215-
initialized: true);
1216-
}
1217-
for (int i = 0; i < formals.parameters!.length; i++) {
12181207
FormalParameterBuilder parameter = formals.parameters![i];
12191208
Expression? initializer = parameter.variable!.initializer;
12201209
bool inferInitializer;
@@ -1705,10 +1694,11 @@ class BodyBuilder extends StackListenerImpl
17051694
}
17061695
if (doFinishConstructor) {
17071696
List<FormalParameterBuilder>? formals = _context.formals;
1697+
List<Object>? superParametersAsArguments =
1698+
formals != null ? createSuperParametersAsArguments(formals) : null;
1699+
_declareFormals();
17081700
finishConstructor(AsyncMarker.Sync, null,
1709-
superParametersAsArguments: formals != null
1710-
? createSuperParametersAsArguments(formals)
1711-
: null);
1701+
superParametersAsArguments: superParametersAsArguments);
17121702
}
17131703
return _initializers;
17141704
}
@@ -1755,6 +1745,26 @@ class BodyBuilder extends StackListenerImpl
17551745
return arguments;
17561746
}
17571747

1748+
void _declareFormals() {
1749+
if (thisVariable != null && _context.isConstructor) {
1750+
// `thisVariable` usually appears in `_context.formals`, but for a
1751+
// constructor, it doesn't. So declare it separately.
1752+
typeInferrer.flowAnalysis.declare(
1753+
thisVariable!, new SharedTypeView(thisVariable!.type),
1754+
initialized: true);
1755+
}
1756+
List<FormalParameterBuilder>? formals = _context.formals;
1757+
if (formals != null) {
1758+
for (int i = 0; i < formals.length; i++) {
1759+
FormalParameterBuilder parameter = formals[i];
1760+
VariableDeclaration variable = parameter.variable!;
1761+
typeInferrer.flowAnalysis.declare(
1762+
variable, new SharedTypeView(variable.type),
1763+
initialized: true);
1764+
}
1765+
}
1766+
}
1767+
17581768
void finishConstructor(AsyncMarker asyncModifier, Statement? body,
17591769
{required List<Object /* Expression | NamedExpression */ >?
17601770
superParametersAsArguments}) {
@@ -1800,24 +1810,11 @@ class BodyBuilder extends StackListenerImpl
18001810
"to be sorted by occurrence in file.");
18011811

18021812
FunctionNode function = _context.function;
1803-
List<FormalParameterBuilder>? formals = _context.formals;
1804-
if (formals != null) {
1805-
for (int i = 0; i < formals.length; i++) {
1806-
FormalParameterBuilder parameter = formals[i];
1807-
VariableDeclaration variable = parameter.variable!;
1808-
// TODO(paulberry): `skipDuplicateCheck` is currently needed to work
1809-
// around a failure in
1810-
// co19/Language/Expressions/Postfix_Expressions/conditional_increment_t02;
1811-
// fix this.
1812-
typeInferrer.flowAnalysis.declare(
1813-
variable, new SharedTypeView(variable.type),
1814-
initialized: true, skipDuplicateCheck: true);
1815-
}
1816-
}
18171813

18181814
Set<String>? namedSuperParameterNames;
18191815
List<Expression>? positionalSuperParametersAsArguments;
18201816
List<NamedExpression>? namedSuperParametersAsArguments;
1817+
List<FormalParameterBuilder>? formals = _context.formals;
18211818
if (superParametersAsArguments != null) {
18221819
for (Object superParameterAsArgument in superParametersAsArguments) {
18231820
if (superParameterAsArgument is Expression) {

0 commit comments

Comments
 (0)