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

Side by Side Diff: pkg/compiler/lib/src/js_backend/enqueuer.dart

Issue 2527973002: Remove direct access to enqueuer through use of WorldImpact (Closed)
Patch Set: Cleanup Created 4 years 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) 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 library dart2js.js.enqueue; 5 library dart2js.js.enqueue;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 8
9 import '../common/backend_api.dart' show Backend; 9 import '../common/backend_api.dart' show Backend;
10 import '../common/codegen.dart' show CodegenWorkItem; 10 import '../common/codegen.dart' show CodegenWorkItem;
(...skipping 25 matching lines...) Expand all
36 import '../universe/selector.dart' show Selector; 36 import '../universe/selector.dart' show Selector;
37 import '../universe/world_builder.dart'; 37 import '../universe/world_builder.dart';
38 import '../universe/use.dart' 38 import '../universe/use.dart'
39 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; 39 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind;
40 import '../universe/world_impact.dart' 40 import '../universe/world_impact.dart'
41 show ImpactUseCase, ImpactStrategy, WorldImpact, WorldImpactVisitor; 41 show ImpactUseCase, ImpactStrategy, WorldImpact, WorldImpactVisitor;
42 import '../util/util.dart' show Setlet; 42 import '../util/util.dart' show Setlet;
43 import '../world.dart'; 43 import '../world.dart';
44 44
45 /// [Enqueuer] which is specific to code generation. 45 /// [Enqueuer] which is specific to code generation.
46 class CodegenEnqueuer implements Enqueuer { 46 class CodegenEnqueuer extends Enqueuer {
47 final String name; 47 final String name;
48 @deprecated 48 @deprecated
49 final Compiler _compiler; // TODO(ahe): Remove this dependency. 49 final Compiler _compiler; // TODO(ahe): Remove this dependency.
50 final EnqueuerStrategy strategy; 50 final EnqueuerStrategy strategy;
51 final Map<String, Set<Element>> instanceMembersByName = 51 final Map<String, Set<Element>> instanceMembersByName =
52 new Map<String, Set<Element>>(); 52 new Map<String, Set<Element>>();
53 final Map<String, Set<Element>> instanceFunctionsByName = 53 final Map<String, Set<Element>> instanceFunctionsByName =
54 new Map<String, Set<Element>>(); 54 new Map<String, Set<Element>>();
55 final Set<ClassElement> _processedClasses = new Set<ClassElement>(); 55 final Set<ClassElement> _processedClasses = new Set<ClassElement>();
56 Set<ClassElement> recentClasses = new Setlet<ClassElement>(); 56 Set<ClassElement> recentClasses = new Setlet<ClassElement>();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 throw new SpannableAssertionFailure( 116 throw new SpannableAssertionFailure(
117 element, "Codegen work list is closed. Trying to add $element"); 117 element, "Codegen work list is closed. Trying to add $element");
118 } 118 }
119 queue.add(new CodegenWorkItem(_compiler, element)); 119 queue.add(new CodegenWorkItem(_compiler, element));
120 // TODO(sigmund): add other missing dependencies (internals, selectors 120 // TODO(sigmund): add other missing dependencies (internals, selectors
121 // enqueued after allocations). 121 // enqueued after allocations).
122 _compiler.dumpInfoTask 122 _compiler.dumpInfoTask
123 .registerDependency(_compiler.currentElement, element); 123 .registerDependency(_compiler.currentElement, element);
124 } 124 }
125 125
126 void applyImpact(ImpactStrategy impactStrategy, WorldImpact worldImpact, 126 void applyImpact(WorldImpact worldImpact, {Element impactSource}) {
127 {Element impactSource}) { 127 if (worldImpact.isEmpty) return;
128 impactStrategy.visitImpact( 128 impactStrategy.visitImpact(
129 impactSource, worldImpact, impactVisitor, impactUse); 129 impactSource, worldImpact, impactVisitor, impactUse);
130 } 130 }
131 131
132 void registerInstantiatedType(InterfaceType type) { 132 void registerInstantiatedType(InterfaceType type) {
133 _registerInstantiatedType(type); 133 _registerInstantiatedType(type);
134 } 134 }
135 135
136 void _registerInstantiatedType(InterfaceType type, 136 void _registerInstantiatedType(InterfaceType type,
137 {bool mirrorUsage: false, bool nativeUsage: false}) { 137 {bool mirrorUsage: false, bool nativeUsage: false}) {
138 task.measure(() { 138 task.measure(() {
139 ClassElement cls = type.element; 139 ClassElement cls = type.element;
140 bool isNative = backend.isNative(cls); 140 bool isNative = backend.isNative(cls);
141 _universe.registerTypeInstantiation(type, 141 _universe.registerTypeInstantiation(type,
142 isNative: isNative, 142 isNative: isNative,
143 byMirrors: mirrorUsage, onImplemented: (ClassElement cls) { 143 byMirrors: mirrorUsage, onImplemented: (ClassElement cls) {
144 backend.registerImplementedClass(cls, this); 144 applyImpact(
145 backend.registerImplementedClass(cls, forResolution: false));
145 }); 146 });
146 if (nativeUsage) { 147 if (nativeUsage) {
147 nativeEnqueuer.onInstantiatedType(type); 148 nativeEnqueuer.onInstantiatedType(type);
148 } 149 }
149 backend.registerInstantiatedType(type); 150 backend.registerInstantiatedType(type);
150 // TODO(johnniwinther): Share this reasoning with [Universe]. 151 // TODO(johnniwinther): Share this reasoning with [Universe].
151 if (!cls.isAbstract || isNative || mirrorUsage) { 152 if (!cls.isAbstract || isNative || mirrorUsage) {
152 processInstantiatedClass(cls); 153 processInstantiatedClass(cls);
153 } 154 }
154 }); 155 });
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 message: "Class $superclass has not been " 266 message: "Class $superclass has not been "
266 "processed in resolution.")); 267 "processed in resolution."));
267 */ 268 */
268 269
269 _processedClasses.add(superclass); 270 _processedClasses.add(superclass);
270 recentClasses.add(superclass); 271 recentClasses.add(superclass);
271 superclass.implementation.forEachMember(processInstantiatedClassMember); 272 superclass.implementation.forEachMember(processInstantiatedClassMember);
272 // We only tell the backend once that [superclass] was instantiated, so 273 // We only tell the backend once that [superclass] was instantiated, so
273 // any additional dependencies must be treated as global 274 // any additional dependencies must be treated as global
274 // dependencies. 275 // dependencies.
275 backend.registerInstantiatedClass(superclass, this); 276 applyImpact(backend.registerInstantiatedClass(superclass,
277 forResolution: false));
276 } 278 }
277 279
278 ClassElement superclass = cls; 280 ClassElement superclass = cls;
279 while (superclass != null) { 281 while (superclass != null) {
280 processClass(superclass); 282 processClass(superclass);
281 superclass = superclass.superclass; 283 superclass = superclass.superclass;
282 } 284 }
283 }); 285 });
284 } 286 }
285 287
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 */ 351 */
350 void registerStaticUse(StaticUse staticUse) { 352 void registerStaticUse(StaticUse staticUse) {
351 strategy.processStaticUse(this, staticUse); 353 strategy.processStaticUse(this, staticUse);
352 } 354 }
353 355
354 void registerStaticUseInternal(StaticUse staticUse) { 356 void registerStaticUseInternal(StaticUse staticUse) {
355 Element element = staticUse.element; 357 Element element = staticUse.element;
356 assert(invariant(element, element.isDeclaration, 358 assert(invariant(element, element.isDeclaration,
357 message: "Element ${element} is not the declaration.")); 359 message: "Element ${element} is not the declaration."));
358 _universe.registerStaticUse(staticUse); 360 _universe.registerStaticUse(staticUse);
359 backend.registerStaticUse(this, element); 361 applyImpact(backend.registerStaticUse(element, forResolution: false));
360 bool addElement = true; 362 bool addElement = true;
361 switch (staticUse.kind) { 363 switch (staticUse.kind) {
362 case StaticUseKind.STATIC_TEAR_OFF: 364 case StaticUseKind.STATIC_TEAR_OFF:
363 backend.registerGetOfStaticFunction(this); 365 applyImpact(backend.registerGetOfStaticFunction());
364 break; 366 break;
365 case StaticUseKind.FIELD_GET: 367 case StaticUseKind.FIELD_GET:
366 case StaticUseKind.FIELD_SET: 368 case StaticUseKind.FIELD_SET:
367 case StaticUseKind.CLOSURE: 369 case StaticUseKind.CLOSURE:
368 // TODO(johnniwinther): Avoid this. Currently [FIELD_GET] and 370 // TODO(johnniwinther): Avoid this. Currently [FIELD_GET] and
369 // [FIELD_SET] contains [BoxFieldElement]s which we cannot enqueue. 371 // [FIELD_SET] contains [BoxFieldElement]s which we cannot enqueue.
370 // Also [CLOSURE] contains [LocalFunctionElement] which we cannot 372 // Also [CLOSURE] contains [LocalFunctionElement] which we cannot
371 // enqueue. 373 // enqueue.
372 addElement = false; 374 addElement = false;
373 break; 375 break;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 420
419 void _registerIsCheck(DartType type) { 421 void _registerIsCheck(DartType type) {
420 type = _universe.registerIsCheck(type, _compiler.resolution); 422 type = _universe.registerIsCheck(type, _compiler.resolution);
421 // Even in checked mode, type annotations for return type and argument 423 // Even in checked mode, type annotations for return type and argument
422 // types do not imply type checks, so there should never be a check 424 // types do not imply type checks, so there should never be a check
423 // against the type variable of a typedef. 425 // against the type variable of a typedef.
424 assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef); 426 assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef);
425 } 427 }
426 428
427 void registerCallMethodWithFreeTypeVariables(Element element) { 429 void registerCallMethodWithFreeTypeVariables(Element element) {
428 backend.registerCallMethodWithFreeTypeVariables(element, this); 430 applyImpact(backend.registerCallMethodWithFreeTypeVariables(element,
431 forResolution: false));
429 } 432 }
430 433
431 void registerClosurizedMember(TypedElement element) { 434 void registerClosurizedMember(TypedElement element) {
432 assert(element.isInstanceMember); 435 assert(element.isInstanceMember);
433 if (element.type.containsTypeVariables) { 436 if (element.type.containsTypeVariables) {
434 backend.registerClosureWithFreeTypeVariables(element, this); 437 applyImpact(backend.registerClosureWithFreeTypeVariables(element,
438 forResolution: false));
435 } 439 }
436 backend.registerBoundClosure(this); 440 applyImpact(backend.registerBoundClosure());
437 } 441 }
438 442
439 void forEach(void f(WorkItem work)) { 443 void forEach(void f(WorkItem work)) {
440 do { 444 do {
441 while (queue.isNotEmpty) { 445 while (queue.isNotEmpty) {
442 // TODO(johnniwinther): Find an optimal process order. 446 // TODO(johnniwinther): Find an optimal process order.
443 filter.processWorkItem(f, queue.removeLast()); 447 filter.processWorkItem(f, queue.removeLast());
444 } 448 }
445 List recents = recentClasses.toList(growable: false); 449 List recents = recentClasses.toList(growable: false);
446 recentClasses.clear(); 450 recentClasses.clear();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 static const ImpactUseCase IMPACT_USE = 488 static const ImpactUseCase IMPACT_USE =
485 const ImpactUseCase('CodegenEnqueuer'); 489 const ImpactUseCase('CodegenEnqueuer');
486 490
487 ImpactUseCase get impactUse => IMPACT_USE; 491 ImpactUseCase get impactUse => IMPACT_USE;
488 492
489 bool isProcessed(Element member) => 493 bool isProcessed(Element member) =>
490 member.isAbstract || generatedCode.containsKey(member); 494 member.isAbstract || generatedCode.containsKey(member);
491 495
492 void registerNoSuchMethod(Element element) { 496 void registerNoSuchMethod(Element element) {
493 if (!enabledNoSuchMethod && backend.enabledNoSuchMethod) { 497 if (!enabledNoSuchMethod && backend.enabledNoSuchMethod) {
494 backend.enableNoSuchMethod(this); 498 applyImpact(backend.enableNoSuchMethod());
495 enabledNoSuchMethod = true; 499 enabledNoSuchMethod = true;
496 } 500 }
497 } 501 }
498 502
499 void _logSpecificSummary(log(message)) { 503 void _logSpecificSummary(log(message)) {
500 log('Compiled ${generatedCode.length} methods.'); 504 log('Compiled ${generatedCode.length} methods.');
501 } 505 }
502 506
503 void forgetElement(Element element, Compiler compiler) { 507 void forgetElement(Element element, Compiler compiler) {
504 _forgetElement(element); 508 _forgetElement(element);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 @override 549 @override
546 void visitStaticUse(StaticUse staticUse) { 550 void visitStaticUse(StaticUse staticUse) {
547 enqueuer.registerStaticUse(staticUse); 551 enqueuer.registerStaticUse(staticUse);
548 } 552 }
549 553
550 @override 554 @override
551 void visitTypeUse(TypeUse typeUse) { 555 void visitTypeUse(TypeUse typeUse) {
552 enqueuer.registerTypeUse(typeUse); 556 enqueuer.registerTypeUse(typeUse);
553 } 557 }
554 } 558 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698