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

Unified Diff: frog/leg/compile_time_constants.dart

Issue 9663068: Avoid cyclic computations in compile-time constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 | frog/leg/warnings.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/compile_time_constants.dart
diff --git a/frog/leg/compile_time_constants.dart b/frog/leg/compile_time_constants.dart
index 0d7f07d5e869fad06098f9036787dcbffa196064..bb3f67cedad55bca0fe1bd30f5ff9a2d9df2e4de 100644
--- a/frog/leg/compile_time_constants.dart
+++ b/frog/leg/compile_time_constants.dart
@@ -453,14 +453,18 @@ class ConstructedConstant extends ObjectConstant {
class ConstantHandler extends CompilerTask {
// Contains the initial value of fields. Must contain all static and global
// initializations of used fields. May contain caches for instance fields.
- final Map<VariableElement, Dynamic> initialVariableValues;
+ final Map<VariableElement, Constant> initialVariableValues;
// Map from compile-time constants to their JS name.
final Map<Constant, String> compiledConstants;
+ // The set of variable elements that are in the process of being computed.
+ final Set<VariableElement> pendingVariables;
+
ConstantHandler(Compiler compiler)
: initialVariableValues = new Map<VariableElement, Dynamic>(),
compiledConstants = new Map<Constant, String>(),
+ pendingVariables = new Set<Constant>(),
super(compiler);
String get name() => 'ConstantHandler';
@@ -483,6 +487,7 @@ class ConstantHandler extends CompilerTask {
// Shortcut if it has already been compiled.
if (initialVariableValues.containsKey(element)) return;
compileVariableWithDefinitions(element, work.resolutionTree);
+ assert(pendingVariables.isEmpty());
}
compileVariable(VariableElement element) {
@@ -508,10 +513,19 @@ class ConstantHandler extends CompilerTask {
// No initial value.
value = new NullConstant();
} else {
+ if (pendingVariables.contains(element)) {
+ MessageKind kind = MessageKind.CYCLIC_COMPILE_TIME_CONSTANTS;
+ compiler.reportError(node,
+ new CompileTimeConstantError(kind, const []));
+ }
+ pendingVariables.add(element);
+
Node right = assignment.arguments.head;
CompileTimeConstantEvaluator evaluator =
new CompileTimeConstantEvaluator(this, definitions, compiler);
value = evaluator.evaluate(right);
+
+ pendingVariables.remove(element);
}
initialVariableValues[element] = value;
return value;
« no previous file with comments | « no previous file | frog/leg/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698