Skip to content

Commit

Permalink
Flow analysis: inline _removePromotedAll at the call site.
Browse files Browse the repository at this point in the history
There was only one call site, and the logic is clearer if all the
logic is in one method.

Change-Id: I59a6e0ce1e3345039146525a9bcd0b72025cbb5d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115006
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Sep 4, 2019
1 parent c73df64 commit 39b60a6
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions pkg/front_end/lib/src/fasta/flow_analysis/flow_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,19 @@ class FlowModel<Variable, Type> {
/// be able to remove this method.
FlowModel<Variable, Type> removePromotedAll(
Iterable<Variable> variables, Set<Variable> referencedVariables) {
Map<Variable, VariableModel<Type>> newVariableInfo =
_removePromotedAll(variableInfo, variables, referencedVariables);

if (identical(newVariableInfo, variableInfo)) return this;

Map<Variable, VariableModel<Type>> newVariableInfo;
for (Variable variable in variables) {
assert(() {
referencedVariables?.add(variable);
return true;
}());
VariableModel<Type> info = variableInfo[variable];
if (info?.promotedType != null) {
(newVariableInfo ??= new Map<Variable, VariableModel<Type>>.from(
variableInfo))[variable] = info.withPromotedType(null);
}
}
if (newVariableInfo == null) return this;
return new FlowModel<Variable, Type>._(reachable, newVariableInfo);
}

Expand Down Expand Up @@ -971,34 +979,6 @@ class FlowModel<Variable, Type> {
return _updateVariableInfo(variable, newInfoForVar);
}

/// Updates a "variableInfo" [map] to indicate that a set of [variable] is no
/// longer promoted, treating the map as immutable.
///
/// If assertions are enabled and [referencedVariables] is not `null`, all
/// variables in [variables] will be stored in [referencedVariables] as a side
/// effect of this call.
Map<Variable, VariableModel<Type>> _removePromotedAll(
Map<Variable, VariableModel<Type>> map,
Iterable<Variable> variables,
Set<Variable> referencedVariables) {
if (map.isEmpty) return const {};
Map<Variable, VariableModel<Type>> result;
for (Variable variable in variables) {
assert(() {
referencedVariables?.add(variable);
return true;
}());
VariableModel<Type> info = map[variable];
if (info?.promotedType != null) {
(result ??=
new Map<Variable, VariableModel<Type>>.from(map))[variable] =
info.withPromotedType(null);
}
}
if (result == null) return map;
return result;
}

/// Returns a new [FlowModel] where the information for [variable] is replaced
/// with [model].
FlowModel<Variable, Type> _updateVariableInfo(
Expand Down

0 comments on commit 39b60a6

Please sign in to comment.