Revert "[dart2wasm] Check import/export pragmas in user code"

This reverts commit 35bc17a0fa.

Reason for revert: Breaking flutter web engine unit tests: https://github.com/flutter/flutter/issues/149600

Original change's description:
> [dart2wasm] Check import/export pragmas in user code
>
> Change-Id: I926d108a4571d685c67d3a174a8e506910cce8f7
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369020
> Commit-Queue: Ömer Ağacan <omersa@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

Change-Id: Iba57910e7492abb7371172ecdb4fc2cc18fed66e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369500
Reviewed-by: Siva Annamalai <asiva@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Jackson Gardner <jacksongardner@google.com>
This commit is contained in:
Jackson Gardner 2024-06-03 17:28:36 +00:00 committed by Commit Queue
parent 030b79dc1c
commit 9fa160b706
6 changed files with 1 additions and 87 deletions

View file

@ -17641,17 +17641,6 @@ const MessageCode messageVoidWithTypeArguments = const MessageCode(
correctionMessage: r"""Try removing the type arguments.""",
);
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeWasmImportOrExportInUserCode =
messageWasmImportOrExportInUserCode;
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageWasmImportOrExportInUserCode = const MessageCode(
"WasmImportOrExportInUserCode",
problemMessage:
r"""Pragmas `wasm:import` and `wasm:export` are for internal use only and cannot be used by user code.""",
);
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeWeakReferenceMismatchReturnAndArgumentTypes =
messageWeakReferenceMismatchReturnAndArgumentTypes;

View file

@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:_fe_analyzer_shared/src/messages/codes.dart'
show Message, LocatedMessage, messageWasmImportOrExportInUserCode;
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/shared_interop_transformer.dart';
@ -243,11 +243,6 @@ class WasmTarget extends Target {
ReferenceFromIndex? referenceFromIndex,
{void Function(String msg)? logger,
ChangedStructureNotifier? changedStructureNotifier}) {
// Check `wasm:import` and `wasm:export` pragmas before FFI transforms as
// FFI transforms convert JS interop annotations to these pragmas.
_checkWasmImportExportPragmas(libraries, coreTypes,
diagnosticReporter as DiagnosticReporter<Message, LocatedMessage>);
Set<Library> transitiveImportingJSInterop = {
...jsInteropHelper.calculateTransitiveImportsOfJsInteropIfUsed(
component, Uri.parse("package:js/js.dart")),
@ -523,49 +518,3 @@ class WasmVerification extends Verification {
return false;
}
}
final _dartCoreUri = Uri.parse('dart:core');
/// Check that `wasm:import` and `wasm:export` pragmas are only used in `dart:`
/// libraries and in tests, with the exception of
/// `reject_import_export_pragmas` test.
void _checkWasmImportExportPragmas(List<Library> libraries, CoreTypes coreTypes,
DiagnosticReporter<Message, LocatedMessage> diagnosticReporter) {
for (Library library in libraries) {
final importUri = library.importUri;
if (importUri.isScheme('dart') ||
(importUri.path.contains('tests/web/wasm') &&
!importUri.path.contains('reject_import_export_pragmas'))) {
continue;
}
for (Member member in library.members) {
for (Expression annotation in member.annotations) {
if (annotation is! ConstantExpression) {
continue;
}
final annotationConstant = annotation.constant;
if (annotationConstant is! InstanceConstant) {
continue;
}
final cls = annotationConstant.classNode;
if (cls.name == 'pragma' &&
cls.enclosingLibrary.importUri == _dartCoreUri) {
final pragmaName = annotationConstant
.fieldValues[coreTypes.pragmaName.fieldReference];
if (pragmaName is StringConstant) {
if (pragmaName.value == 'wasm:import' ||
pragmaName.value == 'wasm:export') {
diagnosticReporter.report(
messageWasmImportOrExportInUserCode,
annotation.fileOffset,
0,
library.fileUri,
);
}
}
}
}
}
}
}

View file

@ -1115,8 +1115,6 @@ VarAsTypeName/part_wrapped_script1: Fail
VarAsTypeName/script1: Fail # Too many problems
VariableCouldBeNullDueToWrite/analyzerCode: Fail
VariableCouldBeNullDueToWrite/example: Fail
WasmImportOrExportInUserCode/analyzerCode: Fail
WasmImportOrExportInUserCode/example: Fail
WeakReferenceMismatchReturnAndArgumentTypes/analyzerCode: Fail
WeakReferenceMismatchReturnAndArgumentTypes/example: Fail
WeakReferenceNotOneArgument/analyzerCode: Fail

View file

@ -7011,9 +7011,6 @@ ResourceIdentifiersNotStatic:
ResourceIdentifiersMultiple:
problemMessage: "Only one resource identifier pragma can be used at a time."
WasmImportOrExportInUserCode:
problemMessage: "Pragmas `wasm:import` and `wasm:export` are for internal use only and cannot be used by user code."
WeakReferenceNotStatic:
problemMessage: "Weak reference pragma can be used on a static method only."

View file

@ -114,7 +114,6 @@ placing
pointer`s
pragma
pragma('vm:deeply
pragmas
preexisting
pubspec.yaml
r
@ -150,6 +149,4 @@ u
unavailable
unsound
v
wasm:export
wasm:import
x

View file

@ -1,16 +0,0 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// 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.
// Test that importing `dart:ffi` and using `wasm:import` and export pragmas
// are not allowed.
import 'dart:ffi'; //# 01: compile-time error
@pragma('wasm:export', 'f') //# 02: compile-time error
void f() {}
@pragma('wasm:import', 'g') //# 03: compile-time error
external double g(double x);
void main() {}