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

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: 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 print("Pass 2 queue length: ${world.queue2.length}");
388 pass = 2;
389 while (!world.queue2.isEmpty()) {
390 WorkItem work = world.queue2.removeLast();
ricow1 2012/06/07 06:35:49 should we remove it from the set as well for consi
Søren Gjesse 2012/06/07 08:06:12 Done in the RecompilationQueue class.
391 var oldCode = world.universe.generatedCode[work.element];
392 world.universe.generatedCode.remove(work.element);
393 try {
394 withCurrentElement(work.element, () => work.run(this, world));
395 } catch (Pass2BailoutException ex) {
396 world.universe.generatedCode[work.element] = oldCode;
397 }
398 var newCode = world.universe.generatedCode[work.element];
399 if (newCode != oldCode) {
400 print("PASS 2 OPTIMIZATION:");
401 print("Before: $oldCode");
402 print("After: $newCode");
403 }
404 }
384 assert(world.checkNoEnqueuedInvokedInstanceMethods()); 405 assert(world.checkNoEnqueuedInvokedInstanceMethods());
385 world.registerFieldClosureInvocations(); 406 world.registerFieldClosureInvocations();
386 } 407 }
387 408
388 TreeElements analyzeElement(Element element) { 409 TreeElements analyzeElement(Element element) {
389 assert(parser !== null); 410 assert(parser !== null);
390 Node tree = parser.parse(element); 411 Node tree = parser.parse(element);
391 validator.validate(tree); 412 validator.validate(tree);
392 unparseValidator.check(element); 413 unparseValidator.check(element);
393 TreeElements elements = resolver.resolve(element); 414 TreeElements elements = resolver.resolve(element);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 if (message is TypeWarning) { 477 if (message is TypeWarning) {
457 // TODO(ahe): Don't supress these warning when the type checker 478 // TODO(ahe): Don't supress these warning when the type checker
458 // is more complete. 479 // is more complete.
459 if (message.message.kind === MessageKind.NOT_ASSIGNABLE) return; 480 if (message.message.kind === MessageKind.NOT_ASSIGNABLE) return;
460 if (message.message.kind === MessageKind.MISSING_RETURN) return; 481 if (message.message.kind === MessageKind.MISSING_RETURN) return;
461 if (message.message.kind === MessageKind.MAYBE_MISSING_RETURN) return; 482 if (message.message.kind === MessageKind.MAYBE_MISSING_RETURN) return;
462 if (message.message.kind === MessageKind.ADDITIONAL_ARGUMENT) return; 483 if (message.message.kind === MessageKind.ADDITIONAL_ARGUMENT) return;
463 if (message.message.kind === MessageKind.METHOD_NOT_FOUND) return; 484 if (message.message.kind === MessageKind.METHOD_NOT_FOUND) return;
464 } 485 }
465 SourceSpan span = spanFromNode(node); 486 SourceSpan span = spanFromNode(node);
487
466 reportDiagnostic(span, "${magenta('warning:')} $message", false); 488 reportDiagnostic(span, "${magenta('warning:')} $message", false);
467 } 489 }
468 490
469 reportError(Node node, var message) { 491 reportError(Node node, var message) {
470 SourceSpan span = spanFromNode(node); 492 SourceSpan span = spanFromNode(node);
471 reportDiagnostic(span, "${red('error:')} $message", true); 493 reportDiagnostic(span, "${red('error:')} $message", true);
472 throw new CompilerCancelledException(message.toString()); 494 throw new CompilerCancelledException(message.toString());
473 } 495 }
474 496
475 abstract void reportDiagnostic(SourceSpan span, String message, bool fatal); 497 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 { 575 class CompilerCancelledException implements Exception {
554 final String reason; 576 final String reason;
555 CompilerCancelledException(this.reason); 577 CompilerCancelledException(this.reason);
556 578
557 String toString() { 579 String toString() {
558 String banner = 'compiler cancelled'; 580 String banner = 'compiler cancelled';
559 return (reason !== null) ? '$banner: $reason' : '$banner'; 581 return (reason !== null) ? '$banner: $reason' : '$banner';
560 } 582 }
561 } 583 }
562 584
585 class Pass2BailoutException implements Exception {
586 final String reason;
587 Pass2BailoutException(this.reason);
588
589 String toString() {
590 return 'Pass 2 not supported: $reason';
591 }
592 }
593
563 class Tracer { 594 class Tracer {
564 final bool enabled = false; 595 final bool enabled = false;
565 596
566 const Tracer(); 597 const Tracer();
567 598
568 void traceCompilation(String methodName) { 599 void traceCompilation(String methodName) {
569 } 600 }
570 601
571 void traceGraph(String name, var graph) { 602 void traceGraph(String name, var graph) {
572 } 603 }
(...skipping 17 matching lines...) Expand all
590 // invariant that endOffset > beginOffset, but for EOF the 621 // invariant that endOffset > beginOffset, but for EOF the
591 // charoffset of the next token may be [beginOffset]. This can 622 // charoffset of the next token may be [beginOffset]. This can
592 // also happen for synthetized tokens that are produced during 623 // also happen for synthetized tokens that are produced during
593 // error handling. 624 // error handling.
594 final endOffset = 625 final endOffset =
595 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); 626 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1);
596 assert(endOffset > beginOffset); 627 assert(endOffset > beginOffset);
597 return f(beginOffset, endOffset); 628 return f(beginOffset, endOffset);
598 } 629 }
599 } 630 }
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