| 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 part of dart2js_incremental; |
| 6 | 6 |
| 7 import 'dart:profiler' show | 7 /// Do not call this method directly. It will be made private. |
| 8 UserTag; | 8 // TODO(ahe): Make this method private. |
| 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( | 9 Compiler reuseCompiler( |
| 29 {DiagnosticHandler diagnosticHandler, | 10 {DiagnosticHandler diagnosticHandler, |
| 30 CompilerInputProvider inputProvider, | 11 CompilerInputProvider inputProvider, |
| 31 CompilerOutputProvider outputProvider, | 12 CompilerOutputProvider outputProvider, |
| 32 List<String> options: const [], | 13 List<String> options: const [], |
| 33 Compiler cachedCompiler, | 14 Compiler cachedCompiler, |
| 34 Uri libraryRoot, | 15 Uri libraryRoot, |
| 35 Uri packageRoot, | 16 Uri packageRoot, |
| 36 bool packagesAreImmutable: false}) { | 17 bool packagesAreImmutable: false, |
| 37 UserTag oldTag = new UserTag('reuseCompiler').makeCurrent(); | 18 Map<String, dynamic> environment}) { |
| 19 UserTag oldTag = new UserTag('_reuseCompiler').makeCurrent(); |
| 38 if (libraryRoot == null) { | 20 if (libraryRoot == null) { |
| 39 throw 'Missing libraryRoot'; | 21 throw 'Missing libraryRoot'; |
| 40 } | 22 } |
| 41 if (inputProvider == null) { | 23 if (inputProvider == null) { |
| 42 throw 'Missing inputProvider'; | 24 throw 'Missing inputProvider'; |
| 43 } | 25 } |
| 44 if (diagnosticHandler == null) { | 26 if (diagnosticHandler == null) { |
| 45 throw 'Missing diagnosticHandler'; | 27 throw 'Missing diagnosticHandler'; |
| 46 } | 28 } |
| 47 if (outputProvider == null) { | 29 if (outputProvider == null) { |
| 48 outputProvider = NullSink.outputProvider; | 30 outputProvider = NullSink.outputProvider; |
| 49 } | 31 } |
| 32 if (environment == null) { |
| 33 environment = {}; |
| 34 } |
| 50 Compiler compiler = cachedCompiler; | 35 Compiler compiler = cachedCompiler; |
| 51 if (compiler == null || | 36 if (compiler == null || |
| 52 compiler.libraryRoot != libraryRoot || | 37 compiler.libraryRoot != libraryRoot || |
| 53 !compiler.hasIncrementalSupport || | 38 !compiler.hasIncrementalSupport || |
| 54 compiler.hasCrashed || | 39 compiler.hasCrashed || |
| 55 compiler.compilerWasCancelled || | 40 compiler.compilerWasCancelled || |
| 56 compiler.enqueuer.resolution.hasEnqueuedEverything || | 41 compiler.enqueuer.resolution.hasEnqueuedEverything || |
| 57 compiler.deferredLoadTask.splitProgram) { | 42 compiler.deferredLoadTask.splitProgram) { |
| 58 if (compiler != null && compiler.hasIncrementalSupport) { | 43 if (compiler != null && compiler.hasIncrementalSupport) { |
| 59 print('***FLUSH***'); | 44 print('***FLUSH***'); |
| 60 if (compiler.hasCrashed) { | 45 if (compiler.hasCrashed) { |
| 61 print('Unable to reuse compiler due to crash.'); | 46 print('Unable to reuse compiler due to crash.'); |
| 62 } else if (compiler.compilerWasCancelled) { | 47 } else if (compiler.compilerWasCancelled) { |
| 63 print('Unable to reuse compiler due to cancel.'); | 48 print('Unable to reuse compiler due to cancel.'); |
| 64 } else if (compiler.enqueuer.resolution.hasEnqueuedEverything) { | 49 } else if (compiler.enqueuer.resolution.hasEnqueuedEverything) { |
| 65 print('Unable to reuse compiler due to dart:mirrors.'); | 50 print('Unable to reuse compiler due to dart:mirrors.'); |
| 66 } else if (compiler.deferredLoadTask.splitProgram) { | 51 } else if (compiler.deferredLoadTask.splitProgram) { |
| 67 print('Unable to reuse compiler due to deferred loading.'); | 52 print('Unable to reuse compiler due to deferred loading.'); |
| 68 } else { | 53 } else { |
| 69 print('Unable to reuse compiler.'); | 54 print('Unable to reuse compiler.'); |
| 70 } | 55 } |
| 71 } | 56 } |
| 72 compiler = new Compiler( | 57 compiler = new Compiler( |
| 73 inputProvider, | 58 inputProvider, |
| 74 outputProvider, | 59 outputProvider, |
| 75 diagnosticHandler, | 60 diagnosticHandler, |
| 76 libraryRoot, | 61 libraryRoot, |
| 77 packageRoot, | 62 packageRoot, |
| 78 options, | 63 options, |
| 79 {}); | 64 environment); |
| 80 } else { | 65 } else { |
| 81 compiler | 66 compiler |
| 82 ..outputProvider = outputProvider | 67 ..outputProvider = outputProvider |
| 83 ..provider = inputProvider | 68 ..provider = inputProvider |
| 84 ..handler = diagnosticHandler | 69 ..handler = diagnosticHandler |
| 85 ..enqueuer.resolution.queueIsClosed = false | 70 ..enqueuer.resolution.queueIsClosed = false |
| 86 ..enqueuer.resolution.hasEnqueuedEverything = false | 71 ..enqueuer.resolution.hasEnqueuedEverything = false |
| 87 ..enqueuer.resolution.hasEnqueuedReflectiveStaticFields = false | 72 ..enqueuer.resolution.hasEnqueuedReflectiveStaticFields = false |
| 88 ..enqueuer.codegen.queueIsClosed = false | 73 ..enqueuer.codegen.queueIsClosed = false |
| 89 ..enqueuer.codegen.hasEnqueuedEverything = false | 74 ..enqueuer.codegen.hasEnqueuedEverything = false |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (library.isPlatformLibrary || | 137 if (library.isPlatformLibrary || |
| 153 (packagesAreImmutable && library.isPackageLibrary)) { | 138 (packagesAreImmutable && library.isPackageLibrary)) { |
| 154 compiler.libraries[uri] = library; | 139 compiler.libraries[uri] = library; |
| 155 compiler.libraryLoader.reuseLibrary(library); | 140 compiler.libraryLoader.reuseLibrary(library); |
| 156 } | 141 } |
| 157 }); | 142 }); |
| 158 } | 143 } |
| 159 oldTag.makeCurrent(); | 144 oldTag.makeCurrent(); |
| 160 return compiler; | 145 return compiler; |
| 161 } | 146 } |
| OLD | NEW |