mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 11:18:49 +00:00
Renamed some scoping classes to make their usage clearer.
BUG= R=sra@google.com Review-Url: https://codereview.chromium.org/2975323002 .
This commit is contained in:
parent
9f059e58b4
commit
45c57c8859
|
@ -53,10 +53,11 @@ abstract class ClosureDataLookup<T> {
|
|||
|
||||
/// Look up information about a loop, in case any variables it declares need
|
||||
/// to be boxed/snapshotted.
|
||||
LoopClosureScope getLoopClosureScope(T loopNode);
|
||||
CapturedLoopScope getCapturedLoopScope(T loopNode);
|
||||
|
||||
/// Accessor to the information about closures that the SSA builder will use.
|
||||
ClosureScope getClosureScope(MemberEntity entity);
|
||||
/// Accessor to the information about scopes that closures capture. Used by
|
||||
/// the SSA builder.
|
||||
CapturedScope getCapturedScope(MemberEntity entity);
|
||||
}
|
||||
|
||||
/// Class that represents one level of scoping information, whether this scope
|
||||
|
@ -105,8 +106,8 @@ class ScopeInfo {
|
|||
|
||||
/// Class representing the usage of a scope that has been captured in the
|
||||
/// context of a closure.
|
||||
class ClosureScope extends ScopeInfo {
|
||||
const ClosureScope();
|
||||
class CapturedScope extends ScopeInfo {
|
||||
const CapturedScope();
|
||||
|
||||
/// If true, this closure accesses a variable that was defined in an outside
|
||||
/// scope and this variable gets modified at some point (sometimes we say that
|
||||
|
@ -137,8 +138,8 @@ class ClosureScope extends ScopeInfo {
|
|||
/// the result would be [5, 5, 5, 5, 5]. Because of this difference we need to
|
||||
/// create a closure for these sorts of loops to capture the variable's value at
|
||||
/// each iteration, by boxing the iteration variable[s].
|
||||
class LoopClosureScope extends ClosureScope {
|
||||
const LoopClosureScope();
|
||||
class CapturedLoopScope extends CapturedScope {
|
||||
const CapturedLoopScope();
|
||||
|
||||
/// True if this loop scope declares in the first part of the loop
|
||||
/// `for (<here>;...;...)` any variables that need to be boxed.
|
||||
|
@ -251,7 +252,7 @@ class ClosureRepresentationInfo extends ScopeInfo {
|
|||
}
|
||||
|
||||
class ClosureTask extends ClosureConversionTask<Node> {
|
||||
Map<Node, ClosureScopeImpl> _closureInfoMap = <Node, ClosureScopeImpl>{};
|
||||
Map<Node, CapturedScopeImpl> _closureInfoMap = <Node, CapturedScopeImpl>{};
|
||||
Map<Element, ClosureClassMap> _closureMappingCache =
|
||||
<Element, ClosureClassMap>{};
|
||||
Compiler compiler;
|
||||
|
@ -268,15 +269,16 @@ class ClosureTask extends ClosureConversionTask<Node> {
|
|||
createClosureClasses(closedWorldRefiner);
|
||||
}
|
||||
|
||||
ClosureScope _getClosureScope(Node node) {
|
||||
CapturedScope _getCapturedScope(Node node) {
|
||||
var value = _closureInfoMap[node];
|
||||
return value == null ? const ClosureScope() : value;
|
||||
return value == null ? const CapturedScope() : value;
|
||||
}
|
||||
|
||||
ClosureScope getClosureScope(covariant MemberElement member) {
|
||||
CapturedScope getCapturedScope(covariant MemberElement member) {
|
||||
ResolvedAst resolvedAst = member.resolvedAst;
|
||||
if (resolvedAst.kind != ResolvedAstKind.PARSED) return const ClosureScope();
|
||||
return _getClosureScope(resolvedAst.node);
|
||||
if (resolvedAst.kind != ResolvedAstKind.PARSED)
|
||||
return const CapturedScope();
|
||||
return _getCapturedScope(resolvedAst.node);
|
||||
}
|
||||
|
||||
ScopeInfo getScopeInfo(Element member) {
|
||||
|
@ -287,9 +289,9 @@ class ClosureTask extends ClosureConversionTask<Node> {
|
|||
return getClosureToClassMapping(member);
|
||||
}
|
||||
|
||||
LoopClosureScope getLoopClosureScope(Node loopNode) {
|
||||
CapturedLoopScope getCapturedLoopScope(Node loopNode) {
|
||||
var value = _closureInfoMap[loopNode];
|
||||
return value == null ? const LoopClosureScope() : value;
|
||||
return value == null ? const CapturedLoopScope() : value;
|
||||
}
|
||||
|
||||
/// Returns the [ClosureClassMap] computed for [resolvedAst].
|
||||
|
@ -655,7 +657,7 @@ class SynthesizedCallMethodElementX extends BaseFunctionElementX
|
|||
|
||||
// The box-element for a scope, and the captured variables that need to be
|
||||
// stored in the box.
|
||||
class ClosureScopeImpl implements ClosureScope, LoopClosureScope {
|
||||
class CapturedScopeImpl implements CapturedScope, CapturedLoopScope {
|
||||
final BoxLocal boxElement;
|
||||
final Map<Local, BoxFieldElement> capturedVariables;
|
||||
|
||||
|
@ -664,7 +666,7 @@ class ClosureScopeImpl implements ClosureScope, LoopClosureScope {
|
|||
// Otherwise contains the empty List.
|
||||
List<Local> boxedLoopVariables = const <Local>[];
|
||||
|
||||
ClosureScopeImpl(this.boxElement, this.capturedVariables);
|
||||
CapturedScopeImpl(this.boxElement, this.capturedVariables);
|
||||
|
||||
Local get context => boxElement;
|
||||
|
||||
|
@ -687,16 +689,16 @@ class ClosureScopeImpl implements ClosureScope, LoopClosureScope {
|
|||
|
||||
// Should not be called. Added to make the new interface happy.
|
||||
bool localIsUsedInTryOrSync(Local variable) =>
|
||||
throw new UnsupportedError("ClosureScopeImpl.localIsUsedInTryOrSync");
|
||||
throw new UnsupportedError("CapturedScopeImpl.localIsUsedInTryOrSync");
|
||||
|
||||
// Should not be called. Added to make the new interface happy.
|
||||
Local get thisLocal =>
|
||||
throw new UnsupportedError("ClosureScopeImpl.thisLocal");
|
||||
throw new UnsupportedError("CapturedScopeImpl.thisLocal");
|
||||
|
||||
String toString() {
|
||||
String separator = '';
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.write('ClosureScopeImpl(');
|
||||
sb.write('CapturedScopeImpl(');
|
||||
if (boxElement != null) {
|
||||
sb.write('box=$boxElement');
|
||||
separator = ',';
|
||||
|
@ -740,12 +742,12 @@ class ClosureClassMap implements ClosureRepresentationInfo {
|
|||
/// their locations.
|
||||
final Map<Local, FieldEntity> freeVariableMap = new Map<Local, FieldEntity>();
|
||||
|
||||
/// Maps [Loop] and [FunctionExpression] nodes to their [ClosureScopeImpl] which
|
||||
/// Maps [Loop] and [FunctionExpression] nodes to their [CapturedScopeImpl] which
|
||||
/// contains their box and the captured variables that are stored in the box.
|
||||
/// This map will be empty if the method/closure of this [ClosureData] does
|
||||
/// not contain any nested closure.
|
||||
final Map<Node, ClosureScopeImpl> capturingScopes =
|
||||
new Map<Node, ClosureScopeImpl>();
|
||||
final Map<Node, CapturedScopeImpl> capturingScopes =
|
||||
new Map<Node, CapturedScopeImpl>();
|
||||
|
||||
/// Set of [variable]s referenced in this scope that are used inside a
|
||||
/// `try` block or a `sync*` generator (this is important to know because
|
||||
|
@ -816,7 +818,7 @@ class ClosureClassMap implements ClosureRepresentationInfo {
|
|||
if (variable is BoxLocal) return;
|
||||
f(variable, copy);
|
||||
});
|
||||
capturingScopes.values.forEach((ClosureScopeImpl scope) {
|
||||
capturingScopes.values.forEach((CapturedScopeImpl scope) {
|
||||
scope.forEachCapturedVariable(f);
|
||||
});
|
||||
}
|
||||
|
@ -827,7 +829,7 @@ class ClosureClassMap implements ClosureRepresentationInfo {
|
|||
if (!isVariableBoxed(variable)) return;
|
||||
f(variable, copy);
|
||||
});
|
||||
capturingScopes.values.forEach((ClosureScopeImpl scope) {
|
||||
capturingScopes.values.forEach((CapturedScopeImpl scope) {
|
||||
scope.forEachCapturedVariable(f);
|
||||
});
|
||||
}
|
||||
|
@ -850,7 +852,7 @@ class ClosureTranslator extends Visitor {
|
|||
bool inTryStatement = false;
|
||||
|
||||
final Map<Element, ClosureClassMap> closureMappingCache;
|
||||
final Map<Node, ClosureScopeImpl> closureInfo;
|
||||
final Map<Node, CapturedScopeImpl> closureInfo;
|
||||
|
||||
// Map of captured variables. Initially they will map to `null`. If
|
||||
// a variable needs to be boxed then the scope declaring the variable
|
||||
|
@ -1261,7 +1263,7 @@ class ClosureTranslator extends Visitor {
|
|||
boxCapturedVariable(variable);
|
||||
}
|
||||
if (!scopeMapping.isEmpty) {
|
||||
ClosureScopeImpl scope = new ClosureScopeImpl(box, scopeMapping);
|
||||
CapturedScopeImpl scope = new CapturedScopeImpl(box, scopeMapping);
|
||||
closureData.capturingScopes[node] = scope;
|
||||
assert(closureInfo[node] == null);
|
||||
closureInfo[node] = scope;
|
||||
|
@ -1326,7 +1328,7 @@ class ClosureTranslator extends Visitor {
|
|||
}
|
||||
}
|
||||
});
|
||||
ClosureScopeImpl scopeData = closureData.capturingScopes[node];
|
||||
CapturedScopeImpl scopeData = closureData.capturingScopes[node];
|
||||
if (scopeData == null) return;
|
||||
scopeData.boxedLoopVariables = boxedLoopVariables;
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ class KernelClosureConversionTask extends ClosureConversionTask<ir.Node> {
|
|||
|
||||
/// Map of the scoping information that corresponds to a particular entity.
|
||||
Map<Entity, ScopeInfo> _scopeMap = <Entity, ScopeInfo>{};
|
||||
Map<ir.Node, ClosureScope> _scopesCapturedInClosureMap =
|
||||
<ir.Node, ClosureScope>{};
|
||||
Map<ir.Node, CapturedScope> _scopesCapturedInClosureMap =
|
||||
<ir.Node, CapturedScope>{};
|
||||
|
||||
Map<Entity, ClosureRepresentationInfo> _closureRepresentationMap =
|
||||
<Entity, ClosureRepresentationInfo>{};
|
||||
|
@ -88,7 +88,7 @@ class KernelClosureConversionTask extends ClosureConversionTask<ir.Node> {
|
|||
if (_scopeMap.keys.contains(entity)) return;
|
||||
ir.Node node = _elementMap.getMemberNode(entity);
|
||||
if (_scopesCapturedInClosureMap.keys.contains(node)) return;
|
||||
ClosureScopeBuilder translator = new ClosureScopeBuilder(
|
||||
CapturedScopeBuilder translator = new CapturedScopeBuilder(
|
||||
_scopesCapturedInClosureMap,
|
||||
_scopeMap,
|
||||
entity,
|
||||
|
@ -153,15 +153,15 @@ class KernelClosureConversionTask extends ClosureConversionTask<ir.Node> {
|
|||
// TODO(efortuna): Eventually scopesCapturedInClosureMap[node] should always
|
||||
// be non-null, and we should just test that with an assert.
|
||||
@override
|
||||
ClosureScope getClosureScope(MemberEntity entity) =>
|
||||
CapturedScope getCapturedScope(MemberEntity entity) =>
|
||||
_scopesCapturedInClosureMap[_elementMap.getMemberNode(entity)] ??
|
||||
const ClosureScope();
|
||||
const CapturedScope();
|
||||
|
||||
@override
|
||||
// TODO(efortuna): Eventually scopesCapturedInClosureMap[node] should always
|
||||
// be non-null, and we should just test that with an assert.
|
||||
LoopClosureScope getLoopClosureScope(ir.Node loopNode) =>
|
||||
_scopesCapturedInClosureMap[loopNode] ?? const LoopClosureScope();
|
||||
CapturedLoopScope getCapturedLoopScope(ir.Node loopNode) =>
|
||||
_scopesCapturedInClosureMap[loopNode] ?? const CapturedLoopScope();
|
||||
|
||||
@override
|
||||
// TODO(efortuna): Eventually closureRepresentationMap[node] should always be
|
||||
|
@ -212,20 +212,20 @@ class KernelScopeInfo extends ScopeInfo {
|
|||
bool isBoxed(Local variable) => boxedVariables.contains(variable);
|
||||
}
|
||||
|
||||
class KernelClosureScope extends KernelScopeInfo implements ClosureScope {
|
||||
class KernelCapturedScope extends KernelScopeInfo implements CapturedScope {
|
||||
final Local context;
|
||||
|
||||
KernelClosureScope(Set<Local> boxedVariables, this.context, Local thisLocal)
|
||||
KernelCapturedScope(Set<Local> boxedVariables, this.context, Local thisLocal)
|
||||
: super.withBoxedVariables(boxedVariables, thisLocal);
|
||||
|
||||
bool get requiresContextBox => boxedVariables.isNotEmpty;
|
||||
}
|
||||
|
||||
class KernelLoopClosureScope extends KernelClosureScope
|
||||
implements LoopClosureScope {
|
||||
class KernelCapturedLoopScope extends KernelCapturedScope
|
||||
implements CapturedLoopScope {
|
||||
final List<Local> boxedLoopVariables;
|
||||
|
||||
KernelLoopClosureScope(Set<Local> boxedVariables, this.boxedLoopVariables,
|
||||
KernelCapturedLoopScope(Set<Local> boxedVariables, this.boxedLoopVariables,
|
||||
Local context, Local thisLocal)
|
||||
: super(boxedVariables, context, thisLocal);
|
||||
|
||||
|
|
|
@ -10,14 +10,14 @@ import '../kernel/element_map.dart';
|
|||
import 'closure.dart';
|
||||
|
||||
/// This builder walks the code to determine what variables are captured/free at
|
||||
/// various points to build ClosureScope that can respond to queries
|
||||
/// various points to build CapturedScope that can respond to queries
|
||||
/// about how a particular variable is being used at any point in the code.
|
||||
class ClosureScopeBuilder extends ir.Visitor {
|
||||
class CapturedScopeBuilder extends ir.Visitor {
|
||||
/// A map of each visited call node with the associated information about what
|
||||
/// variables are captured/used. Each ir.Node key corresponds to a scope that
|
||||
/// was encountered while visiting a closure (initially called through
|
||||
/// [translateLazyIntializer] or [translateConstructorOrProcedure]).
|
||||
final Map<ir.Node, ClosureScope> _scopesCapturedInClosureMap;
|
||||
final Map<ir.Node, CapturedScope> _scopesCapturedInClosureMap;
|
||||
|
||||
/// Map entities to their corresponding scope information (such as what
|
||||
/// variables are captured/used).
|
||||
|
@ -69,7 +69,7 @@ class ClosureScopeBuilder extends ir.Visitor {
|
|||
/// scope information.
|
||||
final Entity _originalEntity;
|
||||
|
||||
ClosureScopeBuilder(
|
||||
CapturedScopeBuilder(
|
||||
this._scopesCapturedInClosureMap,
|
||||
this._scopeInfoMap,
|
||||
this._originalEntity,
|
||||
|
@ -77,7 +77,7 @@ class ClosureScopeBuilder extends ir.Visitor {
|
|||
this._localsMap,
|
||||
this._kernelToElementMap);
|
||||
|
||||
/// Update the [ClosureScope] object corresponding to
|
||||
/// Update the [CapturedScope] object corresponding to
|
||||
/// this node if any variables are captured.
|
||||
void attachCapturedScopeVariables(ir.Node node) {
|
||||
Set<Local> capturedVariablesForScope = new Set<Local>();
|
||||
|
@ -103,7 +103,7 @@ class ClosureScopeBuilder extends ir.Visitor {
|
|||
}
|
||||
|
||||
assert(_scopeInfoMap[_nodeToEntity(node)] != null);
|
||||
_scopesCapturedInClosureMap[node] = new KernelClosureScope(
|
||||
_scopesCapturedInClosureMap[node] = new KernelCapturedScope(
|
||||
capturedVariablesForScope,
|
||||
_nodeToEntity(_executableContext),
|
||||
thisLocal);
|
||||
|
@ -215,9 +215,9 @@ class ClosureScopeBuilder extends ir.Visitor {
|
|||
}
|
||||
}
|
||||
});
|
||||
KernelClosureScope scope = _scopesCapturedInClosureMap[node];
|
||||
KernelCapturedScope scope = _scopesCapturedInClosureMap[node];
|
||||
if (scope == null) return;
|
||||
_scopesCapturedInClosureMap[node] = new KernelLoopClosureScope(
|
||||
_scopesCapturedInClosureMap[node] = new KernelCapturedLoopScope(
|
||||
scope.boxedVariables,
|
||||
boxedLoopVariables,
|
||||
scope.context,
|
||||
|
|
|
@ -132,9 +132,9 @@ class KernelToLocalsMapImpl implements KernelToLocalsMap {
|
|||
}
|
||||
|
||||
@override
|
||||
LoopClosureScope getLoopClosureScope(
|
||||
CapturedLoopScope getCapturedLoopScope(
|
||||
ClosureDataLookup closureLookup, ir.TreeNode node) {
|
||||
return closureLookup.getLoopClosureScope(node);
|
||||
return closureLookup.getCapturedLoopScope(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -315,8 +315,9 @@ abstract class KernelToLocalsMap {
|
|||
/// if [node] is not a jump target.
|
||||
JumpTarget getJumpTargetForWhile(ir.WhileStatement node);
|
||||
|
||||
/// Returns the [LoopClosureScope] for the loop [node] in [closureClassMaps].
|
||||
LoopClosureScope getLoopClosureScope(
|
||||
/// Returns the [CapturedLoopScope] for the loop [node] in
|
||||
/// [closureClassMaps].
|
||||
CapturedLoopScope getCapturedLoopScope(
|
||||
ClosureDataLookup closureLookup, ir.TreeNode node);
|
||||
}
|
||||
|
||||
|
|
|
@ -1011,7 +1011,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
ScopeInfo newScopeInfo = closureDataLookup.getScopeInfo(callee);
|
||||
localsHandler.scopeInfo = newScopeInfo;
|
||||
if (resolvedAst.kind == ResolvedAstKind.PARSED) {
|
||||
localsHandler.enterScope(closureDataLookup.getClosureScope(callee),
|
||||
localsHandler.enterScope(closureDataLookup.getCapturedScope(callee),
|
||||
forGenerativeConstructorBody: callee.isGenerativeConstructorBody);
|
||||
}
|
||||
buildInitializers(callee, constructorResolvedAsts, fieldValues);
|
||||
|
@ -1366,7 +1366,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
// If there are locals that escape (ie mutated in closures), we
|
||||
// pass the box to the constructor.
|
||||
// The box must be passed before any type variable.
|
||||
ClosureScope scopeData = closureDataLookup.getClosureScope(constructor);
|
||||
CapturedScope scopeData = closureDataLookup.getCapturedScope(constructor);
|
||||
if (scopeData.requiresContextBox) {
|
||||
bodyCallInputs.add(localsHandler.readLocal(scopeData.context));
|
||||
}
|
||||
|
@ -1427,7 +1427,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
localsHandler.startFunction(
|
||||
element,
|
||||
closureDataLookup.getScopeInfo(element),
|
||||
closureDataLookup.getClosureScope(element),
|
||||
closureDataLookup.getCapturedScope(element),
|
||||
parameters,
|
||||
isGenerativeConstructorBody: element.isGenerativeConstructorBody);
|
||||
close(new HGoto()).addSuccessor(block);
|
||||
|
@ -1461,7 +1461,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
ParameterElement parameterElement = _parameterElement;
|
||||
if (element.isGenerativeConstructorBody) {
|
||||
if (closureDataLookup
|
||||
.getClosureScope(element)
|
||||
.getCapturedScope(element)
|
||||
.isBoxed(parameterElement)) {
|
||||
// The parameter will be a field in the box passed as the
|
||||
// last parameter. So no need to have it.
|
||||
|
@ -1705,7 +1705,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
|
||||
loopHandler.handleLoop(
|
||||
node,
|
||||
closureDataLookup.getLoopClosureScope(node),
|
||||
closureDataLookup.getCapturedLoopScope(node),
|
||||
elements.getTargetDefinition(node),
|
||||
buildInitializer,
|
||||
buildCondition,
|
||||
|
@ -1720,7 +1720,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
return popBoolified();
|
||||
}
|
||||
|
||||
loopHandler.handleLoop(node, closureDataLookup.getLoopClosureScope(node),
|
||||
loopHandler.handleLoop(node, closureDataLookup.getCapturedLoopScope(node),
|
||||
elements.getTargetDefinition(node), () {}, buildCondition, () {}, () {
|
||||
visit(node.body);
|
||||
});
|
||||
|
@ -1729,7 +1729,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
visitDoWhile(ast.DoWhile node) {
|
||||
assert(isReachable);
|
||||
LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
|
||||
var loopClosureInfo = closureDataLookup.getLoopClosureScope(node);
|
||||
var loopClosureInfo = closureDataLookup.getCapturedLoopScope(node);
|
||||
localsHandler.startLoop(loopClosureInfo);
|
||||
loopDepth++;
|
||||
JumpTarget target = elements.getTargetDefinition(node);
|
||||
|
@ -5439,7 +5439,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
buildProtectedByFinally(() {
|
||||
loopHandler.handleLoop(
|
||||
node,
|
||||
closureDataLookup.getLoopClosureScope(node),
|
||||
closureDataLookup.getCapturedLoopScope(node),
|
||||
elements.getTargetDefinition(node),
|
||||
buildInitializer,
|
||||
buildCondition,
|
||||
|
@ -5512,7 +5512,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
|
||||
loopHandler.handleLoop(
|
||||
node,
|
||||
closureDataLookup.getLoopClosureScope(node),
|
||||
closureDataLookup.getCapturedLoopScope(node),
|
||||
elements.getTargetDefinition(node),
|
||||
buildInitializer,
|
||||
buildCondition,
|
||||
|
@ -5637,7 +5637,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
|
||||
loopHandler.handleLoop(
|
||||
node,
|
||||
closureDataLookup.getLoopClosureScope(node),
|
||||
closureDataLookup.getCapturedLoopScope(node),
|
||||
elements.getTargetDefinition(node),
|
||||
buildInitializer,
|
||||
buildCondition,
|
||||
|
@ -5992,7 +5992,7 @@ class SsaAstGraphBuilder extends ast.Visitor
|
|||
}
|
||||
|
||||
void buildLoop() {
|
||||
loopHandler.handleLoop(node, closureDataLookup.getLoopClosureScope(node),
|
||||
loopHandler.handleLoop(node, closureDataLookup.getCapturedLoopScope(node),
|
||||
switchTarget, () {}, buildCondition, () {}, buildSwitch);
|
||||
}
|
||||
|
||||
|
|
|
@ -345,8 +345,8 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
|
||||
// If there are locals that escape (i.e. mutated in closures), we pass the
|
||||
// box to the constructor.
|
||||
ClosureScope scopeData =
|
||||
closureDataLookup.getClosureScope(constructorElement);
|
||||
CapturedScope scopeData =
|
||||
closureDataLookup.getCapturedScope(constructorElement);
|
||||
if (scopeData.requiresContextBox) {
|
||||
bodyCallInputs.add(localsHandler.readLocal(scopeData.context));
|
||||
}
|
||||
|
@ -608,7 +608,7 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
ScopeInfo oldScopeInfo = localsHandler.scopeInfo;
|
||||
ScopeInfo newScopeInfo = closureDataLookup.getScopeInfo(element);
|
||||
localsHandler.scopeInfo = newScopeInfo;
|
||||
localsHandler.enterScope(closureDataLookup.getClosureScope(element));
|
||||
localsHandler.enterScope(closureDataLookup.getCapturedScope(element));
|
||||
inlinedFrom(element, () {
|
||||
_buildInitializers(constructor, constructorChain, fieldValues);
|
||||
});
|
||||
|
@ -696,7 +696,7 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
localsHandler.startFunction(
|
||||
targetElement,
|
||||
closureDataLookup.getScopeInfo(targetElement),
|
||||
closureDataLookup.getClosureScope(targetElement),
|
||||
closureDataLookup.getCapturedScope(targetElement),
|
||||
parameterMap,
|
||||
isGenerativeConstructorBody: targetElement is ConstructorBodyEntity);
|
||||
close(new HGoto()).addSuccessor(block);
|
||||
|
@ -893,7 +893,7 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
JumpTarget jumpTarget = localsMap.getJumpTargetForFor(forStatement);
|
||||
loopHandler.handleLoop(
|
||||
forStatement,
|
||||
localsMap.getLoopClosureScope(closureDataLookup, forStatement),
|
||||
localsMap.getCapturedLoopScope(closureDataLookup, forStatement),
|
||||
jumpTarget,
|
||||
buildInitializer,
|
||||
buildCondition,
|
||||
|
@ -1022,7 +1022,7 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
|
||||
loopHandler.handleLoop(
|
||||
forInStatement,
|
||||
localsMap.getLoopClosureScope(closureDataLookup, forInStatement),
|
||||
localsMap.getCapturedLoopScope(closureDataLookup, forInStatement),
|
||||
localsMap.getJumpTargetForForIn(forInStatement),
|
||||
buildInitializer,
|
||||
buildCondition,
|
||||
|
@ -1073,7 +1073,7 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
|
||||
loopHandler.handleLoop(
|
||||
forInStatement,
|
||||
localsMap.getLoopClosureScope(closureDataLookup, forInStatement),
|
||||
localsMap.getCapturedLoopScope(closureDataLookup, forInStatement),
|
||||
localsMap.getJumpTargetForForIn(forInStatement),
|
||||
buildInitializer,
|
||||
buildCondition,
|
||||
|
@ -1120,7 +1120,7 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
// Build fake try body:
|
||||
loopHandler.handleLoop(
|
||||
forInStatement,
|
||||
localsMap.getLoopClosureScope(closureDataLookup, forInStatement),
|
||||
localsMap.getCapturedLoopScope(closureDataLookup, forInStatement),
|
||||
localsMap.getJumpTargetForForIn(forInStatement),
|
||||
buildInitializer,
|
||||
buildCondition,
|
||||
|
@ -1171,7 +1171,7 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
|
||||
loopHandler.handleLoop(
|
||||
whileStatement,
|
||||
localsMap.getLoopClosureScope(closureDataLookup, whileStatement),
|
||||
localsMap.getCapturedLoopScope(closureDataLookup, whileStatement),
|
||||
localsMap.getJumpTargetForWhile(whileStatement),
|
||||
() {},
|
||||
buildCondition,
|
||||
|
@ -1185,8 +1185,8 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
// TODO(efortuna): I think this can be rewritten using
|
||||
// LoopHandler.handleLoop with some tricks about when the "update" happens.
|
||||
LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
|
||||
LoopClosureScope loopClosureInfo =
|
||||
localsMap.getLoopClosureScope(closureDataLookup, doStatement);
|
||||
CapturedLoopScope loopClosureInfo =
|
||||
localsMap.getCapturedLoopScope(closureDataLookup, doStatement);
|
||||
localsHandler.startLoop(loopClosureInfo);
|
||||
JumpTarget target = localsMap.getJumpTargetForDo(doStatement);
|
||||
JumpHandler jumpHandler = loopHandler.beginLoopHeader(doStatement, target);
|
||||
|
@ -1724,7 +1724,7 @@ class KernelSsaGraphBuilder extends ir.Visitor
|
|||
void buildLoop() {
|
||||
loopHandler.handleLoop(
|
||||
switchStatement,
|
||||
localsMap.getLoopClosureScope(closureDataLookup, switchStatement),
|
||||
localsMap.getCapturedLoopScope(closureDataLookup, switchStatement),
|
||||
switchTarget,
|
||||
() {},
|
||||
buildCondition,
|
||||
|
|
|
@ -360,9 +360,9 @@ class KernelAstAdapter extends KernelToElementMapBaseMixin
|
|||
}
|
||||
|
||||
@override
|
||||
LoopClosureScope getLoopClosureScope(
|
||||
CapturedLoopScope getCapturedLoopScope(
|
||||
ClosureDataLookup closureLookup, ir.TreeNode node) {
|
||||
return closureLookup.getLoopClosureScope(getNode(node));
|
||||
return closureLookup.getCapturedLoopScope(getNode(node));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ class LocalsHandler {
|
|||
|
||||
/// If the scope (function or loop) [node] has captured variables then this
|
||||
/// method creates a box and sets up the redirections.
|
||||
void enterScope(ClosureScope closureInfo,
|
||||
void enterScope(CapturedScope closureInfo,
|
||||
{bool forGenerativeConstructorBody: false}) {
|
||||
// See if any variable in the top-scope of the function is captured. If yes
|
||||
// we need to create a box-object.
|
||||
|
@ -198,7 +198,7 @@ class LocalsHandler {
|
|||
///
|
||||
/// Invariant: [function] must be an implementation element.
|
||||
void startFunction(MemberEntity element, ScopeInfo scopeInfo,
|
||||
ClosureScope scopeData, Map<Local, TypeMask> parameters,
|
||||
CapturedScope scopeData, Map<Local, TypeMask> parameters,
|
||||
{bool isGenerativeConstructorBody}) {
|
||||
assert(!(element is MemberElement && !element.isImplementation),
|
||||
failedAt(element));
|
||||
|
@ -476,7 +476,7 @@ class LocalsHandler {
|
|||
/// <updates>
|
||||
/// goto loop-entry;
|
||||
/// loop-exit:
|
||||
void startLoop(LoopClosureScope loopInfo) {
|
||||
void startLoop(CapturedLoopScope loopInfo) {
|
||||
if (loopInfo.hasBoxedLoopVariables) {
|
||||
// If there are boxed loop variables then we set up the box and
|
||||
// redirections already now. This way the initializer can write its
|
||||
|
@ -509,7 +509,7 @@ class LocalsHandler {
|
|||
});
|
||||
}
|
||||
|
||||
void enterLoopBody(LoopClosureScope loopInfo) {
|
||||
void enterLoopBody(CapturedLoopScope loopInfo) {
|
||||
// If there are no declared boxed loop variables then we did not create the
|
||||
// box before the initializer and we have to create the box now.
|
||||
if (!loopInfo.hasBoxedLoopVariables) {
|
||||
|
@ -517,7 +517,7 @@ class LocalsHandler {
|
|||
}
|
||||
}
|
||||
|
||||
void enterLoopUpdates(LoopClosureScope loopInfo) {
|
||||
void enterLoopUpdates(CapturedLoopScope loopInfo) {
|
||||
// If there are declared boxed loop variables then the updates might have
|
||||
// access to the box and we must switch to a new box before executing the
|
||||
// updates.
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import 'package:kernel/ast.dart' as ir;
|
||||
|
||||
import '../closure.dart' show LoopClosureScope;
|
||||
import '../closure.dart' show CapturedLoopScope;
|
||||
import '../elements/jumps.dart';
|
||||
import '../io/source_information.dart';
|
||||
import '../tree/tree.dart' as ast;
|
||||
|
@ -29,7 +29,7 @@ abstract class LoopHandler<T> {
|
|||
/// None of the functions must leave anything on the stack.
|
||||
void handleLoop(
|
||||
T loop,
|
||||
LoopClosureScope loopClosureInfo,
|
||||
CapturedLoopScope loopClosureInfo,
|
||||
JumpTarget jumpTarget,
|
||||
void initialize(),
|
||||
HInstruction condition(),
|
||||
|
|
|
@ -252,7 +252,7 @@ bool areCapturedVariablesEquivalent(FieldEntity a, FieldEntity b) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool areClosureScopesEquivalent(ClosureScope a, ClosureScope b) {
|
||||
bool areCapturedScopesEquivalent(CapturedScope a, CapturedScope b) {
|
||||
if (a == b) return true;
|
||||
if (a == null || b == null) return false;
|
||||
if (!areLocalsEquivalent(a.context, b.context)) {
|
||||
|
@ -265,7 +265,7 @@ bool areClosureScopesEquivalent(ClosureScope a, ClosureScope b) {
|
|||
a.forEachBoxedVariable((k, v) => aBoxed[k] = v);
|
||||
var bBoxed = {};
|
||||
b.forEachBoxedVariable((k, v) => bBoxed[k] = v);
|
||||
checkMaps(aBoxed, bBoxed, 'ClosureScope.boxedVariables', areLocalsEquivalent,
|
||||
checkMaps(aBoxed, bBoxed, 'CapturedScope.boxedVariables', areLocalsEquivalent,
|
||||
areElementsEquivalent);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue