Chromium Code Reviews| Index: pkg/compiler/lib/src/dart2js.dart |
| diff --git a/pkg/compiler/lib/src/dart2js.dart b/pkg/compiler/lib/src/dart2js.dart |
| index 7d19ec05997a581c1494393637201f935e03cd4f..52f9300cdc6ca8ca17ea7566bdcec7fa2fcd91b0 100644 |
| --- a/pkg/compiler/lib/src/dart2js.dart |
| +++ b/pkg/compiler/lib/src/dart2js.dart |
| @@ -838,54 +838,131 @@ void batchMain(List<String> batchArguments) { |
| final bool USE_SERIALIZED_DART_CORE = |
| Platform.environment['USE_SERIALIZED_DART_CORE'] == 'true'; |
|
Harry Terkelsen
2016/06/20 16:36:11
this and SERIALIZED_COMPILATION should use const b
Johnni Winther
2016/06/23 13:07:47
Yes. I initially wanted to but (on Windows at leas
|
| -/// Mock URI used only in testing when [USE_SERIALIZED_DART_CORE] is enabled. |
| +final bool SERIALIZED_COMPILATION = |
| + Platform.environment['SERIALIZED_COMPILATION'] == 'true'; |
| + |
| +/// Mock URI used only in testing when [USE_SERIALIZED_DART_CORE] or |
| +/// [SERIALIZED_COMPILATION] is enabled. |
| final Uri _SERIALIZED_URI = Uri.parse('file:fake.data'); |
| void _useSerializedDataForDartCore(CompileFunc oldCompileFunc) { |
| - String serializedData; |
| - |
| + /// Run the [oldCompileFunc] with [serializedData] added as resolution input. |
| Future<api.CompilationResult> compileWithSerializedData( |
| CompilerOptions compilerOptions, |
| api.CompilerInput compilerInput, |
| api.CompilerDiagnostics compilerDiagnostics, |
| - api.CompilerOutput compilerOutput) async { |
| - CompilerImpl compiler = new CompilerImpl( |
| - compilerInput, compilerOutput, compilerDiagnostics, compilerOptions); |
| - compiler.serialization.deserializeFromText(_SERIALIZED_URI, serializedData); |
| - return compiler.run(compilerOptions.entryPoint).then((bool success) { |
| - return new api.CompilationResult(compiler, isSuccess: success); |
| - }); |
| + api.CompilerOutput compilerOutput, |
| + String serializedData) async { |
|
Harry Terkelsen
2016/06/20 16:36:11
this doesn't look like it needs to be async
Johnni Winther
2016/06/23 13:07:47
Done.
|
| + api.CompilerInput input = compilerInput; |
| + CompilerOptions options = compilerOptions; |
| + if (serializedData != null) { |
| + input = new _CompilerInput(input, serializedData); |
| + List<Uri> resolutionInputs = compilerOptions.resolutionInputs; |
| + if (resolutionInputs == null) { |
| + resolutionInputs = <Uri>[_SERIALIZED_URI]; |
| + } else if (!resolutionInputs.contains(_SERIALIZED_URI)) { |
| + resolutionInputs = new List<Uri>.from(resolutionInputs) |
| + ..add(_SERIALIZED_URI); |
| + } |
| + options = options.copy(resolutionInputs: resolutionInputs); |
| + } |
| + return oldCompileFunc(options, input, compilerDiagnostics, compilerOutput); |
| } |
| - Future<api.CompilationResult> generateSerializedDataForDartCore( |
| + /// Serialize [entryPoint] |
| + Future<api.CompilationResult> serialize( |
| + Uri entryPoint, |
| + CompilerOptions compilerOptions, |
| + api.CompilerInput compilerInput, |
| + api.CompilerDiagnostics compilerDiagnostics, |
| + api.CompilerOutput compilerOutput, |
| + [String serializedData]) async { |
|
Harry Terkelsen
2016/06/20 16:36:11
ditto
Johnni Winther
2016/06/23 13:07:47
Done.
|
| + CompilerOptions options = new CompilerOptions.parse( |
| + entryPoint: entryPoint, |
| + libraryRoot: compilerOptions.libraryRoot, |
| + packageRoot: compilerOptions.packageRoot, |
| + packageConfig: compilerOptions.packageConfig, |
| + packagesDiscoveryProvider: compilerOptions.packagesDiscoveryProvider, |
| + environment: compilerOptions.environment, |
| + resolutionOutput: _SERIALIZED_URI, |
| + options: [Flags.resolveOnly]); |
| + return compileWithSerializedData(options, compilerInput, |
| + compilerDiagnostics, compilerOutput, serializedData); |
| + } |
| + |
| + // Local cache for the serialized data for dart:core. |
| + String serializedDartCoreData; |
|
Harry Terkelsen
2016/06/20 16:36:11
nit: consider renaming to serializedDartCore in th
Johnni Winther
2016/06/23 13:07:47
Done.
|
| + |
| + /// Serialize the entry point using serialized data from dart:core and run |
| + /// [oldCompileFunc] using serialized data for whole program. |
| + Future<api.CompilationResult> compileWithSerializedTestData( |
|
Harry Terkelsen
2016/06/20 16:36:11
I'm not sure what 'Test' means in this context
Johnni Winther
2016/06/23 13:07:47
Renamed to 'compileFromSerializedData'
|
| CompilerOptions compilerOptions, |
| api.CompilerInput compilerInput, |
| api.CompilerDiagnostics compilerDiagnostics, |
| api.CompilerOutput compilerOutput) async { |
| _CompilerOutput output = new _CompilerOutput(); |
| - api.CompilationResult result = await oldCompileFunc( |
| - new CompilerOptions.parse( |
| - entryPoint: Uris.dart_core, |
| - libraryRoot: compilerOptions.libraryRoot, |
| - packageRoot: compilerOptions.packageRoot, |
| - packageConfig: compilerOptions.packageConfig, |
| - packagesDiscoveryProvider: |
| - compilerOptions.packagesDiscoveryProvider, |
| - environment: compilerOptions.environment, |
| - resolutionOutput: _SERIALIZED_URI, |
| - options: [Flags.resolveOnly]), |
| + api.CompilationResult result = await serialize( |
| + compilerOptions.entryPoint, |
| + compilerOptions, |
| compilerInput, |
| compilerDiagnostics, |
| - output); |
| - serializedData = output.serializedData; |
| - compileFunc = compileWithSerializedData; |
| - return compileWithSerializedData( |
| + output, |
| + serializedDartCoreData); |
| + if (!result.isSuccess) { |
| + return result; |
| + } |
| + return compileWithSerializedData(compilerOptions, compilerInput, |
| + compilerDiagnostics, compilerOutput, output.serializedData); |
| + } |
| + |
| + /// Compiles the entry point using the serialized data from dart:core. |
| + Future<api.CompilationResult> compileWithSerializedDartCoreData( |
| + CompilerOptions compilerOptions, |
| + api.CompilerInput compilerInput, |
| + api.CompilerDiagnostics compilerDiagnostics, |
| + api.CompilerOutput compilerOutput) async { |
| + return compileWithSerializedData(compilerOptions, compilerInput, |
| + compilerDiagnostics, compilerOutput, serializedDartCoreData); |
| + } |
| + |
| + /// Serialize dart:core data into [serializedDartCoreData] and setup the |
| + /// [compileFunc] to run the compiler using this data. |
| + Future<api.CompilationResult> generateSerializedDataForDartCore( |
| + CompilerOptions compilerOptions, |
| + api.CompilerInput compilerInput, |
| + api.CompilerDiagnostics compilerDiagnostics, |
| + api.CompilerOutput compilerOutput) async { |
| + _CompilerOutput output = new _CompilerOutput(); |
| + await serialize(Uris.dart_core, compilerOptions, compilerInput, |
| + compilerDiagnostics, output); |
| + serializedDartCoreData = output.serializedData; |
| + if (SERIALIZED_COMPILATION) { |
| + compileFunc = compileWithSerializedTestData; |
| + } else { |
| + compileFunc = compileWithSerializedDartCoreData; |
| + } |
| + return compileFunc( |
| compilerOptions, compilerInput, compilerDiagnostics, compilerOutput); |
| } |
| compileFunc = generateSerializedDataForDartCore; |
| } |
| +class _CompilerInput implements api.CompilerInput { |
| + final api.CompilerInput _input; |
| + final String _data; |
| + |
| + _CompilerInput(this._input, this._data); |
| + |
| + @override |
| + Future readFromUri(Uri uri) { |
| + if (uri == _SERIALIZED_URI) { |
| + return new Future.value(_data); |
| + } |
| + return _input.readFromUri(uri); |
| + } |
| +} |
| + |
| class _CompilerOutput extends NullCompilerOutput { |
| _BufferedEventSink sink; |