Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Side by Side Diff: pkg/compiler/lib/src/dart2js.dart

Issue 2086443002: Support completely serialized compilation in batch mode. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/options.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.cmdline; 5 library dart2js.cmdline;
6 6
7 import 'dart:async' show EventSink, Future; 7 import 'dart:async' show EventSink, Future;
8 import 'dart:convert' show UTF8, LineSplitter; 8 import 'dart:convert' show UTF8, LineSplitter;
9 import 'dart:io' show exit, File, FileMode, Platform, stdin, stderr; 9 import 'dart:io' show exit, File, FileMode, Platform, stdin, stderr;
10 10
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 } else { 829 } else {
830 print(">>> TEST FAIL"); 830 print(">>> TEST FAIL");
831 } 831 }
832 stderr.writeln(">>> EOF STDERR"); 832 stderr.writeln(">>> EOF STDERR");
833 subscription.resume(); 833 subscription.resume();
834 }); 834 });
835 }); 835 });
836 } 836 }
837 837
838 final bool USE_SERIALIZED_DART_CORE = 838 final bool USE_SERIALIZED_DART_CORE =
839 Platform.environment['USE_SERIALIZED_DART_CORE'] == 'true'; 839 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
840 840
841 /// Mock URI used only in testing when [USE_SERIALIZED_DART_CORE] is enabled. 841 final bool SERIALIZED_COMPILATION =
842 Platform.environment['SERIALIZED_COMPILATION'] == 'true';
843
844 /// Mock URI used only in testing when [USE_SERIALIZED_DART_CORE] or
845 /// [SERIALIZED_COMPILATION] is enabled.
842 final Uri _SERIALIZED_URI = Uri.parse('file:fake.data'); 846 final Uri _SERIALIZED_URI = Uri.parse('file:fake.data');
843 847
844 void _useSerializedDataForDartCore(CompileFunc oldCompileFunc) { 848 void _useSerializedDataForDartCore(CompileFunc oldCompileFunc) {
845 String serializedData; 849 /// Run the [oldCompileFunc] with [serializedData] added as resolution input.
846
847 Future<api.CompilationResult> compileWithSerializedData( 850 Future<api.CompilationResult> compileWithSerializedData(
848 CompilerOptions compilerOptions, 851 CompilerOptions compilerOptions,
849 api.CompilerInput compilerInput, 852 api.CompilerInput compilerInput,
850 api.CompilerDiagnostics compilerDiagnostics, 853 api.CompilerDiagnostics compilerDiagnostics,
851 api.CompilerOutput compilerOutput) async { 854 api.CompilerOutput compilerOutput,
852 CompilerImpl compiler = new CompilerImpl( 855 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.
853 compilerInput, compilerOutput, compilerDiagnostics, compilerOptions); 856 api.CompilerInput input = compilerInput;
854 compiler.serialization.deserializeFromText(_SERIALIZED_URI, serializedData); 857 CompilerOptions options = compilerOptions;
855 return compiler.run(compilerOptions.entryPoint).then((bool success) { 858 if (serializedData != null) {
856 return new api.CompilationResult(compiler, isSuccess: success); 859 input = new _CompilerInput(input, serializedData);
857 }); 860 List<Uri> resolutionInputs = compilerOptions.resolutionInputs;
861 if (resolutionInputs == null) {
862 resolutionInputs = <Uri>[_SERIALIZED_URI];
863 } else if (!resolutionInputs.contains(_SERIALIZED_URI)) {
864 resolutionInputs = new List<Uri>.from(resolutionInputs)
865 ..add(_SERIALIZED_URI);
866 }
867 options = options.copy(resolutionInputs: resolutionInputs);
868 }
869 return oldCompileFunc(options, input, compilerDiagnostics, compilerOutput);
858 } 870 }
859 871
872 /// Serialize [entryPoint]
873 Future<api.CompilationResult> serialize(
874 Uri entryPoint,
875 CompilerOptions compilerOptions,
876 api.CompilerInput compilerInput,
877 api.CompilerDiagnostics compilerDiagnostics,
878 api.CompilerOutput compilerOutput,
879 [String serializedData]) async {
Harry Terkelsen 2016/06/20 16:36:11 ditto
Johnni Winther 2016/06/23 13:07:47 Done.
880 CompilerOptions options = new CompilerOptions.parse(
881 entryPoint: entryPoint,
882 libraryRoot: compilerOptions.libraryRoot,
883 packageRoot: compilerOptions.packageRoot,
884 packageConfig: compilerOptions.packageConfig,
885 packagesDiscoveryProvider: compilerOptions.packagesDiscoveryProvider,
886 environment: compilerOptions.environment,
887 resolutionOutput: _SERIALIZED_URI,
888 options: [Flags.resolveOnly]);
889 return compileWithSerializedData(options, compilerInput,
890 compilerDiagnostics, compilerOutput, serializedData);
891 }
892
893 // Local cache for the serialized data for dart:core.
894 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.
895
896 /// Serialize the entry point using serialized data from dart:core and run
897 /// [oldCompileFunc] using serialized data for whole program.
898 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'
899 CompilerOptions compilerOptions,
900 api.CompilerInput compilerInput,
901 api.CompilerDiagnostics compilerDiagnostics,
902 api.CompilerOutput compilerOutput) async {
903 _CompilerOutput output = new _CompilerOutput();
904 api.CompilationResult result = await serialize(
905 compilerOptions.entryPoint,
906 compilerOptions,
907 compilerInput,
908 compilerDiagnostics,
909 output,
910 serializedDartCoreData);
911 if (!result.isSuccess) {
912 return result;
913 }
914 return compileWithSerializedData(compilerOptions, compilerInput,
915 compilerDiagnostics, compilerOutput, output.serializedData);
916 }
917
918 /// Compiles the entry point using the serialized data from dart:core.
919 Future<api.CompilationResult> compileWithSerializedDartCoreData(
920 CompilerOptions compilerOptions,
921 api.CompilerInput compilerInput,
922 api.CompilerDiagnostics compilerDiagnostics,
923 api.CompilerOutput compilerOutput) async {
924 return compileWithSerializedData(compilerOptions, compilerInput,
925 compilerDiagnostics, compilerOutput, serializedDartCoreData);
926 }
927
928 /// Serialize dart:core data into [serializedDartCoreData] and setup the
929 /// [compileFunc] to run the compiler using this data.
860 Future<api.CompilationResult> generateSerializedDataForDartCore( 930 Future<api.CompilationResult> generateSerializedDataForDartCore(
861 CompilerOptions compilerOptions, 931 CompilerOptions compilerOptions,
862 api.CompilerInput compilerInput, 932 api.CompilerInput compilerInput,
863 api.CompilerDiagnostics compilerDiagnostics, 933 api.CompilerDiagnostics compilerDiagnostics,
864 api.CompilerOutput compilerOutput) async { 934 api.CompilerOutput compilerOutput) async {
865 _CompilerOutput output = new _CompilerOutput(); 935 _CompilerOutput output = new _CompilerOutput();
866 api.CompilationResult result = await oldCompileFunc( 936 await serialize(Uris.dart_core, compilerOptions, compilerInput,
867 new CompilerOptions.parse( 937 compilerDiagnostics, output);
868 entryPoint: Uris.dart_core, 938 serializedDartCoreData = output.serializedData;
869 libraryRoot: compilerOptions.libraryRoot, 939 if (SERIALIZED_COMPILATION) {
870 packageRoot: compilerOptions.packageRoot, 940 compileFunc = compileWithSerializedTestData;
871 packageConfig: compilerOptions.packageConfig, 941 } else {
872 packagesDiscoveryProvider: 942 compileFunc = compileWithSerializedDartCoreData;
873 compilerOptions.packagesDiscoveryProvider, 943 }
874 environment: compilerOptions.environment, 944 return compileFunc(
875 resolutionOutput: _SERIALIZED_URI,
876 options: [Flags.resolveOnly]),
877 compilerInput,
878 compilerDiagnostics,
879 output);
880 serializedData = output.serializedData;
881 compileFunc = compileWithSerializedData;
882 return compileWithSerializedData(
883 compilerOptions, compilerInput, compilerDiagnostics, compilerOutput); 945 compilerOptions, compilerInput, compilerDiagnostics, compilerOutput);
884 } 946 }
885 947
886 compileFunc = generateSerializedDataForDartCore; 948 compileFunc = generateSerializedDataForDartCore;
887 } 949 }
888 950
951 class _CompilerInput implements api.CompilerInput {
952 final api.CompilerInput _input;
953 final String _data;
954
955 _CompilerInput(this._input, this._data);
956
957 @override
958 Future readFromUri(Uri uri) {
959 if (uri == _SERIALIZED_URI) {
960 return new Future.value(_data);
961 }
962 return _input.readFromUri(uri);
963 }
964 }
965
889 class _CompilerOutput extends NullCompilerOutput { 966 class _CompilerOutput extends NullCompilerOutput {
890 _BufferedEventSink sink; 967 _BufferedEventSink sink;
891 968
892 @override 969 @override
893 EventSink<String> createEventSink(String name, String extension) { 970 EventSink<String> createEventSink(String name, String extension) {
894 if (name == '' && extension == 'data') { 971 if (name == '' && extension == 'data') {
895 return sink = new _BufferedEventSink(); 972 return sink = new _BufferedEventSink();
896 } 973 }
897 return super.createEventSink(name, extension); 974 return super.createEventSink(name, extension);
898 } 975 }
(...skipping 12 matching lines...) Expand all
911 @override 988 @override
912 void close() { 989 void close() {
913 // Do nothing. 990 // Do nothing.
914 } 991 }
915 992
916 @override 993 @override
917 void addError(errorEvent, [StackTrace stackTrace]) { 994 void addError(errorEvent, [StackTrace stackTrace]) {
918 // Ignore 995 // Ignore
919 } 996 }
920 } 997 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698