Improve resolution/codegen separation invariant.

BUG=
R=asgerf@google.com

Review URL: https://codereview.chromium.org//1126163002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45593 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
johnniwinther@google.com 2015-05-07 13:30:05 +00:00
parent 654c4b4675
commit f238761664
3 changed files with 23 additions and 8 deletions

View file

@ -25,6 +25,7 @@ abstract class WorkItem {
* Invariant: [element] must be a declaration element.
*/
final AstElement element;
TreeElements get resolutionTree;
WorkItem(this.element, this.compilationContext) {
@ -186,16 +187,30 @@ class CodegenRegistry extends Registry {
/// [WorkItem] used exclusively by the [CodegenEnqueuer].
class CodegenWorkItem extends WorkItem {
Registry registry;
final TreeElements resolutionTree;
CodegenWorkItem(AstElement element,
ItemCompilationContext compilationContext)
: this.resolutionTree = element.resolvedAst.elements,
super(element, compilationContext) {
assert(invariant(element, resolutionTree != null,
factory CodegenWorkItem(
Compiler compiler,
AstElement element,
ItemCompilationContext compilationContext) {
// If this assertion fails, the resolution callbacks of the backend may be
// missing call of form registry.registerXXX. Alternatively, the code
// generation could spuriously be adding dependencies on things we know we
// don't need.
assert(invariant(element,
compiler.enqueuer.resolution.hasBeenResolved(element),
message: "$element has not been resolved."));
assert(invariant(element, element.resolvedAst.elements != null,
message: 'Resolution tree is null for $element in codegen work item'));
return new CodegenWorkItem.internal(element, compilationContext);
}
CodegenWorkItem.internal(
AstElement element,
ItemCompilationContext compilationContext)
: super(element, compilationContext);
TreeElements get resolutionTree => element.resolvedAst.elements;
void run(Compiler compiler, CodegenEnqueuer world) {
if (world.isProcessed(element)) return;

View file

@ -853,7 +853,7 @@ class CodegenEnqueuer extends Enqueuer {
"Codegen work list is closed. Trying to add $element");
}
CodegenWorkItem workItem = new CodegenWorkItem(
element, itemCompilationContextCreator());
compiler, element, itemCompilationContextCreator());
queue.add(workItem);
return true;
}

View file

@ -75,7 +75,7 @@ Future<String> compile(String code,
new leg.ResolutionWorkItem(element, context);
resolutionWork.run(compiler, compiler.enqueuer.resolution);
leg.CodegenWorkItem work =
new leg.CodegenWorkItem(element, context);
new leg.CodegenWorkItem(compiler, element, context);
compiler.phase = Compiler.PHASE_COMPILING;
work.run(compiler, compiler.enqueuer.codegen);
js.JavaScriptBackend backend = compiler.backend;