| 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 dart2js.test.memory_compiler; | 5 library dart2js.test.memory_compiler; |
| 6 | 6 |
| 7 import 'memory_source_file_helper.dart'; | 7 import 'memory_source_file_helper.dart'; |
| 8 | 8 |
| 9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| 10 show NullSink; | 10 show NullSink; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 Compiler compiler = new Compiler(readStringFromUri, | 159 Compiler compiler = new Compiler(readStringFromUri, |
| 160 outputProvider, | 160 outputProvider, |
| 161 handler, | 161 handler, |
| 162 libraryRoot, | 162 libraryRoot, |
| 163 packageRoot, | 163 packageRoot, |
| 164 options, | 164 options, |
| 165 {}); | 165 {}); |
| 166 if (cachedCompiler != null) { | 166 if (cachedCompiler != null) { |
| 167 compiler.coreLibrary = cachedCompiler.libraries['dart:core']; | 167 compiler.coreLibrary = cachedCompiler.libraries['dart:core']; |
| 168 compiler.types = cachedCompiler.types; | 168 compiler.types = cachedCompiler.types.copy(compiler); |
| 169 cachedCompiler.libraries.forEach((String uri, library) { | 169 cachedCompiler.libraries.forEach((String uri, library) { |
| 170 if (library.isPlatformLibrary) { | 170 if (library.isPlatformLibrary) { |
| 171 compiler.libraries[uri] = library; | 171 compiler.libraries[uri] = library; |
| 172 compiler.onLibraryLoaded(library, library.canonicalUri); | 172 compiler.onLibraryLoaded(library, library.canonicalUri); |
| 173 } | 173 } |
| 174 }); | 174 }); |
| 175 | 175 |
| 176 compiler.symbolConstructor = cachedCompiler.symbolConstructor; | 176 compiler.symbolConstructor = cachedCompiler.symbolConstructor; |
| 177 compiler.mirrorSystemClass = cachedCompiler.mirrorSystemClass; | 177 compiler.mirrorSystemClass = cachedCompiler.mirrorSystemClass; |
| 178 compiler.mirrorsUsedClass = cachedCompiler.mirrorsUsedClass; | 178 compiler.mirrorsUsedClass = cachedCompiler.mirrorsUsedClass; |
| 179 compiler.mirrorSystemGetNameFunction = | 179 compiler.mirrorSystemGetNameFunction = |
| 180 cachedCompiler.mirrorSystemGetNameFunction; | 180 cachedCompiler.mirrorSystemGetNameFunction; |
| 181 compiler.symbolImplementationClass = | 181 compiler.symbolImplementationClass = |
| 182 cachedCompiler.symbolImplementationClass; | 182 cachedCompiler.symbolImplementationClass; |
| 183 compiler.symbolValidatedConstructor = | 183 compiler.symbolValidatedConstructor = |
| 184 cachedCompiler.symbolValidatedConstructor; | 184 cachedCompiler.symbolValidatedConstructor; |
| 185 compiler.mirrorsUsedConstructor = cachedCompiler.mirrorsUsedConstructor; | 185 compiler.mirrorsUsedConstructor = cachedCompiler.mirrorsUsedConstructor; |
| 186 compiler.deferredLibraryClass = cachedCompiler.deferredLibraryClass; | 186 compiler.deferredLibraryClass = cachedCompiler.deferredLibraryClass; |
| 187 | 187 |
| 188 Map cachedTreeElements = | 188 Map cachedTreeElements = |
| 189 cachedCompiler.enqueuer.resolution.resolvedElements; | 189 cachedCompiler.enqueuer.resolution.resolvedElements; |
| 190 cachedTreeElements.forEach((element, treeElements) { | 190 cachedTreeElements.forEach((element, treeElements) { |
| 191 if (element.getLibrary().isPlatformLibrary) { | 191 if (element.getLibrary().isPlatformLibrary) { |
| 192 compiler.enqueuer.resolution.resolvedElements[element] = | 192 compiler.enqueuer.resolution.resolvedElements[element] = |
| 193 treeElements; | 193 treeElements; |
| 194 } | 194 } |
| 195 }); | 195 }); |
| 196 |
| 197 // One potential problem that can occur when reusing elements is that there |
| 198 // is a stale reference to an old compiler object. By nulling out the old |
| 199 // compiler's fields, such stale references are easier to identify. |
| 200 cachedCompiler.scanner = null; |
| 201 cachedCompiler.dietParser = null; |
| 202 cachedCompiler.parser = null; |
| 203 cachedCompiler.patchParser = null; |
| 204 cachedCompiler.libraryLoader = null; |
| 205 cachedCompiler.validator = null; |
| 206 cachedCompiler.resolver = null; |
| 207 cachedCompiler.closureToClassMapper = null; |
| 208 cachedCompiler.checker = null; |
| 209 cachedCompiler.irBuilder = null; |
| 210 cachedCompiler.typesTask = null; |
| 211 cachedCompiler.backend = null; |
| 212 cachedCompiler.enqueuer = null; |
| 213 cachedCompiler.deferredLoadTask = null; |
| 214 cachedCompiler.mirrorUsageAnalyzerTask = null; |
| 215 cachedCompiler.dumpInfoTask = null; |
| 216 cachedCompiler.buildId = null; |
| 196 } | 217 } |
| 197 return compiler; | 218 return compiler; |
| 198 } | 219 } |
| 199 | 220 |
| 200 Future<MirrorSystem> mirrorSystemFor(Map<String,String> memorySourceFiles, | 221 Future<MirrorSystem> mirrorSystemFor(Map<String,String> memorySourceFiles, |
| 201 {DiagnosticHandler diagnosticHandler, | 222 {DiagnosticHandler diagnosticHandler, |
| 202 List<String> options: const [], | 223 List<String> options: const [], |
| 203 bool showDiagnostics: true}) { | 224 bool showDiagnostics: true}) { |
| 204 Uri libraryRoot = Uri.base.resolve('sdk/'); | 225 Uri libraryRoot = Uri.base.resolve('sdk/'); |
| 205 Uri packageRoot = Uri.base.resolve('${Platform.packageRoot}/'); | 226 Uri packageRoot = Uri.base.resolve('${Platform.packageRoot}/'); |
| 206 Uri script = Uri.base.resolveUri(Platform.script); | 227 Uri script = Uri.base.resolveUri(Platform.script); |
| 207 | 228 |
| 208 var provider = new MemorySourceFileProvider(memorySourceFiles); | 229 var provider = new MemorySourceFileProvider(memorySourceFiles); |
| 209 var handler = | 230 var handler = |
| 210 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); | 231 createDiagnosticHandler(diagnosticHandler, provider, showDiagnostics); |
| 211 | 232 |
| 212 List<Uri> libraries = <Uri>[]; | 233 List<Uri> libraries = <Uri>[]; |
| 213 memorySourceFiles.forEach((String path, _) { | 234 memorySourceFiles.forEach((String path, _) { |
| 214 libraries.add(new Uri(scheme: 'memory', path: path)); | 235 libraries.add(new Uri(scheme: 'memory', path: path)); |
| 215 }); | 236 }); |
| 216 | 237 |
| 217 return analyze(libraries, libraryRoot, packageRoot, | 238 return analyze(libraries, libraryRoot, packageRoot, |
| 218 provider, handler, options); | 239 provider, handler, options); |
| 219 } | 240 } |
| OLD | NEW |