OLD | NEW |
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; |
11 import '../common/registry.dart' show Registry; | 11 import '../common/registry.dart' show Registry; |
12 import '../common/names.dart' show Identifiers; | 12 import '../common/names.dart' show Identifiers; |
| 13 import '../common/tasks.dart' show CompilerTask; |
13 import '../common/work.dart' show WorkItem; | 14 import '../common/work.dart' show WorkItem; |
14 import '../common.dart'; | 15 import '../common.dart'; |
15 import '../compiler.dart' show Compiler; | 16 import '../compiler.dart' show Compiler; |
16 import '../dart_types.dart' show DartType, InterfaceType; | 17 import '../dart_types.dart' show DartType, InterfaceType; |
17 import '../elements/elements.dart' | 18 import '../elements/elements.dart' |
18 show | 19 show |
19 ClassElement, | 20 ClassElement, |
20 ConstructorElement, | 21 ConstructorElement, |
21 Element, | 22 Element, |
22 Elements, | 23 Elements, |
23 Entity, | 24 Entity, |
24 FunctionElement, | 25 FunctionElement, |
25 LibraryElement, | 26 LibraryElement, |
26 Member, | 27 Member, |
27 MemberElement, | 28 MemberElement, |
28 MethodElement, | 29 MethodElement, |
29 Name, | 30 Name, |
30 TypedElement, | 31 TypedElement, |
31 TypedefElement; | 32 TypedefElement; |
32 import '../enqueue.dart'; | 33 import '../enqueue.dart'; |
33 import '../js/js.dart' as js; | 34 import '../js/js.dart' as js; |
34 import '../native/native.dart' as native; | 35 import '../native/native.dart' as native; |
35 import '../options.dart'; | 36 import '../options.dart'; |
36 import '../types/types.dart' show TypeMaskStrategy; | 37 import '../types/types.dart' show TypeMaskStrategy; |
37 import '../universe/selector.dart' show Selector; | 38 import '../universe/selector.dart' show Selector; |
38 import '../universe/world_builder.dart'; | 39 import '../universe/world_builder.dart'; |
39 import '../universe/use.dart' | 40 import '../universe/use.dart' |
40 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; | 41 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; |
41 import '../universe/world_impact.dart' | 42 import '../universe/world_impact.dart' |
42 show ImpactUseCase, WorldImpact, WorldImpactVisitor; | 43 show ImpactUseCase, ImpactStrategy, WorldImpact, WorldImpactVisitor; |
43 import '../util/util.dart' show Setlet; | 44 import '../util/util.dart' show Setlet; |
44 import '../world.dart'; | 45 import '../world.dart'; |
45 | 46 |
46 /// [Enqueuer] which is specific to code generation. | 47 /// [Enqueuer] which is specific to code generation. |
47 class CodegenEnqueuer implements Enqueuer { | 48 class CodegenEnqueuer implements Enqueuer { |
48 final String name; | 49 final String name; |
49 @deprecated | 50 @deprecated |
50 final Compiler _compiler; // TODO(ahe): Remove this dependency. | 51 final Compiler _compiler; // TODO(ahe): Remove this dependency. |
51 final EnqueuerStrategy strategy; | 52 final EnqueuerStrategy strategy; |
52 final Map<String, Set<Element>> instanceMembersByName = | 53 final Map<String, Set<Element>> instanceMembersByName = |
53 new Map<String, Set<Element>>(); | 54 new Map<String, Set<Element>>(); |
54 final Map<String, Set<Element>> instanceFunctionsByName = | 55 final Map<String, Set<Element>> instanceFunctionsByName = |
55 new Map<String, Set<Element>>(); | 56 new Map<String, Set<Element>>(); |
56 final Set<ClassElement> _processedClasses = new Set<ClassElement>(); | 57 final Set<ClassElement> _processedClasses = new Set<ClassElement>(); |
57 Set<ClassElement> recentClasses = new Setlet<ClassElement>(); | 58 Set<ClassElement> recentClasses = new Setlet<ClassElement>(); |
58 final CodegenWorldBuilderImpl _universe = | 59 final CodegenWorldBuilderImpl _universe = |
59 new CodegenWorldBuilderImpl(const TypeMaskStrategy()); | 60 new CodegenWorldBuilderImpl(const TypeMaskStrategy()); |
60 | 61 |
61 | |
62 bool queueIsClosed = false; | 62 bool queueIsClosed = false; |
63 EnqueueTask task; | 63 final CompilerTask task; |
64 native.NativeEnqueuer nativeEnqueuer; // Set by EnqueueTask | 64 final native.NativeEnqueuer nativeEnqueuer; |
65 | |
66 | 65 |
67 WorldImpactVisitor impactVisitor; | 66 WorldImpactVisitor impactVisitor; |
68 | 67 |
69 CodegenEnqueuer(Compiler compiler, this.strategy) | 68 CodegenEnqueuer(this.task, Compiler compiler, this.strategy) |
70 : queue = new Queue<CodegenWorkItem>(), | 69 : queue = new Queue<CodegenWorkItem>(), |
71 newlyEnqueuedElements = compiler.cacheStrategy.newSet(), | 70 newlyEnqueuedElements = compiler.cacheStrategy.newSet(), |
72 newlySeenSelectors = compiler.cacheStrategy.newSet(), | 71 newlySeenSelectors = compiler.cacheStrategy.newSet(), |
| 72 nativeEnqueuer = compiler.backend.nativeCodegenEnqueuer(), |
73 this.name = 'codegen enqueuer', | 73 this.name = 'codegen enqueuer', |
74 this._compiler = compiler { | 74 this._compiler = compiler { |
75 impactVisitor = new _EnqueuerImpactVisitor(this); | 75 impactVisitor = new _EnqueuerImpactVisitor(this); |
76 } | 76 } |
77 | 77 |
78 CodegenWorldBuilder get universe => _universe; | 78 CodegenWorldBuilder get universe => _universe; |
79 | 79 |
80 Backend get backend => _compiler.backend; | 80 Backend get backend => _compiler.backend; |
81 | 81 |
82 CompilerOptions get options => _compiler.options; | 82 CompilerOptions get options => _compiler.options; |
(...skipping 29 matching lines...) Expand all Loading... |
112 | 112 |
113 if (options.hasIncrementalSupport && !isProcessed(element)) { | 113 if (options.hasIncrementalSupport && !isProcessed(element)) { |
114 newlyEnqueuedElements.add(element); | 114 newlyEnqueuedElements.add(element); |
115 } | 115 } |
116 | 116 |
117 if (queueIsClosed) { | 117 if (queueIsClosed) { |
118 throw new SpannableAssertionFailure( | 118 throw new SpannableAssertionFailure( |
119 element, "Codegen work list is closed. Trying to add $element"); | 119 element, "Codegen work list is closed. Trying to add $element"); |
120 } | 120 } |
121 queue.add(new CodegenWorkItem(_compiler, element)); | 121 queue.add(new CodegenWorkItem(_compiler, element)); |
122 if (options.dumpInfo) { | 122 // TODO(sigmund): add other missing dependencies (internals, selectors |
123 // TODO(sigmund): add other missing dependencies (internals, selectors | 123 // enqueued after allocations). |
124 // enqueued after allocations), also enable only for the codegen enqueuer. | 124 _compiler.dumpInfoTask |
125 _compiler.dumpInfoTask | 125 .registerDependency(_compiler.currentElement, element); |
126 .registerDependency(_compiler.currentElement, element); | |
127 } | |
128 } | 126 } |
129 | 127 |
130 void applyImpact(WorldImpact worldImpact, {Element impactSource}) { | 128 void applyImpact(ImpactStrategy impactStrategy, WorldImpact worldImpact, |
131 _compiler.impactStrategy | 129 {Element impactSource}) { |
132 .visitImpact(impactSource, worldImpact, impactVisitor, impactUse); | 130 impactStrategy.visitImpact( |
| 131 impactSource, worldImpact, impactVisitor, impactUse); |
133 } | 132 } |
134 | 133 |
135 void registerInstantiatedType(InterfaceType type) { | 134 void registerInstantiatedType(InterfaceType type) { |
136 _registerInstantiatedType(type); | 135 _registerInstantiatedType(type); |
137 } | 136 } |
138 | 137 |
139 void _registerInstantiatedType(InterfaceType type, | 138 void _registerInstantiatedType(InterfaceType type, |
140 {bool mirrorUsage: false, bool nativeUsage: false}) { | 139 {bool mirrorUsage: false, bool nativeUsage: false}) { |
141 task.measure(() { | 140 task.measure(() { |
142 ClassElement cls = type.element; | 141 ClassElement cls = type.element; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 if (options.enableTypeAssertions) { | 411 if (options.enableTypeAssertions) { |
413 _registerIsCheck(type); | 412 _registerIsCheck(type); |
414 } | 413 } |
415 break; | 414 break; |
416 case TypeUseKind.TYPE_LITERAL: | 415 case TypeUseKind.TYPE_LITERAL: |
417 break; | 416 break; |
418 } | 417 } |
419 } | 418 } |
420 | 419 |
421 void _registerIsCheck(DartType type) { | 420 void _registerIsCheck(DartType type) { |
422 type = _universe.registerIsCheck(type, _compiler); | 421 type = _universe.registerIsCheck(type, _compiler.resolution); |
423 // Even in checked mode, type annotations for return type and argument | 422 // Even in checked mode, type annotations for return type and argument |
424 // types do not imply type checks, so there should never be a check | 423 // types do not imply type checks, so there should never be a check |
425 // against the type variable of a typedef. | 424 // against the type variable of a typedef. |
426 assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef); | 425 assert(!type.isTypeVariable || !type.element.enclosingElement.isTypedef); |
427 } | 426 } |
428 | 427 |
429 void registerCallMethodWithFreeTypeVariables(Element element) { | 428 void registerCallMethodWithFreeTypeVariables(Element element) { |
430 backend.registerCallMethodWithFreeTypeVariables(element, this); | 429 backend.registerCallMethodWithFreeTypeVariables(element, this); |
431 } | 430 } |
432 | 431 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if (!enabledNoSuchMethod && backend.enabledNoSuchMethod) { | 494 if (!enabledNoSuchMethod && backend.enabledNoSuchMethod) { |
496 backend.enableNoSuchMethod(this); | 495 backend.enableNoSuchMethod(this); |
497 enabledNoSuchMethod = true; | 496 enabledNoSuchMethod = true; |
498 } | 497 } |
499 } | 498 } |
500 | 499 |
501 void _logSpecificSummary(log(message)) { | 500 void _logSpecificSummary(log(message)) { |
502 log('Compiled ${generatedCode.length} methods.'); | 501 log('Compiled ${generatedCode.length} methods.'); |
503 } | 502 } |
504 | 503 |
505 void forgetElement(Element element) { | 504 void forgetElement(Element element, Compiler compiler) { |
506 _forgetElement(element); | 505 _forgetElement(element); |
507 generatedCode.remove(element); | 506 generatedCode.remove(element); |
508 if (element is MemberElement) { | 507 if (element is MemberElement) { |
509 for (Element closure in element.nestedClosures) { | 508 for (Element closure in element.nestedClosures) { |
510 generatedCode.remove(closure); | 509 generatedCode.remove(closure); |
511 removeFromSet(instanceMembersByName, closure); | 510 removeFromSet(instanceMembersByName, closure); |
512 removeFromSet(instanceFunctionsByName, closure); | 511 removeFromSet(instanceFunctionsByName, closure); |
513 } | 512 } |
514 } | 513 } |
515 } | 514 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 @override | 546 @override |
548 void visitStaticUse(StaticUse staticUse) { | 547 void visitStaticUse(StaticUse staticUse) { |
549 enqueuer.registerStaticUse(staticUse); | 548 enqueuer.registerStaticUse(staticUse); |
550 } | 549 } |
551 | 550 |
552 @override | 551 @override |
553 void visitTypeUse(TypeUse typeUse) { | 552 void visitTypeUse(TypeUse typeUse) { |
554 enqueuer.registerTypeUse(typeUse); | 553 enqueuer.registerTypeUse(typeUse); |
555 } | 554 } |
556 } | 555 } |
OLD | NEW |