Skip to content

Commit

Permalink
[stable] [dart2wasm] Check dart:ffi imports and wasm:import/export pr…
Browse files Browse the repository at this point in the history
…agmas in user code

- Disallow importing `dart:ffi` in user code.
- Disallow `wasm:import` and `wasm:export` pragmas in user code.

Bug: #53910

Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/369040
Cherry-pick-request: #55890
Change-Id: Ifaaeb4f2c4b13bd5f564ffbf5281d6439ac6dd56
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369040
Reviewed-by: Alexander Thomas <[email protected]>
Reviewed-by: Martin Kustermann <[email protected]>
Commit-Queue: Martin Kustermann <[email protected]>
  • Loading branch information
mkustermann authored and Commit Queue committed Jun 4, 2024
1 parent dc9ede5 commit 4079c8d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2742,6 +2742,16 @@ Message _withArgumentsCyclicTypedef(String name) {
);
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> 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<Message Function(String name, String string)>
templateDebugTrace =
Expand Down
16 changes: 9 additions & 7 deletions pkg/_js_interop_checks/lib/js_interop_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
show
Message,
LocatedMessage,
messageDartFfiLibraryInDart2Wasm,
messageJsInteropDartJsInteropAnnotationForStaticInteropOnly,
messageJsInteropEnclosingClassJSAnnotation,
messageJsInteropEnclosingClassJSAnnotationContext,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/front_end/messages.status
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/front_end/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

0 comments on commit 4079c8d

Please sign in to comment.