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

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

Issue 10584009: Refactor the collection of initializer list types (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Minor fix 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 5
6 /** 6 /**
7 * If true, print a warning for each method that was resolved, but not 7 * If true, print a warning for each method that was resolved, but not
8 * compiled. 8 * compiled.
9 */ 9 */
10 final bool REPORT_EXCESS_RESOLUTION = false; 10 final bool REPORT_EXCESS_RESOLUTION = false;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 abstract void enqueueHelpers(Enqueuer world); 46 abstract void enqueueHelpers(Enqueuer world);
47 abstract String codegen(WorkItem work); 47 abstract String codegen(WorkItem work);
48 abstract void processNativeClasses(Enqueuer world, 48 abstract void processNativeClasses(Enqueuer world,
49 Collection<LibraryElement> libraries); 49 Collection<LibraryElement> libraries);
50 abstract void assembleProgram(); 50 abstract void assembleProgram();
51 abstract List<CompilerTask> get tasks(); 51 abstract List<CompilerTask> get tasks();
52 } 52 }
53 53
54 class JavaScriptBackend extends Backend { 54 class JavaScriptBackend extends Backend {
floitsch 2012/06/20 10:20:33 We should probably move the class out of the compi
Søren Gjesse 2012/06/21 08:51:35 Will do.
55 SsaBuilderTask builder; 55 SsaBuilderTask builder;
56 SsaOptimizerTask optimizer; 56 SsaOptimizerTask optimizer;
57 SsaCodeGeneratorTask generator; 57 SsaCodeGeneratorTask generator;
58 CodeEmitterTask emitter; 58 CodeEmitterTask emitter;
59 final Map<Element, Map<Element, HType>> fieldInitializers;
60 final Map<Element, Map<Element, bool>> fieldIntegerSetters;
59 61
60 List<CompilerTask> get tasks() { 62 List<CompilerTask> get tasks() {
61 return <CompilerTask>[builder, optimizer, generator, emitter]; 63 return <CompilerTask>[builder, optimizer, generator, emitter];
62 } 64 }
63 65
64 JavaScriptBackend(Compiler compiler) 66 JavaScriptBackend(Compiler compiler)
65 : emitter = new CodeEmitterTask(compiler), 67 : emitter = new CodeEmitterTask(compiler),
68 fieldInitializers = new Map<Element, Map<Element, HType>>(),
69 fieldIntegerSetters = new Map<Element, Map<Element, bool>>(),
66 super(compiler) { 70 super(compiler) {
67 builder = new SsaBuilderTask(this); 71 builder = new SsaBuilderTask(this);
68 optimizer = new SsaOptimizerTask(this); 72 optimizer = new SsaOptimizerTask(this);
69 generator = new SsaCodeGeneratorTask(this); 73 generator = new SsaCodeGeneratorTask(this);
70 } 74 }
71 75
72 void enqueueHelpers(Enqueuer world) { 76 void enqueueHelpers(Enqueuer world) {
73 enqueueAllTopLevelFunctions(compiler.jsHelperLibrary, world); 77 enqueueAllTopLevelFunctions(compiler.jsHelperLibrary, world);
74 enqueueAllTopLevelFunctions(compiler.interceptorsLibrary, world); 78 enqueueAllTopLevelFunctions(compiler.interceptorsLibrary, world);
75 for (var helper in [const SourceString('Closure'), 79 for (var helper in [const SourceString('Closure'),
(...skipping 18 matching lines...) Expand all
94 } 98 }
95 99
96 void processNativeClasses(Enqueuer world, 100 void processNativeClasses(Enqueuer world,
97 Collection<LibraryElement> libraries) { 101 Collection<LibraryElement> libraries) {
98 native.processNativeClasses(world, emitter, libraries); 102 native.processNativeClasses(world, emitter, libraries);
99 } 103 }
100 104
101 void assembleProgram() { 105 void assembleProgram() {
102 emitter.assembleProgram(); 106 emitter.assembleProgram();
103 } 107 }
108
109 void updateFieldInitializers(Type type,
110 Element field,
111 HType propagatedType) {
112 assert(field.isField());
113 Map<Element, HType> fields =
114 fieldInitializers.putIfAbsent(
115 type.element, () => new Map<Element, HType>());
116 if (!fields.containsKey(field)) {
117 fields[field] = propagatedType;
118 } else {
119 if (fields[field] != propagatedType) fields[field] = HType.UNKNOWN;
floitsch 2012/06/20 10:20:33 can't you just union the types?
Søren Gjesse 2012/06/21 08:51:35 Done, that should also be better.
120 }
121 }
122
123 bool couldHaveFieldSingleTypeInitializers(Type type,
124 Element field,
125 HType requestedType) {
126 assert(field.isField());
127 if (type == null) return false;
128 // If there is no information on the initializer it might still be
129 // initialized to integers only.
130 if (!fieldInitializers.containsKey(type.element)) return true;
131 Map<Element, HType> fields = fieldInitializers[type.element];
132 HType propagatedType = fields[field];
133 if (propagatedType == null) return true;
134 return propagatedType == requestedType;
135 }
136
137 bool hasFieldSingleTypeInitializers(Type type,
138 Element field,
139 HType requestedType) {
140 assert(field.isField());
141 if (type == null) return false;
142 if (!fieldInitializers.containsKey(type.element)) return false;
143 Map<Element, HType> fields = fieldInitializers[type.element];
144 HType propagatedType = fields[field];
145 if (propagatedType == null) return false;
146 return propagatedType == requestedType;
147 }
148
149 void updateFieldIntegerSetters(Type type, Element field, bool isInteger) {
150 assert(field.isField());
151 Map<Element, bool> fields =
152 fieldIntegerSetters.putIfAbsent(
153 type.element, () => new Map<Element, bool>());
154 if (!fields.containsKey(field)) {
155 fields[field] = isInteger;
156 } else {
157 fields[field] = fields[field] && isInteger;
158 }
159 }
160
161 bool couldHaveFieldOnlyIntegerSetters(Type type, Element field) {
floitsch 2012/06/20 10:20:33 Doesn't the field element contain the enclosing c
Søren Gjesse 2012/06/21 08:51:35 It does. The element of the type can be a sub-clas
162 assert(field.isField());
163 if (type == null) return false;
164 if (!fieldIntegerSetters.containsKey(type.element)) return true;
165 Map<Element, bool> fields = fieldIntegerSetters[type.element];
166 if (!fields.containsKey(field)) return false;
167 return fields[field];
168 }
169
170 bool hasFieldOnlyIntegerSetters(Type type, Element field) {
floitsch 2012/06/20 10:20:33 I would remove this method. It is identical to the
Søren Gjesse 2012/06/21 08:51:35 Changed the name to onlyFieldIntegerSettersSoFar (
171 assert(field.isField());
172 if (type == null) return false;
173 if (!fieldIntegerSetters.containsKey(type.element)) return true;
174 Map<Element, bool> fields = fieldIntegerSetters[type.element];
175 if (!fields.containsKey(field)) return false;
176 return fields[field];
177 }
104 } 178 }
105 179
106 class Compiler implements DiagnosticListener { 180 class Compiler implements DiagnosticListener {
107 final Map<String, LibraryElement> libraries; 181 final Map<String, LibraryElement> libraries;
108 int nextFreeClassId = 0; 182 int nextFreeClassId = 0;
109 World world; 183 World world;
110 String assembledCode; 184 String assembledCode;
111 Namer namer; 185 Namer namer;
112 Types types; 186 Types types;
113 final bool enableTypeAssertions; 187 final bool enableTypeAssertions;
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 checker.check(tree, elements); 616 checker.check(tree, elements);
543 return elements; 617 return elements;
544 } 618 }
545 619
546 TreeElements analyze(WorkItem work, Enqueuer world) { 620 TreeElements analyze(WorkItem work, Enqueuer world) {
547 if (work.isAnalyzed()) return work.resolutionTree; 621 if (work.isAnalyzed()) return work.resolutionTree;
548 if (progress.elapsedInMs() > 500) { 622 if (progress.elapsedInMs() > 500) {
549 // TODO(ahe): Add structured diagnostics to the compiler API and 623 // TODO(ahe): Add structured diagnostics to the compiler API and
550 // use it to separate this from the --verbose option. 624 // use it to separate this from the --verbose option.
551 if (phase == PHASE_RESOLVING) { 625 if (phase == PHASE_RESOLVING) {
552 log('Resolved ${enqueuer.resolution.resolvedElements.length}' 626 log('Resolved ${enqueuer.resolution.resolvedElements.length} '
553 'elements.'); 627 'elements.');
554 progress.reset(); 628 progress.reset();
555 } 629 }
556 } 630 }
557 Element element = work.element; 631 Element element = work.element;
558 TreeElements result = world.getCachedElements(element); 632 TreeElements result = world.getCachedElements(element);
559 if (result !== null) return result; 633 if (result !== null) return result;
560 if (world !== enqueuer.resolution) { 634 if (world !== enqueuer.resolution) {
561 internalErrorOnElement(element, 635 internalErrorOnElement(element,
562 'Internal error: unresolved element: $element.'); 636 'Internal error: unresolved element: $element.');
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 // invariant that endOffset > beginOffset, but for EOF the 838 // invariant that endOffset > beginOffset, but for EOF the
765 // charoffset of the next token may be [beginOffset]. This can 839 // charoffset of the next token may be [beginOffset]. This can
766 // also happen for synthetized tokens that are produced during 840 // also happen for synthetized tokens that are produced during
767 // error handling. 841 // error handling.
768 final endOffset = 842 final endOffset =
769 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); 843 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1);
770 assert(endOffset > beginOffset); 844 assert(endOffset > beginOffset);
771 return f(beginOffset, endOffset); 845 return f(beginOffset, endOffset);
772 } 846 }
773 } 847 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/enqueue.dart » ('j') | lib/compiler/implementation/ssa/optimize.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698