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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/custom_elements_analysis.dart

Issue 368593002: Register the constructors of custom elements for deferred loading (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
« no previous file with comments | « no previous file | tests/compiler/dart2js/deferred_custom_element_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * Support for Custom Elements. 8 * Support for Custom Elements.
9 * 9 *
10 * The support for custom elements the compiler builds a table that maps the 10 * The support for custom elements the compiler builds a table that maps the
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 void onQueueEmpty(Enqueuer enqueuer) { 112 void onQueueEmpty(Enqueuer enqueuer) {
113 joinFor(enqueuer).flush(enqueuer); 113 joinFor(enqueuer).flush(enqueuer);
114 } 114 }
115 115
116 bool get needsTable => codegenJoin.demanded; 116 bool get needsTable => codegenJoin.demanded;
117 117
118 bool needsClass(ClassElement classElement) => 118 bool needsClass(ClassElement classElement) =>
119 codegenJoin.activeClasses.contains(classElement); 119 codegenJoin.activeClasses.contains(classElement);
120 120
121 List<Element> constructors(ClassElement classElement) => 121 List<Element> constructors(ClassElement classElement) =>
122 codegenJoin.escapingConstructors(classElement); 122 codegenJoin.computeEscapingConstructors(classElement);
123 } 123 }
124 124
125 125
126 class CustomElementsAnalysisJoin { 126 class CustomElementsAnalysisJoin {
127 final JavaScriptBackend backend; 127 final JavaScriptBackend backend;
128 Compiler get compiler => backend.compiler; 128 Compiler get compiler => backend.compiler;
129 129
130 // Classes that are candidates for needing constructors. Classes are moved to 130 // Classes that are candidates for needing constructors. Classes are moved to
131 // [activeClasses] when we know they need constructors. 131 // [activeClasses] when we know they need constructors.
132 final instantiatedClasses = new Set<ClassElement>(); 132 final instantiatedClasses = new Set<ClassElement>();
(...skipping 18 matching lines...) Expand all
151 for (ClassElement classElement in instantiatedClasses) { 151 for (ClassElement classElement in instantiatedClasses) {
152 bool isNative = classElement.isNative; 152 bool isNative = classElement.isNative;
153 bool isExtension = 153 bool isExtension =
154 !isNative && Elements.isNativeOrExtendsNative(classElement); 154 !isNative && Elements.isNativeOrExtendsNative(classElement);
155 // Generate table entries for native classes that are explicitly named and 155 // Generate table entries for native classes that are explicitly named and
156 // extensions that fix our criteria. 156 // extensions that fix our criteria.
157 if ((isNative && selectedClasses.contains(classElement)) || 157 if ((isNative && selectedClasses.contains(classElement)) ||
158 (isExtension && 158 (isExtension &&
159 (allClassesSelected || selectedClasses.contains(classElement)))) { 159 (allClassesSelected || selectedClasses.contains(classElement)))) {
160 newActiveClasses.add(classElement); 160 newActiveClasses.add(classElement);
161 escapingConstructors(classElement).forEach(enqueuer.registerStaticUse); 161 Iterable<Element> escapingConstructors =
162 computeEscapingConstructors(classElement);
163 escapingConstructors.forEach(enqueuer.registerStaticUse);
164 escapingConstructors
165 .forEach(compiler.globalDependencies.registerDependency);
162 // Force the generaton of the type constant that is the key to an entry 166 // Force the generaton of the type constant that is the key to an entry
163 // in the generated table. 167 // in the generated table.
164 Constant constant = makeTypeConstant(classElement); 168 Constant constant = makeTypeConstant(classElement);
165 backend.registerCompileTimeConstant( 169 backend.registerCompileTimeConstant(
166 constant, compiler.globalDependencies); 170 constant, compiler.globalDependencies);
167 backend.constants.addCompileTimeConstantForEmission(constant); 171 backend.constants.addCompileTimeConstantForEmission(constant);
168 } 172 }
169 } 173 }
170 activeClasses.addAll(newActiveClasses); 174 activeClasses.addAll(newActiveClasses);
171 instantiatedClasses.removeAll(newActiveClasses); 175 instantiatedClasses.removeAll(newActiveClasses);
172 } 176 }
173 177
174 TypeConstant makeTypeConstant(ClassElement element) { 178 TypeConstant makeTypeConstant(ClassElement element) {
175 DartType elementType = element.rawType; 179 DartType elementType = element.rawType;
176 DartType constantType = backend.typeImplementation.rawType; 180 DartType constantType = backend.typeImplementation.rawType;
177 return new TypeConstant(elementType, constantType); 181 return new TypeConstant(elementType, constantType);
178 } 182 }
179 183
180 List<Element> escapingConstructors(ClassElement classElement) { 184 List<Element> computeEscapingConstructors(ClassElement classElement) {
181 List<Element> result = <Element>[]; 185 List<Element> result = <Element>[];
182 // Only classes that extend native classes have constructors in the table. 186 // Only classes that extend native classes have constructors in the table.
183 // We could refine this to classes that extend Element, but that would break 187 // We could refine this to classes that extend Element, but that would break
184 // the tests and there is no sane reason to subclass other native classes. 188 // the tests and there is no sane reason to subclass other native classes.
185 if (classElement.isNative) return result; 189 if (classElement.isNative) return result;
186 190
187 selectGenerativeConstructors(ClassElement enclosing, Element member) { 191 selectGenerativeConstructors(ClassElement enclosing, Element member) {
188 if (member.isGenerativeConstructor) { 192 if (member.isGenerativeConstructor) {
189 // Ignore constructors that cannot be called with zero arguments. 193 // Ignore constructors that cannot be called with zero arguments.
190 FunctionElement constructor = member; 194 FunctionElement constructor = member;
191 FunctionSignature parameters = constructor.functionSignature; 195 FunctionSignature parameters = constructor.functionSignature;
192 if (parameters.requiredParameterCount == 0) { 196 if (parameters.requiredParameterCount == 0) {
193 result.add(member); 197 result.add(member);
194 } 198 }
195 } 199 }
196 } 200 }
197 classElement.forEachMember(selectGenerativeConstructors, 201 classElement.forEachMember(selectGenerativeConstructors,
198 includeBackendMembers: false, 202 includeBackendMembers: false,
199 includeSuperAndInjectedMembers: false); 203 includeSuperAndInjectedMembers: false);
200 return result; 204 return result;
201 } 205 }
202 } 206 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/deferred_custom_element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698