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

Unified Diff: pkg/compiler/lib/src/ssa/optimize.dart

Issue 2263853002: Constant-fold type variable of constant value (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix type Created 4 years, 4 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/ssa/nodes.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/optimize.dart
diff --git a/pkg/compiler/lib/src/ssa/optimize.dart b/pkg/compiler/lib/src/ssa/optimize.dart
index 492b8c5a4ef587d3b3465756507c8f28ecd20df3..031922228f881912a882b621935a64d4a3312644 100644
--- a/pkg/compiler/lib/src/ssa/optimize.dart
+++ b/pkg/compiler/lib/src/ssa/optimize.dart
@@ -1036,6 +1036,44 @@ class SsaInstructionSimplifier extends HBaseVisitor
HInstruction visitOneShotInterceptor(HOneShotInterceptor node) {
return handleInterceptedCall(node);
}
+
+ HInstruction visitTypeInfoReadVariable(HTypeInfoReadVariable node) {
+ TypeVariableType variable = node.variable;
+ HInstruction object = node.object;
+
+ HInstruction finishGroundType(InterfaceType groundType) {
+ InterfaceType typeAtVariable =
+ groundType.asInstanceOf(variable.element.enclosingClass);
+ if (typeAtVariable != null) {
+ int index = variable.element.index;
+ DartType typeArgument = typeAtVariable.typeArguments[index];
+ HInstruction replacement = new HTypeInfoExpression(
+ TypeInfoExpressionKind.COMPLETE,
+ typeArgument,
+ const <HInstruction>[],
+ backend.dynamicType);
+ return replacement;
+ }
+ return node;
+ }
+
+ // Type variable evaluated in the context of a constant can be replaced with
+ // a ground term type.
+ if (object is HConstant) {
+ ConstantValue value = object.constant;
+ if (value is ConstructedConstantValue) {
+ return finishGroundType(value.type);
+ }
+ return node;
+ }
+
+ // TODO(sra): HTypeInfoReadVariable on an instance creation can be replaced
+ // with an input of the instance creation's HTypeInfoExpression (or a
+ // HTypeInfoExpression of an input). This would in effect store-forward the
+ // type parameters.
+
+ return node;
+ }
}
class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
« no previous file with comments | « pkg/compiler/lib/src/ssa/nodes.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698