Skip to content

Commit c3f6e4f

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2js] Allow for consistent CLI flags for staged compilations.
Issue: #60353 Change-Id: I58f9f17b6916fec0d6279e1659618950aa695f81 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416327 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Nate Biggs <[email protected]>
1 parent 3a3dfcb commit c3f6e4f

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

pkg/compiler/lib/src/options.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum CompilerStage {
3232
CompilerPhase.codegen,
3333
CompilerPhase.emitJs,
3434
},
35+
canCompileFromEntryUri: true,
3536
),
3637
dumpInfoAll(
3738
'dump-info-all',
@@ -43,8 +44,9 @@ enum CompilerStage {
4344
CompilerPhase.emitJs,
4445
CompilerPhase.dumpInfo,
4546
},
47+
canCompileFromEntryUri: true,
4648
),
47-
cfe('cfe', phases: {CompilerPhase.cfe}),
49+
cfe('cfe', phases: {CompilerPhase.cfe}, canCompileFromEntryUri: true),
4850
deferredLoadIds(
4951
'deferred-load-ids',
5052
dataOutputName: 'deferred_load_ids.data',
@@ -80,11 +82,13 @@ enum CompilerStage {
8082
this._stageFlag, {
8183
this.dataOutputName,
8284
required this.phases,
85+
this.canCompileFromEntryUri = false,
8386
});
8487

8588
final Set<CompilerPhase> phases;
8689
final String _stageFlag;
8790
final String? dataOutputName;
91+
final bool canCompileFromEntryUri;
8892

8993
bool get emitsJs => phases.contains(CompilerPhase.emitJs);
9094
bool get shouldOnlyComputeDill => this == CompilerStage.cfe;
@@ -329,12 +333,12 @@ class CompilerOptions implements DiagnosticOptions {
329333

330334
/// Returns the compilation target specified by these options.
331335
Uri get compilationTarget =>
332-
_inputDillUri ?? entryUri ?? _defaultInputDillUri;
336+
_inputDillUri ??
337+
(stage.canCompileFromEntryUri ? entryUri : null) ??
338+
_defaultInputDillUri;
333339

334-
bool get shouldLoadFromDill {
335-
final targetPath = (_inputDillUri ?? entryUri)?.path;
336-
return targetPath == null || targetPath.endsWith('.dill');
337-
}
340+
bool get shouldLoadFromDill =>
341+
entryUri == null || compilationTarget.path.endsWith('.dill');
338342

339343
/// Location of the package configuration file.
340344
Uri? packageConfig;
@@ -655,11 +659,11 @@ class CompilerOptions implements DiagnosticOptions {
655659
/// If specified, a bundle of optimizations to enable (or disable).
656660
int? optimizationLevel;
657661

658-
/// The shard to serialize when using [Flags.writeCodegen].
662+
/// The shard to serialize when running the codegen phase.
659663
int? codegenShard;
660664

661-
/// The number of shards to serialize when using [Flags.writeCodegen] or to
662-
/// deserialize when using [Flags.readCodegen].
665+
/// The number of shards to serialize when running the codegen phase or to
666+
/// deserialize when running the emit-js phase.
663667
int? codegenShards;
664668

665669
/// Arguments passed to the front end about how it is invoked.

pkg/compiler/test/end_to_end/command_line_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ main() {
176176
'${Flags.stage}=closed-world',
177177
'--out=/some/path/prefix-',
178178
], writeClosedWorld: '/some/path/prefix-world.data');
179+
await test([
180+
'${Flags.stage}=closed-world',
181+
'foo.dart',
182+
], writeClosedWorld: 'world.data');
179183

180184
// Run global inference only
181185
await test(
@@ -234,6 +238,11 @@ main() {
234238
readClosedWorld: '/some/path/foo.dataworld.data',
235239
writeData: '/some/path/foo.dataglobal.data',
236240
);
241+
await test(
242+
['foo.dart', '${Flags.stage}=global-inference'],
243+
readClosedWorld: 'world.data',
244+
writeData: 'global.data',
245+
);
237246

238247
// Run codegen only
239248
await test(
@@ -361,6 +370,19 @@ main() {
361370
codegenShard: 10,
362371
codegenShards: 11,
363372
);
373+
await test(
374+
[
375+
'${Flags.stage}=codegen',
376+
'${Flags.codegenShard}=10',
377+
'${Flags.codegenShards}=11',
378+
'foo.dart',
379+
],
380+
readClosedWorld: 'world.data',
381+
readData: 'global.data',
382+
writeCodegen: 'codegen',
383+
codegenShard: 10,
384+
codegenShards: 11,
385+
);
364386

365387
// Run emitter only
366388
await test(
@@ -450,6 +472,14 @@ main() {
450472
codegenShards: 11,
451473
out: '/some/path/prefix-out.js',
452474
);
475+
await test(
476+
['${Flags.stage}=emit-js', '${Flags.codegenShards}=11', 'foo.dart'],
477+
readClosedWorld: 'world.data',
478+
readData: 'global.data',
479+
readCodegen: 'codegen',
480+
codegenShards: 11,
481+
out: 'out.js',
482+
);
453483

454484
// Run codegen and emitter only
455485
await test(
@@ -503,6 +533,12 @@ main() {
503533
readData: '/some/path/prefix-global.data',
504534
out: '/some/path/prefix-out.js',
505535
);
536+
await test(
537+
['${Flags.stage}=codegen-emit-js', 'foo.dart'],
538+
readClosedWorld: 'world.data',
539+
readData: 'global.data',
540+
out: 'out.js',
541+
);
506542

507543
// Invalid states with stage flag
508544
// Codegen stage

0 commit comments

Comments
 (0)