diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c316d8f8c40..12122532d11e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,16 @@ This is a patch release that: - Fixes an issue in dart2wasm compiler that can result in incorrect nullability of type parameter (see [#55741]) +- Disallows `dart:ffi` imports in user code in dart2wasm (e.g. issue [#53910]) as + dart2wasm's currently only supports a small subset of `dart:ffi` (tracking + issue [#46690]). + [#55767]: https://github.com/dart-lang/sdk/issues/55767 [#55872]: https://github.com/dart-lang/sdk/issues/55872 [#55876]: https://github.com/dart-lang/sdk/issues/55876 [#55741]: https://github.com/dart-lang/sdk/issues/55741 +[#55733]: https://github.com/dart-lang/sdk/issues/53910 +[#46690]: https://github.com/dart-lang/sdk/issues/46690 ## 3.4.2 - 2024-05-29 diff --git a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart index 0bbd8926aa22..5ba5d9296b3d 100644 --- a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart +++ b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart @@ -2742,6 +2742,16 @@ Message _withArgumentsCyclicTypedef(String name) { ); } +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const Code codeDartFfiLibraryInDart2Wasm = + messageDartFfiLibraryInDart2Wasm; + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const MessageCode messageDartFfiLibraryInDart2Wasm = const MessageCode( + "DartFfiLibraryInDart2Wasm", + problemMessage: r"""'dart:ffi' can't be imported when compiling to Wasm.""", +); + // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. const Template templateDebugTrace = diff --git a/pkg/_js_interop_checks/lib/js_interop_checks.dart b/pkg/_js_interop_checks/lib/js_interop_checks.dart index 02151ef99246..4cbd3363659d 100644 --- a/pkg/_js_interop_checks/lib/js_interop_checks.dart +++ b/pkg/_js_interop_checks/lib/js_interop_checks.dart @@ -8,6 +8,7 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart' show Message, LocatedMessage, + messageDartFfiLibraryInDart2Wasm, messageJsInteropDartJsInteropAnnotationForStaticInteropOnly, messageJsInteropEnclosingClassJSAnnotation, messageJsInteropEnclosingClassJSAnnotationContext, @@ -134,7 +135,8 @@ class JsInteropChecks extends RecursiveVisitor { 'package:js/js.dart', 'package:js/js_util.dart', 'dart:js_util', - 'dart:js' + 'dart:js', + 'dart:ffi', ]; /// Libraries that use `external` to exclude from checks on external. @@ -550,12 +552,12 @@ class JsInteropChecks extends RecursiveVisitor { _allowedUseOfDart2WasmDisallowedInteropLibrariesTestPatterns .any((pattern) => uri.path.contains(pattern)); if (allowedToImport) return; - _reporter.report( - templateJsInteropDisallowedInteropLibraryInDart2Wasm - .withArguments(dependencyUriString), - dependency.fileOffset, - dependencyUriString.length, - node.fileUri); + final message = dependencyUriString == 'dart:ffi' + ? messageDartFfiLibraryInDart2Wasm + : templateJsInteropDisallowedInteropLibraryInDart2Wasm + .withArguments(dependencyUriString); + _reporter.report(message, dependency.fileOffset, + dependencyUriString.length, node.fileUri); } } } diff --git a/pkg/front_end/messages.status b/pkg/front_end/messages.status index 4cb0eccf3bae..095ca6af6aba 100644 --- a/pkg/front_end/messages.status +++ b/pkg/front_end/messages.status @@ -188,6 +188,8 @@ CyclicRedirectingFactoryConstructors/part_wrapped_script: Fail # Error is report CyclicRedirectingFactoryConstructors/script: Fail # Error is reported for each factory involved in the cycle. CyclicRepresentationDependency/analyzerCode: Fail CyclicTypedef/example: Fail +DartFfiLibraryInDart2Wasm/analyzerCode: Fail +DartFfiLibraryInDart2Wasm/example: Fail DeferredAfterPrefix/example: Fail DeferredExtensionImport/analyzerCode: Fail DeferredExtensionImport/part_wrapped_script: Fail diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml index 98df5912b784..6c70c9a8d040 100644 --- a/pkg/front_end/messages.yaml +++ b/pkg/front_end/messages.yaml @@ -7528,3 +7528,6 @@ NoMacroApplicationTarget: MacroDefinitionApplicationSameLibraryCycle: problemMessage: "The macro '#name' can't be applied in the same library cycle where it is defined." correctionMessage: Try moving it to a different library that does not import the one where it is applied. + +DartFfiLibraryInDart2Wasm: + problemMessage: "'dart:ffi' can't be imported when compiling to Wasm." diff --git a/tests/lib/js/static_interop_test/disallowed_interop_libraries_test.dart b/tests/lib/js/static_interop_test/disallowed_interop_libraries_test.dart index 37cb8bc4e8f5..a8f6c4b9f54c 100644 --- a/tests/lib/js/static_interop_test/disallowed_interop_libraries_test.dart +++ b/tests/lib/js/static_interop_test/disallowed_interop_libraries_test.dart @@ -20,4 +20,8 @@ // ^ // [web] JS interop library 'package:js/js_util.dart' can't be imported when compiling to Wasm. +/**/ import 'dart:ffi'; +// ^ +// [web] 'dart:ffi' can't be imported when compiling to Wasm. + void main() {}