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

Side by Side Diff: dart/pkg/dart2js_incremental/lib/library_updater.dart

Issue 738743002: Incremental compilation of added class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r41886 Created 6 years, 1 month 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library dart2js_incremental.library_updater; 5 library dart2js_incremental.library_updater;
6 6
7 import 'dart:async' show 7 import 'dart:async' show
8 Future; 8 Future;
9 9
10 import 'dart:convert' show 10 import 'dart:convert' show
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 221
222 return _failedUpdates.isEmpty; 222 return _failedUpdates.isEmpty;
223 } 223 }
224 224
225 bool canReuseAddedElement( 225 bool canReuseAddedElement(
226 PartialElement element, 226 PartialElement element,
227 ScopeContainerElement container) { 227 ScopeContainerElement container) {
228 if (element is PartialFunctionElement) { 228 if (element is PartialFunctionElement) {
229 addFunction(element, container); 229 addFunction(element, container);
230 return true; 230 return true;
231 } else if (element is PartialClassElement) {
232 addClass(element, container);
233 return true;
231 } 234 }
232 return cannotReuse(element, "Added element that isn't a function."); 235 return cannotReuse(element, "Added element that isn't a function.");
233 } 236 }
234 237
235 void addFunction( 238 void addFunction(
236 PartialFunctionElement element, 239 PartialFunctionElement element,
237 ScopeContainerElement container) { 240 ScopeContainerElement container) {
238 invalidateScopesAffectedBy(element, container); 241 invalidateScopesAffectedBy(element, container);
239 242
240 updates.add(new AddedFunctionUpdate(compiler, element, container)); 243 updates.add(new AddedFunctionUpdate(compiler, element, container));
241 } 244 }
242 245
246 void addClass(
247 PartialClassElement element,
248 LibraryElementX library) {
249 invalidateScopesAffectedBy(element, library);
250
251 updates.add(new AddedClassUpdate(compiler, element, library));
252 }
253
243 bool canReuseRemovedElement(PartialElement element) { 254 bool canReuseRemovedElement(PartialElement element) {
244 if (element is PartialFunctionElement) { 255 if (element is PartialFunctionElement) {
245 removeFunction(element); 256 removeFunction(element);
246 return true; 257 return true;
247 } 258 }
248 return cannotReuse(element, "Removed element that isn't a function."); 259 return cannotReuse(element, "Removed element that isn't a function.");
249 } 260 }
250 261
251 void removeFunction(PartialFunctionElement element) { 262 void removeFunction(PartialFunctionElement element) {
252 logVerbose("Removed method $element."); 263 logVerbose("Removed method $element.");
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 String computeUpdateJs() { 421 String computeUpdateJs() {
411 Set existingClasses = 422 Set existingClasses =
412 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); 423 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses);
413 424
414 List<Update> removals = <Update>[]; 425 List<Update> removals = <Update>[];
415 List<Element> updatedElements = applyUpdates(removals); 426 List<Element> updatedElements = applyUpdates(removals);
416 if (compiler.progress != null) { 427 if (compiler.progress != null) {
417 compiler.progress.reset(); 428 compiler.progress.reset();
418 } 429 }
419 for (Element element in updatedElements) { 430 for (Element element in updatedElements) {
420 compiler.enqueuer.resolution.addToWorkList(element); 431 if (!element.isClass) {
432 compiler.enqueuer.resolution.addToWorkList(element);
433 }
421 } 434 }
422 compiler.processQueue(compiler.enqueuer.resolution, null); 435 compiler.processQueue(compiler.enqueuer.resolution, null);
423 436
424 compiler.phase = Compiler.PHASE_DONE_RESOLVING; 437 compiler.phase = Compiler.PHASE_DONE_RESOLVING;
425 438
426 for (Element element in updatedElements) { 439 for (Element element in updatedElements) {
427 compiler.enqueuer.codegen.addToWorkList(element); 440 if (!element.isClass) {
441 compiler.enqueuer.codegen.addToWorkList(element);
442 }
428 } 443 }
429 compiler.processQueue(compiler.enqueuer.codegen, null); 444 compiler.processQueue(compiler.enqueuer.codegen, null);
430 445
431 List<jsAst.Statement> updates = <jsAst.Statement>[]; 446 List<jsAst.Statement> updates = <jsAst.Statement>[];
432 447
433 Set newClasses = 448 Set newClasses =
434 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); 449 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses);
435 newClasses.removeAll(existingClasses); 450 newClasses.removeAll(existingClasses);
436 451
437 List<jsAst.Statement> inherits = <jsAst.Statement>[]; 452 List<jsAst.Statement> inherits = <jsAst.Statement>[];
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 } 659 }
645 660
646 PartialFunctionElement apply() { 661 PartialFunctionElement apply() {
647 if (!wasStateCaptured) throw "captureState must be called before apply."; 662 if (!wasStateCaptured) throw "captureState must be called before apply.";
648 removeFromEnclosing(); 663 removeFromEnclosing();
649 reuseElement(); 664 reuseElement();
650 return null; 665 return null;
651 } 666 }
652 667
653 void removeFromEnclosing() { 668 void removeFromEnclosing() {
669 // TODO(ahe): Need to recompute duplicated elements logic again. Simplest
670 // solution is probably to remove all elements from enclosing scope and add
671 // them back.
654 PartialClassElement cls = element.enclosingClass; 672 PartialClassElement cls = element.enclosingClass;
655 if (cls == null) { 673 if (cls == null) {
656 removeFromLibrary(element.library); 674 removeFromLibrary(element.library);
657 } else { 675 } else {
658 removeFromEnclosingClass(cls); 676 removeFromEnclosingClass(cls);
659 } 677 }
660 } 678 }
661 679
662 void removeFromEnclosingClass(PartialClassElement cls) { 680 void removeFromEnclosingClass(PartialClassElement cls) {
663 cls.localMembersCache = null; 681 cls.localMembersCache = null;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 731
714 AddedFunctionUpdate(Compiler compiler, this.element, this.container) 732 AddedFunctionUpdate(Compiler compiler, this.element, this.container)
715 : super(compiler) { 733 : super(compiler) {
716 if (container == null) { 734 if (container == null) {
717 throw "container is null"; 735 throw "container is null";
718 } 736 }
719 } 737 }
720 738
721 PartialFunctionElement get before => null; 739 PartialFunctionElement get before => null;
722 740
723 PartialElement get after => element; 741 PartialFunctionElement get after => element;
724 742
725 PartialFunctionElement apply() { 743 PartialFunctionElement apply() {
726 Element enclosing = container; 744 Element enclosing = container;
727 if (enclosing.isLibrary) { 745 if (enclosing.isLibrary) {
728 // TODO(ahe): Reuse compilation unit instead? 746 // TODO(ahe): Reuse compilation unit of element instead?
729 enclosing = enclosing.compilationUnit; 747 enclosing = enclosing.compilationUnit;
730 } 748 }
731 PartialFunctionElement copy = element.copyWithEnclosing(enclosing); 749 PartialFunctionElement copy = element.copyWithEnclosing(enclosing);
732 container.addMember(copy, compiler); 750 container.addMember(copy, compiler);
733 return copy; 751 return copy;
734 } 752 }
735 } 753 }
736 754
755 class AddedClassUpdate extends Update with JsFeatures {
756 final PartialClassElement element;
757
758 final LibraryElementX library;
759
760 AddedClassUpdate(Compiler compiler, this.element, this.library)
761 : super(compiler);
762
763 PartialClassElement get before => null;
764
765 PartialClassElement get after => element;
766
767 PartialFunctionElement apply() {
768 // TODO(ahe): Reuse compilation unit of element instead?
769 CompilationUnitElementX compilationUnit = library.compilationUnit;
770 PartialClassElement copy = element.copyWithEnclosing(compilationUnit);
771 compilationUnit.addMember(copy, compiler);
772 return copy;
773 }
774 }
775
737 /// Returns all qualified names in [element] with less than four identifiers. A 776 /// Returns all qualified names in [element] with less than four identifiers. A
738 /// qualified name is an identifier followed by a sequence of dots and 777 /// qualified name is an identifier followed by a sequence of dots and
739 /// identifiers, for example, "x", and "x.y.z". But not "x.y.z.w" ("w" is the 778 /// identifiers, for example, "x", and "x.y.z". But not "x.y.z.w" ("w" is the
740 /// fourth identifier). 779 /// fourth identifier).
741 /// 780 ///
742 /// The longest possible name that can be resolved is three identifiers, for 781 /// The longest possible name that can be resolved is three identifiers, for
743 /// example, "prefix.MyClass.staticMethod". Since four or more identifiers 782 /// example, "prefix.MyClass.staticMethod". Since four or more identifiers
744 /// cannot resolve to anything statically, they're not included in the returned 783 /// cannot resolve to anything statically, they're not included in the returned
745 /// value of this method. 784 /// value of this method.
746 Set<String> qualifiedNamesIn(PartialElement element) { 785 Set<String> qualifiedNamesIn(PartialElement element) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 866
828 ClassEmitter get classEmitter => backend.emitter.oldEmitter.classEmitter; 867 ClassEmitter get classEmitter => backend.emitter.oldEmitter.classEmitter;
829 868
830 List<String> computeFields(ClassElement cls) { 869 List<String> computeFields(ClassElement cls) {
831 // TODO(ahe): Rewrite for new emitter. 870 // TODO(ahe): Rewrite for new emitter.
832 ClassBuilder builder = new ClassBuilder(cls, namer); 871 ClassBuilder builder = new ClassBuilder(cls, namer);
833 classEmitter.emitFields(cls, builder, ""); 872 classEmitter.emitFields(cls, builder, "");
834 return builder.fields; 873 return builder.fields;
835 } 874 }
836 } 875 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698