9f33810b01
Currently the 'load-ids' controls both how deferred modules are loaded and whether or not the compiler emits a deferred map JSON file. This change separates these 2 actions into 2 separate flags. 'deferred-map' now provides the URI for the JSON file. And 'use-load-ids' controls how deferred modules are loaded. This is needed for some tools that might not want to use load ids but still need to process the deferred map file. Change-Id: I6909307f058d8f97dd8987e421f693ee97d6572f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499520 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
103 lines
3.8 KiB
Dart
103 lines
3.8 KiB
Dart
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:front_end/src/api_prototype/constant_evaluator.dart' as kernel;
|
|
import 'package:kernel/ast.dart';
|
|
import 'package:kernel/class_hierarchy.dart';
|
|
import 'package:kernel/core_types.dart';
|
|
import 'package:kernel/library_index.dart';
|
|
import 'package:kernel/type_environment.dart';
|
|
import 'package:vm/transformations/vm_constant_evaluator.dart';
|
|
|
|
import 'compiler_options.dart';
|
|
import 'target.dart';
|
|
|
|
class ConstantEvaluator extends kernel.ConstantEvaluator
|
|
implements VMConstantEvaluator {
|
|
final bool _checkBounds;
|
|
final bool _minify;
|
|
final bool _deferredLoadingEnabled;
|
|
final bool _deferredLoadingViaEmbedderLoadId;
|
|
|
|
final Procedure? _dartInternalCheckBoundsGetter;
|
|
final Procedure? _dartInternalMinifyGetter;
|
|
final Procedure? _dartInternalDeferredLoadingEnabled;
|
|
final Procedure? _dartInternalDeferredLoadingViaEmbedderLoadId;
|
|
|
|
ConstantEvaluator(
|
|
WasmCompilerOptions options,
|
|
WasmTarget target,
|
|
Component component,
|
|
CoreTypes coreTypes,
|
|
ClassHierarchy classHierarchy,
|
|
LibraryIndex libraryIndex,
|
|
) : _checkBounds = !options.translatorOptions.omitBoundsChecks,
|
|
_minify = options.translatorOptions.minify,
|
|
_deferredLoadingEnabled =
|
|
options.translatorOptions.enableDeferredLoading ||
|
|
options.translatorOptions.enableMultiModuleStressTestMode,
|
|
_deferredLoadingViaEmbedderLoadId = options.useLoadIds,
|
|
_dartInternalCheckBoundsGetter = libraryIndex.tryGetProcedure(
|
|
"dart:_internal",
|
|
LibraryIndex.topLevel,
|
|
"get:checkBounds",
|
|
),
|
|
_dartInternalMinifyGetter = libraryIndex.tryGetProcedure(
|
|
"dart:_internal",
|
|
LibraryIndex.topLevel,
|
|
"get:minify",
|
|
),
|
|
_dartInternalDeferredLoadingEnabled = libraryIndex.tryGetProcedure(
|
|
"dart:_internal",
|
|
LibraryIndex.topLevel,
|
|
"get:deferredLoadingEnabled",
|
|
),
|
|
_dartInternalDeferredLoadingViaEmbedderLoadId = libraryIndex
|
|
.tryGetProcedure(
|
|
"dart:_internal",
|
|
LibraryIndex.topLevel,
|
|
"get:deferredLoadingViaEmbedderLoadId",
|
|
),
|
|
super(
|
|
target.dartLibrarySupport,
|
|
target.constantsBackend,
|
|
component,
|
|
options.environment,
|
|
TypeEnvironment(coreTypes, classHierarchy),
|
|
const kernel.SimpleErrorReporter(),
|
|
enableTripleShift: true,
|
|
enableAsserts: options.translatorOptions.enableAsserts,
|
|
errorOnUnevaluatedConstant: true,
|
|
);
|
|
|
|
@override
|
|
Constant visitStaticGet(StaticGet node) {
|
|
final target = node.target;
|
|
if (target == _dartInternalCheckBoundsGetter) {
|
|
return canonicalize(BoolConstant(_checkBounds));
|
|
}
|
|
if (target == _dartInternalMinifyGetter) {
|
|
return canonicalize(BoolConstant(_minify));
|
|
}
|
|
if (target == _dartInternalDeferredLoadingEnabled) {
|
|
return canonicalize(BoolConstant(_deferredLoadingEnabled));
|
|
}
|
|
if (target == _dartInternalDeferredLoadingViaEmbedderLoadId) {
|
|
return canonicalize(BoolConstant(_deferredLoadingViaEmbedderLoadId));
|
|
}
|
|
return super.visitStaticGet(node);
|
|
}
|
|
|
|
// TODO: We may want consider (similar to the VM) supporting a
|
|
// `wasm:const-evaluate` pragma that we recognize here, and then make sure
|
|
// functions with the pragma are evaluated before TFA (raise a compile-time
|
|
// error if they are not).
|
|
@override
|
|
bool shouldEvaluateMember(Member node) =>
|
|
node == _dartInternalCheckBoundsGetter ||
|
|
node == _dartInternalMinifyGetter ||
|
|
node == _dartInternalDeferredLoadingEnabled ||
|
|
node == _dartInternalDeferredLoadingViaEmbedderLoadId;
|
|
}
|