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

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: Rebase + status file 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
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 954bbb322b098ba6952a00c43ccdf123fbcf4c38..a62a69c033750fd13729f460e51c01d20b52df6c 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,26 @@ 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, read its value from the
+ // receiver object.
+ 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
@@ -2767,12 +2772,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;
-}
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698