Skip to content

Commit

Permalink
[dart2js] Update Dart2jsStage definitions and CLI surface area.
Browse files Browse the repository at this point in the history
Today to invoke Dart2js with sequential actions there are 2 ways to specify the stage from the command line. By specifying a `write-<stage-data>=<some-uri>` or by using `stage=<some-stage>`. Internally we use the former via a similar (but separate) concept to Dart2jsStage. The goal here is to consolidate all these different entry points.

The new CLI works as follows:
- To run the compiler in full you can:
  - Pass no additional flags as before
  - Specify 'stage=all'
  - 'dump-info-all' runs the full compilation from scratch but includes
    dump info.
- To run the compiler in sequential mode you specify a stage:
  - Each stage has its own name passed to the '--stage' flag.
  - All the intermediate data URIs can be passed to every stage and only
    the relevant ones are used for any given stage. If no URI is passed
    then a default URI is used.
  - 'dump-info' is now its own stage. Partial dump info data is
    always included in the emit-js and codegen-emit-js steps.
  - 'cfe-only' flag is maintained for compatibility with Flutter CLI.


Change-Id: I67965d7708688a85c866d8abef3716bee23a083f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358740
Reviewed-by: Sigmund Cherem <[email protected]>
Commit-Queue: Nate Biggs <[email protected]>
  • Loading branch information
natebiggs authored and Commit Queue committed Apr 2, 2024
1 parent 4ea4eec commit f54eb08
Show file tree
Hide file tree
Showing 20 changed files with 410 additions and 981 deletions.
15 changes: 4 additions & 11 deletions pkg/compiler/lib/src/commandline_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class Flags {
static const String disableTypeInference = '--disable-type-inference';
static const String disableRtiOptimization = '--disable-rti-optimization';
static const String dumpInfo = '--dump-info';
static const String readDumpInfoData = '--read-dump-info-data';
static const String writeDumpInfoData = '--write-dump-info-data';
static const String dumpInfoDataUri = '--dump-info-data';
static const String dumpDeferredGraph = '--dump-deferred-graph';
static const String deferredLoadIdMapUri = '--deferred-load-ids';
static const String dumpSsa = '--dump-ssa';
Expand Down Expand Up @@ -119,16 +118,10 @@ class Flags {

static const String dillDependencies = '--dill-dependencies';
static const String sources = '--sources';
static const String readData = '--read-data';
static const String writeData = '--write-data';
static const String globalInferenceUri = '--global-inference-data';
static const String memoryMappedFiles = '--memory-map-files';
static const String noClosedWorldInData = '--no-closed-world-in-data';
static const String writeClosedWorld = '--write-closed-world';
static const String readClosedWorld = '--read-closed-world';
static const String readCodegen = '--read-codegen';
static const String writeCodegen = '--write-codegen';
static const String readModularAnalysis = '--read-modular-analysis';
static const String writeModularAnalysis = '--write-modular-analysis';
static const String closedWorldUri = '--closed-world-data';
static const String codegenUri = '--codegen-data';
static const String codegenShard = '--codegen-shard';
static const String codegenShards = '--codegen-shards';
static const String cfeOnly = '--cfe-only';
Expand Down
57 changes: 28 additions & 29 deletions pkg/compiler/lib/src/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import 'kernel/front_end_adapter.dart' show CompilerFileSystem;
import 'kernel/kernel_strategy.dart';
import 'kernel/kernel_world.dart';
import 'null_compiler_output.dart' show NullCompilerOutput;
import 'options.dart' show CompilerOptions, Dart2JSStage;
import 'options.dart' show CompilerOptions, CompilerStage;
import 'phase/load_kernel.dart' as load_kernel;
import 'resolution/enqueuer.dart';
import 'serialization/serialization.dart';
Expand Down Expand Up @@ -136,7 +136,7 @@ class Compiler {

_ResolutionStatus? _resolutionStatus;

Dart2JSStage get stage => options.stage;
CompilerStage get stage => options.stage;

bool compilationFailed = false;

Expand Down Expand Up @@ -407,12 +407,12 @@ class Compiler {
if (retainDataForTesting) {
componentForTesting = component;
}
if (options.features.newDumpInfo.isEnabled && options.dumpInfo) {
if (options.features.newDumpInfo.isEnabled && stage.emitsDumpInfo) {
untrimmedComponentForDumpInfo = component;
}
if (stage.shouldOnlyComputeDill) {
Set<Uri> includedLibraries = output.libraries!.toSet();
if (stage.shouldLoadFromDill) {
if (options.shouldLoadFromDill) {
if (options.dumpUnusedLibraries) {
dumpUnusedLibraries(component, includedLibraries);
}
Expand Down Expand Up @@ -531,7 +531,7 @@ class Compiler {
Uri rootLibraryUri = output.rootLibraryUri!;
List<Uri> libraries = output.libraries!;
closedWorld = computeClosedWorld(component, rootLibraryUri, libraries);
if (stage == Dart2JSStage.closedWorld && closedWorld != null) {
if (stage.shouldWriteClosedWorld && closedWorld != null) {
serializationTask.serializeClosedWorld(closedWorld, indices);
if (options.producesModifiedDill) {
serializationTask.serializeComponent(component,
Expand All @@ -553,8 +553,8 @@ class Compiler {

bool shouldStopAfterClosedWorld(JClosedWorld? closedWorld) =>
closedWorld == null ||
stage == Dart2JSStage.closedWorld ||
stage == Dart2JSStage.deferredLoadIds ||
stage.shouldWriteClosedWorld ||
stage.emitsDeferredLoadIds ||
stopAfterClosedWorldForTesting;

Future<GlobalTypeInferenceResults> produceGlobalTypeInferenceResults(
Expand All @@ -564,7 +564,7 @@ class Compiler {
GlobalTypeInferenceResults globalTypeInferenceResults;
if (!stage.shouldReadGlobalInference) {
globalTypeInferenceResults = performGlobalTypeInference(closedWorld);
if (stage == Dart2JSStage.globalInference) {
if (stage.shouldWriteGlobalInference) {
serializationTask.serializeGlobalTypeInference(
globalTypeInferenceResults, indices);
} else if (options.testMode) {
Expand All @@ -585,7 +585,7 @@ class Compiler {
}

bool get shouldStopAfterGlobalTypeInference =>
stage == Dart2JSStage.globalInference ||
stage.shouldWriteGlobalInference ||
stopAfterGlobalTypeInferenceForTesting;

CodegenInputs initializeCodegen(
Expand All @@ -602,34 +602,34 @@ class Compiler {
SerializationIndices indices) async {
CodegenInputs codegenInputs = initializeCodegen(globalTypeInferenceResults);
CodegenResults codegenResults;
if (!stage.shouldReadCodegenShards) {
if (stage.shouldReadCodegenShards && options.codegenShards != null) {
codegenResults = await serializationTask.deserializeCodegen(
backendStrategy,
globalTypeInferenceResults.closedWorld,
codegenInputs,
useDeferredSourceReads,
sourceLookup,
indices);
} else {
codegenResults = OnDemandCodegenResults(
codegenInputs, backendStrategy.functionCompiler);
if (stage == Dart2JSStage.codegenSharded) {
if (stage.shouldWriteCodegen) {
serializationTask.serializeCodegen(
backendStrategy,
globalTypeInferenceResults.closedWorld.abstractValueDomain,
codegenResults,
indices);
}
} else {
codegenResults = await serializationTask.deserializeCodegen(
backendStrategy,
globalTypeInferenceResults.closedWorld,
codegenInputs,
useDeferredSourceReads,
sourceLookup,
indices);
}
return codegenResults;
}

bool get shouldStopAfterCodegen => stage == Dart2JSStage.codegenSharded;
bool get shouldStopAfterCodegen => stage.shouldWriteCodegen;

// Only use deferred reads for the linker phase as most deferred entities will
// not be needed. In other stages we use most of this data so it's not worth
// not be needed. In other phases we use most of this data so it's not worth
// deferring.
bool get useDeferredSourceReads => stage == Dart2JSStage.jsEmitter;
bool get useDeferredSourceReads => stage == CompilerStage.jsEmitter;

Future<void> runSequentialPhases() async {
// Load kernel.
Expand All @@ -656,13 +656,12 @@ class Compiler {
AbstractValueDomain? abstractValueDomainForDumpInfo;
OutputUnitData? outputUnitDataForDumpInfo;
DataSinkWriter? sinkForDumpInfo;
if (options.dumpInfoReadUri != null || options.dumpInfo) {
if (stage.emitsDumpInfo) {
globalTypeInferenceResultsForDumpInfo = globalTypeInferenceResults;
abstractValueDomainForDumpInfo = closedWorld.abstractValueDomain;
outputUnitDataForDumpInfo = closedWorld.outputUnitData;
indicesForDumpInfo = indices;
}
if (options.dumpInfoWriteUri != null) {
} else if (stage.shouldWriteDumpInfoData) {
sinkForDumpInfo = serializationTask.dataSinkWriterForDumpInfo(
closedWorld.abstractValueDomain, indices);
dumpInfoRegistry.registerDataSinkWriter(sinkForDumpInfo);
Expand All @@ -675,7 +674,7 @@ class Compiler {
if (shouldStopAfterCodegen) return;
final inferredData = globalTypeInferenceResults.inferredData;

if (options.dumpInfoReadUri != null) {
if (stage.shouldReadDumpInfoData) {
final dumpInfoData =
await serializationTask.deserializeDumpInfoProgramData(
backendStrategy,
Expand All @@ -688,14 +687,14 @@ class Compiler {
// Link.
final programSize = runCodegenEnqueuer(
codegenResults, inferredData, sourceLookup, closedWorld);
if (options.dumpInfo || options.dumpInfoWriteUri != null) {
if (stage.emitsDumpInfo || stage.shouldWriteDumpInfoData) {
final dumpInfoData = DumpInfoProgramData.fromEmitterResults(
backendStrategy.emitterTask,
dumpInfoRegistry,
codegenResults,
programSize);
dumpInfoRegistry.close();
if (options.dumpInfoWriteUri != null) {
if (stage.shouldWriteDumpInfoData) {
serializationTask.serializeDumpInfoProgramData(sinkForDumpInfo!,
backendStrategy, dumpInfoData, dumpInfoRegistry);
} else {
Expand Down Expand Up @@ -738,7 +737,7 @@ class Compiler {

KClosedWorld kClosedWorld = resolutionWorldBuilder.closeWorld(reporter);
OutputUnitData result = deferredLoadTask.run(mainFunction, kClosedWorld);
if (options.stage == Dart2JSStage.deferredLoadIds) return null;
if (stage.emitsDeferredLoadIds) return null;

// Impact data is no longer needed.
if (!retainDataForTesting) {
Expand Down
Loading

0 comments on commit f54eb08

Please sign in to comment.