Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 trydart.caching_compiler; | 5 library trydart.caching_compiler; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink; | 7 import 'dart:profiler' show |
| 8 UserTag; | |
| 8 | 9 |
| 9 import 'package:compiler/compiler.dart' show | 10 import 'package:compiler/compiler.dart' show |
| 10 CompilerInputProvider, | 11 CompilerInputProvider, |
| 11 CompilerOutputProvider, | 12 CompilerOutputProvider, |
| 12 Diagnostic, | 13 Diagnostic, |
| 13 DiagnosticHandler; | 14 DiagnosticHandler; |
| 14 | 15 |
| 15 import 'package:compiler/implementation/apiimpl.dart' show | 16 import 'package:compiler/implementation/apiimpl.dart' show |
| 16 Compiler; | 17 Compiler; |
| 17 | 18 |
| 18 import 'package:compiler/implementation/dart2jslib.dart' show | 19 import 'package:compiler/implementation/dart2jslib.dart' show |
| 19 LibraryLoaderTask, // TODO(ahe): Remove this import. | 20 LibraryLoaderTask, // TODO(ahe): Remove this import. |
| 20 NullSink; | 21 NullSink; |
| 21 | 22 |
| 22 import 'package:compiler/implementation/js_backend/js_backend.dart' show | 23 import 'package:compiler/implementation/js_backend/js_backend.dart' show |
| 23 JavaScriptBackend; | 24 JavaScriptBackend; |
| 24 | 25 |
| 25 import 'package:compiler/implementation/elements/elements.dart' show | 26 import 'package:compiler/implementation/elements/elements.dart' show |
| 26 LibraryElement; | 27 LibraryElement; |
| 27 | 28 |
| 29 import 'package:compiler/implementation/native_handler.dart' as native; | |
| 30 | |
| 28 void clearLibraryLoader(LibraryLoaderTask libraryLoader) { | 31 void clearLibraryLoader(LibraryLoaderTask libraryLoader) { |
| 29 // TODO(ahe): Move this method to [LibraryLoader]. | 32 // TODO(ahe): Move this method to [LibraryLoader]. |
| 30 libraryLoader | 33 libraryLoader |
| 31 ..libraryResourceUriMap.clear() | 34 ..libraryResourceUriMap.clear() |
| 32 ..libraryNames.clear(); | 35 ..libraryNames.clear(); |
| 33 } | 36 } |
| 34 | 37 |
| 35 void reuseLibrary( | 38 void reuseLibrary( |
| 36 LibraryLoaderTask libraryLoader, | 39 LibraryLoaderTask libraryLoader, |
| 37 LibraryElement library) { | 40 LibraryElement library) { |
| 38 // TODO(ahe): Move this method to [LibraryLoader]. | 41 // TODO(ahe): Move this method to [LibraryLoader]. |
| 39 String name = library.getLibraryOrScriptName(); | 42 String name = library.getLibraryOrScriptName(); |
| 40 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; | 43 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; |
| 41 libraryLoader | 44 libraryLoader |
| 42 ..libraryResourceUriMap[resourceUri] = library | 45 ..libraryResourceUriMap[resourceUri] = library |
| 43 ..libraryNames[name] = library; | 46 ..libraryNames[name] = library; |
| 44 } | 47 } |
| 45 | 48 |
| 46 Compiler reuseCompiler( | 49 Compiler reuseCompiler( |
| 47 {DiagnosticHandler diagnosticHandler, | 50 {DiagnosticHandler diagnosticHandler, |
| 48 CompilerInputProvider inputProvider, | 51 CompilerInputProvider inputProvider, |
| 49 CompilerOutputProvider outputProvider, | 52 CompilerOutputProvider outputProvider, |
| 50 List<String> options: const [], | 53 List<String> options: const [], |
| 51 Compiler cachedCompiler, | 54 Compiler cachedCompiler, |
| 52 Uri libraryRoot, | 55 Uri libraryRoot, |
| 53 Uri packageRoot}) { | 56 Uri packageRoot, |
| 57 bool packagesAreImmutable: false}) { | |
| 58 new UserTag('reuseCompiler').makeCurrent(); | |
|
kasperl
2014/06/23 12:15:06
Shouldn't you be leaving the reuseCompiler tag at
ahe
2014/06/23 12:33:28
Done.
| |
| 54 if (libraryRoot == null) { | 59 if (libraryRoot == null) { |
| 55 throw 'Missing libraryRoot'; | 60 throw 'Missing libraryRoot'; |
| 56 } | 61 } |
| 57 if (inputProvider == null) { | 62 if (inputProvider == null) { |
| 58 throw 'Missing inputProvider'; | 63 throw 'Missing inputProvider'; |
| 59 } | 64 } |
| 60 if (diagnosticHandler == null) { | 65 if (diagnosticHandler == null) { |
| 61 throw 'Missing diagnosticHandler'; | 66 throw 'Missing diagnosticHandler'; |
| 62 } | 67 } |
| 63 if (outputProvider == null) { | 68 if (outputProvider == null) { |
| 64 outputProvider = NullSink.outputProvider; | 69 outputProvider = NullSink.outputProvider; |
| 65 } | 70 } |
| 66 Compiler compiler = cachedCompiler; | 71 Compiler compiler = cachedCompiler; |
| 67 if (compiler == null || compiler.libraryRoot != libraryRoot) { | 72 if (compiler == null || |
| 73 compiler.libraryRoot != libraryRoot || | |
| 74 compiler.hasCrashed || | |
| 75 compiler.compilerWasCancelled || | |
| 76 compiler.enqueuer.resolution.hasEnqueuedEverything || | |
| 77 compiler.deferredLoadTask.splitProgram) { | |
| 78 if (compiler != null) { | |
| 79 print('***FLUSH***'); | |
| 80 if (compiler.hasCrashed) { | |
| 81 print('Unable to reuse compiler due to crash.'); | |
| 82 } else if (compiler.compilerWasCancelled) { | |
| 83 print('Unable to reuse compiler due to cancel.'); | |
| 84 } else if (compiler.enqueuer.resolution.hasEnqueuedEverything) { | |
| 85 print('Unable to reuse compiler due to dart:mirrors.'); | |
| 86 } else if (compiler.deferredLoadTask.splitProgram) { | |
| 87 print('Unable to reuse compiler due to deferred loading.'); | |
| 88 } else { | |
| 89 print('Unable to reuse compiler.'); | |
| 90 } | |
| 91 } | |
| 68 compiler = new Compiler( | 92 compiler = new Compiler( |
| 69 inputProvider, | 93 inputProvider, |
| 70 outputProvider, | 94 outputProvider, |
| 71 diagnosticHandler, | 95 diagnosticHandler, |
| 72 libraryRoot, | 96 libraryRoot, |
| 73 packageRoot, | 97 packageRoot, |
| 74 options, | 98 options, |
| 75 {}); | 99 {}); |
| 76 } else { | 100 } else { |
| 77 compiler | 101 compiler |
| 78 ..outputProvider = outputProvider | 102 ..outputProvider = outputProvider |
| 79 ..provider = inputProvider | 103 ..provider = inputProvider |
| 80 ..handler = diagnosticHandler | 104 ..handler = diagnosticHandler |
| 81 ..enqueuer.resolution.queueIsClosed = false | 105 ..enqueuer.resolution.queueIsClosed = false |
| 106 ..enqueuer.resolution.hasEnqueuedEverything = false | |
| 107 ..enqueuer.resolution.hasEnqueuedReflectiveStaticFields = false | |
| 82 ..enqueuer.codegen.queueIsClosed = false | 108 ..enqueuer.codegen.queueIsClosed = false |
| 109 ..enqueuer.codegen.hasEnqueuedEverything = false | |
| 110 ..enqueuer.codegen.hasEnqueuedReflectiveStaticFields = false | |
| 83 ..assembledCode = null | 111 ..assembledCode = null |
| 84 ..compilationFailed = false; | 112 ..compilationFailed = false; |
| 85 JavaScriptBackend backend = compiler.backend; | 113 JavaScriptBackend backend = compiler.backend; |
| 86 | 114 |
| 115 backend.emitter.cachedElements.addAll(backend.generatedCode.keys); | |
| 116 | |
| 117 compiler.enqueuer.codegen.newlyEnqueuedElements.clear(); | |
| 118 | |
| 87 backend.emitter.containerBuilder | 119 backend.emitter.containerBuilder |
| 88 ..staticGetters.clear() | 120 ..staticGetters.clear() |
| 89 ..methodClosures.clear(); | 121 ..methodClosures.clear(); |
| 90 | 122 |
| 91 backend.emitter.nsmEmitter | 123 backend.emitter.nsmEmitter |
| 92 ..trivialNsmHandlers.clear(); | 124 ..trivialNsmHandlers.clear(); |
| 93 | 125 |
| 94 backend.emitter.typeTestEmitter | 126 backend.emitter.typeTestEmitter |
| 95 ..checkedClasses = null | 127 ..checkedClasses = null |
| 96 ..checkedFunctionTypes = null | 128 ..checkedFunctionTypes = null |
| 97 ..checkedGenericFunctionTypes.clear() | 129 ..checkedGenericFunctionTypes.clear() |
| 98 ..checkedNonGenericFunctionTypes.clear() | 130 ..checkedNonGenericFunctionTypes.clear() |
| 99 ..rtiNeededClasses.clear() | 131 ..rtiNeededClasses.clear() |
| 100 ..cachedClassesUsingTypeVariableTests = null; | 132 ..cachedClassesUsingTypeVariableTests = null; |
| 101 | 133 |
| 102 backend.emitter.interceptorEmitter | 134 backend.emitter.interceptorEmitter |
| 103 ..interceptorInvocationNames.clear(); | 135 ..interceptorInvocationNames.clear(); |
| 104 | 136 |
| 105 backend.emitter.metadataEmitter | 137 backend.emitter.metadataEmitter |
| 106 ..globalMetadata.clear() | 138 ..globalMetadata.clear() |
| 107 ..globalMetadataMap.clear(); | 139 ..globalMetadataMap.clear(); |
| 108 | 140 |
| 109 backend.emitter.nativeEmitter | 141 backend.emitter.nativeEmitter |
| 110 ..nativeBuffer.clear() | 142 ..nativeBuffer.clear() |
| 111 ..nativeClasses.clear() | 143 ..nativeClasses.clear() |
| 112 ..nativeMethods.clear(); | 144 ..nativeMethods.clear(); |
| 113 | 145 |
| 114 backend.emitter | 146 backend.emitter |
| 115 ..needsDefineClass = false | |
| 116 ..needsMixinSupport = false | |
| 117 ..needsLazyInitializer = false | |
| 118 ..outputBuffers.clear() | 147 ..outputBuffers.clear() |
| 119 ..deferredConstants.clear() | 148 ..deferredConstants.clear() |
| 120 ..isolateProperties = null | 149 ..isolateProperties = null |
| 121 ..classesCollector = null | 150 ..classesCollector = null |
| 122 ..neededClasses.clear() | 151 ..neededClasses.clear() |
| 123 ..outputClassLists.clear() | 152 ..outputClassLists.clear() |
| 124 ..nativeClasses.clear() | 153 ..nativeClasses.clear() |
| 125 ..mangledFieldNames.clear() | 154 ..mangledFieldNames.clear() |
| 126 ..mangledGlobalFieldNames.clear() | 155 ..mangledGlobalFieldNames.clear() |
| 127 ..recordedMangledNames.clear() | 156 ..recordedMangledNames.clear() |
| 128 ..additionalProperties.clear() | 157 ..additionalProperties.clear() |
| 129 ..readTypeVariables.clear() | 158 ..readTypeVariables.clear() |
| 130 ..instantiatedClasses = null | 159 ..instantiatedClasses = null |
| 131 ..precompiledFunction.clear() | 160 ..precompiledFunction.clear() |
| 132 ..precompiledConstructorNames.clear() | 161 ..precompiledConstructorNames.clear() |
| 133 ..hasMakeConstantList = false | 162 ..hasMakeConstantList = false |
| 134 ..elementDescriptors.clear(); | 163 ..elementDescriptors.clear(); |
| 135 | 164 |
| 136 backend | 165 backend |
| 137 ..preMirrorsMethodCount = 0; | 166 ..preMirrorsMethodCount = 0; |
| 138 | 167 |
| 139 Map libraries = new Map.from(compiler.libraries); | 168 Map libraries = new Map.from(compiler.libraries); |
| 140 compiler.libraries.clear(); | 169 compiler.libraries.clear(); |
| 141 clearLibraryLoader(compiler.libraryLoader); | 170 clearLibraryLoader(compiler.libraryLoader); |
| 142 libraries.forEach((String uri, LibraryElement library) { | 171 libraries.forEach((String uri, LibraryElement library) { |
| 143 if (library.isPlatformLibrary) { | 172 if (library.isPlatformLibrary || |
| 173 (packagesAreImmutable && library.isPackageLibrary)) { | |
| 144 compiler.libraries[uri] = library; | 174 compiler.libraries[uri] = library; |
| 145 reuseLibrary(compiler.libraryLoader, library); | 175 reuseLibrary(compiler.libraryLoader, library); |
| 146 } | 176 } |
| 147 }); | 177 }); |
| 148 } | 178 } |
| 149 return compiler; | 179 return compiler; |
| 150 } | 180 } |
| OLD | NEW |