@@ -19,67 +19,114 @@ import 'package:front_end/src/fasta/kernel/utils.dart'
19
19
import "package:front_end/src/api_prototype/memory_file_system.dart"
20
20
show MemoryFileSystem;
21
21
22
- final Uri dart2jsUrl = Uri .base .resolve ("pkg/compiler/bin/dart2js.dart" );
23
- final Uri invalidateUri = Uri .parse ("package:compiler/src/filenames.dart" );
24
22
Directory outDir;
25
- Uri normalDill;
26
- Uri bootstrappedDill;
27
23
28
24
main () async {
29
25
outDir =
30
26
Directory .systemTemp.createTempSync ("incremental_load_from_dill_test" );
31
- normalDill = outDir.uri.resolve ("dart2js.full.dill" );
32
- bootstrappedDill = outDir.uri.resolve ("dart2js.bootstrap.dill" );
33
- Uri nonexisting = outDir.uri.resolve ("dart2js.nonexisting.dill" );
34
- Uri nonLoadable = outDir.uri.resolve ("dart2js.nonloadable.dill" );
35
27
try {
36
- // Compile dart2js without bootstrapping.
37
- Stopwatch stopwatch = new Stopwatch ()..start ();
38
- await normalCompile ();
39
- print ("Normal compile took ${stopwatch .elapsedMilliseconds } ms" );
40
-
41
- // Create a file that cannot be (fully) loaded as a dill file.
42
- List <int > corruptData = new File .fromUri (normalDill).readAsBytesSync ();
43
- for (int i = 10 * (corruptData.length ~ / 16 );
44
- i < 15 * (corruptData.length ~ / 16 );
45
- ++ i) {
46
- corruptData[i] = 42 ;
47
- }
48
- new File .fromUri (nonLoadable).writeAsBytesSync (corruptData);
49
-
50
- // Compile dart2js, bootstrapping from the just-compiled dill,
51
- // a nonexisting file and a dill file that isn't valid.
52
- for (List <Object > bootstrapData in [
53
- [normalDill, true ],
54
- [nonexisting, false ],
55
- // [nonLoadable, false] // disabled for now
56
- ]) {
57
- Uri bootstrapWith = bootstrapData[0 ];
58
- bool bootstrapExpect = bootstrapData[1 ];
59
- stopwatch.reset ();
60
- bool bootstrapResult = await bootstrapCompile (bootstrapWith);
61
- Expect .equals (bootstrapExpect, bootstrapResult);
62
- print ("Bootstrapped compile(s) from ${bootstrapWith .pathSegments .last } "
63
- "took ${stopwatch .elapsedMilliseconds } ms" );
64
-
65
- // Compare the two files.
66
- List <int > normalDillData = new File .fromUri (normalDill).readAsBytesSync ();
67
- List <int > bootstrappedDillData =
68
- new File .fromUri (bootstrappedDill).readAsBytesSync ();
69
- Expect .equals (normalDillData.length, bootstrappedDillData.length);
70
- for (int i = 0 ; i < normalDillData.length; ++ i) {
71
- if (normalDillData[i] != bootstrappedDillData[i]) {
72
- Expect .fail ("Normally compiled and bootstrapped compile differs." );
73
- }
74
- }
75
- }
76
-
28
+ await testDart2jsCompile ();
77
29
await testDisappearingLibrary ();
30
+ await testDeferredLibrary ();
78
31
} finally {
79
32
outDir.deleteSync (recursive: true );
80
33
}
81
34
}
82
35
36
+ /// Test loading from a dill file with a deferred library.
37
+ /// This is done by bootstrapping with no changes.
38
+ void testDeferredLibrary () async {
39
+ final Uri input = outDir.uri.resolve ("testDeferredLibrary_main.dart" );
40
+ final Uri b = outDir.uri.resolve ("testDeferredLibrary_b.dart" );
41
+ Uri output = outDir.uri.resolve ("testDeferredLibrary_full.dill" );
42
+ Uri bootstrappedOutput =
43
+ outDir.uri.resolve ("testDeferredLibrary_full_from_bootstrap.dill" );
44
+ new File .fromUri (input).writeAsStringSync ("""
45
+ import 'testDeferredLibrary_b.dart' deferred as b;
46
+
47
+ void main() {
48
+ print(b.foo());
49
+ }
50
+ """ );
51
+ new File .fromUri (b).writeAsStringSync ("""
52
+ String foo() => "hello from foo in b";
53
+ """ );
54
+
55
+ Stopwatch stopwatch = new Stopwatch ()..start ();
56
+ await normalCompile (input, output);
57
+ print ("Normal compile took ${stopwatch .elapsedMilliseconds } ms" );
58
+
59
+ stopwatch.reset ();
60
+ bool bootstrapResult = await bootstrapCompile (
61
+ input, bootstrappedOutput, output, [],
62
+ performSizeTests: false );
63
+ print ("Bootstrapped compile(s) from ${output .pathSegments .last } "
64
+ "took ${stopwatch .elapsedMilliseconds } ms" );
65
+ Expect .isTrue (bootstrapResult);
66
+
67
+ // Compare the two files.
68
+ List <int > normalDillData = new File .fromUri (output).readAsBytesSync ();
69
+ List <int > bootstrappedDillData =
70
+ new File .fromUri (bootstrappedOutput).readAsBytesSync ();
71
+ checkBootstrappedIsEqual (normalDillData, bootstrappedDillData);
72
+ }
73
+
74
+ void testDart2jsCompile () async {
75
+ final Uri dart2jsUrl = Uri .base .resolve ("pkg/compiler/bin/dart2js.dart" );
76
+ final Uri invalidateUri = Uri .parse ("package:compiler/src/filenames.dart" );
77
+ Uri normalDill = outDir.uri.resolve ("dart2js.full.dill" );
78
+ Uri bootstrappedDill = outDir.uri.resolve ("dart2js.bootstrap.dill" );
79
+ Uri nonexisting = outDir.uri.resolve ("dart2js.nonexisting.dill" );
80
+ Uri nonLoadable = outDir.uri.resolve ("dart2js.nonloadable.dill" );
81
+
82
+ // Compile dart2js without bootstrapping.
83
+ Stopwatch stopwatch = new Stopwatch ()..start ();
84
+ await normalCompile (dart2jsUrl, normalDill);
85
+ print ("Normal compile took ${stopwatch .elapsedMilliseconds } ms" );
86
+
87
+ // Create a file that cannot be (fully) loaded as a dill file.
88
+ List <int > corruptData = new File .fromUri (normalDill).readAsBytesSync ();
89
+ for (int i = 10 * (corruptData.length ~ / 16 );
90
+ i < 15 * (corruptData.length ~ / 16 );
91
+ ++ i) {
92
+ corruptData[i] = 42 ;
93
+ }
94
+ new File .fromUri (nonLoadable).writeAsBytesSync (corruptData);
95
+
96
+ // Compile dart2js, bootstrapping from the just-compiled dill,
97
+ // a nonexisting file and a dill file that isn't valid.
98
+ for (List <Object > bootstrapData in [
99
+ [normalDill, true ],
100
+ [nonexisting, false ],
101
+ // [nonLoadable, false] // disabled for now
102
+ ]) {
103
+ Uri bootstrapWith = bootstrapData[0 ];
104
+ bool bootstrapExpect = bootstrapData[1 ];
105
+ stopwatch.reset ();
106
+ bool bootstrapResult = await bootstrapCompile (
107
+ dart2jsUrl, bootstrappedDill, bootstrapWith, [invalidateUri]);
108
+ Expect .equals (bootstrapExpect, bootstrapResult);
109
+ print ("Bootstrapped compile(s) from ${bootstrapWith .pathSegments .last } "
110
+ "took ${stopwatch .elapsedMilliseconds } ms" );
111
+
112
+ // Compare the two files.
113
+ List <int > normalDillData = new File .fromUri (normalDill).readAsBytesSync ();
114
+ List <int > bootstrappedDillData =
115
+ new File .fromUri (bootstrappedDill).readAsBytesSync ();
116
+ checkBootstrappedIsEqual (normalDillData, bootstrappedDillData);
117
+ }
118
+ }
119
+
120
+ void checkBootstrappedIsEqual (
121
+ List <int > normalDillData, List <int > bootstrappedDillData) {
122
+ Expect .equals (normalDillData.length, bootstrappedDillData.length);
123
+ for (int i = 0 ; i < normalDillData.length; ++ i) {
124
+ if (normalDillData[i] != bootstrappedDillData[i]) {
125
+ Expect .fail ("Normally compiled and bootstrapped compile differs." );
126
+ }
127
+ }
128
+ }
129
+
83
130
/// Compile an application with n libraries, then
84
131
/// compile "the same" application, but with m < n libraries,
85
132
/// where (at least one) of the missing libraries are "in the middle"
@@ -123,7 +170,6 @@ void testDisappearingLibrary() async {
123
170
IncrementalCompiler compiler =
124
171
new IncrementalKernelGenerator (options, main);
125
172
var program = await compiler.computeDelta ();
126
- print (program);
127
173
libCount2 = serializeProgram (program);
128
174
if (program.libraries.length != 2 ) {
129
175
throw "Expected 2 libraries, got ${program .libraries .length }" ;
@@ -169,24 +215,29 @@ CompilerOptions getOptions() {
169
215
return options;
170
216
}
171
217
172
- Future <bool > normalCompile () async {
218
+ Future <bool > normalCompile (Uri input, Uri output ) async {
173
219
CompilerOptions options = getOptions ();
174
- IncrementalCompiler compiler =
175
- new IncrementalKernelGenerator (options, dart2jsUrl);
220
+ IncrementalCompiler compiler = new IncrementalKernelGenerator (options, input);
176
221
var y = await compiler.computeDelta ();
177
- await writeProgramToFile (y, normalDill );
222
+ await writeProgramToFile (y, output );
178
223
return compiler.bootstrapSuccess;
179
224
}
180
225
181
- Future <bool > bootstrapCompile (Uri bootstrapWith) async {
226
+ Future <bool > bootstrapCompile (
227
+ Uri input, Uri output, Uri bootstrapWith, List <Uri > invalidateUris,
228
+ {bool performSizeTests: true }) async {
182
229
CompilerOptions options = getOptions ();
183
230
IncrementalCompiler compiler =
184
- new IncrementalKernelGenerator (options, dart2jsUrl, bootstrapWith);
185
- compiler.invalidate (invalidateUri);
231
+ new IncrementalKernelGenerator (options, input, bootstrapWith);
232
+ for (Uri invalidateUri in invalidateUris) {
233
+ compiler.invalidate (invalidateUri);
234
+ }
186
235
var bootstrappedProgram = await compiler.computeDelta ();
187
236
bool result = compiler.bootstrapSuccess;
188
- await writeProgramToFile (bootstrappedProgram, bootstrappedDill);
189
- compiler.invalidate (invalidateUri);
237
+ await writeProgramToFile (bootstrappedProgram, output);
238
+ for (Uri invalidateUri in invalidateUris) {
239
+ compiler.invalidate (invalidateUri);
240
+ }
190
241
191
242
var partialProgram = await compiler.computeDelta ();
192
243
var emptyProgram = await compiler.computeDelta ();
@@ -198,9 +249,11 @@ Future<bool> bootstrapCompile(Uri bootstrapWith) async {
198
249
var emptyLibUris =
199
250
emptyProgram.libraries.map ((lib) => lib.importUri).toList ();
200
251
201
- Expect .isTrue (fullLibUris.length > partialLibUris.length);
202
- Expect .isTrue (partialLibUris.isNotEmpty);
203
- Expect .isTrue (emptyLibUris.isEmpty);
252
+ if (performSizeTests) {
253
+ Expect .isTrue (fullLibUris.length > partialLibUris.length);
254
+ Expect .isTrue (partialLibUris.isNotEmpty);
255
+ Expect .isTrue (emptyLibUris.isEmpty);
256
+ }
204
257
205
258
return result;
206
259
}
0 commit comments