Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 1158693003: dart2js cps: Change how type variables are accessed in constructors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 717bc066de9e57009f9b8ca12f1e1c682cae61b2..54144d0aeee518bb0a9e92832fa40017a8a239c3 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart
@@ -111,6 +111,8 @@ class Environment {
}
return true;
}
+
+ bool contains(Local local) => variable2index.containsKey(local);
}
/// The abstract base class of objects that emit jumps to a continuation and
@@ -2634,23 +2636,25 @@ class JsIrBuilder extends IrBuilder {
/// corresponding type argument (field initializers are evaluated before the
/// receiver object is created).
ir.Primitive buildTypeVariableAccess(TypeVariableType variable) {
- ir.Parameter accessTypeArgumentParameter() {
- for (int i = 0; i < environment.length; i++) {
- Local local = environment.index2variable[i];
- if (local is TypeInformationParameter &&
- local.variable == variable.element) {
- return environment.index2value[i];
- }
- }
- throw 'unable to find constructor parameter for type variable $variable.';
+ // If the local exists in the environment, use that.
+ // This is put here when we are inside a constructor or field initializer,
+ // (or possibly a closure inside one of these).
+ Local local = new TypeVariableLocal(variable, state.currentElement);
+ if (environment.contains(local)) {
+ return environment.lookup(local);
}
- if (jsState.inInitializers) {
- return accessTypeArgumentParameter();
- } else {
- ir.Primitive target = buildThis();
- return addPrimitive(new ir.ReadTypeVariable(variable, target));
- }
+ // If the type variable is not in a local, access it one the receiver.
karlklose 2015/05/28 08:12:19 'access it one the receiver' -> 'read the value fr
asgerf 2015/05/28 09:34:21 Done.
+ ir.Primitive target = buildThis();
+ return addPrimitive(new ir.ReadTypeVariable(variable, target));
+ }
+
+ /// Make the given type variable accessible through the local environment
+ /// with the value of [binding].
+ void declareTypeVariable(TypeVariableType variable, DartType binding) {
+ environment.extend(
+ new TypeVariableLocal(variable, state.currentElement),
+ buildTypeExpression(binding));
}
@override
@@ -2764,12 +2768,3 @@ class CatchClauseInfo {
this.stackTraceVariable,
this.buildCatchBlock});
}
-
-/// Synthetic parameter to a JavaScript factory method that takes the type
-/// argument given for the type variable [variable].
-class TypeInformationParameter implements Local {
- final TypeVariableElement variable;
- final ExecutableElement executableContext;
- TypeInformationParameter(this.variable, this.executableContext);
- String get name => variable.name;
-}

Powered by Google App Engine
This is Rietveld 408576698