mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
[pkg:js] Add JsInteropChecks to Wasm backend
Also cleans up and unifies some behavior across the backends: - avoiding reinstantiating JsInteropChecks for every library - having the native classes as a member instead of recomputing on dart2js Now that these checks exist, we can add lib/js/static_interop_test to the test directories the wasm trybot runs. Change-Id: I912aae988afe7915e80cc13d00b8c47818dfa520 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255760 Commit-Queue: Srujan Gaddam <srujzs@google.com> Reviewed-by: Joshua Litt <joshualitt@google.com> Reviewed-by: William Hesse <whesse@google.com>
This commit is contained in:
parent
0872189d94
commit
9f10a3bc16
|
@ -74,6 +74,7 @@ class Dart2jsTarget extends Target {
|
|||
final CompilerOptions? options;
|
||||
final bool canPerformGlobalTransforms;
|
||||
final bool supportsUnevaluatedConstants;
|
||||
Map<String, ir.Class>? _nativeClasses;
|
||||
|
||||
Dart2jsTarget(this.name, this.flags,
|
||||
{this.options,
|
||||
|
@ -148,16 +149,16 @@ class Dart2jsTarget extends Target {
|
|||
ReferenceFromIndex? referenceFromIndex,
|
||||
{void Function(String msg)? logger,
|
||||
ChangedStructureNotifier? changedStructureNotifier}) {
|
||||
var nativeClasses = JsInteropChecks.getNativeClasses(component);
|
||||
_nativeClasses = JsInteropChecks.getNativeClasses(component);
|
||||
var jsInteropChecks = JsInteropChecks(
|
||||
coreTypes,
|
||||
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
||||
_nativeClasses!);
|
||||
var jsUtilOptimizer = JsUtilOptimizer(coreTypes, hierarchy);
|
||||
var staticInteropClassEraser =
|
||||
StaticInteropClassEraser(coreTypes, referenceFromIndex);
|
||||
for (var library in libraries) {
|
||||
JsInteropChecks(
|
||||
coreTypes,
|
||||
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
||||
nativeClasses)
|
||||
.visitLibrary(library);
|
||||
jsInteropChecks.visitLibrary(library);
|
||||
// TODO (rileyporter): Merge js_util optimizations with other lowerings
|
||||
// in the single pass in `transformations/lowering.dart`.
|
||||
jsUtilOptimizer.visitLibrary(library);
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
// 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:_fe_analyzer_shared/src/messages/codes.dart'
|
||||
show Message, LocatedMessage;
|
||||
import 'package:_js_interop_checks/js_interop_checks.dart';
|
||||
import 'package:_js_interop_checks/src/js_interop.dart' as jsInteropHelper;
|
||||
import 'package:_js_interop_checks/src/transformations/js_util_wasm_optimizer.dart';
|
||||
import 'package:_js_interop_checks/src/transformations/static_interop_class_eraser.dart';
|
||||
|
@ -32,6 +35,7 @@ class WasmTarget extends Target {
|
|||
Class? _compactLinkedCustomHashSet;
|
||||
Class? _oneByteString;
|
||||
Class? _twoByteString;
|
||||
Map<String, Class>? _nativeClasses;
|
||||
|
||||
@override
|
||||
bool get enableNoSuchMethodForwarders => true;
|
||||
|
@ -87,16 +91,24 @@ class WasmTarget extends Target {
|
|||
}
|
||||
|
||||
void _performJSInteropTransformations(
|
||||
Component component,
|
||||
CoreTypes coreTypes,
|
||||
ClassHierarchy hierarchy,
|
||||
List<Library> interopDependentLibraries,
|
||||
DiagnosticReporter diagnosticReporter,
|
||||
ReferenceFromIndex? referenceFromIndex) {
|
||||
_nativeClasses ??= JsInteropChecks.getNativeClasses(component);
|
||||
final jsInteropChecks = JsInteropChecks(
|
||||
coreTypes,
|
||||
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
||||
_nativeClasses!);
|
||||
final jsUtilOptimizer = JsUtilWasmOptimizer(coreTypes, hierarchy);
|
||||
final staticInteropClassEraser = StaticInteropClassEraser(
|
||||
coreTypes, referenceFromIndex,
|
||||
libraryForJavaScriptObject: 'dart:_js_helper',
|
||||
classNameOfJavaScriptObject: 'JSValue');
|
||||
for (Library library in interopDependentLibraries) {
|
||||
jsInteropChecks.visitLibrary(library);
|
||||
jsUtilOptimizer.visitLibrary(library);
|
||||
staticInteropClassEraser.visitLibrary(library);
|
||||
}
|
||||
|
@ -133,8 +145,8 @@ class WasmTarget extends Target {
|
|||
if (transitiveImportingJSInterop.isEmpty) {
|
||||
logger?.call("Skipped JS interop transformations");
|
||||
} else {
|
||||
_performJSInteropTransformations(coreTypes, hierarchy,
|
||||
transitiveImportingJSInterop, referenceFromIndex);
|
||||
_performJSInteropTransformations(component, coreTypes, hierarchy,
|
||||
transitiveImportingJSInterop, diagnosticReporter, referenceFromIndex);
|
||||
logger?.call("Transformed JS interop classes");
|
||||
}
|
||||
transformMixins.transformLibraries(
|
||||
|
|
|
@ -6,6 +6,7 @@ environment:
|
|||
|
||||
# Use 'any' constraints here; we get our versions from the DEPS file.
|
||||
dependencies:
|
||||
_fe_analyzer_shared: any
|
||||
_js_interop_checks: any
|
||||
args: any
|
||||
front_end: any
|
||||
|
|
|
@ -164,16 +164,16 @@ class DevCompilerTarget extends Target {
|
|||
{void Function(String msg)? logger,
|
||||
ChangedStructureNotifier? changedStructureNotifier}) {
|
||||
_nativeClasses ??= JsInteropChecks.getNativeClasses(component);
|
||||
var jsInteropChecks = JsInteropChecks(
|
||||
coreTypes,
|
||||
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
||||
_nativeClasses!);
|
||||
var jsUtilOptimizer = JsUtilOptimizer(coreTypes, hierarchy);
|
||||
var staticInteropClassEraser =
|
||||
StaticInteropClassEraser(coreTypes, referenceFromIndex);
|
||||
for (var library in libraries) {
|
||||
_CovarianceTransformer(library).transform();
|
||||
JsInteropChecks(
|
||||
coreTypes,
|
||||
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
||||
_nativeClasses!)
|
||||
.visitLibrary(library);
|
||||
jsInteropChecks.visitLibrary(library);
|
||||
jsUtilOptimizer.visitLibrary(library);
|
||||
staticInteropClassEraser.visitLibrary(library);
|
||||
}
|
||||
|
|
|
@ -3146,7 +3146,8 @@
|
|||
"-ndart2wasm-hostasserts-linux-x64-d8",
|
||||
"language",
|
||||
"corelib",
|
||||
"web/wasm"
|
||||
"web/wasm",
|
||||
"lib/js/static_interop_test"
|
||||
],
|
||||
"shards": 3,
|
||||
"fileset": "dart2wasm_hostasserts"
|
||||
|
|
Loading…
Reference in a new issue