Flow analysis: clean up public method call to functionExpression_begin.

In a future CL, I plan to refactor some of the flow analysis API so
that the CFE can supply subexpressions to flow analysis before they
are lowered, rather than after. This should help reduce the risk of
bugs where lowering leads to type promotion being lost
(e.g. https://github.com/dart-lang/sdk/issues/52183).

The refactor I'm planning will be easier if there are no calls to the
flow analysis API within flow analysis itself, so to prepare for it,
this CL moves the body of `FlowAnalysisImpl.functionExpression_begin`
to a private method, and updates both `functionExpression_begin` and
`lateInitializer_begin` (which use the same underlying logic) to call
that private method.

Bug: https://github.com/dart-lang/sdk/issues/52189
Change-Id: I1185418225b8a402670e6eece6599c326fdc234a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309440
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Paul Berry 2023-06-16 10:18:05 +00:00 committed by Commit Queue
parent 1912fcc50b
commit 788a3a95c2

View file

@ -4149,11 +4149,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
@override
void functionExpression_begin(Node node) {
AssignedVariablesNodeInfo info = _assignedVariables.getInfoForNode(node);
_current = _current.conservativeJoin(const [], info.written);
_stack.add(new _FunctionExpressionContext(_current));
_current = _current.conservativeJoin(_assignedVariables.anywhere.written,
_assignedVariables.anywhere.captured);
_functionExpression_begin(node);
}
@override
@ -4368,7 +4364,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
// `late x = LAZY_MAGIC(() => expr);` (where `LAZY_MAGIC` creates a lazy
// evaluation thunk that gets replaced by the result of `expr` once it is
// evaluated).
functionExpression_begin(node);
_functionExpression_begin(node);
}
@override
@ -5033,6 +5029,14 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
}
}
void _functionExpression_begin(Node node) {
AssignedVariablesNodeInfo info = _assignedVariables.getInfoForNode(node);
_current = _current.conservativeJoin(const [], info.written);
_stack.add(new _FunctionExpressionContext(_current));
_current = _current.conservativeJoin(_assignedVariables.anywhere.written,
_assignedVariables.anywhere.captured);
}
void _functionExpression_end() {
_SimpleContext<Type> context =
_stack.removeLast() as _FunctionExpressionContext<Type>;