From 9fa160b706598d71f0449c58d13f8d3111773a70 Mon Sep 17 00:00:00 2001 From: Jackson Gardner Date: Mon, 3 Jun 2024 17:28:36 +0000 Subject: [PATCH] Revert "[dart2wasm] Check import/export pragmas in user code" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 35bc17a0fa3a347089dfcd7a1c4f781b37c32db7. 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 > Reviewed-by: Martin Kustermann Change-Id: Iba57910e7492abb7371172ecdb4fc2cc18fed66e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369500 Reviewed-by: Siva Annamalai Bot-Commit: Rubber Stamper Commit-Queue: Jackson Gardner --- .../lib/src/messages/codes_generated.dart | 11 ---- pkg/dart2wasm/lib/target.dart | 53 +------------------ pkg/front_end/messages.status | 2 - pkg/front_end/messages.yaml | 3 -- .../test/spell_checking_list_messages.txt | 3 -- .../reject_import_export_pragmas_test.dart | 16 ------ 6 files changed, 1 insertion(+), 87 deletions(-) delete mode 100644 tests/web/wasm/reject_import_export_pragmas_test.dart 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 268a8e113f1..5654df8a14f 100644 --- a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart +++ b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart @@ -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 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 codeWeakReferenceMismatchReturnAndArgumentTypes = messageWeakReferenceMismatchReturnAndArgumentTypes; diff --git a/pkg/dart2wasm/lib/target.dart b/pkg/dart2wasm/lib/target.dart index 9ddd59b3fcf..5e45646617d 100644 --- a/pkg/dart2wasm/lib/target.dart +++ b/pkg/dart2wasm/lib/target.dart @@ -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); - Set 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 libraries, CoreTypes coreTypes, - DiagnosticReporter 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, - ); - } - } - } - } - } - } -} diff --git a/pkg/front_end/messages.status b/pkg/front_end/messages.status index 32ac127953e..0fc61fd51f2 100644 --- a/pkg/front_end/messages.status +++ b/pkg/front_end/messages.status @@ -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 diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml index e96affc7587..d5d7dfe297e 100644 --- a/pkg/front_end/messages.yaml +++ b/pkg/front_end/messages.yaml @@ -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." diff --git a/pkg/front_end/test/spell_checking_list_messages.txt b/pkg/front_end/test/spell_checking_list_messages.txt index a6f6b3f70b6..92d541053c6 100644 --- a/pkg/front_end/test/spell_checking_list_messages.txt +++ b/pkg/front_end/test/spell_checking_list_messages.txt @@ -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 diff --git a/tests/web/wasm/reject_import_export_pragmas_test.dart b/tests/web/wasm/reject_import_export_pragmas_test.dart deleted file mode 100644 index edf4cf166dc..00000000000 --- a/tests/web/wasm/reject_import_export_pragmas_test.dart +++ /dev/null @@ -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() {}