Skip to content

Commit 24c0507

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: remove the State.exit method.
It was redundant with State.setReachable(false), and it did not have the necessary logic to avoid creating State objects when unnecessary. Change-Id: If9e0b8b586dab0e681f4ee0bc7b792d49e1e5f4b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109897 Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 0a29936 commit 24c0507

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class FlowAnalysis<Statement, Expression, Variable, Type> {
327327
if (breakIndex != null) {
328328
_stack[breakIndex] = _join(_stack[breakIndex], _current);
329329
}
330-
_current = _current.exit();
330+
_current = _current.setReachable(false);
331331
}
332332

333333
void handleContinue(Statement target) {
@@ -336,13 +336,13 @@ class FlowAnalysis<Statement, Expression, Variable, Type> {
336336
var continueIndex = breakIndex + 1;
337337
_stack[continueIndex] = _join(_stack[continueIndex], _current);
338338
}
339-
_current = _current.exit();
339+
_current = _current.setReachable(false);
340340
}
341341

342342
/// Register the fact that the current state definitely exists, e.g. returns
343343
/// from the body, throws an exception, etc.
344344
void handleExit() {
345-
_current = _current.exit();
345+
_current = _current.setReachable(false);
346346
}
347347

348348
void ifNullExpression_end() {
@@ -756,15 +756,6 @@ class State<Variable, Type> {
756756
);
757757
}
758758

759-
/// Updates the state to indicate that the control flow path is unreachable.
760-
State<Variable, Type> exit() {
761-
return State<Variable, Type>._(
762-
false,
763-
notAssigned,
764-
promoted,
765-
);
766-
}
767-
768759
/// Updates the state to indicate that the given [variable] has been
769760
/// determined to contain a non-null value.
770761
///

pkg/analyzer/test/src/dart/resolution/flow_analysis_unit_test.dart

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ main() {
143143
});
144144
});
145145

146-
test('exit', () {
147-
var s1 = State<_Var, _Type>(true);
148-
var s2 = s1.exit();
149-
expect(s2.reachable, false);
150-
expect(s2.notAssigned, same(s1.notAssigned));
151-
expect(s2.promoted, same(s1.promoted));
152-
});
153-
154146
group('promote', () {
155147
test('unpromoted -> unchanged (same)', () {
156148
var h = _Harness();
@@ -327,7 +319,7 @@ main() {
327319
test('reachability', () {
328320
var h = _Harness();
329321
var reachable = State<_Var, _Type>(true);
330-
var unreachable = reachable.exit();
322+
var unreachable = reachable.setReachable(false);
331323
expect(reachable.restrict(h, emptySet, reachable, {}), same(reachable));
332324
expect(reachable.restrict(h, emptySet, unreachable, {}),
333325
same(unreachable));

0 commit comments

Comments
 (0)