Skip to content

Commit

Permalink
Move experimental flag defaults to CFE
Browse files Browse the repository at this point in the history
Change-Id: I9f1890f349fb19bbd792af071adc14ad4e50c364
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98010
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
  • Loading branch information
johnniwinther authored and commit-bot@chromium.org committed Mar 28, 2019
1 parent cc00203 commit b978fdd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
16 changes: 3 additions & 13 deletions pkg/compiler/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class CompilerOptions implements DiagnosticOptions {
{Uri librariesSpecificationUri, Uri platformBinaries}) {
Map<fe.ExperimentalFlag, bool> languageExperiments =
_extractExperiments(options);
if (equalMaps(languageExperiments, defaultExperimentalFlags)) {
if (equalMaps(languageExperiments, fe.defaultExperimentalFlags)) {
platformBinaries ??= fe.computePlatformBinariesLocation();
}
return new CompilerOptions()
Expand Down Expand Up @@ -424,7 +424,7 @@ class CompilerOptions implements DiagnosticOptions {
throw new ArgumentError("[packageRoot] must end with a /");
}
if (platformBinaries == null &&
equalMaps(languageExperiments, defaultExperimentalFlags)) {
equalMaps(languageExperiments, fe.defaultExperimentalFlags)) {
throw new ArgumentError("Missing required ${Flags.platformBinaries}");
}
}
Expand Down Expand Up @@ -564,18 +564,8 @@ List<Uri> _extractUriListOption(List<String> options, String flag) {
Map<fe.ExperimentalFlag, bool> _extractExperiments(List<String> options) {
List<String> experiments =
_extractOptionalCsvOption(options, Flags.enableLanguageExperiments);
Map<fe.ExperimentalFlag, bool> flags = fe.parseExperimentalFlags(
return fe.parseExperimentalFlags(
experiments, (String error) => throw new ArgumentError(error));
for (fe.ExperimentalFlag flag in defaultExperimentalFlags.keys) {
flags[flag] ??= defaultExperimentalFlags[flag];
}
return flags;
}

const Map<fe.ExperimentalFlag, bool> defaultExperimentalFlags = {
fe.ExperimentalFlag.constantUpdate2018: false,
fe.ExperimentalFlag.controlFlowCollections: false,
fe.ExperimentalFlag.spreadCollections: false,
};

const String _UNDETERMINED_BUILD_ID = "build number could not be determined";
43 changes: 26 additions & 17 deletions pkg/front_end/lib/src/api_prototype/compiler_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'package:kernel/target/targets.dart' show Target;

import 'diagnostic_message.dart' show DiagnosticMessageHandler;

import 'experimental_flags.dart' show ExperimentalFlag, parseExperimentalFlag;
import 'experimental_flags.dart'
show defaultExperimentalFlags, ExperimentalFlag, parseExperimentalFlag;

import 'file_system.dart' show FileSystem;

Expand Down Expand Up @@ -209,30 +210,38 @@ class CompilerOptions {

/// Parse experimental flags from a list of strings, each of which is either a
/// flag name or a flag name prefixed by 'no-'. Return a map of flags to their
/// values that can be passed to [experimentalFlags].
/// values that can be passed to [experimentalFlags]. The returned map is
/// normalized to contain default values for unmentioned flags.
///
/// If an unknown flag is mentioned, or a flag is mentioned more than once,
/// the supplied error handler is called with an error message.
Map<ExperimentalFlag, bool> parseExperimentalFlags(
Iterable<String> experiments, void onError(String message)) {
Map<ExperimentalFlag, bool> flags = <ExperimentalFlag, bool>{};
if (experiments == null) return flags;
for (String experiment in experiments) {
bool value = true;
if (experiment.startsWith("no-")) {
value = false;
experiment = experiment.substring(3);
}
ExperimentalFlag flag = parseExperimentalFlag(experiment);
if (flag == null) {
onError("Unknown experiment: " + experiment);
} else if (flags.containsKey(flag)) {
if (flags[flag] != value) {
onError("Experiment specified with conflicting values: " + experiment);
if (experiments != null) {
for (String experiment in experiments) {
bool value = true;
if (experiment.startsWith("no-")) {
value = false;
experiment = experiment.substring(3);
}
ExperimentalFlag flag = parseExperimentalFlag(experiment);
if (flag == null) {
onError("Unknown experiment: " + experiment);
} else if (flags.containsKey(flag)) {
if (flags[flag] != value) {
onError(
"Experiment specified with conflicting values: " + experiment);
}
} else {
flags[flag] = value;
}
} else {
flags[flag] = value;
}
}
for (ExperimentalFlag flag in ExperimentalFlag.values) {
assert(defaultExperimentalFlags.containsKey(flag),
"No default value for $flag.");
flags[flag] ??= defaultExperimentalFlags[flag];
}
return flags;
}
7 changes: 7 additions & 0 deletions pkg/front_end/lib/src/api_prototype/experimental_flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ ExperimentalFlag parseExperimentalFlag(String flag) {
}
return null;
}

const Map<ExperimentalFlag, bool> defaultExperimentalFlags = {
ExperimentalFlag.constantUpdate2018: false,
ExperimentalFlag.controlFlowCollections: false,
ExperimentalFlag.setLiterals: true,
ExperimentalFlag.spreadCollections: false,
};
3 changes: 2 additions & 1 deletion pkg/front_end/lib/src/api_unstable/dart2js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export '../api_prototype/diagnostic_message.dart'
getMessageRelatedInformation,
getMessageUri;

export '../api_prototype/experimental_flags.dart' show ExperimentalFlag;
export '../api_prototype/experimental_flags.dart'
show defaultExperimentalFlags, ExperimentalFlag;

export '../api_prototype/file_system.dart'
show FileSystem, FileSystemEntity, FileSystemException;
Expand Down
7 changes: 5 additions & 2 deletions pkg/front_end/lib/src/base/processed_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import 'package:package_config/src/packages_impl.dart' show MapPackages;
import '../api_prototype/compiler_options.dart'
show CompilerOptions, DiagnosticMessage;

import '../api_prototype/experimental_flags.dart' show ExperimentalFlag;
import '../api_prototype/experimental_flags.dart'
show defaultExperimentalFlags, ExperimentalFlag;

import '../api_prototype/file_system.dart'
show FileSystem, FileSystemEntity, FileSystemException;
Expand Down Expand Up @@ -310,9 +311,11 @@ class ProcessedOptions {
_raw.target ?? new NoneTarget(new TargetFlags(legacyMode: legacyMode));

bool isExperimentEnabled(ExperimentalFlag flag) {
assert(defaultExperimentalFlags.containsKey(flag),
"No default value for $flag.");
// TODO(askesc): Determine default flag value from specification file.
if (flag == ExperimentalFlag.setLiterals) return true;
return _raw.experimentalFlags[flag] ?? false;
return _raw.experimentalFlags[flag] ?? defaultExperimentalFlags[flag];
}

/// Get an outline component that summarizes the SDK, if any.
Expand Down

0 comments on commit b978fdd

Please sign in to comment.