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

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

Issue 1636193002: Store-forwarding for ReadTypeVariable (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/type_propagation.dart
diff --git a/pkg/compiler/lib/src/cps_ir/type_propagation.dart b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
index 62776671f9bc33a71596702f6c7440018d32b12c..f1944ce5a88217e7debaaf8622e8ea196496396e 100644
--- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart
+++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart
@@ -2275,6 +2275,44 @@ class TransformingVisitor extends DeepRecursiveVisitor {
}
return null;
}
+
+ visitReadTypeVariable(ReadTypeVariable node) {
+ // Pattern match on
+ //
+ // ReadTypeVariable(var, CreateInstance(..., TypeExpression(arguments)))
+ //
+ // and extract the argument that corresponds to the type variable. This is a
+ // shrinking reduction.
+ //
+ // TODO(sra): This is a shrinking reduction that does not depend on inferred
+ // types so it should be done in the shrinking reductions pass.
+ //
+ // TODO(sra): A non-shrinking version of this rewrite could be done as part
+ // of scalar replacement.
+
+ if (node.target.definition is CreateInstance) {
+ CreateInstance instance = node.target.definition;
+ if (instance.typeInformation != null &&
+ instance.typeInformation.definition is TypeExpression) {
+ TypeExpression typeExpression = instance.typeInformation.definition;
+ assert(typeExpression.kind == TypeExpressionKind.INSTANCE);
+ ClassElement context = node.variable.element.enclosingClass;
+ // In the general case, a substitution could generate a large type
+ // term. Avoid this by restricting to direct indexing.
+ // TODO(sra): Also include cases that require substitution but the end
+ // result is the same as some indexing or a simple constant type.
+ if (!functionCompiler.glue.needsSubstitutionForTypeVariableAccess(
+ context)) {
+ int index = functionCompiler.glue.getTypeVariableIndex(node.variable);
+ if (0 <= index && index < typeExpression.arguments.length) {
+ node.replaceUsesWith(typeExpression.arguments[index].definition);
+ return new CpsFragment();
+ }
+ }
+ }
+ }
+ return null;
+ }
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698