mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:59:47 +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 CompilerOptions? options;
|
||||||
final bool canPerformGlobalTransforms;
|
final bool canPerformGlobalTransforms;
|
||||||
final bool supportsUnevaluatedConstants;
|
final bool supportsUnevaluatedConstants;
|
||||||
|
Map<String, ir.Class>? _nativeClasses;
|
||||||
|
|
||||||
Dart2jsTarget(this.name, this.flags,
|
Dart2jsTarget(this.name, this.flags,
|
||||||
{this.options,
|
{this.options,
|
||||||
|
@ -148,16 +149,16 @@ class Dart2jsTarget extends Target {
|
||||||
ReferenceFromIndex? referenceFromIndex,
|
ReferenceFromIndex? referenceFromIndex,
|
||||||
{void Function(String msg)? logger,
|
{void Function(String msg)? logger,
|
||||||
ChangedStructureNotifier? changedStructureNotifier}) {
|
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 jsUtilOptimizer = JsUtilOptimizer(coreTypes, hierarchy);
|
||||||
var staticInteropClassEraser =
|
var staticInteropClassEraser =
|
||||||
StaticInteropClassEraser(coreTypes, referenceFromIndex);
|
StaticInteropClassEraser(coreTypes, referenceFromIndex);
|
||||||
for (var library in libraries) {
|
for (var library in libraries) {
|
||||||
JsInteropChecks(
|
jsInteropChecks.visitLibrary(library);
|
||||||
coreTypes,
|
|
||||||
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
|
||||||
nativeClasses)
|
|
||||||
.visitLibrary(library);
|
|
||||||
// TODO (rileyporter): Merge js_util optimizations with other lowerings
|
// TODO (rileyporter): Merge js_util optimizations with other lowerings
|
||||||
// in the single pass in `transformations/lowering.dart`.
|
// in the single pass in `transformations/lowering.dart`.
|
||||||
jsUtilOptimizer.visitLibrary(library);
|
jsUtilOptimizer.visitLibrary(library);
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
// for details. All rights reserved. Use of this source code is governed by a
|
// 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.
|
// 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/js_interop.dart' as jsInteropHelper;
|
||||||
import 'package:_js_interop_checks/src/transformations/js_util_wasm_optimizer.dart';
|
import 'package:_js_interop_checks/src/transformations/js_util_wasm_optimizer.dart';
|
||||||
import 'package:_js_interop_checks/src/transformations/static_interop_class_eraser.dart';
|
import 'package:_js_interop_checks/src/transformations/static_interop_class_eraser.dart';
|
||||||
|
@ -32,6 +35,7 @@ class WasmTarget extends Target {
|
||||||
Class? _compactLinkedCustomHashSet;
|
Class? _compactLinkedCustomHashSet;
|
||||||
Class? _oneByteString;
|
Class? _oneByteString;
|
||||||
Class? _twoByteString;
|
Class? _twoByteString;
|
||||||
|
Map<String, Class>? _nativeClasses;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get enableNoSuchMethodForwarders => true;
|
bool get enableNoSuchMethodForwarders => true;
|
||||||
|
@ -87,16 +91,24 @@ class WasmTarget extends Target {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _performJSInteropTransformations(
|
void _performJSInteropTransformations(
|
||||||
|
Component component,
|
||||||
CoreTypes coreTypes,
|
CoreTypes coreTypes,
|
||||||
ClassHierarchy hierarchy,
|
ClassHierarchy hierarchy,
|
||||||
List<Library> interopDependentLibraries,
|
List<Library> interopDependentLibraries,
|
||||||
|
DiagnosticReporter diagnosticReporter,
|
||||||
ReferenceFromIndex? referenceFromIndex) {
|
ReferenceFromIndex? referenceFromIndex) {
|
||||||
|
_nativeClasses ??= JsInteropChecks.getNativeClasses(component);
|
||||||
|
final jsInteropChecks = JsInteropChecks(
|
||||||
|
coreTypes,
|
||||||
|
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
||||||
|
_nativeClasses!);
|
||||||
final jsUtilOptimizer = JsUtilWasmOptimizer(coreTypes, hierarchy);
|
final jsUtilOptimizer = JsUtilWasmOptimizer(coreTypes, hierarchy);
|
||||||
final staticInteropClassEraser = StaticInteropClassEraser(
|
final staticInteropClassEraser = StaticInteropClassEraser(
|
||||||
coreTypes, referenceFromIndex,
|
coreTypes, referenceFromIndex,
|
||||||
libraryForJavaScriptObject: 'dart:_js_helper',
|
libraryForJavaScriptObject: 'dart:_js_helper',
|
||||||
classNameOfJavaScriptObject: 'JSValue');
|
classNameOfJavaScriptObject: 'JSValue');
|
||||||
for (Library library in interopDependentLibraries) {
|
for (Library library in interopDependentLibraries) {
|
||||||
|
jsInteropChecks.visitLibrary(library);
|
||||||
jsUtilOptimizer.visitLibrary(library);
|
jsUtilOptimizer.visitLibrary(library);
|
||||||
staticInteropClassEraser.visitLibrary(library);
|
staticInteropClassEraser.visitLibrary(library);
|
||||||
}
|
}
|
||||||
|
@ -133,8 +145,8 @@ class WasmTarget extends Target {
|
||||||
if (transitiveImportingJSInterop.isEmpty) {
|
if (transitiveImportingJSInterop.isEmpty) {
|
||||||
logger?.call("Skipped JS interop transformations");
|
logger?.call("Skipped JS interop transformations");
|
||||||
} else {
|
} else {
|
||||||
_performJSInteropTransformations(coreTypes, hierarchy,
|
_performJSInteropTransformations(component, coreTypes, hierarchy,
|
||||||
transitiveImportingJSInterop, referenceFromIndex);
|
transitiveImportingJSInterop, diagnosticReporter, referenceFromIndex);
|
||||||
logger?.call("Transformed JS interop classes");
|
logger?.call("Transformed JS interop classes");
|
||||||
}
|
}
|
||||||
transformMixins.transformLibraries(
|
transformMixins.transformLibraries(
|
||||||
|
|
|
@ -6,6 +6,7 @@ environment:
|
||||||
|
|
||||||
# Use 'any' constraints here; we get our versions from the DEPS file.
|
# Use 'any' constraints here; we get our versions from the DEPS file.
|
||||||
dependencies:
|
dependencies:
|
||||||
|
_fe_analyzer_shared: any
|
||||||
_js_interop_checks: any
|
_js_interop_checks: any
|
||||||
args: any
|
args: any
|
||||||
front_end: any
|
front_end: any
|
||||||
|
|
|
@ -164,16 +164,16 @@ class DevCompilerTarget extends Target {
|
||||||
{void Function(String msg)? logger,
|
{void Function(String msg)? logger,
|
||||||
ChangedStructureNotifier? changedStructureNotifier}) {
|
ChangedStructureNotifier? changedStructureNotifier}) {
|
||||||
_nativeClasses ??= JsInteropChecks.getNativeClasses(component);
|
_nativeClasses ??= JsInteropChecks.getNativeClasses(component);
|
||||||
|
var jsInteropChecks = JsInteropChecks(
|
||||||
|
coreTypes,
|
||||||
|
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
||||||
|
_nativeClasses!);
|
||||||
var jsUtilOptimizer = JsUtilOptimizer(coreTypes, hierarchy);
|
var jsUtilOptimizer = JsUtilOptimizer(coreTypes, hierarchy);
|
||||||
var staticInteropClassEraser =
|
var staticInteropClassEraser =
|
||||||
StaticInteropClassEraser(coreTypes, referenceFromIndex);
|
StaticInteropClassEraser(coreTypes, referenceFromIndex);
|
||||||
for (var library in libraries) {
|
for (var library in libraries) {
|
||||||
_CovarianceTransformer(library).transform();
|
_CovarianceTransformer(library).transform();
|
||||||
JsInteropChecks(
|
jsInteropChecks.visitLibrary(library);
|
||||||
coreTypes,
|
|
||||||
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>,
|
|
||||||
_nativeClasses!)
|
|
||||||
.visitLibrary(library);
|
|
||||||
jsUtilOptimizer.visitLibrary(library);
|
jsUtilOptimizer.visitLibrary(library);
|
||||||
staticInteropClassEraser.visitLibrary(library);
|
staticInteropClassEraser.visitLibrary(library);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3146,7 +3146,8 @@
|
||||||
"-ndart2wasm-hostasserts-linux-x64-d8",
|
"-ndart2wasm-hostasserts-linux-x64-d8",
|
||||||
"language",
|
"language",
|
||||||
"corelib",
|
"corelib",
|
||||||
"web/wasm"
|
"web/wasm",
|
||||||
|
"lib/js/static_interop_test"
|
||||||
],
|
],
|
||||||
"shards": 3,
|
"shards": 3,
|
||||||
"fileset": "dart2wasm_hostasserts"
|
"fileset": "dart2wasm_hostasserts"
|
||||||
|
|
Loading…
Reference in a new issue