Chromium Code Reviews| Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart |
| diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart |
| index 366f409a5402c530d03bb36588e4ee3a58807736..15f45f91e2cdf1dd1c871792d3457799c720830d 100644 |
| --- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart |
| +++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart |
| @@ -208,6 +208,30 @@ class IrBuilderDelimitedState { |
| abstract class IrBuilder { |
| IrBuilder _makeInstance(); |
| + /// A map from TryStatements in the AST to their analysis information. |
| + /// |
| + /// This include which variables should be copied into [ir.MutableVariable]s |
|
floitsch
2015/02/16 14:54:07
includes
Kevin Millikin (Google)
2015/02/24 11:59:24
Done.
|
| + /// on entry to the try and copied out on exit. |
| + Map<ast.TryStatement, TryStatementInfo> get tryStatements; |
|
asgerf
2015/02/20 10:10:07
I thought the IR builder was supposed to be indepe
Kevin Millikin (Google)
2015/02/24 11:59:24
Acknowledged.
|
| + |
| + /// The set of local variables that will spend their lifetime as |
| + /// [ir.MutableVariable]s due to being captured by a nested function. |
| + Set<Local> get mutableCapturedVariables; |
| + |
| + /// True if [local] should currently be accessed from a [ir.MutableVariable]. |
| + bool isInMutableVariable(Local local); |
| + |
| + /// Creates a [ir.MutableVariable] for the given local. |
| + void makeMutableVariable(Local local); |
| + |
| + /// Remove an [ir.MutableVariable] for a local. |
| + /// |
| + /// Subsequent access to the local will be direct rather than through the |
| + /// mutable variable. This is used for variables that do not spend their |
| + /// entire lifetime as mutable variables (e.g., variables that are boxed |
| + /// in mutable variables for a try block). |
| + void removeMutableVariable(Local local); |
| + |
| void declareLocalVariable(LocalVariableElement element, |
| {ir.Primitive initialValue}); |
| ir.Primitive buildLocalGet(LocalElement element); |
| @@ -1518,7 +1542,7 @@ class DartIrBuilderSharedState { |
| final Map<Local, ir.MutableVariable> local2mutable = |
| <Local, ir.MutableVariable>{}; |
| - final DartCapturedVariableInfo capturedVariables; |
| + final DartCapturedVariables capturedVariables; |
| /// Creates a [MutableVariable] for the given local. |
| void makeMutableVariable(Local local) { |
| @@ -1550,17 +1574,32 @@ class DartIrBuilder extends IrBuilder { |
| DartIrBuilder(ConstantSystem constantSystem, |
| ExecutableElement currentElement, |
| - DartCapturedVariableInfo capturedVariables) |
| + DartCapturedVariables capturedVariables) |
| : dartState = new DartIrBuilderSharedState(capturedVariables) { |
| _init(constantSystem, currentElement); |
| } |
| - /// True if [local] should currently be accessed from a [MutableVariable]. |
| + Map<ast.TryStatement, TryStatementInfo> get tryStatements { |
| + return dartState.capturedVariables.tryStatements; |
| + } |
| + |
| + Set<Local> get mutableCapturedVariables { |
| + return dartState.capturedVariables.capturedVariables; |
| + } |
| + |
| bool isInMutableVariable(Local local) { |
| return dartState.local2mutable.containsKey(local) && |
| !dartState.registerizedMutableVariables.contains(local); |
| } |
| + void makeMutableVariable(Local local) { |
| + dartState.makeMutableVariable(local); |
| + } |
| + |
| + void removeMutableVariable(Local local) { |
| + dartState.local2mutable.remove(local); |
| + } |
| + |
| /// Gets the [MutableVariable] containing the value of [local]. |
| ir.MutableVariable getMutableVariable(Local local) { |
| return dartState.local2mutable[local]; |
| @@ -1734,6 +1773,12 @@ class JsIrBuilder extends IrBuilder { |
| _init(constantSystem, currentElement); |
| } |
| + Map<ast.TryStatement, TryStatementInfo> get tryStatements => null; |
| + Set<Local> get mutableCapturedVariables => null; |
| + bool isInMutableVariable(Local local) => false; |
| + void makeMutableVariable(Local local) {} |
| + void removeMutableVariable(Local local) {} |
| + |
| void _enterClosureEnvironment(ClosureEnvironment env) { |
| if (env == null) return; |
| @@ -2007,10 +2052,32 @@ class ClosureEnvironment { |
| ClosureEnvironment(this.selfReference, this.thisLocal, this.freeVariables); |
| } |
| -/// Information about which variables are captured by a nested function. |
| -/// |
| -/// This is used by the [DartIrBuilder] instead of [ClosureScope] and |
| -/// [ClosureEnvironment]. |
| -abstract class DartCapturedVariableInfo { |
| - Iterable<Local> get capturedVariables; |
| +class TryStatementInfo { |
| + final TryStatementInfo parent; |
| + final List<TryStatementInfo> children = <TryStatementInfo>[]; |
| + final Set<LocalVariableElement> declared = new Set<LocalVariableElement>(); |
| + final Set<LocalVariableElement> boxedOnEntry = |
| + new Set<LocalVariableElement>(); |
| + |
| + TryStatementInfo(this.parent) { |
| + if (parent != null) parent.children.add(this); |
| + } |
| + |
| + void computeVariablesBoxedOnEntry(Set<LocalVariableElement> boxedInParent) { |
|
floitsch
2015/02/16 14:54:07
Comments.
At the very least mention that the argum
Kevin Millikin (Google)
2015/02/24 11:59:24
This whole approach is overly complicated. I've c
|
| + Set<LocalVariableElement> boxed = |
| + new Set<LocalVariableElement>.from(boxedOnEntry); |
| + if (boxedInParent != null) { |
| + // Initially, variables are marked as boxed on entry if they are assigned |
| + // in this try but not including variables assigned only in some nested |
|
floitsch
2015/02/16 14:54:07
I don't understand this comment.
|
| + // try. However, these do not have to be boxed if they are boxed in the |
| + // immediately enclosing try. |
|
asgerf
2015/02/20 10:10:07
I would remove the word "However" here.
|
| + boxedOnEntry.removeAll(boxedInParent); |
| + // Variables are boxed in this try if they are boxed in the immediately |
| + // enclosing try or boxed on entry to this try. |
|
floitsch
2015/02/16 14:54:07
The boxed-on-entry happens earlier. It's slightly
|
| + boxed.addAll(boxedInParent); |
| + } |
| + for (TryStatementInfo child in children) { |
| + child.computeVariablesBoxedOnEntry(boxed); |
| + } |
| + } |
| } |