mirror of
https://github.com/dart-lang/sdk
synced 2024-07-25 04:15:45 +00:00
Reland "[dart2js] Move Dart2js const conditional simplifier to phase 0b, the CFE linker."
This is a reland of commit fdfca11d39
Original change's description:
> [dart2js] Move Dart2js const conditional simplifier to phase 0b, the CFE linker.
>
> Change-Id: I9ed7f46c5641c28dc71b7712dbd4e8d2062b1f4d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332820
> Reviewed-by: Sigmund Cherem <sigmund@google.com>
> Reviewed-by: Mayank Patke <fishythefish@google.com>
Change-Id: I0ddf00c551196085e2a17936d15d6bc46c76efad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336580
Commit-Queue: Nate Biggs <natebiggs@google.com>
Reviewed-by: Mayank Patke <fishythefish@google.com>
This commit is contained in:
parent
193db9b70e
commit
2b4b9cb753
|
@ -47,14 +47,12 @@ import 'inferrer/types.dart'
|
|||
show GlobalTypeInferenceResults, GlobalTypeInferenceTask;
|
||||
import 'inferrer/wrapped.dart' show WrappedAbstractValueStrategy;
|
||||
import 'io/source_information.dart';
|
||||
import 'ir/annotations.dart';
|
||||
import 'js_backend/codegen_inputs.dart' show CodegenInputs;
|
||||
import 'js_backend/enqueuer.dart';
|
||||
import 'js_backend/inferred_data.dart';
|
||||
import 'js_model/js_strategy.dart';
|
||||
import 'js_model/js_world.dart';
|
||||
import 'js_model/locals.dart';
|
||||
import 'kernel/dart2js_target.dart';
|
||||
import 'kernel/front_end_adapter.dart' show CompilerFileSystem;
|
||||
import 'kernel/kernel_strategy.dart';
|
||||
import 'kernel/kernel_world.dart';
|
||||
|
@ -437,34 +435,6 @@ class Compiler {
|
|||
bool shouldStopAfterLoadKernel(load_kernel.Output? output) =>
|
||||
output == null || compilationFailed || stage.shouldOnlyComputeDill;
|
||||
|
||||
void simplifyConstConditionals(ir.Component component) {
|
||||
void reportMessage(
|
||||
fe.LocatedMessage message, List<fe.LocatedMessage>? context) {
|
||||
reportLocatedMessage(reporter, message, context);
|
||||
}
|
||||
|
||||
bool shouldNotInline(ir.TreeNode node) {
|
||||
if (node is! ir.Annotatable) {
|
||||
return false;
|
||||
}
|
||||
return computePragmaAnnotationDataFromIr(node).any((pragma) =>
|
||||
pragma == const PragmaAnnotationData('noInline') ||
|
||||
pragma == const PragmaAnnotationData('never-inline'));
|
||||
}
|
||||
|
||||
fe.ConstConditionalSimplifier(
|
||||
const Dart2jsDartLibrarySupport(),
|
||||
const Dart2jsConstantsBackend(supportsUnevaluatedConstants: false),
|
||||
component,
|
||||
reportMessage,
|
||||
environmentDefines: environment.definitions,
|
||||
evaluationMode: options.useLegacySubtyping
|
||||
? fe.EvaluationMode.weak
|
||||
: fe.EvaluationMode.strong,
|
||||
shouldNotInline: shouldNotInline)
|
||||
.run();
|
||||
}
|
||||
|
||||
GlobalTypeInferenceResults performGlobalTypeInference(
|
||||
JClosedWorld closedWorld) {
|
||||
FunctionEntity mainFunction = closedWorld.elementEnvironment.mainFunction!;
|
||||
|
@ -551,11 +521,6 @@ class Compiler {
|
|||
ir.Component component = output.component;
|
||||
JClosedWorld? closedWorld;
|
||||
if (!stage.shouldReadClosedWorld) {
|
||||
// If we're deserializing the closed world, the input .dill already
|
||||
// contains the modified AST, so the transformer only needs to run if
|
||||
// the closed world is being computed from scratch.
|
||||
simplifyConstConditionals(component);
|
||||
|
||||
Uri rootLibraryUri = output.rootLibraryUri!;
|
||||
List<Uri> libraries = output.libraries!;
|
||||
closedWorld = computeClosedWorld(component, rootLibraryUri, libraries);
|
||||
|
|
|
@ -22,9 +22,14 @@ import '../commandline_options.dart';
|
|||
import '../common.dart';
|
||||
import '../diagnostics/diagnostic_listener.dart';
|
||||
import '../environment.dart';
|
||||
import '../ir/annotations.dart';
|
||||
import '../ir/constants.dart';
|
||||
import '../kernel/dart2js_target.dart'
|
||||
show Dart2jsTarget, implicitlyUsedLibraries;
|
||||
show
|
||||
Dart2jsConstantsBackend,
|
||||
Dart2jsDartLibrarySupport,
|
||||
Dart2jsTarget,
|
||||
implicitlyUsedLibraries;
|
||||
import '../kernel/front_end_adapter.dart';
|
||||
import '../kernel/transformations/global/transform.dart' as globalTransforms;
|
||||
import '../options.dart';
|
||||
|
@ -113,6 +118,36 @@ class _LoadFromKernelResult {
|
|||
_LoadFromKernelResult(this.component, this.entryLibrary);
|
||||
}
|
||||
|
||||
void _simplifyConstConditionals(ir.Component component, CompilerOptions options,
|
||||
ir.ClassHierarchy classHierarchy, DiagnosticReporter reporter) {
|
||||
void reportMessage(
|
||||
fe.LocatedMessage message, List<fe.LocatedMessage>? context) {
|
||||
reportLocatedMessage(reporter, message, context);
|
||||
}
|
||||
|
||||
bool shouldNotInline(ir.TreeNode node) {
|
||||
if (node is! ir.Annotatable) {
|
||||
return false;
|
||||
}
|
||||
return computePragmaAnnotationDataFromIr(node).any((pragma) =>
|
||||
pragma == const PragmaAnnotationData('noInline') ||
|
||||
pragma == const PragmaAnnotationData('never-inline'));
|
||||
}
|
||||
|
||||
fe.ConstConditionalSimplifier(
|
||||
const Dart2jsDartLibrarySupport(),
|
||||
const Dart2jsConstantsBackend(supportsUnevaluatedConstants: false),
|
||||
component,
|
||||
reportMessage,
|
||||
environmentDefines: options.environment,
|
||||
classHierarchy: classHierarchy,
|
||||
evaluationMode: options.useLegacySubtyping
|
||||
? fe.EvaluationMode.weak
|
||||
: fe.EvaluationMode.strong,
|
||||
shouldNotInline: shouldNotInline)
|
||||
.run();
|
||||
}
|
||||
|
||||
// Perform any backend-specific transforms here that can be done on both
|
||||
// serialized components and components from source.
|
||||
void _doTransformsOnKernelLoad(
|
||||
|
@ -142,6 +177,7 @@ void _doTransformsOnKernelLoad(
|
|||
.visitComponent(component);
|
||||
globalTransforms.transformLibraries(
|
||||
component.libraries, constantsEvaluator, coreTypes, options);
|
||||
_simplifyConstConditionals(component, options, classHierarchy, reporter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue