Skip to content

Commit a63045d

Browse files
fishythefishCommit Queue
authored andcommitted
[dart2wasm] Remove dart:js_util from supported libraries
Since that stops `dart:_js_annotations` from building on dart2wasm, let's stop supporting that, too. This causes `package:js` to no longer work on dart2wasm, but none of the allowlisted packages use it any longer, so we can simply migrate tests off of it. Fixes: #56502 Fixes: #61550 Change-Id: I6a6a696438255ebf25a5a17131cdbd327ba81581 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453645 Commit-Queue: Mayank Patke <[email protected]> Reviewed-by: Srujan Gaddam <[email protected]> Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Nate Biggs <[email protected]>
1 parent 34da5f3 commit a63045d

36 files changed

+444
-651
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
**Released on:** Unreleased
44

5+
### Libraries
6+
7+
#### `dart:js_util`
8+
9+
- dart2wasm no longer supports `dart:js_util`. Any code that imports
10+
`dart:js_util` will no longer compile with dart2wasm. Consequently, code that
11+
depends on `package:js` will no longer compile with dart2wasm either.
12+
See [#61550][] for more details.
13+
14+
[#61550]: https://github.com/dart-lang/sdk/issues/61550
15+
516
## 3.10.0
617

718
**Released on:** Unreleased

pkg/_js_interop_checks/lib/js_interop_checks.dart

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import 'package:front_end/src/api_prototype/codes.dart'
1515
codeDartFfiLibraryInDart2Wasm,
1616
codeJsInteropDartClassExtendsJSClass,
1717
codeJsInteropDartJsInteropAnnotationForStaticInteropOnly,
18-
codeJsInteropDisallowedInteropLibraryInDart2Wasm,
1918
codeJsInteropEnclosingClassJSAnnotation,
2019
codeJsInteropEnclosingClassJSAnnotationContext,
2120
codeJsInteropExtensionTypeMemberNotInterop,
@@ -88,8 +87,7 @@ class JsInteropChecks extends RecursiveVisitor {
8887

8988
final ExportChecker exportChecker;
9089
final bool isDart2Wasm;
91-
92-
final List<String> _disallowedInteropLibrariesInDart2Wasm;
90+
final bool enableExperimentalFfi;
9391

9492
/// Native tests to exclude from checks on external.
9593
// TODO(rileyporter): Use ExternalName from CFE to exclude native tests.
@@ -103,29 +101,7 @@ class JsInteropChecks extends RecursiveVisitor {
103101
RegExp(r'(?<!generated_)tests/lib/js'),
104102
];
105103

106-
static final List<Pattern>
107-
_allowedUseOfDart2WasmDisallowedInteropLibrariesTestPatterns = [
108-
// Benchmarks.
109-
RegExp(r'BigIntParsePrint/dart/native_version_javascript.dart'),
110-
RegExp(r'JSInterop/dart/jsinterop_lib.dart'),
111-
// Tests.
112-
RegExp(r'(?<!generated_)tests/lib/js/export'),
113-
// Negative lookahead to test the violation.
114-
RegExp(
115-
r'(?<!generated_)tests/lib/js/static_interop_test(?!/disallowed_interop_libraries_test.dart)',
116-
),
117-
RegExp(r'(?<!generated_)tests/web/wasm/(?!ffi/).*'),
118-
// Flutter tests.
119-
RegExp(r'flutter/lib/web_ui/test'),
120-
];
121-
122-
// TODO(srujzs): Help migrate some of these away. Once we're done, we can
123-
// remove `dart:*` interop libraries from the check as they can be moved out
124-
// of `libraries.json`.
125104
static const allowedInteropLibrariesInDart2WasmPackages = [
126-
// Both these packages re-export other interop libraries
127-
'js',
128-
'js_util',
129105
// Flutter/benchmarks.
130106
'flutter',
131107
'engine',
@@ -137,14 +113,6 @@ class JsInteropChecks extends RecursiveVisitor {
137113
'url_launcher_web',
138114
];
139115

140-
/// Interop libraries that cannot be used in dart2wasm.
141-
static const _disallowedInteropLibrariesInDart2WasmByDefault = [
142-
'package:js/js.dart',
143-
'package:js/js_util.dart',
144-
'dart:js_util',
145-
'dart:ffi',
146-
];
147-
148116
/// Libraries that use `external` to exclude from checks on external.
149117
static const Iterable<String> _pathsWithAllowedDartExternalUsage = <String>[
150118
'_foreign_helper', // for foreign helpers
@@ -173,7 +141,7 @@ class JsInteropChecks extends RecursiveVisitor {
173141
this._reporter,
174142
this._nativeClasses, {
175143
this.isDart2Wasm = false,
176-
bool enableExperimentalFfi = false,
144+
this.enableExperimentalFfi = false,
177145
}) : exportChecker = ExportChecker(_reporter, _coreTypes.objectClass),
178146
_functionToJSTarget = _coreTypes.index.getTopLevelProcedure(
179147
'dart:js_interop',
@@ -185,11 +153,7 @@ class JsInteropChecks extends RecursiveVisitor {
185153
),
186154
_staticTypeContext = StatefulStaticTypeContext.stacked(
187155
TypeEnvironment(_coreTypes, hierarchy),
188-
),
189-
_disallowedInteropLibrariesInDart2Wasm = [
190-
for (final entry in _disallowedInteropLibrariesInDart2WasmByDefault)
191-
if (!(entry == 'dart:ffi' && enableExperimentalFfi)) entry,
192-
] {
156+
) {
193157
extensionIndex = ExtensionIndex(
194158
_coreTypes,
195159
_staticTypeContext.typeEnvironment,
@@ -625,34 +589,24 @@ class JsInteropChecks extends RecursiveVisitor {
625589
/// Check that [node] doesn't depend on any disallowed interop libraries in
626590
/// dart2wasm.
627591
///
628-
/// We allowlist `dart:*` libraries, select packages, and test patterns.
592+
/// We allowlist `dart:*` libraries and select packages.
629593
void _checkDisallowedLibrariesForDart2Wasm(Library node) {
630594
final uri = node.importUri;
631595
for (final dependency in node.dependencies) {
632596
final dependencyUriString = dependency.targetLibrary.importUri.toString();
633-
if (_disallowedInteropLibrariesInDart2Wasm.contains(
634-
dependencyUriString,
635-
)) {
597+
if (!enableExperimentalFfi && dependencyUriString == 'dart:ffi') {
636598
// TODO(srujzs): While we allow these imports for all `dart:*`
637599
// libraries, we may want to restrict this further, as it may include
638600
// `dart:ui`.
639601
final allowedToImport =
640602
uri.isScheme('dart') ||
641-
(uri.isScheme('package') &&
642-
allowedInteropLibrariesInDart2WasmPackages.any(
643-
(pkg) => uri.pathSegments.first == pkg,
644-
)) ||
645-
_allowedUseOfDart2WasmDisallowedInteropLibrariesTestPatterns.any(
646-
(pattern) => uri.path.contains(pattern),
647-
);
603+
uri.isScheme('package') &&
604+
allowedInteropLibrariesInDart2WasmPackages.contains(
605+
uri.pathSegments.first,
606+
);
648607
if (allowedToImport) return;
649-
final message = dependencyUriString == 'dart:ffi'
650-
? codeDartFfiLibraryInDart2Wasm
651-
: codeJsInteropDisallowedInteropLibraryInDart2Wasm.withArgumentsOld(
652-
dependencyUriString,
653-
);
654608
_reporter.report(
655-
message,
609+
codeDartFfiLibraryInDart2Wasm,
656610
dependency.fileOffset,
657611
dependencyUriString.length,
658612
node.fileUri,
@@ -683,9 +637,7 @@ class JsInteropChecks extends RecursiveVisitor {
683637
bool _isAllowedTrustTypesUsage(Class cls) {
684638
final uri = cls.enclosingLibrary.importUri;
685639
return uri.isScheme('dart') && uri.path == 'ui' ||
686-
_allowedTrustTypesTestPatterns.any(
687-
(pattern) => uri.path.contains(pattern),
688-
);
640+
_allowedTrustTypesTestPatterns.any(uri.path.contains);
689641
}
690642

691643
/// Check that JS interop class [node], that only has an @JS annotation, is
@@ -731,7 +683,7 @@ class JsInteropChecks extends RecursiveVisitor {
731683
final uri = member.enclosingLibrary.importUri;
732684
return uri.isScheme('dart') &&
733685
_pathsWithAllowedDartExternalUsage.contains(uri.path) ||
734-
_allowedNativeTestPatterns.any((pattern) => uri.path.contains(pattern));
686+
_allowedNativeTestPatterns.any(uri.path.contains);
735687
}
736688

737689
/// Assumes given [member] is not JS interop, and reports an error if

pkg/_js_interop_checks/lib/src/transformations/shared_interop_transformer.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import 'js_util_optimizer.dart';
2525
import 'static_interop_mock_validator.dart';
2626

2727
class SharedInteropTransformer extends Transformer {
28+
final bool _supportsJsUtil;
29+
2830
final Procedure _callMethodVarArgs;
29-
final Procedure _createDartExport;
3031
final Procedure _createJSInteropWrapper;
31-
final Procedure _createStaticInteropMock;
3232
final JsInteropDiagnosticReporter _diagnosticReporter;
3333
final ExportChecker _exportChecker;
3434
final ExtensionIndex _extensionIndex;
@@ -60,19 +60,16 @@ class SharedInteropTransformer extends Transformer {
6060
this._diagnosticReporter,
6161
this._exportChecker,
6262
this._extensionIndex,
63-
) : _callMethodVarArgs = _typeEnvironment.coreTypes.index
63+
) : _supportsJsUtil = _typeEnvironment.coreTypes.index.containsLibrary(
64+
'dart:js_util',
65+
),
66+
_callMethodVarArgs = _typeEnvironment.coreTypes.index
6467
.getTopLevelProcedure(
6568
'dart:js_interop_unsafe',
6669
'JSObjectUnsafeUtilExtension|callMethodVarArgs',
6770
),
68-
_createDartExport = _typeEnvironment.coreTypes.index.getTopLevelProcedure(
69-
'dart:js_util',
70-
'createDartExport',
71-
),
7271
_createJSInteropWrapper = _typeEnvironment.coreTypes.index
7372
.getTopLevelProcedure('dart:js_interop', 'createJSInteropWrapper'),
74-
_createStaticInteropMock = _typeEnvironment.coreTypes.index
75-
.getTopLevelProcedure('dart:js_util', 'createStaticInteropMock'),
7673
_functionToJS = _typeEnvironment.coreTypes.index.getTopLevelProcedure(
7774
'dart:js_interop',
7875
'FunctionToJSExportedDartFunction|get#toJS',
@@ -133,12 +130,19 @@ class SharedInteropTransformer extends Transformer {
133130
'JSAnyUtilityExtension|typeofEquals',
134131
);
135132

133+
late final Procedure _createDartExport = _typeEnvironment.coreTypes.index
134+
.getTopLevelProcedure('dart:js_util', 'createDartExport');
135+
late final Procedure _createStaticInteropMock = _typeEnvironment
136+
.coreTypes
137+
.index
138+
.getTopLevelProcedure('dart:js_util', 'createStaticInteropMock');
139+
136140
@override
137141
TreeNode visitStaticInvocation(StaticInvocation node) {
138142
_invocation = node;
139143
TreeNode replacement = invocation;
140144
final target = invocation.target;
141-
if (target == _createDartExport) {
145+
if (_supportsJsUtil && target == _createDartExport) {
142146
final typeArguments = invocation.arguments.types;
143147
assert(typeArguments.length == 1);
144148
if (_verifyExportable(typeArguments[0])) {
@@ -158,7 +162,7 @@ class SharedInteropTransformer extends Transformer {
158162
arguments.length == 2 ? arguments[1] : null,
159163
);
160164
}
161-
} else if (target == _createStaticInteropMock) {
165+
} else if (_supportsJsUtil && target == _createStaticInteropMock) {
162166
final typeArguments = invocation.arguments.types;
163167
assert(typeArguments.length == 2);
164168
final staticInteropType = typeArguments[0];

pkg/dart2wasm/lib/js/callback_specializer.dart

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -277,65 +277,6 @@ class CallbackSpecializer {
277277
return (dartProcedure, functionTrampoline);
278278
}
279279

280-
/// Lowers an invocation of `allowInterop<type>(foo)` to:
281-
///
282-
/// let #var = foo in
283-
/// _isDartFunctionWrapped<type>(#var) ?
284-
/// #var :
285-
/// _wrapDartFunction<type>(#var, jsWrapperFunction(#var));
286-
///
287-
/// The use of two functions here is necessary because we do not allow
288-
/// `WasmExternRef` to be an argument or return type for a tear off.
289-
///
290-
/// Note: _wrapDartFunction tracks wrapped Dart functions in a map. When
291-
/// these Dart functions flow to JS, they are replaced by their wrappers. If
292-
/// the wrapper should ever flow back into Dart then it will be replaced by
293-
/// the original Dart function.
294-
// TODO(srujzs): It looks like there's no more code that references this
295-
// function anymore in dart2wasm. Should we delete this lowering and related
296-
// code?
297-
Expression allowInterop(StaticInvocation staticInvocation) {
298-
final argument = staticInvocation.arguments.positional.single;
299-
final type = argument.getStaticType(_staticTypeContext) as FunctionType;
300-
final (jsWrapperFunction, exportedFunction) = _getJSWrapperFunction(
301-
staticInvocation.target, type,
302-
boxExternRef: false, needsCastClosure: false, captureThis: false);
303-
final v = VariableDeclaration('#var',
304-
initializer: argument, type: type, isSynthesized: true);
305-
return Let(
306-
v,
307-
ConditionalExpression(
308-
StaticInvocation(_util.isDartFunctionWrappedTarget,
309-
Arguments([VariableGet(v)], types: [type])),
310-
VariableGet(v),
311-
StaticInvocation(
312-
_util.wrapDartFunctionTarget,
313-
Arguments([
314-
VariableGet(v),
315-
BlockExpression(
316-
Block([
317-
// This ensures TFA will retain the function which the
318-
// JS code will call. The backend in return will export
319-
// the function due to `@pragma('wasm:weak-export', ...)`
320-
ExpressionStatement(StaticInvocation(
321-
_util.exportWasmFunctionTarget,
322-
Arguments([
323-
ConstantExpression(
324-
StaticTearOffConstant(exportedFunction))
325-
])))
326-
]),
327-
StaticInvocation(
328-
jsWrapperFunction,
329-
Arguments([
330-
StaticInvocation(_util.jsObjectFromDartObjectTarget,
331-
Arguments([VariableGet(v)]))
332-
]))),
333-
], types: [
334-
type
335-
])),
336-
type));
337-
}
338-
339280
Expression _createJSValue(Expression value) =>
340281
StaticInvocation(_util.jsValueBoxTarget, Arguments([value]));
341282

pkg/dart2wasm/lib/js/interop_transformer.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ class InteropTransformer extends Transformer {
7575
Expression visitStaticInvocation(StaticInvocation node) {
7676
node = super.visitStaticInvocation(node) as StaticInvocation;
7777
Procedure target = node.target;
78-
if (target == _util.allowInteropTarget) {
79-
return _callbackSpecializer.allowInterop(node);
80-
} else if (target == _util.functionToJSTarget) {
78+
if (target == _util.functionToJSTarget) {
8179
return _callbackSpecializer.functionToJS(node);
8280
} else if (target == _util.functionToJSCaptureThisTarget) {
8381
return _callbackSpecializer.functionToJS(node, captureThis: true);

pkg/dart2wasm/lib/js/runtime_generator.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ class RuntimeFinalizer {
161161
JSMethods performJSInteropTransformations(List<Library> libraries,
162162
CoreTypes coreTypes, ClassHierarchy classHierarchy) {
163163
Set<Library> transitiveImportingJSInterop = {
164-
...calculateTransitiveImportsOfJsInteropIfUsed(
165-
libraries, Uri.parse("package:js/js.dart")),
166-
...calculateTransitiveImportsOfJsInteropIfUsed(
167-
libraries, Uri.parse("dart:_js_annotations")),
168164
...calculateTransitiveImportsOfJsInteropIfUsed(
169165
libraries, Uri.parse("dart:_js_helper")),
170166
...calculateTransitiveImportsOfJsInteropIfUsed(

pkg/dart2wasm/lib/js/util.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ enum AnnotationType { import, export, weakExport }
1414
class CoreTypesUtil {
1515
final ExtensionIndex extensionIndex;
1616
final CoreTypes coreTypes;
17-
final Procedure allowInteropTarget;
1817
final Procedure dartifyRawTarget;
1918
final Procedure functionToJSTarget;
2019
final Procedure functionToJSCaptureThisTarget;
@@ -168,9 +167,7 @@ class CoreTypesUtil {
168167
};
169168

170169
CoreTypesUtil(this.coreTypes, this.extensionIndex)
171-
: allowInteropTarget = coreTypes.index
172-
.getTopLevelProcedure('dart:js_util', 'allowInterop'),
173-
dartifyRawTarget = coreTypes.index
170+
: dartifyRawTarget = coreTypes.index
174171
.getTopLevelProcedure('dart:_js_helper', 'dartifyRaw'),
175172
functionToJSTarget = coreTypes.index.getTopLevelProcedure(
176173
'dart:js_interop', 'FunctionToJSExportedDartFunction|get#toJS'),

pkg/dart2wasm/lib/target.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ class WasmTarget extends Target {
160160
'dart:io',
161161
'dart:js_interop',
162162
'dart:js_interop_unsafe',
163-
'dart:js_util',
164163
'dart:nativewrappers',
165164
'dart:typed_data',
166165
];
@@ -180,7 +179,6 @@ class WasmTarget extends Target {
180179
'dart:collection',
181180
'dart:js_interop',
182181
'dart:js_interop_unsafe',
183-
'dart:js_util',
184182
'dart:typed_data',
185183
];
186184

@@ -205,9 +203,6 @@ class WasmTarget extends Target {
205203
// Flutter's dart:ui is also package:ui (in test mode)
206204
if (importerString.startsWith('package:ui/')) return true;
207205

208-
// package:js can import dart:js_util & dart:_js_*
209-
if (importerString.startsWith('package:js/')) return true;
210-
211206
return false;
212207
}
213208

@@ -283,10 +278,6 @@ class WasmTarget extends Target {
283278
}
284279

285280
Set<Library> transitiveImportingJSInterop = {
286-
...jsInteropHelper.calculateTransitiveImportsOfJsInteropIfUsed(
287-
component.libraries, Uri.parse("package:js/js.dart")),
288-
...jsInteropHelper.calculateTransitiveImportsOfJsInteropIfUsed(
289-
component.libraries, Uri.parse("dart:_js_annotations")),
290281
...jsInteropHelper.calculateTransitiveImportsOfJsInteropIfUsed(
291282
component.libraries, Uri.parse("dart:js_interop")),
292283
...jsInteropHelper.calculateTransitiveImportsOfJsInteropIfUsed(
@@ -589,7 +580,7 @@ void _checkWasmImportExportPragmas(List<Library> libraries, CoreTypes coreTypes,
589580
if (importUri.isScheme('dart') ||
590581
(importUri.isScheme('package') &&
591582
JsInteropChecks.allowedInteropLibrariesInDart2WasmPackages
592-
.any((pkg) => importUri.pathSegments.first == pkg))) {
583+
.contains(importUri.pathSegments.first))) {
593584
continue;
594585
}
595586

pkg/dart2wasm/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ dependencies:
2424
# Use 'any' constraints here; we get our versions from the DEPS file.
2525
dev_dependencies:
2626
expect: any
27-
js: any
2827
lints: any

pkg/dart2wasm/test/dry_run/testcases/import_package_js.dart

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)