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.enqueue; | 5 library dart2js.enqueue; |
6 | 6 |
7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
8 | 8 |
9 import 'cache_strategy.dart'; | 9 import 'cache_strategy.dart'; |
10 import 'common/backend_api.dart' show Backend; | 10 import 'common/backend_api.dart' show Backend; |
11 import 'common/names.dart' show Identifiers; | 11 import 'common/names.dart' show Identifiers; |
12 import 'common/resolution.dart' show Resolution, ResolutionWorkItem; | 12 import 'common/resolution.dart' show Resolution, ResolutionWorkItem; |
13 import 'common/tasks.dart' show CompilerTask; | 13 import 'common/tasks.dart' show CompilerTask; |
14 import 'common/work.dart' show WorkItem; | 14 import 'common/work.dart' show WorkItem; |
15 import 'common.dart'; | 15 import 'common.dart'; |
16 import 'compiler.dart' show Compiler, GlobalDependencyRegistry; | 16 import 'compiler.dart' show Compiler, GlobalDependencyRegistry; |
17 import 'core_types.dart' show CommonElements; | |
18 import 'options.dart'; | 17 import 'options.dart'; |
19 import 'dart_types.dart' show DartType, InterfaceType; | 18 import 'dart_types.dart' show DartType, InterfaceType; |
20 import 'elements/elements.dart' | 19 import 'elements/elements.dart' |
21 show | 20 show |
22 AnalyzableElement, | 21 AnalyzableElement, |
23 AstElement, | 22 AstElement, |
24 ClassElement, | 23 ClassElement, |
25 ConstructorElement, | 24 ConstructorElement, |
26 Element, | 25 Element, |
27 Entity, | 26 Entity, |
28 LibraryElement, | |
29 LocalFunctionElement, | |
30 MemberElement; | 27 MemberElement; |
31 import 'elements/entities.dart'; | 28 import 'elements/entities.dart'; |
32 import 'native/native.dart' as native; | 29 import 'native/native.dart' as native; |
33 import 'types/types.dart' show TypeMaskStrategy; | 30 import 'types/types.dart' show TypeMaskStrategy; |
34 import 'universe/world_builder.dart'; | 31 import 'universe/world_builder.dart'; |
35 import 'universe/use.dart' | 32 import 'universe/use.dart' |
36 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; | 33 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; |
37 import 'universe/world_impact.dart' | 34 import 'universe/world_impact.dart' |
38 show ImpactStrategy, ImpactUseCase, WorldImpact, WorldImpactVisitor; | 35 show ImpactStrategy, ImpactUseCase, WorldImpact, WorldImpactVisitor; |
39 import 'util/enumset.dart'; | 36 import 'util/enumset.dart'; |
(...skipping 12 matching lines...) Expand all Loading... |
52 super(compiler.measurer) { | 49 super(compiler.measurer) { |
53 _resolution = new ResolutionEnqueuer( | 50 _resolution = new ResolutionEnqueuer( |
54 this, | 51 this, |
55 compiler.options, | 52 compiler.options, |
56 compiler.resolution, | 53 compiler.resolution, |
57 compiler.options.analyzeOnly && compiler.options.analyzeMain | 54 compiler.options.analyzeOnly && compiler.options.analyzeMain |
58 ? const DirectEnqueuerStrategy() | 55 ? const DirectEnqueuerStrategy() |
59 : const TreeShakingEnqueuerStrategy(), | 56 : const TreeShakingEnqueuerStrategy(), |
60 compiler.globalDependencies, | 57 compiler.globalDependencies, |
61 compiler.backend, | 58 compiler.backend, |
62 compiler.coreClasses, | |
63 compiler.cacheStrategy); | 59 compiler.cacheStrategy); |
64 _codegen = compiler.backend.createCodegenEnqueuer(this, compiler); | 60 _codegen = compiler.backend.createCodegenEnqueuer(this, compiler); |
65 } | 61 } |
66 | 62 |
67 ResolutionEnqueuer get resolution => _resolution; | 63 ResolutionEnqueuer get resolution => _resolution; |
68 Enqueuer get codegen => _codegen; | 64 Enqueuer get codegen => _codegen; |
69 | 65 |
70 void forgetEntity(Entity entity) { | 66 void forgetEntity(Entity entity) { |
71 resolution.forgetEntity(entity, compiler); | 67 resolution.forgetEntity(entity, compiler); |
72 codegen.forgetEntity(entity, compiler); | 68 codegen.forgetEntity(entity, compiler); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 class ResolutionEnqueuer extends EnqueuerImpl { | 125 class ResolutionEnqueuer extends EnqueuerImpl { |
130 static const ImpactUseCase IMPACT_USE = | 126 static const ImpactUseCase IMPACT_USE = |
131 const ImpactUseCase('ResolutionEnqueuer'); | 127 const ImpactUseCase('ResolutionEnqueuer'); |
132 | 128 |
133 final CompilerTask task; | 129 final CompilerTask task; |
134 final String name; | 130 final String name; |
135 final Resolution _resolution; | 131 final Resolution _resolution; |
136 final CompilerOptions _options; | 132 final CompilerOptions _options; |
137 final Backend backend; | 133 final Backend backend; |
138 final GlobalDependencyRegistry _globalDependencies; | 134 final GlobalDependencyRegistry _globalDependencies; |
139 final CommonElements _commonElements; | |
140 final native.NativeEnqueuer nativeEnqueuer; | 135 final native.NativeEnqueuer nativeEnqueuer; |
141 | 136 |
142 final EnqueuerStrategy strategy; | 137 final EnqueuerStrategy strategy; |
143 Set<ClassEntity> _recentClasses = new Setlet<ClassEntity>(); | 138 Set<ClassEntity> _recentClasses = new Setlet<ClassEntity>(); |
144 final ResolutionWorldBuilderImpl _universe; | 139 final ResolutionWorldBuilderImpl _universe; |
145 | 140 |
146 bool queueIsClosed = false; | 141 bool queueIsClosed = false; |
147 | 142 |
148 WorldImpactVisitor _impactVisitor; | 143 WorldImpactVisitor _impactVisitor; |
149 | 144 |
150 /// All declaration elements that have been processed by the resolver. | 145 /// All declaration elements that have been processed by the resolver. |
151 final Set<AstElement> _processedElements = new Set<AstElement>(); | 146 final Set<Entity> _processedElements = new Set<Entity>(); |
152 | 147 |
153 final Queue<WorkItem> _queue = new Queue<WorkItem>(); | 148 final Queue<WorkItem> _queue = new Queue<WorkItem>(); |
154 | 149 |
155 /// Queue of deferred resolution actions to execute when the resolution queue | 150 /// Queue of deferred resolution actions to execute when the resolution queue |
156 /// has been emptied. | 151 /// has been emptied. |
157 final Queue<_DeferredAction> _deferredQueue = new Queue<_DeferredAction>(); | 152 final Queue<_DeferredAction> _deferredQueue = new Queue<_DeferredAction>(); |
158 | 153 |
159 ResolutionEnqueuer( | 154 ResolutionEnqueuer( |
160 this.task, | 155 this.task, |
161 this._options, | 156 this._options, |
162 Resolution resolution, | 157 Resolution resolution, |
163 this.strategy, | 158 this.strategy, |
164 this._globalDependencies, | 159 this._globalDependencies, |
165 Backend backend, | 160 Backend backend, |
166 this._commonElements, | |
167 CacheStrategy cacheStrategy, | 161 CacheStrategy cacheStrategy, |
168 [this.name = 'resolution enqueuer']) | 162 [this.name = 'resolution enqueuer']) |
169 : this.backend = backend, | 163 : this.backend = backend, |
170 this._resolution = resolution, | 164 this._resolution = resolution, |
171 this.nativeEnqueuer = backend.nativeResolutionEnqueuer(), | 165 this.nativeEnqueuer = backend.nativeResolutionEnqueuer(), |
172 _universe = new ResolutionWorldBuilderImpl( | 166 _universe = new ResolutionWorldBuilderImpl( |
173 backend, resolution, cacheStrategy, const TypeMaskStrategy()) { | 167 backend, resolution, cacheStrategy, const TypeMaskStrategy()) { |
174 _impactVisitor = new EnqueuerImplImpactVisitor(this); | 168 _impactVisitor = new EnqueuerImplImpactVisitor(this); |
175 } | 169 } |
176 | 170 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 if (queueIsClosed) { | 408 if (queueIsClosed) { |
415 throw new SpannableAssertionFailure( | 409 throw new SpannableAssertionFailure( |
416 element, "Resolution work list is closed. Trying to add $element."); | 410 element, "Resolution work list is closed. Trying to add $element."); |
417 } | 411 } |
418 | 412 |
419 applyImpact(backend.registerUsedElement(element, forResolution: true)); | 413 applyImpact(backend.registerUsedElement(element, forResolution: true)); |
420 _openWorld.registerUsedElement(element); | 414 _openWorld.registerUsedElement(element); |
421 | 415 |
422 ResolutionWorkItem workItem = _resolution.createWorkItem(element); | 416 ResolutionWorkItem workItem = _resolution.createWorkItem(element); |
423 _queue.add(workItem); | 417 _queue.add(workItem); |
424 | |
425 // Enable isolate support if we start using something from the isolate | |
426 // library, or timers for the async library. We exclude constant fields, | |
427 // which are ending here because their initializing expression is compiled. | |
428 LibraryElement library = element.library; | |
429 if (!universe.hasIsolateSupport && (!element.isField || !element.isConst)) { | |
430 String uri = library.canonicalUri.toString(); | |
431 if (uri == 'dart:isolate') { | |
432 _enableIsolateSupport(); | |
433 } else if (uri == 'dart:async') { | |
434 if (element.name == '_createTimer' || | |
435 element.name == '_createPeriodicTimer') { | |
436 // The [:Timer:] class uses the event queue of the isolate | |
437 // library, so we make sure that event queue is generated. | |
438 _enableIsolateSupport(); | |
439 } | |
440 } | |
441 } | |
442 | |
443 if (element.isGetter && element.name == Identifiers.runtimeType_) { | |
444 // Enable runtime type support if we discover a getter called runtimeType. | |
445 // We have to enable runtime type before hitting the codegen, so | |
446 // that constructors know whether they need to generate code for | |
447 // runtime type. | |
448 _universe.hasRuntimeTypeSupport = true; | |
449 // TODO(ahe): Record precise dependency here. | |
450 applyImpact(backend.registerRuntimeType()); | |
451 } else if (_commonElements.isFunctionApplyMethod(element)) { | |
452 _universe.hasFunctionApplySupport = true; | |
453 } | |
454 } | 418 } |
455 | 419 |
456 void _registerNoSuchMethod(Element element) { | 420 void _registerNoSuchMethod(Element element) { |
457 backend.registerNoSuchMethod(element); | 421 backend.registerNoSuchMethod(element); |
458 } | 422 } |
459 | 423 |
460 void _enableIsolateSupport() { | |
461 _universe.hasIsolateSupport = true; | |
462 applyImpact(backend.enableIsolateSupport(forResolution: true)); | |
463 } | |
464 | |
465 /// Adds an action to the deferred task queue. | 424 /// Adds an action to the deferred task queue. |
466 /// The action is performed the next time the resolution queue has been | 425 /// The action is performed the next time the resolution queue has been |
467 /// emptied. | 426 /// emptied. |
468 /// | 427 /// |
469 /// The queue is processed in FIFO order. | 428 /// The queue is processed in FIFO order. |
470 void addDeferredAction(Entity entity, void action()) { | 429 void addDeferredAction(Entity entity, void action()) { |
471 if (queueIsClosed) { | 430 if (queueIsClosed) { |
472 throw new SpannableAssertionFailure( | 431 throw new SpannableAssertionFailure( |
473 entity, | 432 entity, |
474 "Resolution work list is closed. " | 433 "Resolution work list is closed. " |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 } | 553 } |
595 | 554 |
596 typedef void _DeferredActionFunction(); | 555 typedef void _DeferredActionFunction(); |
597 | 556 |
598 class _DeferredAction { | 557 class _DeferredAction { |
599 final Element element; | 558 final Element element; |
600 final _DeferredActionFunction action; | 559 final _DeferredActionFunction action; |
601 | 560 |
602 _DeferredAction(this.element, this.action); | 561 _DeferredAction(this.element, this.action); |
603 } | 562 } |
OLD | NEW |