Skip to content

Commit d4f3c02

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: Get rid of initialize and _freshVariableInfo.
The FlowModel._freshVariableInfo field was an optimization with dubious benefit (it avoided a single allocation when seeing a variable for the first time). And it is getting in the way of changes I have planned for dart-lang/language#1274 (which will require each fresh variable to be allocated different information). Removing FlowModel._freshVariableInfo means that now we have a call to VariableModel.fresh() whenever we see a variable for the first time, so we can take advantage of this to elimiate the VariableModel.initialize() method, and simply allocate the VariableModel in the initialized state when it's appropriate to do so. Change-Id: I4b6f7d004fff72eaa4025fdf79e9ca29a81d7f96 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174566 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent f6e4b77 commit d4f3c02

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,9 +1286,6 @@ class FlowModel<Variable, Type> {
12861286
/// variable that is no longer in scope.
12871287
final Map<Variable, VariableModel<Variable, Type> /*!*/ > variableInfo;
12881288

1289-
/// Variable model for variables that have never been seen before.
1290-
final VariableModel<Variable, Type> _freshVariableInfo;
1291-
12921289
/// The empty map, used to [join] variables.
12931290
final Map<Variable, VariableModel<Variable, Type>> _emptyVariableMap = {};
12941291

@@ -1302,8 +1299,7 @@ class FlowModel<Variable, Type> {
13021299
);
13031300

13041301
@visibleForTesting
1305-
FlowModel.withInfo(this.reachable, this.variableInfo)
1306-
: _freshVariableInfo = new VariableModel.fresh() {
1302+
FlowModel.withInfo(this.reachable, this.variableInfo) {
13071303
assert(reachable != null);
13081304
assert(() {
13091305
for (VariableModel<Variable, Type> value in variableInfo.values) {
@@ -1376,17 +1372,15 @@ class FlowModel<Variable, Type> {
13761372
/// A local variable is [initialized] if its declaration has an initializer.
13771373
/// A function parameter is always initialized, so [initialized] is `true`.
13781374
FlowModel<Variable, Type> declare(Variable variable, bool initialized) {
1379-
VariableModel<Variable, Type> newInfoForVar = _freshVariableInfo;
1380-
if (initialized) {
1381-
newInfoForVar = newInfoForVar.initialize();
1382-
}
1375+
VariableModel<Variable, Type> newInfoForVar =
1376+
new VariableModel.fresh(assigned: initialized);
13831377

13841378
return _updateVariableInfo(variable, newInfoForVar);
13851379
}
13861380

13871381
/// Gets the info for the given [variable], creating it if it doesn't exist.
13881382
VariableModel<Variable, Type> infoFor(Variable variable) =>
1389-
variableInfo[variable] ?? _freshVariableInfo;
1383+
variableInfo[variable] ?? new VariableModel.fresh();
13901384

13911385
/// Builds a [FlowModel] based on `this`, but extending the `tested` set to
13921386
/// include types from [other]. This is used at the bottom of certain kinds
@@ -2060,11 +2054,10 @@ class VariableModel<Variable, Type> {
20602054

20612055
/// Creates a [VariableModel] representing a variable that's never been seen
20622056
/// before.
2063-
VariableModel.fresh()
2057+
VariableModel.fresh({this.assigned = false})
20642058
: promotedTypes = null,
20652059
tested = const [],
2066-
assigned = false,
2067-
unassigned = true,
2060+
unassigned = !assigned,
20682061
writeCaptured = false;
20692062

20702063
/// Returns a new [VariableModel] in which any promotions present have been
@@ -2077,16 +2070,6 @@ class VariableModel<Variable, Type> {
20772070
null, tested, assigned, false, writeCaptured);
20782071
}
20792072

2080-
/// Returns a new [VariableModel] reflecting the fact that the variable was
2081-
/// just initialized.
2082-
VariableModel<Variable, Type> initialize() {
2083-
if (promotedTypes == null && tested.isEmpty && assigned && !unassigned) {
2084-
return this;
2085-
}
2086-
return new VariableModel<Variable, Type>(
2087-
null, const [], true, false, writeCaptured);
2088-
}
2089-
20902073
/// Returns an updated model reflect a control path that is known to have
20912074
/// previously passed through some [other] state. See [FlowModel.restrict]
20922075
/// for details.

0 commit comments

Comments
 (0)