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

Side by Side Diff: lib/compiler/implementation/compiler.dart

Issue 10537025: Prototype re-compiling methods in dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class WorkItem { 5 class WorkItem {
6 final Element element; 6 final Element element;
7 TreeElements resolutionTree; 7 TreeElements resolutionTree;
8 bool allowSpeculativeOptimization = true; 8 bool allowSpeculativeOptimization = true;
9 List<HTypeGuard> guards = const <HTypeGuard>[]; 9 List<HTypeGuard> guards = const <HTypeGuard>[];
10 10
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 ClassElement listClass; 104 ClassElement listClass;
105 105
106 Element get currentElement() => _currentElement; 106 Element get currentElement() => _currentElement;
107 withCurrentElement(Element element, f()) { 107 withCurrentElement(Element element, f()) {
108 Element old = currentElement; 108 Element old = currentElement;
109 _currentElement = element; 109 _currentElement = element;
110 try { 110 try {
111 return f(); 111 return f();
112 } catch (CompilerCancelledException ex) { 112 } catch (CompilerCancelledException ex) {
113 throw; 113 throw;
114 } catch (Pass2BailoutException ex) {
115 throw;
114 } catch (var ex) { 116 } catch (var ex) {
115 unhandledExceptionOnElement(element); 117 unhandledExceptionOnElement(element);
116 throw; 118 throw;
117 } finally { 119 } finally {
118 _currentElement = old; 120 _currentElement = old;
119 } 121 }
120 } 122 }
121 123
122 List<CompilerTask> tasks; 124 List<CompilerTask> tasks;
123 ScannerTask scanner; 125 ScannerTask scanner;
124 DietParserTask dietParser; 126 DietParserTask dietParser;
125 ParserTask parser; 127 ParserTask parser;
126 TreeValidatorTask validator; 128 TreeValidatorTask validator;
127 UnparseValidator unparseValidator; 129 UnparseValidator unparseValidator;
128 ResolverTask resolver; 130 ResolverTask resolver;
129 TypeCheckerTask checker; 131 TypeCheckerTask checker;
130 Backend backend; 132 Backend backend;
131 ConstantHandler constantHandler; 133 ConstantHandler constantHandler;
132 EnqueueTask enqueuer; 134 EnqueueTask enqueuer;
135 int pass = 1;
133 136
134 static final SourceString MAIN = const SourceString('main'); 137 static final SourceString MAIN = const SourceString('main');
135 static final SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod'); 138 static final SourceString NO_SUCH_METHOD = const SourceString('noSuchMethod');
136 static final SourceString NO_SUCH_METHOD_EXCEPTION = 139 static final SourceString NO_SUCH_METHOD_EXCEPTION =
137 const SourceString('NoSuchMethodException'); 140 const SourceString('NoSuchMethodException');
138 static final SourceString START_ROOT_ISOLATE = 141 static final SourceString START_ROOT_ISOLATE =
139 const SourceString('startRootIsolate'); 142 const SourceString('startRootIsolate');
140 bool enabledNoSuchMethod = false; 143 bool enabledNoSuchMethod = false;
141 144
142 Stopwatch codegenProgress; 145 Stopwatch codegenProgress;
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 377
375 processQueue(Enqueuer world, Element main) { 378 processQueue(Enqueuer world, Element main) {
376 backend.processNativeClasses(world, libraries.getValues()); 379 backend.processNativeClasses(world, libraries.getValues());
377 world.addToWorkList(main); 380 world.addToWorkList(main);
378 codegenProgress.reset(); 381 codegenProgress.reset();
379 while (!world.queue.isEmpty()) { 382 while (!world.queue.isEmpty()) {
380 WorkItem work = world.queue.removeLast(); 383 WorkItem work = world.queue.removeLast();
381 withCurrentElement(work.element, () => work.run(this, world)); 384 withCurrentElement(work.element, () => work.run(this, world));
382 } 385 }
383 world.queueIsClosed = true; 386 world.queueIsClosed = true;
387 log("Recompilation candidates queue length: "
388 "${world.recompilationCandidates.length}");
389 pass = 2;
390 while (!world.recompilationCandidates.isEmpty()) {
391 WorkItem work = world.recompilationCandidates.next();
392 var oldCode = world.universe.generatedCode[work.element];
393 world.universe.generatedCode.remove(work.element);
394 try {
395 withCurrentElement(work.element, () => work.run(this, world));
396 } catch (Pass2BailoutException ex) {
397 world.universe.generatedCode[work.element] = oldCode;
398 }
399 var newCode = world.universe.generatedCode[work.element];
400 if (newCode != oldCode) {
401 log("PASS 2 OPTIMIZATION:");
402 log("Before: $oldCode");
403 log("After: $newCode");
404 }
405 }
384 assert(world.checkNoEnqueuedInvokedInstanceMethods()); 406 assert(world.checkNoEnqueuedInvokedInstanceMethods());
385 world.registerFieldClosureInvocations(); 407 world.registerFieldClosureInvocations();
386 } 408 }
387 409
388 TreeElements analyzeElement(Element element) { 410 TreeElements analyzeElement(Element element) {
389 assert(parser !== null); 411 assert(parser !== null);
390 Node tree = parser.parse(element); 412 Node tree = parser.parse(element);
391 validator.validate(tree); 413 validator.validate(tree);
392 unparseValidator.check(element); 414 unparseValidator.check(element);
393 TreeElements elements = resolver.resolve(element); 415 TreeElements elements = resolver.resolve(element);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 if (message is TypeWarning) { 478 if (message is TypeWarning) {
457 // TODO(ahe): Don't supress these warning when the type checker 479 // TODO(ahe): Don't supress these warning when the type checker
458 // is more complete. 480 // is more complete.
459 if (message.message.kind === MessageKind.NOT_ASSIGNABLE) return; 481 if (message.message.kind === MessageKind.NOT_ASSIGNABLE) return;
460 if (message.message.kind === MessageKind.MISSING_RETURN) return; 482 if (message.message.kind === MessageKind.MISSING_RETURN) return;
461 if (message.message.kind === MessageKind.MAYBE_MISSING_RETURN) return; 483 if (message.message.kind === MessageKind.MAYBE_MISSING_RETURN) return;
462 if (message.message.kind === MessageKind.ADDITIONAL_ARGUMENT) return; 484 if (message.message.kind === MessageKind.ADDITIONAL_ARGUMENT) return;
463 if (message.message.kind === MessageKind.METHOD_NOT_FOUND) return; 485 if (message.message.kind === MessageKind.METHOD_NOT_FOUND) return;
464 } 486 }
465 SourceSpan span = spanFromNode(node); 487 SourceSpan span = spanFromNode(node);
488
466 reportDiagnostic(span, "${magenta('warning:')} $message", false); 489 reportDiagnostic(span, "${magenta('warning:')} $message", false);
467 } 490 }
468 491
469 reportError(Node node, var message) { 492 reportError(Node node, var message) {
470 SourceSpan span = spanFromNode(node); 493 SourceSpan span = spanFromNode(node);
471 reportDiagnostic(span, "${red('error:')} $message", true); 494 reportDiagnostic(span, "${red('error:')} $message", true);
472 throw new CompilerCancelledException(message.toString()); 495 throw new CompilerCancelledException(message.toString());
473 } 496 }
474 497
475 abstract void reportDiagnostic(SourceSpan span, String message, bool fatal); 498 abstract void reportDiagnostic(SourceSpan span, String message, bool fatal);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 class CompilerCancelledException implements Exception { 576 class CompilerCancelledException implements Exception {
554 final String reason; 577 final String reason;
555 CompilerCancelledException(this.reason); 578 CompilerCancelledException(this.reason);
556 579
557 String toString() { 580 String toString() {
558 String banner = 'compiler cancelled'; 581 String banner = 'compiler cancelled';
559 return (reason !== null) ? '$banner: $reason' : '$banner'; 582 return (reason !== null) ? '$banner: $reason' : '$banner';
560 } 583 }
561 } 584 }
562 585
586 class Pass2BailoutException implements Exception {
587 final String reason;
588 Pass2BailoutException(this.reason);
589
590 String toString() {
591 return 'Pass 2 not supported: $reason';
592 }
593 }
594
563 class Tracer { 595 class Tracer {
564 final bool enabled = false; 596 final bool enabled = false;
565 597
566 const Tracer(); 598 const Tracer();
567 599
568 void traceCompilation(String methodName) { 600 void traceCompilation(String methodName) {
569 } 601 }
570 602
571 void traceGraph(String name, var graph) { 603 void traceGraph(String name, var graph) {
572 } 604 }
(...skipping 17 matching lines...) Expand all
590 // invariant that endOffset > beginOffset, but for EOF the 622 // invariant that endOffset > beginOffset, but for EOF the
591 // charoffset of the next token may be [beginOffset]. This can 623 // charoffset of the next token may be [beginOffset]. This can
592 // also happen for synthetized tokens that are produced during 624 // also happen for synthetized tokens that are produced during
593 // error handling. 625 // error handling.
594 final endOffset = 626 final endOffset =
595 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); 627 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1);
596 assert(endOffset > beginOffset); 628 assert(endOffset > beginOffset);
597 return f(beginOffset, endOffset); 629 return f(beginOffset, endOffset);
598 } 630 }
599 } 631 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/enqueue.dart » ('j') | lib/compiler/implementation/enqueue.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698