Chromium Code Reviews| Index: lib/compiler/implementation/compiler.dart |
| diff --git a/lib/compiler/implementation/compiler.dart b/lib/compiler/implementation/compiler.dart |
| index 40d7b97c40c0c68ea1385cd7c99d8766951e3198..b8f08d9d9423ed6926d86a6f26b3172074ac186b 100644 |
| --- a/lib/compiler/implementation/compiler.dart |
| +++ b/lib/compiler/implementation/compiler.dart |
| @@ -29,7 +29,6 @@ const bool DUMP_INFERRED_TYPES = false; |
| */ |
| const String BUILD_ID = 'build number could not be determined'; |
| - |
| /** |
| * Contains backend-specific data that is used throughout the compilation of |
| * one work item. |
| @@ -39,12 +38,19 @@ class ItemCompilationContext { |
| class WorkItem { |
| final ItemCompilationContext compilationContext; |
| + /** |
| + * Documentation wanted -- johnniwinther |
| + * |
| + * Invariant: [element] must be an declaration element. |
|
ngeoffray
2012/09/20 11:38:37
an -> a
Johnni Winther
2012/09/21 09:18:25
Done.
|
| + */ |
| final Element element; |
| TreeElements resolutionTree; |
| bool allowSpeculativeOptimization = true; |
| List<HTypeGuard> guards = const <HTypeGuard>[]; |
| - WorkItem(this.element, this.resolutionTree, this.compilationContext); |
| + WorkItem(this.element, this.resolutionTree, this.compilationContext) { |
| + assert(invariant(element, element.isDeclaration)); |
| + } |
| bool isAnalyzed() => resolutionTree !== null; |
| @@ -608,11 +614,12 @@ class Compiler implements DiagnosticListener { |
| assert(phase == PHASE_RECOMPILING); |
| while (!world.recompilationCandidates.isEmpty()) { |
| WorkItem work = world.recompilationCandidates.next(); |
| - CodeBuffer oldCode = world.universe.generatedCode[work.element]; |
| - world.universe.generatedCode.remove(work.element); |
| - world.universe.generatedBailoutCode.remove(work.element); |
| - withCurrentElement(work.element, () => work.run(this, world)); |
| - CodeBuffer newCode = world.universe.generatedCode[work.element]; |
| + Element element = work.element; |
| + CodeBuffer oldCode = world.universe.generatedCode[element]; |
| + world.universe.generatedCode.remove(element); |
| + world.universe.generatedBailoutCode.remove(element); |
| + withCurrentElement(element, () => work.run(this, world)); |
| + CodeBuffer newCode = world.universe.generatedCode[element]; |
| if (REPORT_PASS2_OPTIMIZATIONS && newCode != oldCode) { |
| log("Pass 2 optimization:"); |
| log("Before:\n$oldCode"); |
| @@ -670,6 +677,7 @@ class Compiler implements DiagnosticListener { |
| } |
| TreeElements analyzeElement(Element element) { |
| + assert(invariant(element, element.isDeclaration)); |
| TreeElements elements = enqueuer.resolution.getCachedElements(element); |
| if (elements !== null) return elements; |
| final int allowed = ElementCategory.VARIABLE | ElementCategory.FUNCTION |
| @@ -713,6 +721,7 @@ class Compiler implements DiagnosticListener { |
| 'Internal error: unresolved element: $element.'); |
| } |
| result = analyzeElement(element); |
| + assert(invariant(element, element.isDeclaration)); |
| enqueuer.resolution.resolvedElements[element] = result; |
| return result; |
| } |
| @@ -950,3 +959,19 @@ class SourceSpan { |
| String toString() => 'SourceSpan($uri, $begin, $end)'; |
| } |
| + |
| +/** |
| + * Throws an [InvariantException] if [condition] is [:false:]. |
| + * |
| + * Use this method to provide better information for assertion by calling |
| + * [invariant] as the argument to an [:assert:] statement: |
| + * |
| + * assert(invariant(position, isValid)); |
| + * |
| + * [spanable] must be non-null and will be used to provide positional |
| + * information in the generated error message. |
| + */ |
| +// TODO(johnniwinther): Use [spanable] and [message] to provide better |
| +// information on assertion errors. |
| +bool invariant(Spanable spanable, bool condition, {String message: null}) => |
|
ahe
2012/09/20 11:12:07
Please don't use => shorthand when it doesn't fit
Johnni Winther
2012/09/21 09:18:25
Done.
|
| + spanable != null && condition; |