| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library fletchc.fletch_enqueuer; | 5 library dartino_compiler.dartino_enqueuer; |
| 6 | 6 |
| 7 import 'dart:collection' show | 7 import 'dart:collection' show |
| 8 Queue; | 8 Queue; |
| 9 | 9 |
| 10 import 'package:compiler/src/common/tasks.dart' show | 10 import 'package:compiler/src/common/tasks.dart' show |
| 11 CompilerTask; | 11 CompilerTask; |
| 12 | 12 |
| 13 import 'package:compiler/src/universe/world_impact.dart' show | 13 import 'package:compiler/src/universe/world_impact.dart' show |
| 14 WorldImpact; | 14 WorldImpact; |
| 15 | 15 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 LocalFunctionElement, | 49 LocalFunctionElement, |
| 50 Name, | 50 Name, |
| 51 TypedElement; | 51 TypedElement; |
| 52 | 52 |
| 53 import 'package:compiler/src/resolution/tree_elements.dart' show | 53 import 'package:compiler/src/resolution/tree_elements.dart' show |
| 54 TreeElements; | 54 TreeElements; |
| 55 | 55 |
| 56 import 'package:compiler/src/util/util.dart' show | 56 import 'package:compiler/src/util/util.dart' show |
| 57 Hashing; | 57 Hashing; |
| 58 | 58 |
| 59 import 'fletch_compiler_implementation.dart' show | 59 import 'dartino_compiler_implementation.dart' show |
| 60 FletchCompilerImplementation; | 60 DartinoCompilerImplementation; |
| 61 | 61 |
| 62 import 'dynamic_call_enqueuer.dart' show | 62 import 'dynamic_call_enqueuer.dart' show |
| 63 Closurization, | 63 Closurization, |
| 64 DynamicCallEnqueuer, | 64 DynamicCallEnqueuer, |
| 65 UsageRecorder; | 65 UsageRecorder; |
| 66 | 66 |
| 67 import 'fletch_registry.dart' show | 67 import 'dartino_registry.dart' show |
| 68 ClosureKind, | 68 ClosureKind, |
| 69 FletchRegistry, | 69 DartinoRegistry, |
| 70 FletchRegistry; | 70 DartinoRegistry; |
| 71 | 71 |
| 72 import 'dart:developer'; | 72 import 'dart:developer'; |
| 73 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; | 73 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
| 74 | 74 |
| 75 import 'package:compiler/src/universe/use.dart' show | 75 import 'package:compiler/src/universe/use.dart' show |
| 76 DynamicUse, | 76 DynamicUse, |
| 77 StaticUse; | 77 StaticUse; |
| 78 | 78 |
| 79 import 'package:compiler/src/universe/use.dart'; | 79 import 'package:compiler/src/universe/use.dart'; |
| 80 import 'package:compiler/src/common/work.dart'; | 80 import 'package:compiler/src/common/work.dart'; |
| 81 import 'package:compiler/src/common/resolution.dart'; | 81 import 'package:compiler/src/common/resolution.dart'; |
| 82 import 'package:compiler/src/enqueue.dart'; | 82 import 'package:compiler/src/enqueue.dart'; |
| 83 | 83 |
| 84 part 'enqueuer_mixin.dart'; | 84 part 'enqueuer_mixin.dart'; |
| 85 | 85 |
| 86 /// True if enqueuing of system libraries should be reported in verbose mode. | 86 /// True if enqueuing of system libraries should be reported in verbose mode. |
| 87 const bool logSystemLibraries = | 87 const bool logSystemLibraries = |
| 88 const bool.fromEnvironment("fletchc.logSystemLibraries"); | 88 const bool.fromEnvironment("dartino_compiler.logSystemLibraries"); |
| 89 | 89 |
| 90 /// Returns true if enqueuing of [element] should be reported in verbose | 90 /// Returns true if enqueuing of [element] should be reported in verbose |
| 91 /// mode. See [logSystemLibraries]. | 91 /// mode. See [logSystemLibraries]. |
| 92 bool shouldReportEnqueuingOfElement(Compiler compiler, Element element) { | 92 bool shouldReportEnqueuingOfElement(Compiler compiler, Element element) { |
| 93 if (logSystemLibraries) return true; | 93 if (logSystemLibraries) return true; |
| 94 return compiler.inUserCode(element); | 94 return compiler.inUserCode(element); |
| 95 } | 95 } |
| 96 | 96 |
| 97 /// Custom enqueuer for Fletch. | 97 /// Custom enqueuer for Dartino. |
| 98 class FletchEnqueueTask extends CompilerTask implements EnqueueTask { | 98 class DartinoEnqueueTask extends CompilerTask implements EnqueueTask { |
| 99 final ResolutionEnqueuer resolution; | 99 final ResolutionEnqueuer resolution; |
| 100 | 100 |
| 101 final FletchEnqueuer codegen; | 101 final DartinoEnqueuer codegen; |
| 102 | 102 |
| 103 FletchEnqueueTask(FletchCompilerImplementation compiler) | 103 DartinoEnqueueTask(DartinoCompilerImplementation compiler) |
| 104 : resolution = new ResolutionEnqueuer( | 104 : resolution = new ResolutionEnqueuer( |
| 105 compiler, compiler.backend.createItemCompilationContext, | 105 compiler, compiler.backend.createItemCompilationContext, |
| 106 compiler.analyzeOnly && compiler.analyzeMain | 106 compiler.analyzeOnly && compiler.analyzeMain |
| 107 ? const EnqueuerStrategy() : const TreeShakingEnqueuerStrategy()), | 107 ? const EnqueuerStrategy() : const TreeShakingEnqueuerStrategy()), |
| 108 codegen = new FletchEnqueuer( | 108 codegen = new DartinoEnqueuer( |
| 109 compiler, compiler.backend.createItemCompilationContext), | 109 compiler, compiler.backend.createItemCompilationContext), |
| 110 super(compiler) { | 110 super(compiler) { |
| 111 codegen.task = this; | 111 codegen.task = this; |
| 112 resolution.task = this; | 112 resolution.task = this; |
| 113 codegen.nativeEnqueuer = compiler.backend.nativeCodegenEnqueuer(codegen); | 113 codegen.nativeEnqueuer = compiler.backend.nativeCodegenEnqueuer(codegen); |
| 114 | 114 |
| 115 resolution.nativeEnqueuer = | 115 resolution.nativeEnqueuer = |
| 116 compiler.backend.nativeResolutionEnqueuer(resolution); | 116 compiler.backend.nativeResolutionEnqueuer(resolution); |
| 117 } | 117 } |
| 118 | 118 |
| 119 String get name => 'Fletch enqueue'; | 119 String get name => 'Dartino enqueue'; |
| 120 | 120 |
| 121 void forgetElement(Element element) { | 121 void forgetElement(Element element) { |
| 122 resolution.forgetElement(element); | 122 resolution.forgetElement(element); |
| 123 codegen.forgetElement(element); | 123 codegen.forgetElement(element); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 class FletchEnqueuer extends EnqueuerMixin | 127 class DartinoEnqueuer extends EnqueuerMixin |
| 128 implements CodegenEnqueuer, UsageRecorder { | 128 implements CodegenEnqueuer, UsageRecorder { |
| 129 final ItemCompilationContextCreator itemCompilationContextCreator; | 129 final ItemCompilationContextCreator itemCompilationContextCreator; |
| 130 | 130 |
| 131 final FletchCompilerImplementation compiler; | 131 final DartinoCompilerImplementation compiler; |
| 132 | 132 |
| 133 bool queueIsClosed = false; | 133 bool queueIsClosed = false; |
| 134 | 134 |
| 135 bool hasEnqueuedReflectiveElements = false; | 135 bool hasEnqueuedReflectiveElements = false; |
| 136 | 136 |
| 137 bool hasEnqueuedReflectiveStaticFields = false; | 137 bool hasEnqueuedReflectiveStaticFields = false; |
| 138 | 138 |
| 139 EnqueueTask task; | 139 EnqueueTask task; |
| 140 | 140 |
| 141 // TODO(ahe): Get rid of this? | 141 // TODO(ahe): Get rid of this? |
| 142 var nativeEnqueuer; | 142 var nativeEnqueuer; |
| 143 | 143 |
| 144 final Universe universe = new Universe(const TypeMaskStrategy()); | 144 final Universe universe = new Universe(const TypeMaskStrategy()); |
| 145 | 145 |
| 146 final Set<ElementUsage> _enqueuedUsages = new Set<ElementUsage>(); | 146 final Set<ElementUsage> _enqueuedUsages = new Set<ElementUsage>(); |
| 147 final Map<Element, List<ElementUsage>> _enqueuedUsagesByElement = | 147 final Map<Element, List<ElementUsage>> _enqueuedUsagesByElement = |
| 148 <Element, List<ElementUsage>>{}; | 148 <Element, List<ElementUsage>>{}; |
| 149 | 149 |
| 150 final Queue<ElementUsage> _pendingEnqueuedUsages = | 150 final Queue<ElementUsage> _pendingEnqueuedUsages = |
| 151 new Queue<ElementUsage>(); | 151 new Queue<ElementUsage>(); |
| 152 | 152 |
| 153 final Set<TypeTest> _typeTests = new Set<TypeTest>(); | 153 final Set<TypeTest> _typeTests = new Set<TypeTest>(); |
| 154 | 154 |
| 155 final Queue<TypeTest> _pendingTypeTests = new Queue<TypeTest>(); | 155 final Queue<TypeTest> _pendingTypeTests = new Queue<TypeTest>(); |
| 156 | 156 |
| 157 final DynamicCallEnqueuer dynamicCallEnqueuer; | 157 final DynamicCallEnqueuer dynamicCallEnqueuer; |
| 158 | 158 |
| 159 FletchEnqueuer( | 159 DartinoEnqueuer( |
| 160 FletchCompilerImplementation compiler, | 160 DartinoCompilerImplementation compiler, |
| 161 this.itemCompilationContextCreator) | 161 this.itemCompilationContextCreator) |
| 162 : compiler = compiler, | 162 : compiler = compiler, |
| 163 dynamicCallEnqueuer = new DynamicCallEnqueuer(compiler); | 163 dynamicCallEnqueuer = new DynamicCallEnqueuer(compiler); |
| 164 | 164 |
| 165 bool get queueIsEmpty { | 165 bool get queueIsEmpty { |
| 166 return _pendingEnqueuedUsages.isEmpty && _pendingTypeTests.isEmpty; | 166 return _pendingEnqueuedUsages.isEmpty && _pendingTypeTests.isEmpty; |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool get isResolutionQueue => false; | 169 bool get isResolutionQueue => false; |
| 170 | 170 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 200 } | 200 } |
| 201 | 201 |
| 202 void processQueue() { | 202 void processQueue() { |
| 203 do { | 203 do { |
| 204 do { | 204 do { |
| 205 while (!queueIsEmpty) { | 205 while (!queueIsEmpty) { |
| 206 if (!_pendingEnqueuedUsages.isEmpty) { | 206 if (!_pendingEnqueuedUsages.isEmpty) { |
| 207 ElementUsage usage = _pendingEnqueuedUsages.removeFirst(); | 207 ElementUsage usage = _pendingEnqueuedUsages.removeFirst(); |
| 208 AstElement element = usage.element; | 208 AstElement element = usage.element; |
| 209 TreeElements treeElements = element.resolvedAst.elements; | 209 TreeElements treeElements = element.resolvedAst.elements; |
| 210 FletchRegistry registry = new FletchRegistry(compiler); | 210 DartinoRegistry registry = new DartinoRegistry(compiler); |
| 211 Selector selector = usage.selector; | 211 Selector selector = usage.selector; |
| 212 if (usage.closureKind != null) { | 212 if (usage.closureKind != null) { |
| 213 compiler.context.backend.compileClosurizationUsage( | 213 compiler.context.backend.compileClosurizationUsage( |
| 214 element, selector, treeElements, registry, usage.closureKind); | 214 element, selector, treeElements, registry, usage.closureKind); |
| 215 } else if (selector != null) { | 215 } else if (selector != null) { |
| 216 compiler.context.backend.compileElementUsage( | 216 compiler.context.backend.compileElementUsage( |
| 217 element, selector, treeElements, registry); | 217 element, selector, treeElements, registry); |
| 218 } else { | 218 } else { |
| 219 compiler.context.backend.compileElement( | 219 compiler.context.backend.compileElement( |
| 220 element, treeElements, registry); | 220 element, treeElements, registry); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 331 |
| 332 TypeTest(ClassElement element, InterfaceType type) | 332 TypeTest(ClassElement element, InterfaceType type) |
| 333 : element = element, | 333 : element = element, |
| 334 type = type, | 334 type = type, |
| 335 hashCode = Hashing.mixHashCodeBits(element.hashCode, type.hashCode); | 335 hashCode = Hashing.mixHashCodeBits(element.hashCode, type.hashCode); |
| 336 | 336 |
| 337 bool operator ==(other) { | 337 bool operator ==(other) { |
| 338 return other is TypeTest && element == other.element && type == other.type; | 338 return other is TypeTest && element == other.element && type == other.type; |
| 339 } | 339 } |
| 340 } | 340 } |
| OLD | NEW |