mirror of
https://github.com/dart-lang/sdk
synced 2024-07-01 07:14:29 +00:00
[dart2js] Enable CFE constant evaluation.
Change-Id: Ib449906bbfd95b6510e701606c43ef4c4169313b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240601 Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Joshua Litt <joshualitt@google.com>
This commit is contained in:
parent
30f0e0f4d5
commit
bd0391e66c
|
@ -71,9 +71,12 @@ class Dart2jsTarget extends Target {
|
|||
|
||||
final CompilerOptions? options;
|
||||
final bool canPerformGlobalTransforms;
|
||||
final bool supportsUnevaluatedConstants;
|
||||
|
||||
Dart2jsTarget(this.name, this.flags,
|
||||
{this.options, this.canPerformGlobalTransforms = true});
|
||||
{this.options,
|
||||
this.canPerformGlobalTransforms = true,
|
||||
this.supportsUnevaluatedConstants = true});
|
||||
|
||||
@override
|
||||
bool get enableNoSuchMethodForwarders => true;
|
||||
|
@ -223,8 +226,8 @@ class Dart2jsTarget extends Target {
|
|||
}
|
||||
|
||||
@override
|
||||
ConstantsBackend get constantsBackend =>
|
||||
const Dart2jsConstantsBackend(supportsUnevaluatedConstants: true);
|
||||
ConstantsBackend get constantsBackend => Dart2jsConstantsBackend(
|
||||
supportsUnevaluatedConstants: supportsUnevaluatedConstants);
|
||||
|
||||
@override
|
||||
DartLibrarySupport get dartLibrarySupport =>
|
||||
|
|
|
@ -87,6 +87,9 @@ class FeatureOptions {
|
|||
/// to reduce generated code size.
|
||||
FeatureOption simpleAsyncToFuture = FeatureOption('simple-async-to-future');
|
||||
|
||||
/// Whether or not the CFE should evaluate constants.
|
||||
FeatureOption cfeConstants = FeatureOption('cfe-constants');
|
||||
|
||||
/// [FeatureOption]s which are shipped and cannot be toggled.
|
||||
late final List<FeatureOption> shipped = [
|
||||
newHolders,
|
||||
|
@ -102,7 +105,8 @@ class FeatureOptions {
|
|||
late final List<FeatureOption> canary = [
|
||||
writeUtf8,
|
||||
newDumpInfo,
|
||||
simpleAsyncToFuture
|
||||
simpleAsyncToFuture,
|
||||
cfeConstants,
|
||||
];
|
||||
|
||||
/// Forces canary feature on. This must run after [Option].parse.
|
||||
|
|
|
@ -213,8 +213,12 @@ Future<_LoadFromSourceResult> _loadFromSource(
|
|||
fe.InitializedCompilerState initializedCompilerState,
|
||||
String targetName) async {
|
||||
bool verbose = false;
|
||||
bool cfeConstants = options.features.cfeConstants.isEnabled;
|
||||
Map<String, String> environment = cfeConstants ? options.environment : null;
|
||||
Target target = Dart2jsTarget(targetName, TargetFlags(),
|
||||
options: options, canPerformGlobalTransforms: true);
|
||||
options: options,
|
||||
canPerformGlobalTransforms: true,
|
||||
supportsUnevaluatedConstants: !cfeConstants);
|
||||
fe.FileSystem fileSystem = CompilerFileSystem(compilerInput);
|
||||
fe.Verbosity verbosity = options.verbosity;
|
||||
fe.DiagnosticMessageHandler onDiagnostic = (fe.DiagnosticMessage message) {
|
||||
|
@ -237,6 +241,7 @@ Future<_LoadFromSourceResult> _loadFromSource(
|
|||
..librariesSpecificationUri = options.librariesSpecificationUri
|
||||
..packagesFileUri = options.packageConfig
|
||||
..explicitExperimentalFlags = options.explicitExperimentalFlags
|
||||
..environmentDefines = environment
|
||||
..verbose = verbose
|
||||
..fileSystem = fileSystem
|
||||
..onDiagnostic = onDiagnostic
|
||||
|
@ -266,6 +271,7 @@ Future<_LoadFromSourceResult> _loadFromSource(
|
|||
dependencies,
|
||||
options.packageConfig,
|
||||
explicitExperimentalFlags: options.explicitExperimentalFlags,
|
||||
environmentDefines: environment,
|
||||
nnbdMode:
|
||||
options.useLegacySubtyping ? fe.NnbdMode.Weak : fe.NnbdMode.Strong,
|
||||
invocationModes: options.cfeInvocationModes,
|
||||
|
|
|
@ -129,6 +129,7 @@ InitializedCompilerState initializeCompiler(
|
|||
List<Uri> additionalDills,
|
||||
Uri packagesFileUri,
|
||||
{required Map<ExperimentalFlag, bool> explicitExperimentalFlags,
|
||||
Map<String, String>? environmentDefines,
|
||||
bool verify: false,
|
||||
NnbdMode? nnbdMode,
|
||||
Set<InvocationMode> invocationModes: const <InvocationMode>{},
|
||||
|
@ -144,6 +145,7 @@ InitializedCompilerState initializeCompiler(
|
|||
equalLists(oldState.options.additionalDills, additionalDills) &&
|
||||
equalMaps(oldState.options.explicitExperimentalFlags,
|
||||
explicitExperimentalFlags) &&
|
||||
equalMaps(oldState.options.environmentDefines, environmentDefines) &&
|
||||
oldState.options.verify == verify &&
|
||||
oldState.options.nnbdMode == nnbdMode &&
|
||||
equalSets(oldState.options.invocationModes, invocationModes) &&
|
||||
|
@ -157,6 +159,8 @@ InitializedCompilerState initializeCompiler(
|
|||
..librariesSpecificationUri = librariesSpecificationUri
|
||||
..packagesFileUri = packagesFileUri
|
||||
..explicitExperimentalFlags = explicitExperimentalFlags
|
||||
..environmentDefines = environmentDefines
|
||||
..errorOnUnevaluatedConstant = environmentDefines != null ? true : false
|
||||
..verify = verify
|
||||
..invocationModes = invocationModes
|
||||
..verbosity = verbosity;
|
||||
|
|
|
@ -234,6 +234,18 @@ ProcessedOptions analyzeCommandLine(String programName,
|
|||
});
|
||||
}
|
||||
|
||||
// In order to facilitate the roll out of CFE constants on Dart2js, we need to
|
||||
// be able to support both passing '--no-defines' and also evaluating CFE
|
||||
// constants when the target supports it. This is so we can easily enable or
|
||||
// disable fully evaluating constants in the CFE with a flag. This can be
|
||||
// deleted when the CFE fully evaluates constants for Dart2js in all cases.
|
||||
Map<String, String>? environmentDefines;
|
||||
if (noDefines && target.constantsBackend.supportsUnevaluatedConstants) {
|
||||
// Pass a null environment.
|
||||
} else {
|
||||
environmentDefines = parsedOptions.defines;
|
||||
}
|
||||
|
||||
CompilerOptions compilerOptions = new CompilerOptions()
|
||||
..compileSdk = compileSdk
|
||||
..fileSystem = fileSystem
|
||||
|
@ -249,7 +261,7 @@ ProcessedOptions analyzeCommandLine(String programName,
|
|||
..verify = verify
|
||||
..skipPlatformVerification = skipPlatformVerification
|
||||
..explicitExperimentalFlags = explicitExperimentalFlags
|
||||
..environmentDefines = noDefines ? null : parsedOptions.defines
|
||||
..environmentDefines = environmentDefines
|
||||
..nnbdMode = nnbdMode
|
||||
..enableUnscheduledExperiments = enableUnscheduledExperiments
|
||||
..additionalDills = linkDependencies
|
||||
|
|
Loading…
Reference in New Issue
Block a user