@@ -50,6 +50,7 @@ import 'kernel/kernel_world.dart';
50
50
import 'null_compiler_output.dart' show NullCompilerOutput;
51
51
import 'options.dart' show CompilerOptions;
52
52
import 'phase/load_kernel.dart' as load_kernel;
53
+ import 'phase/modular_analysis.dart' as modular_analysis;
53
54
import 'serialization/task.dart' ;
54
55
import 'serialization/serialization.dart' ;
55
56
import 'serialization/strategies.dart' ;
@@ -322,7 +323,11 @@ class Compiler {
322
323
programSplitConstraintsData = constraintParser.read (programSplitJson);
323
324
}
324
325
325
- if (onlyPerformGlobalTypeInference) {
326
+ if (options.cfeOnly) {
327
+ await runLoadKernel ();
328
+ } else if (options.modularMode) {
329
+ await runModularAnalysis ();
330
+ } else if (onlyPerformGlobalTypeInference) {
326
331
ir.Component component =
327
332
await serializationTask.deserializeComponentAndUpdateOptions ();
328
333
var closedWorldAndIndices =
@@ -357,48 +362,25 @@ class Compiler {
357
362
await generateJavaScriptCode (globalTypeInferenceResults,
358
363
indices: closedWorldAndIndices.indices);
359
364
} else {
360
- final input = load_kernel.Input (options, provider, reporter,
361
- initializedCompilerState, forceSerializationForTesting);
362
- load_kernel.Output output =
363
- await loadKernelTask.measure (() async => load_kernel.run (input));
365
+ load_kernel.Output output = await runLoadKernel ();
364
366
if (output == null || compilationFailed) return ;
365
- reporter.log ("Kernel load complete" );
366
- if (retainDataForTesting) {
367
- componentForTesting = output.component;
368
- }
369
367
370
368
ir.Component component = output.component;
371
369
List <Uri > libraries = output.libraries;
372
370
frontendStrategy.registerLoadedLibraries (component, libraries);
373
-
374
- if (options.modularMode) {
375
- await runModularAnalysis (component, output.moduleLibraries);
376
- } else {
377
- List <ModuleData > data;
378
- if (options.hasModularAnalysisInputs) {
379
- data = await serializationTask.deserializeModuleData (component);
380
- }
381
- frontendStrategy.registerModuleData (data);
382
-
383
- // After we've deserialized modular data, we trim the component of any
384
- // unnecessary dependencies.
385
- // Note: It is critical we wait to trim the dill until after we've
386
- // deserialized modular data because some of this data may reference
387
- // 'trimmed' elements.
388
- if (options.fromDill) {
389
- if (options.dumpUnusedLibraries) {
390
- dumpUnusedLibraries (component, libraries);
391
- }
392
- if (options.entryUri != null ) {
393
- component = trimComponent (component, libraries);
394
- }
395
- }
396
- if (options.cfeOnly) {
397
- await serializationTask.serializeComponent (component);
398
- } else {
399
- await compileFromKernel (output.rootLibraryUri, libraries);
400
- }
371
+ List <ModuleData > data;
372
+ if (options.hasModularAnalysisInputs) {
373
+ data = await serializationTask.deserializeModuleData (component);
401
374
}
375
+ frontendStrategy.registerModuleData (data);
376
+
377
+ // After we've deserialized modular data, we trim the component of any
378
+ // unnecessary dependencies.
379
+ // Note: It is critical we wait to trim the dill until after we've
380
+ // deserialized modular data because some of this data may reference
381
+ // 'trimmed' elements.
382
+ dumpUnusedLibrariesAndTrimComponent (component, libraries);
383
+ await compileFromKernel (output.rootLibraryUri, libraries);
402
384
}
403
385
}
404
386
@@ -498,19 +480,54 @@ class Compiler {
498
480
return closedWorld;
499
481
}
500
482
501
- void runModularAnalysis (
502
- ir.Component component, Iterable <Uri > moduleLibraries) {
483
+ Future <load_kernel.Output > runLoadKernel () async {
484
+ final input = load_kernel.Input (options, provider, reporter,
485
+ initializedCompilerState, forceSerializationForTesting);
486
+ load_kernel.Output output =
487
+ await loadKernelTask.measure (() async => load_kernel.run (input));
488
+ if (output == null || compilationFailed) return null ;
489
+ reporter.log ("Kernel load complete" );
490
+ if (retainDataForTesting) {
491
+ componentForTesting = output.component;
492
+ }
493
+
494
+ if (options.cfeOnly) {
495
+ ir.Component component = output.component;
496
+ dumpUnusedLibrariesAndTrimComponent (component, output.libraries);
497
+ await serializationTask.serializeComponent (component);
498
+ }
499
+ return output;
500
+ }
501
+
502
+ void dumpUnusedLibrariesAndTrimComponent (
503
+ ir.Component component, List <Uri > libraries) {
504
+ if (options.fromDill) {
505
+ if (options.dumpUnusedLibraries) {
506
+ dumpUnusedLibraries (component, libraries);
507
+ }
508
+ if (options.entryUri != null ) {
509
+ component = trimComponent (component, libraries);
510
+ }
511
+ }
512
+ }
513
+
514
+ void runModularAnalysis () async {
515
+ load_kernel.Output output = await runLoadKernel ();
516
+ if (output == null || compilationFailed) return ;
517
+
518
+ ir.Component component = output.component;
519
+ List <Uri > libraries = output.libraries;
520
+ Set <Uri > moduleLibraries = output.moduleLibraries.toSet ();
503
521
_userCodeLocations
504
522
.addAll (moduleLibraries.map ((module) => CodeLocation (module)));
505
- selfTask.measureSubtask ('runModularAnalysis' , () {
506
- var included = moduleLibraries.toSet ();
507
- var elementMap = frontendStrategy.elementMap;
508
- var moduleData = computeModuleData (
509
- component, included, options, reporter, environment, elementMap);
510
- if (compilationFailed) return ;
511
- serializationTask.testModuleSerialization (moduleData, component);
512
- serializationTask.serializeModuleData (moduleData, component, included);
513
- });
523
+ final input = modular_analysis.Input (
524
+ options, reporter, environment, component, libraries, moduleLibraries);
525
+ ModuleData moduleData = await selfTask.measureSubtask (
526
+ 'runModularAnalysis' , () async => modular_analysis.run (input));
527
+ if (compilationFailed) return ;
528
+ serializationTask.testModuleSerialization (moduleData, component);
529
+ serializationTask.serializeModuleData (
530
+ moduleData, component, moduleLibraries);
514
531
}
515
532
516
533
GlobalTypeInferenceResults performGlobalTypeInference (
0 commit comments