OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library trydart.caching_compiler; | |
6 | |
7 import 'dart:profiler' show | |
8 UserTag; | |
9 | |
10 import 'package:compiler/compiler.dart' show | |
11 CompilerInputProvider, | |
12 CompilerOutputProvider, | |
13 Diagnostic, | |
14 DiagnosticHandler; | |
15 | |
16 import 'package:compiler/implementation/apiimpl.dart' show | |
17 Compiler; | |
18 | |
19 import 'package:compiler/implementation/dart2jslib.dart' show | |
20 NullSink; | |
21 | |
22 import 'package:compiler/implementation/js_backend/js_backend.dart' show | |
23 JavaScriptBackend; | |
24 | |
25 import 'package:compiler/implementation/elements/elements.dart' show | |
26 LibraryElement; | |
27 | |
28 Compiler reuseCompiler( | |
29 {DiagnosticHandler diagnosticHandler, | |
30 CompilerInputProvider inputProvider, | |
31 CompilerOutputProvider outputProvider, | |
32 List<String> options: const [], | |
33 Compiler cachedCompiler, | |
34 Uri libraryRoot, | |
35 Uri packageRoot, | |
36 bool packagesAreImmutable: false}) { | |
37 UserTag oldTag = new UserTag('reuseCompiler').makeCurrent(); | |
38 if (libraryRoot == null) { | |
39 throw 'Missing libraryRoot'; | |
40 } | |
41 if (inputProvider == null) { | |
42 throw 'Missing inputProvider'; | |
43 } | |
44 if (diagnosticHandler == null) { | |
45 throw 'Missing diagnosticHandler'; | |
46 } | |
47 if (outputProvider == null) { | |
48 outputProvider = NullSink.outputProvider; | |
49 } | |
50 Compiler compiler = cachedCompiler; | |
51 if (compiler == null || | |
52 compiler.libraryRoot != libraryRoot || | |
53 !compiler.hasIncrementalSupport || | |
54 compiler.hasCrashed || | |
55 compiler.compilerWasCancelled || | |
56 compiler.enqueuer.resolution.hasEnqueuedEverything || | |
57 compiler.deferredLoadTask.splitProgram) { | |
58 if (compiler != null && compiler.hasIncrementalSupport) { | |
59 print('***FLUSH***'); | |
60 if (compiler.hasCrashed) { | |
61 print('Unable to reuse compiler due to crash.'); | |
62 } else if (compiler.compilerWasCancelled) { | |
63 print('Unable to reuse compiler due to cancel.'); | |
64 } else if (compiler.enqueuer.resolution.hasEnqueuedEverything) { | |
65 print('Unable to reuse compiler due to dart:mirrors.'); | |
66 } else if (compiler.deferredLoadTask.splitProgram) { | |
67 print('Unable to reuse compiler due to deferred loading.'); | |
68 } else { | |
69 print('Unable to reuse compiler.'); | |
70 } | |
71 } | |
72 compiler = new Compiler( | |
73 inputProvider, | |
74 outputProvider, | |
75 diagnosticHandler, | |
76 libraryRoot, | |
77 packageRoot, | |
78 options, | |
79 {}); | |
80 } else { | |
81 compiler | |
82 ..outputProvider = outputProvider | |
83 ..provider = inputProvider | |
84 ..handler = diagnosticHandler | |
85 ..enqueuer.resolution.queueIsClosed = false | |
86 ..enqueuer.resolution.hasEnqueuedEverything = false | |
87 ..enqueuer.resolution.hasEnqueuedReflectiveStaticFields = false | |
88 ..enqueuer.codegen.queueIsClosed = false | |
89 ..enqueuer.codegen.hasEnqueuedEverything = false | |
90 ..enqueuer.codegen.hasEnqueuedReflectiveStaticFields = false | |
91 ..assembledCode = null | |
92 ..compilationFailed = false; | |
93 JavaScriptBackend backend = compiler.backend; | |
94 | |
95 backend.emitter.cachedElements.addAll(backend.generatedCode.keys); | |
96 | |
97 compiler.enqueuer.codegen.newlyEnqueuedElements.clear(); | |
98 | |
99 backend.emitter.containerBuilder | |
100 ..staticGetters.clear() | |
101 ..methodClosures.clear(); | |
102 | |
103 backend.emitter.nsmEmitter | |
104 ..trivialNsmHandlers.clear(); | |
105 | |
106 backend.emitter.typeTestEmitter | |
107 ..checkedClasses = null | |
108 ..checkedFunctionTypes = null | |
109 ..checkedGenericFunctionTypes.clear() | |
110 ..checkedNonGenericFunctionTypes.clear() | |
111 ..rtiNeededClasses.clear() | |
112 ..cachedClassesUsingTypeVariableTests = null; | |
113 | |
114 backend.emitter.interceptorEmitter | |
115 ..interceptorInvocationNames.clear(); | |
116 | |
117 backend.emitter.metadataEmitter | |
118 ..globalMetadata.clear() | |
119 ..globalMetadataMap.clear(); | |
120 | |
121 backend.emitter.nativeEmitter | |
122 ..nativeBuffer.clear() | |
123 ..nativeClasses.clear() | |
124 ..nativeMethods.clear(); | |
125 | |
126 backend.emitter | |
127 ..outputBuffers.clear() | |
128 ..deferredConstants.clear() | |
129 ..isolateProperties = null | |
130 ..classesCollector = null | |
131 ..neededClasses.clear() | |
132 ..outputClassLists.clear() | |
133 ..nativeClasses.clear() | |
134 ..mangledFieldNames.clear() | |
135 ..mangledGlobalFieldNames.clear() | |
136 ..recordedMangledNames.clear() | |
137 ..additionalProperties.clear() | |
138 ..readTypeVariables.clear() | |
139 ..instantiatedClasses = null | |
140 ..precompiledFunction.clear() | |
141 ..precompiledConstructorNames.clear() | |
142 ..hasMakeConstantList = false | |
143 ..elementDescriptors.clear(); | |
144 | |
145 backend | |
146 ..preMirrorsMethodCount = 0; | |
147 | |
148 Map libraries = new Map.from(compiler.libraries); | |
149 compiler.libraries.clear(); | |
150 compiler.libraryLoader.reset(); | |
151 libraries.forEach((String uri, LibraryElement library) { | |
152 if (library.isPlatformLibrary || | |
153 (packagesAreImmutable && library.isPackageLibrary)) { | |
154 compiler.libraries[uri] = library; | |
155 compiler.libraryLoader.reuseLibrary(library); | |
156 } | |
157 }); | |
158 } | |
159 oldTag.makeCurrent(); | |
160 return compiler; | |
161 } | |
OLD | NEW |