Skip to content

Commit 1722d67

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2js] Add back support for '--dump-info' flag.
We had kept the 'dump-info' flag to support '--dump-info=binary' vs json output. But this leads to a confusing experience so instead I've added back in support for '--dump-info' on its own. This will emit binary data if the flag is passed with no type. Which will require using dart2js_info tools. Change-Id: Ibf51d3e453375ad143383246dd97e628c1b2a049 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409821 Commit-Queue: Nate Biggs <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent d18af76 commit 1722d67

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

pkg/compiler/lib/src/dart2js.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import 'commandline_options.dart';
1717
import 'common/ram_usage.dart';
1818
import 'compiler.dart' as default_compiler show Compiler;
1919
import 'io/mapped_file.dart';
20-
import 'options.dart' show CompilerOptions, CompilerStage, FeatureOptions;
20+
import 'options.dart'
21+
show CompilerOptions, CompilerStage, DumpInfoFormat, FeatureOptions;
2122
import 'source_file_provider.dart';
2223
import 'util/command_line.dart';
2324
import 'util/util.dart' show stackTraceFilePrefix;
@@ -344,17 +345,17 @@ Future<api.CompilationResult> compile(
344345
}
345346

346347
void setDumpInfo(String argument) {
347-
passThrough(Flags.dumpInfo);
348-
if (argument == Flags.dumpInfo || argument == "${Flags.dumpInfo}=json") {
349-
return;
350-
}
351-
if (argument == "${Flags.dumpInfo}=binary") {
348+
final hasEnumFormatMatch = DumpInfoFormat.values.any(
349+
(e) => '${Flags.dumpInfo}=${e.name}' == argument,
350+
);
351+
if (argument == Flags.dumpInfo || hasEnumFormatMatch) {
352352
passThrough(argument);
353353
return;
354354
}
355355
_helpAndFail(
356356
"Unsupported dump-info format '$argument', "
357-
"supported formats are: json or binary",
357+
"supported formats: "
358+
"${DumpInfoFormat.values.map((e) => e.name).join(', ')}",
358359
);
359360
}
360361

pkg/compiler/lib/src/dump_info.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class DumpInfoJsAstRegistry {
7575
!options.stage.emitsDumpInfo &&
7676
!options.stage.shouldWriteDumpInfoData;
7777

78-
bool get useBinaryFormat => options.useDumpInfoBinaryFormat;
78+
bool get useBinaryFormat => options.dumpInfoFormat == DumpInfoFormat.binary;
7979

8080
void registerEntityAst(Entity? entity, js_ast.Node code) {
8181
if (_disabled) return;
@@ -1637,7 +1637,7 @@ class DumpInfoTask extends CompilerTask implements InfoReporter {
16371637
final bool useBinaryFormat;
16381638

16391639
DumpInfoTask(this.options, this.measurer, this.outputProvider, this.reporter)
1640-
: useBinaryFormat = options.useDumpInfoBinaryFormat,
1640+
: useBinaryFormat = options.dumpInfoFormat == DumpInfoFormat.binary,
16411641
super(measurer);
16421642

16431643
@override

pkg/compiler/lib/src/options.dart

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
library;
66

7+
import 'package:collection/collection.dart';
78
// ignore: implementation_imports
89
import 'package:front_end/src/api_unstable/dart2js.dart' as fe;
910

@@ -126,8 +127,7 @@ enum CompilerStage {
126127
return CompilerStage.values.map((p) => '`${p._stageFlag}`').join(', ');
127128
}
128129

129-
static CompilerStage fromFlag(String? stageFlag) {
130-
if (stageFlag == null) return CompilerStage.all;
130+
static CompilerStage _fromFlagString(String stageFlag) {
131131
for (final stage in CompilerStage.values) {
132132
if (stageFlag == stage._stageFlag) {
133133
return stage;
@@ -138,6 +138,24 @@ enum CompilerStage {
138138
'Supported values are: $validFlagValuesString',
139139
);
140140
}
141+
142+
/// Can be used from outside the compiler to determine which stage will run
143+
/// based on provided flag.
144+
///
145+
/// Used for internal build systems.
146+
static CompilerStage fromFlag(String? stageFlag) {
147+
return stageFlag == null ? CompilerStage.all : _fromFlagString(stageFlag);
148+
}
149+
150+
static CompilerStage fromOptions(CompilerOptions options) {
151+
final stageFlag = options._stageFlag;
152+
if (stageFlag == null) {
153+
return options._dumpInfoFormatOption != null
154+
? CompilerStage.dumpInfoAll
155+
: CompilerStage.all;
156+
}
157+
return _fromFlagString(stageFlag);
158+
}
141159
}
142160

143161
/// A [FeatureOption] is both a set of flags and an option. By default, creating
@@ -290,6 +308,8 @@ abstract class DiagnosticOptions {
290308
bool showPackageWarningsFor(Uri uri);
291309
}
292310

311+
enum DumpInfoFormat { binary, json }
312+
293313
/// Object for passing options to the compiler. Superclasses are used to select
294314
/// subsets of these options, enabling each part of the compiler to depend on
295315
/// as few as possible.
@@ -470,9 +490,10 @@ class CompilerOptions implements DiagnosticOptions {
470490
/// a standalone task (without re-emitting JS).
471491
Uri? _dumpInfoDataUri;
472492

473-
/// Whether to use the new dump-info binary format. This will be the default
474-
/// after a transitional period.
475-
bool useDumpInfoBinaryFormat = false;
493+
/// Which format the user has chosen to emit dump info in if any.
494+
DumpInfoFormat? _dumpInfoFormatOption;
495+
DumpInfoFormat get dumpInfoFormat =>
496+
_dumpInfoFormatOption ?? DumpInfoFormat.json;
476497

477498
/// If set, SSA intermediate form is dumped for methods with names matching
478499
/// this RegExp pattern.
@@ -712,7 +733,7 @@ class CompilerOptions implements DiagnosticOptions {
712733
late final CompilerStage stage = _calculateStage();
713734

714735
CompilerStage _calculateStage() =>
715-
_cfeOnly ? CompilerStage.cfe : CompilerStage.fromFlag(_stageFlag);
736+
_cfeOnly ? CompilerStage.cfe : CompilerStage.fromOptions(this);
716737

717738
Uri? _outputUri;
718739
Uri? outputUri;
@@ -895,9 +916,11 @@ class CompilerOptions implements DiagnosticOptions {
895916
options,
896917
'${Flags.dumpInfoDataUri}=',
897918
)
898-
..useDumpInfoBinaryFormat = _hasOption(
919+
.._dumpInfoFormatOption = _extractEnumOption(
899920
options,
900-
"${Flags.dumpInfo}=binary",
921+
Flags.dumpInfo,
922+
DumpInfoFormat.values,
923+
emptyValue: DumpInfoFormat.binary,
901924
)
902925
..dumpSsaPattern = _extractStringOption(
903926
options,
@@ -1270,6 +1293,22 @@ int? _extractIntOption(List<String> options, String prefix) {
12701293
return (option == null) ? null : int.parse(option);
12711294
}
12721295

1296+
/// Extracts an enum value for the flag given by [prefix].
1297+
///
1298+
/// [emptyValue] is used to provide a default value when the flag is given but
1299+
/// with no '=' value provided.
1300+
T? _extractEnumOption<T extends Enum>(
1301+
List<String> options,
1302+
String prefix,
1303+
List<T> values, {
1304+
T? emptyValue,
1305+
}) {
1306+
if (emptyValue != null && _hasOption(options, prefix)) return emptyValue;
1307+
String? option = _extractStringOption(options, '$prefix=', null);
1308+
if (option == null) return null;
1309+
return values.firstWhereOrNull((e) => e.name == option);
1310+
}
1311+
12731312
bool _hasOption(List<String> options, String option) {
12741313
return options.contains(option);
12751314
}

pkg/compiler/lib/src/serialization/task.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ class SerializationTask extends CompilerTask {
388388
source.registerAbstractValueDomain(abstractValueDomain);
389389
return DumpInfoProgramData.readFromDataSource(
390390
source,
391-
includeCodeText: !_options.useDumpInfoBinaryFormat,
391+
includeCodeText: _options.dumpInfoFormat != DumpInfoFormat.binary,
392392
);
393393
}
394394
}

0 commit comments

Comments
 (0)