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

Unified Diff: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 25478009: Handle compile-time constness for conditionals and type literal calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
diff --git a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
index 5bd59db5216150fb77a0aa3f6521d83d655e815e..a7a608bdf509e7b8eb534eb2bbc450f2118dee97 100644
--- a/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
+++ b/sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
@@ -91,9 +91,6 @@ class ConstantHandler extends CompilerTask {
TreeElements definitions,
{bool isConst: false}) {
return measure(() {
- // Initializers for parameters must be const.
- isConst = isConst || element.modifiers.isConst()
- || !Elements.isStaticOrTopLevel(element);
if (!isConst && lazyStatics.contains(element)) return null;
Node node = element.parseNode(compiler);
@@ -151,9 +148,17 @@ class ConstantHandler extends CompilerTask {
{bool isConst: false}) {
return measure(() {
assert(node != null);
+ Constant constant = definitions.getConstant(node);
+ if (constant != null) {
+ return constant;
+ }
CompileTimeConstantEvaluator evaluator = new CompileTimeConstantEvaluator(
this, definitions, compiler, isConst: isConst);
- return evaluator.evaluate(node);
+ constant = evaluator.evaluate(node);
+ if (constant != null) {
+ definitions.setConstant(node, constant);
+ }
+ return constant;
});
}
@@ -419,6 +424,7 @@ class CompileTimeConstantEvaluator extends Visitor {
}
if (result != null) return result;
} else if (Elements.isClass(element) || Elements.isTypedef(element)) {
+ assert(elements.isTypeLiteral(send));
return makeTypeConstant(element);
} else if (send.receiver != null) {
// Fall through to error handling.
@@ -437,7 +443,10 @@ class CompileTimeConstantEvaluator extends Visitor {
Constant result = constantSystem.identity.fold(left, right);
if (result != null) return result;
} else if (Elements.isClass(element) || Elements.isTypedef(element)) {
- return makeTypeConstant(element);
+ // The node itself is not a constant but we register the selector (the
+ // identifier that refers to the class/typedef) as a constant.
+ Constant typeConstant = makeTypeConstant(element);
+ elements.setConstant(send.selector, typeConstant);
}
return signalNotCompileTimeConstant(send);
} else if (send.isPrefix) {
@@ -555,6 +564,17 @@ class CompileTimeConstantEvaluator extends Visitor {
return signalNotCompileTimeConstant(send);
}
+ Constant visitConditional(Conditional node) {
+ Constant condition = evaluate(node.condition);
+ if (condition == null || !condition.isBool()) {
+ return signalNotCompileTimeConstant(node);
ngeoffray 2013/10/02 10:44:43 IF condition is not bool, we might want a differen
Johnni Winther 2013/10/02 12:39:33 Done.
+ }
+ Constant thenExpression = evaluate(node.thenExpression);
+ Constant elseExpression = evaluate(node.elseExpression);
ngeoffray 2013/10/02 10:44:43 IS evaluating both expressions a requirement from
Johnni Winther 2013/10/02 12:39:33 We don't need to evaluate them but we need to chec
+ BoolConstant boolCondition = condition;
+ return boolCondition.value ? thenExpression : elseExpression;
+ }
+
Constant visitSendSet(SendSet node) {
return signalNotCompileTimeConstant(node);
}

Powered by Google App Engine
This is Rietveld 408576698