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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/program_builder/collector.dart

Issue 2925263002: A step towards handling `new Object()` in compile_from_dill_test (Closed)
Patch Set: Updated cf. comments Created 3 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 dart2js.js_emitter.program_builder; 5 part of dart2js.js_emitter.program_builder;
6 6
7 /** 7 /**
8 * Generates the code for all used classes in the program. Static fields (even 8 * Generates the code for all used classes in the program. Static fields (even
9 * in classes) are ignored, since they can be treated as non-class elements. 9 * in classes) are ignored, since they can be treated as non-class elements.
10 * 10 *
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 .toList()); 203 .toList());
204 204
205 // Compute needed classes. 205 // Compute needed classes.
206 Set<ClassEntity> instantiatedClasses = 206 Set<ClassEntity> instantiatedClasses =
207 // TODO(johnniwinther): This should be accessed from a codegen closed 207 // TODO(johnniwinther): This should be accessed from a codegen closed
208 // world. 208 // world.
209 _worldBuilder.directlyInstantiatedClasses 209 _worldBuilder.directlyInstantiatedClasses
210 .where(computeClassFilter()) 210 .where(computeClassFilter())
211 .toSet(); 211 .toSet();
212 212
213 void addClassWithSuperclasses(ClassElement cls) { 213 void addClassWithSuperclasses(ClassEntity cls) {
214 neededClasses.add(cls); 214 neededClasses.add(cls);
215 for (ClassElement superclass = cls.superclass; 215 for (ClassEntity superclass = _elementEnvironment.getSuperClass(cls);
216 superclass != null; 216 superclass != null;
217 superclass = superclass.superclass) { 217 superclass = _elementEnvironment.getSuperClass(superclass)) {
218 neededClasses.add(superclass); 218 neededClasses.add(superclass);
219 } 219 }
220 } 220 }
221 221
222 void addClassesWithSuperclasses(Iterable<ClassEntity> classes) { 222 void addClassesWithSuperclasses(Iterable<ClassEntity> classes) {
223 for (ClassElement cls in classes) { 223 for (ClassEntity cls in classes) {
224 addClassWithSuperclasses(cls); 224 addClassWithSuperclasses(cls);
225 } 225 }
226 } 226 }
227 227
228 // 1. We need to generate all classes that are instantiated. 228 // 1. We need to generate all classes that are instantiated.
229 addClassesWithSuperclasses(instantiatedClasses); 229 addClassesWithSuperclasses(instantiatedClasses);
230 230
231 // 2. Add all classes used as mixins. 231 // 2. Add all classes used as mixins.
232 Set<ClassElement> mixinClasses = neededClasses 232 Set<ClassEntity> mixinClasses = new Set<ClassEntity>();
233 .where((ClassElement element) => element.isMixinApplication) 233 for (ClassEntity cls in neededClasses) {
234 .map(computeMixinClass) 234 _elementEnvironment.forEachMixin(cls, (ClassEntity mixinClass) {
235 .toSet(); 235 mixinClasses.add(mixinClass);
236 });
237 }
236 neededClasses.addAll(mixinClasses); 238 neededClasses.addAll(mixinClasses);
237 239
238 // 3. Find all classes needed for rti. 240 // 3. Find all classes needed for rti.
239 // It is important that this is the penultimate step, at this point, 241 // It is important that this is the penultimate step, at this point,
240 // neededClasses must only contain classes that have been resolved and 242 // neededClasses must only contain classes that have been resolved and
241 // codegen'd. The rtiNeededClasses may contain additional classes, but 243 // codegen'd. The rtiNeededClasses may contain additional classes, but
242 // these are thought to not have been instantiated, so we neeed to be able 244 // these are thought to not have been instantiated, so we neeed to be able
243 // to identify them later and make sure we only emit "empty shells" without 245 // to identify them later and make sure we only emit "empty shells" without
244 // fields, etc. 246 // fields, etc.
245 classesOnlyNeededForRti = new Set<ClassElement>(); 247 classesOnlyNeededForRti = new Set<ClassElement>();
(...skipping 29 matching lines...) Expand all
275 // 4. Finally, sort the classes. 277 // 4. Finally, sort the classes.
276 List<ClassEntity> sortedClasses = _sorter.sortClasses(neededClasses); 278 List<ClassEntity> sortedClasses = _sorter.sortClasses(neededClasses);
277 279
278 for (ClassEntity cls in sortedClasses) { 280 for (ClassEntity cls in sortedClasses) {
279 if (_nativeData.isNativeOrExtendsNative(cls) && 281 if (_nativeData.isNativeOrExtendsNative(cls) &&
280 !classesOnlyNeededForRti.contains(cls)) { 282 !classesOnlyNeededForRti.contains(cls)) {
281 // For now, native classes and related classes cannot be deferred. 283 // For now, native classes and related classes cannot be deferred.
282 nativeClassesAndSubclasses.add(cls); 284 nativeClassesAndSubclasses.add(cls);
283 assert(!_deferredLoadTask.isDeferredClass(cls), failedAt(cls)); 285 assert(!_deferredLoadTask.isDeferredClass(cls), failedAt(cls));
284 outputClassLists 286 outputClassLists
285 .putIfAbsent(_deferredLoadTask.mainOutputUnit, 287 .putIfAbsent(
286 () => new List<ClassElement>()) 288 _deferredLoadTask.mainOutputUnit, () => new List<ClassEntity>())
287 .add(cls); 289 .add(cls);
288 } else { 290 } else {
289 outputClassLists 291 outputClassLists
290 .putIfAbsent(_deferredLoadTask.outputUnitForClass(cls), 292 .putIfAbsent(_deferredLoadTask.outputUnitForClass(cls),
291 () => new List<ClassElement>()) 293 () => new List<ClassEntity>())
292 .add(cls); 294 .add(cls);
293 } 295 }
294 } 296 }
295 } 297 }
296 298
297 void computeNeededStatics() { 299 void computeNeededStatics() {
298 bool isStaticFunction(MemberEntity element) => 300 bool isStaticFunction(MemberEntity element) =>
299 !element.isInstanceMember && !element.isField; 301 !element.isInstanceMember && !element.isField;
300 302
301 Iterable<MemberEntity> elements = 303 Iterable<MemberEntity> elements =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 } 357 }
356 358
357 void collect() { 359 void collect() {
358 computeNeededDeclarations(); 360 computeNeededDeclarations();
359 computeNeededConstants(); 361 computeNeededConstants();
360 computeNeededStatics(); 362 computeNeededStatics();
361 computeNeededStaticNonFinalFields(); 363 computeNeededStaticNonFinalFields();
362 computeNeededLibraries(); 364 computeNeededLibraries();
363 } 365 }
364 } 366 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698