OLD | NEW |
---|---|
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 ClassElementX, | 69 ClassElementX, |
70 CompilationUnitElementX, | 70 CompilationUnitElementX, |
71 DeclarationSite, | 71 DeclarationSite, |
72 ElementX, | 72 ElementX, |
73 FieldElementX, | 73 FieldElementX, |
74 LibraryElementX; | 74 LibraryElementX; |
75 | 75 |
76 import 'package:compiler/src/universe/universe.dart' show | 76 import 'package:compiler/src/universe/universe.dart' show |
77 Selector; | 77 Selector; |
78 | 78 |
79 import 'package:compiler/src/constants/values.dart' show | |
80 ConstantValue; | |
81 | |
79 import 'diff.dart' show | 82 import 'diff.dart' show |
80 Difference, | 83 Difference, |
81 computeDifference; | 84 computeDifference; |
82 | 85 |
83 typedef void Logger(message); | 86 typedef void Logger(message); |
84 | 87 |
85 typedef bool Reuser( | 88 typedef bool Reuser( |
86 Token diffToken, | 89 Token diffToken, |
87 PartialElement before, | 90 PartialElement before, |
88 PartialElement after); | 91 PartialElement after); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 | 126 |
124 final Set<ElementX> _removedElements = new Set<ElementX>(); | 127 final Set<ElementX> _removedElements = new Set<ElementX>(); |
125 | 128 |
126 final Set<ClassElementX> _classesWithSchemaChanges = | 129 final Set<ClassElementX> _classesWithSchemaChanges = |
127 new Set<ClassElementX>(); | 130 new Set<ClassElementX>(); |
128 | 131 |
129 final Set<ClassElementX> _emittedClasses; | 132 final Set<ClassElementX> _emittedClasses; |
130 | 133 |
131 final Set<ClassElementX> _directlyInstantiatedClasses; | 134 final Set<ClassElementX> _directlyInstantiatedClasses; |
132 | 135 |
136 final Set<ConstantValue> _compiledConstants; | |
137 | |
138 bool _hasComputedNeeds = false; | |
139 | |
133 LibraryUpdater( | 140 LibraryUpdater( |
134 Compiler compiler, | 141 Compiler compiler, |
135 this.inputProvider, | 142 this.inputProvider, |
136 this.uri, | 143 this.uri, |
137 this.logTime, | 144 this.logTime, |
138 this.logVerbose) | 145 this.logVerbose) |
139 : this.compiler = compiler, | 146 : this.compiler = compiler, |
140 _emittedClasses = new Set.from( | 147 _emittedClasses = new Set.from( |
141 compiler == null | 148 compiler == null |
142 ? [] : compiler.backend.emitter.neededClasses), | 149 ? [] : compiler.backend.emitter.neededClasses), |
143 _directlyInstantiatedClasses = new Set.from( | 150 _directlyInstantiatedClasses = new Set.from( |
144 compiler == null | 151 compiler == null |
145 ? [] : compiler.codegenWorld.directlyInstantiatedClasses); | 152 ? [] : compiler.codegenWorld.directlyInstantiatedClasses), |
153 _compiledConstants = new Set<ConstantValue>.identity()..addAll( | |
154 compiler == null | |
155 ? [] : compiler.backend.constants.compiledConstants); | |
ahe
2014/12/11 10:09:00
Conflict resolution.
| |
146 | 156 |
147 /// When [true], updates must be applied (using [applyUpdates]) before the | 157 /// When [true], updates must be applied (using [applyUpdates]) before the |
148 /// [compiler]'s state correctly reflects the updated program. | 158 /// [compiler]'s state correctly reflects the updated program. |
149 bool get hasPendingUpdates => !updates.isEmpty; | 159 bool get hasPendingUpdates => !updates.isEmpty; |
150 | 160 |
151 bool get failed => !_failedUpdates.isEmpty; | 161 bool get failed => !_failedUpdates.isEmpty; |
152 | 162 |
153 /// Used as tear-off passed to [LibraryLoaderTask.resetAsync]. | 163 /// Used as tear-off passed to [LibraryLoaderTask.resetAsync]. |
154 Future<bool> reuseLibrary(LibraryElement library) { | 164 Future<bool> reuseLibrary(LibraryElement library) { |
155 assert(compiler != null); | 165 assert(compiler != null); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 | 611 |
602 List<jsAst.Statement> updates = <jsAst.Statement>[]; | 612 List<jsAst.Statement> updates = <jsAst.Statement>[]; |
603 | 613 |
604 Set<ClassElementX> newClasses = new Set.from( | 614 Set<ClassElementX> newClasses = new Set.from( |
605 compiler.codegenWorld.directlyInstantiatedClasses); | 615 compiler.codegenWorld.directlyInstantiatedClasses); |
606 newClasses.removeAll(_directlyInstantiatedClasses); | 616 newClasses.removeAll(_directlyInstantiatedClasses); |
607 | 617 |
608 if (!newClasses.isEmpty) { | 618 if (!newClasses.isEmpty) { |
609 // Ask the emitter to compute "needs" (only) if new classes were | 619 // Ask the emitter to compute "needs" (only) if new classes were |
610 // instantiated. | 620 // instantiated. |
611 emitter.computeAllNeededEntities(); | 621 _ensureNeedsComputed(); |
ahe
2014/12/11 10:09:00
Conflict resolution.
| |
612 newClasses = new Set.from(emitter.neededClasses); | 622 newClasses = new Set.from(emitter.neededClasses); |
613 newClasses.removeAll(_emittedClasses); | 623 newClasses.removeAll(_emittedClasses); |
614 } else { | 624 } else { |
615 // Make sure that the set of emitted classes is preserved for subsequent | 625 // Make sure that the set of emitted classes is preserved for subsequent |
616 // updates. | 626 // updates. |
617 // TODO(ahe): This is a bit convoluted, find a better approach. | 627 // TODO(ahe): This is a bit convoluted, find a better approach. |
618 emitter.neededClasses | 628 emitter.neededClasses |
619 ..clear() | 629 ..clear() |
620 ..addAll(_emittedClasses); | 630 ..addAll(_emittedClasses); |
621 } | 631 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
661 update.writeUpdateJsOn(updates); | 671 update.writeUpdateJsOn(updates); |
662 } | 672 } |
663 for (Element element in enqueuer.codegen.newlyEnqueuedElements) { | 673 for (Element element in enqueuer.codegen.newlyEnqueuedElements) { |
664 if (element.isField) { | 674 if (element.isField) { |
665 updates.addAll(computeFieldUpdateJs(element)); | 675 updates.addAll(computeFieldUpdateJs(element)); |
666 } else { | 676 } else { |
667 updates.add(computeMethodUpdateJs(element)); | 677 updates.add(computeMethodUpdateJs(element)); |
668 } | 678 } |
669 } | 679 } |
670 | 680 |
681 Set<ConstantValue> newConstants = new Set<ConstantValue>.identity()..addAll( | |
682 compiler.backend.constants.compiledConstants); | |
683 newConstants.removeAll(_compiledConstants); | |
684 | |
685 if (!newConstants.isEmpty) { | |
686 _ensureNeedsComputed(); | |
ahe
2014/12/11 10:09:00
Conflict resolution.
| |
687 List<ConstantValue> constants = | |
688 emitter.outputConstantLists[compiler.deferredLoadTask.mainOutputUnit]; | |
689 if (constants != null) { | |
690 for (ConstantValue constant in constants) { | |
691 if (newConstants.contains(constant)) { | |
692 jsAst.Statement constantInitializer = emitter.oldEmitter | |
693 .buildConstantInitializer(constant).toStatement(); | |
694 updates.add(constantInitializer); | |
695 } | |
696 } | |
697 } | |
698 } | |
699 | |
671 updates.add(js.statement(r''' | 700 updates.add(js.statement(r''' |
672 if (self.$dart_unsafe_eval.pendingStubs) { | 701 if (self.$dart_unsafe_eval.pendingStubs) { |
673 self.$dart_unsafe_eval.pendingStubs.map(function(e) { return e(); }); | 702 self.$dart_unsafe_eval.pendingStubs.map(function(e) { return e(); }); |
674 self.$dart_unsafe_eval.pendingStubs = void 0; | 703 self.$dart_unsafe_eval.pendingStubs = void 0; |
675 } | 704 } |
676 ''')); | 705 ''')); |
677 | 706 |
678 if (updates.length == 1) { | 707 if (updates.length == 1) { |
679 return prettyPrintJs(updates.single); | 708 return prettyPrintJs(updates.single); |
680 } else { | 709 } else { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 String callNameFor(FunctionElement element) { | 793 String callNameFor(FunctionElement element) { |
765 // TODO(ahe): Call a method in the compiler to obtain this name. | 794 // TODO(ahe): Call a method in the compiler to obtain this name. |
766 String callPrefix = namer.callPrefix; | 795 String callPrefix = namer.callPrefix; |
767 int parameterCount = element.functionSignature.parameterCount; | 796 int parameterCount = element.functionSignature.parameterCount; |
768 return '$callPrefix\$$parameterCount'; | 797 return '$callPrefix\$$parameterCount'; |
769 } | 798 } |
770 | 799 |
771 List<String> computeFields(ClassElement cls) { | 800 List<String> computeFields(ClassElement cls) { |
772 return new EmitterHelper(compiler).computeFields(cls); | 801 return new EmitterHelper(compiler).computeFields(cls); |
773 } | 802 } |
803 | |
804 void _ensureNeedsComputed() { | |
805 if (_hasComputedNeeds) return; | |
806 emitter.computeAllNeededEntities(); | |
ahe
2014/12/11 10:09:00
Conflict resolution (computeAllNeededEntities was
| |
807 _hasComputedNeeds = true; | |
808 } | |
774 } | 809 } |
775 | 810 |
776 /// Represents an update (aka patch) of [before] to [after]. We use the word | 811 /// Represents an update (aka patch) of [before] to [after]. We use the word |
777 /// "update" to avoid confusion with the compiler feature of "patch" methods. | 812 /// "update" to avoid confusion with the compiler feature of "patch" methods. |
778 abstract class Update { | 813 abstract class Update { |
779 final Compiler compiler; | 814 final Compiler compiler; |
780 | 815 |
781 PartialElement get before; | 816 PartialElement get before; |
782 | 817 |
783 PartialElement get after; | 818 PartialElement get after; |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 List<String> computeFields(ClassElement cls) { | 1270 List<String> computeFields(ClassElement cls) { |
1236 // TODO(ahe): Rewrite for new emitter. | 1271 // TODO(ahe): Rewrite for new emitter. |
1237 ClassBuilder builder = new ClassBuilder(cls, namer); | 1272 ClassBuilder builder = new ClassBuilder(cls, namer); |
1238 classEmitter.emitFields(cls, builder); | 1273 classEmitter.emitFields(cls, builder); |
1239 return builder.fields; | 1274 return builder.fields; |
1240 } | 1275 } |
1241 } | 1276 } |
1242 | 1277 |
1243 // TODO(ahe): Remove this method. | 1278 // TODO(ahe): Remove this method. |
1244 NO_WARN(x) => x; | 1279 NO_WARN(x) => x; |
OLD | NEW |