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 c3f149849f7..89e02067682 100644 --- a/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart +++ b/pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart @@ -5115,7 +5115,7 @@ const Code codeFfiNativeMustBeExternal = messageFfiNativeMustBeExternal; // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. const MessageCode messageFfiNativeMustBeExternal = const MessageCode( "FfiNativeMustBeExternal", - problemMessage: r"""FfiNative functions must be marked external."""); + problemMessage: r"""Native functions must be marked external."""); // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. const Code codeFfiNativeOnlyNativeFieldWrapperClassCanBePointer = @@ -5133,7 +5133,7 @@ const Template const Template( "FfiNativeUnexpectedNumberOfParameters", problemMessageTemplate: - r"""Unexpected number of FfiNative annotation parameters. Expected #count but has #count2.""", + r"""Unexpected number of Native annotation parameters. Expected #count but has #count2.""", withArguments: _withArgumentsFfiNativeUnexpectedNumberOfParameters); // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. @@ -5148,7 +5148,7 @@ Message _withArgumentsFfiNativeUnexpectedNumberOfParameters( int count, int count2) { return new Message(codeFfiNativeUnexpectedNumberOfParameters, problemMessage: - """Unexpected number of FfiNative annotation parameters. Expected ${count} but has ${count2}.""", + """Unexpected number of Native annotation parameters. Expected ${count} but has ${count2}.""", arguments: {'count': count, 'count2': count2}); } @@ -5158,7 +5158,7 @@ const Template const Template( "FfiNativeUnexpectedNumberOfParametersWithReceiver", problemMessageTemplate: - r"""Unexpected number of FfiNative annotation parameters. Expected #count but has #count2. FfiNative instance method annotation must have receiver as first argument.""", + r"""Unexpected number of Native annotation parameters. Expected #count but has #count2. Native instance method annotation must have receiver as first argument.""", withArguments: _withArgumentsFfiNativeUnexpectedNumberOfParametersWithReceiver); @@ -5174,7 +5174,7 @@ Message _withArgumentsFfiNativeUnexpectedNumberOfParametersWithReceiver( int count, int count2) { return new Message(codeFfiNativeUnexpectedNumberOfParametersWithReceiver, problemMessage: - """Unexpected number of FfiNative annotation parameters. Expected ${count} but has ${count2}. FfiNative instance method annotation must have receiver as first argument.""", + """Unexpected number of Native annotation parameters. Expected ${count} but has ${count2}. Native instance method annotation must have receiver as first argument.""", arguments: {'count': count, 'count2': count2}); } diff --git a/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart b/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart index cf14145c5bf..0eee51c4f27 100644 --- a/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart +++ b/pkg/analyzer/lib/src/dart/error/ffi_code.g.dart @@ -133,7 +133,7 @@ class FfiCode extends AnalyzerErrorCode { /// No parameters. static const FfiCode FFI_NATIVE_MUST_BE_EXTERNAL = FfiCode( 'FFI_NATIVE_MUST_BE_EXTERNAL', - "FfiNative functions must be declared external.", + "Native functions must be declared external.", correctionMessage: "Add the `external` keyword to the function.", ); @@ -151,8 +151,8 @@ class FfiCode extends AnalyzerErrorCode { /// 1: the actual number of parameters static const FfiCode FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS = FfiCode( 'FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS', - "Unexpected number of FfiNative annotation parameters. Expected {0} but " - "has {1}.", + "Unexpected number of Native annotation parameters. Expected {0} but has " + "{1}.", correctionMessage: "Make sure parameters match the function annotated.", ); @@ -162,9 +162,9 @@ class FfiCode extends AnalyzerErrorCode { static const FfiCode FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS_WITH_RECEIVER = FfiCode( 'FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS_WITH_RECEIVER', - "Unexpected number of FfiNative annotation parameters. Expected {0} but " - "has {1}. FfiNative instance method annotation must have receiver as " - "first argument.", + "Unexpected number of Native annotation parameters. Expected {0} but has " + "{1}. Native instance method annotation must have receiver as first " + "argument.", correctionMessage: "Make sure parameters match the function annotated, including an extra " "first parameter for the receiver.", diff --git a/pkg/analyzer/lib/src/generated/ffi_verifier.dart b/pkg/analyzer/lib/src/generated/ffi_verifier.dart index 54107adaa85..3f9cc622b2a 100644 --- a/pkg/analyzer/lib/src/generated/ffi_verifier.dart +++ b/pkg/analyzer/lib/src/generated/ffi_verifier.dart @@ -346,7 +346,7 @@ class FfiVerifier extends RecursiveAstVisitor { declarationElement is PropertyAccessorElementImpl) && !declarationElement.isStatic) { // Instance methods must have the receiver as an extra parameter in the - // FfiNative annotation. + // Native annotation. if (formalParameters.length + 1 != ffiParameterTypes.length) { _errorReporter.reportErrorForNode( FfiCode.FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS_WITH_RECEIVER, @@ -370,7 +370,7 @@ class FfiVerifier extends RecursiveAstVisitor { ffiParameterTypes = ffiParameterTypes.sublist(1); ffiParameters = ffiParameters.sublist(1); } else { - // Number of parameters in the FfiNative annotation must match the + // Number of parameters in the Native annotation must match the // annotated declaration. if (formalParameters.length != ffiParameterTypes.length) { _errorReporter.reportErrorForNode( diff --git a/pkg/analyzer/lib/src/test_utilities/mock_sdk.dart b/pkg/analyzer/lib/src/test_utilities/mock_sdk.dart index 61ca8dd4d6e..a158abcf7d7 100644 --- a/pkg/analyzer/lib/src/test_utilities/mock_sdk.dart +++ b/pkg/analyzer/lib/src/test_utilities/mock_sdk.dart @@ -864,12 +864,6 @@ extension StructPointer on Pointer { external T operator [](int index); } -final class FfiNative { - final String nativeName; - final bool isLeaf; - const FfiNative(this.nativeName, {this.isLeaf = false}); -} - @Since('2.19') final class Native { final String? symbol; diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml index f0c4a9ca902..1b8af4543f9 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml @@ -18455,7 +18455,7 @@ FfiCode: } ``` FFI_NATIVE_MUST_BE_EXTERNAL: - problemMessage: FfiNative functions must be declared external. + problemMessage: Native functions must be declared external. correctionMessage: Add the `external` keyword to the function. comment: No parameters. FFI_NATIVE_ONLY_CLASSES_EXTENDING_NATIVEFIELDWRAPPERCLASS1_CAN_BE_POINTER: @@ -18463,14 +18463,14 @@ FfiCode: correctionMessage: Pass as Handle instead. comment: No parameters. FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS: - problemMessage: Unexpected number of FfiNative annotation parameters. Expected {0} but has {1}. + problemMessage: Unexpected number of Native annotation parameters. Expected {0} but has {1}. correctionMessage: Make sure parameters match the function annotated. comment: |- Parameters: 0: the expected number of parameters 1: the actual number of parameters FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS_WITH_RECEIVER: - problemMessage: Unexpected number of FfiNative annotation parameters. Expected {0} but has {1}. FfiNative instance method annotation must have receiver as first argument. + problemMessage: Unexpected number of Native annotation parameters. Expected {0} but has {1}. Native instance method annotation must have receiver as first argument. correctionMessage: Make sure parameters match the function annotated, including an extra first parameter for the receiver. comment: |- Parameters: @@ -18750,7 +18750,7 @@ FfiCode: returned would have a return type of `Handle`. The analyzer also produces this diagnostic when the value of the `isLeaf` - argument in an `FfiNative` annotation is `true` and the type argument on + argument in an `Native` annotation is `true` and the type argument on the annotation is a function type whose return type is `Handle`. In all of these cases, leaf calls are only supported for the types `bool`, diff --git a/pkg/analyzer/test/src/diagnostics/ffi_leaf_call_must_not_use_handle_test.dart b/pkg/analyzer/test/src/diagnostics/ffi_leaf_call_must_not_use_handle_test.dart index 1420d127647..46909a030ae 100644 --- a/pkg/analyzer/test/src/diagnostics/ffi_leaf_call_must_not_use_handle_test.dart +++ b/pkg/analyzer/test/src/diagnostics/ffi_leaf_call_must_not_use_handle_test.dart @@ -53,11 +53,11 @@ import 'dart:ffi'; base class NativeFieldWrapperClass1 {} base class A extends NativeFieldWrapperClass1 { - @FfiNative)>('foo', isLeaf:true) + @Native)>(symbol: 'foo', isLeaf:true) external Object get foo; } ''', [ - error(FfiCode.LEAF_CALL_MUST_NOT_RETURN_HANDLE, 110, 89), + error(FfiCode.LEAF_CALL_MUST_NOT_RETURN_HANDLE, 110, 94), ]); } @@ -94,10 +94,10 @@ doThings() { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('foo', isLeaf:true) +@Native(symbol: 'foo', isLeaf:true) external Object get foo; ''', [ - error(FfiCode.LEAF_CALL_MUST_NOT_RETURN_HANDLE, 20, 74), + error(FfiCode.LEAF_CALL_MUST_NOT_RETURN_HANDLE, 20, 79), ]); } } diff --git a/pkg/analyzer/test/src/diagnostics/ffi_native_test.dart b/pkg/analyzer/test/src/diagnostics/ffi_native_test.dart index 02ec07f8eb2..6b9b5545feb 100644 --- a/pkg/analyzer/test/src/diagnostics/ffi_native_test.dart +++ b/pkg/analyzer/test/src/diagnostics/ffi_native_test.dart @@ -24,10 +24,10 @@ import 'dart:ffi'; base class NativeFieldWrapperClass1 {} base class Paragraph extends NativeFieldWrapperClass1 { - @FfiNative)>('Paragraph::ideographicBaseline', isLeaf: true) + @Native)>(symbol: 'Paragraph::ideographicBaseline', isLeaf: true) external double get ideographicBaseline; - @FfiNative, Double)>('Paragraph::ideographicBaseline', isLeaf: true) + @Native, Double)>(symbol: 'Paragraph::ideographicBaseline', isLeaf: true) external set ideographicBaseline(double d); } ''', []); @@ -37,11 +37,11 @@ base class Paragraph extends NativeFieldWrapperClass1 { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative +@Native external int foo(); ''', [ - error(CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS, 20, 10), - error(FfiCode.MUST_BE_A_NATIVE_FUNCTION_TYPE, 20, 30), + error(CompileTimeErrorCode.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS, 20, 7), + error(FfiCode.MUST_BE_A_NATIVE_FUNCTION_TYPE, 20, 27), ]); } @@ -49,19 +49,17 @@ external int foo(); await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative() +@Native() external int foo(); ''', [ - error(FfiCode.MUST_BE_A_NATIVE_FUNCTION_TYPE, 20, 32), - error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR, - 31, 1), + error(FfiCode.MUST_BE_A_NATIVE_FUNCTION_TYPE, 20, 29), ]); } test_FfiNativeCanUseHandles() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('DoesntMatter') +@Native(symbol: 'DoesntMatter') external Object doesntMatter(Object); ''', []); } @@ -69,7 +67,7 @@ external Object doesntMatter(Object); test_FfiNativeCanUseLeaf() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('DoesntMatter', isLeaf:true) +@Native(symbol: 'DoesntMatter', isLeaf:true) external int doesntMatter(int x); ''', []); } @@ -78,59 +76,59 @@ external int doesntMatter(int x); await assertErrorsInCode(r''' import 'dart:ffi'; class K { - @FfiNative('DoesntMatter') + @Native(symbol: 'DoesntMatter') external void doesntMatter(double x); } ''', [ error(FfiCode.FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS_WITH_RECEIVER, - 31, 89), + 31, 94), ]); } test_FfiNativeLeafMustNotReturnHandle() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('DoesntMatter', isLeaf:true) +@Native(symbol: 'DoesntMatter', isLeaf:true) external Object doesntMatter(); ''', [ - error(FfiCode.LEAF_CALL_MUST_NOT_RETURN_HANDLE, 19, 90), + error(FfiCode.LEAF_CALL_MUST_NOT_RETURN_HANDLE, 19, 95), ]); } test_FfiNativeLeafMustNotTakeHandles() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('DoesntMatter', isLeaf:true) +@Native(symbol: 'DoesntMatter', isLeaf:true) external void doesntMatter(Object o); ''', [ - error(FfiCode.LEAF_CALL_MUST_NOT_TAKE_HANDLE, 19, 100), + error(FfiCode.LEAF_CALL_MUST_NOT_TAKE_HANDLE, 19, 105), ]); } test_FfiNativeNonFfiParameter() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('doesntmatter') +@Native(symbol: 'doesntmatter') external int nonFfiParameter(int v); ''', [ - error(FfiCode.MUST_BE_A_NATIVE_FUNCTION_TYPE, 19, 85), + error(FfiCode.MUST_BE_A_NATIVE_FUNCTION_TYPE, 19, 90), ]); } test_FfiNativeNonFfiReturnType() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('doesntmatter') +@Native(symbol: 'doesntmatter') external double nonFfiReturnType(int v); ''', [ - error(FfiCode.MUST_BE_A_NATIVE_FUNCTION_TYPE, 19, 92), + error(FfiCode.MUST_BE_A_NATIVE_FUNCTION_TYPE, 19, 97), ]); } test_FfiNativePointerParameter() async { await assertNoErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('free') +@Native(symbol: 'free') external void posixFree(Pointer pointer); '''); } @@ -138,50 +136,50 @@ external void posixFree(Pointer pointer); test_FfiNativeTooFewParameters() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('DoesntMatter') +@Native(symbol: 'DoesntMatter') external void doesntMatter(double x, double y); ''', [ - error(FfiCode.FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS, 19, 97), + error(FfiCode.FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS, 19, 102), ]); } test_FfiNativeTooManyParameters() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('DoesntMatter') +@Native(symbol: 'DoesntMatter') external void doesntMatter(double x); ''', [ - error(FfiCode.FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS, 19, 95), + error(FfiCode.FFI_NATIVE_UNEXPECTED_NUMBER_OF_PARAMETERS, 19, 100), ]); } test_FfiNativeVoidReturn() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('doesntmatter') +@Native(symbol: 'doesntmatter') external void voidReturn(int width, int height, Object outImage); ''', [ - error(FfiCode.MUST_BE_A_SUBTYPE, 19, 133), + error(FfiCode.MUST_BE_A_SUBTYPE, 19, 138), ]); } test_FfiNativeWrongFfiParameter() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('doesntmatter') +@Native(symbol: 'doesntmatter') external int wrongFfiParameter(int v); ''', [ - error(FfiCode.MUST_BE_A_SUBTYPE, 19, 90), + error(FfiCode.MUST_BE_A_SUBTYPE, 19, 95), ]); } test_FfiNativeWrongFfiReturnType() async { await assertErrorsInCode(r''' import 'dart:ffi'; -@FfiNative('doesntmatter') +@Native(symbol: 'doesntmatter') external double wrongFfiReturnType(int v); ''', [ - error(FfiCode.MUST_BE_A_SUBTYPE, 19, 94), + error(FfiCode.MUST_BE_A_SUBTYPE, 19, 99), ]); } } diff --git a/pkg/analyzer/tool/diagnostics/diagnostics.md b/pkg/analyzer/tool/diagnostics/diagnostics.md index 6f6c55ed95f..6bd5f5b33b1 100644 --- a/pkg/analyzer/tool/diagnostics/diagnostics.md +++ b/pkg/analyzer/tool/diagnostics/diagnostics.md @@ -11306,7 +11306,7 @@ argument in an invocation of either `Pointer.asFunction` or returned would have a return type of `Handle`. The analyzer also produces this diagnostic when the value of the `isLeaf` -argument in an `FfiNative` annotation is `true` and the type argument on +argument in an `Native` annotation is `true` and the type argument on the annotation is a function type whose return type is `Handle`. In all of these cases, leaf calls are only supported for the types `bool`, diff --git a/pkg/dart2wasm/lib/ffi_native_transformer.dart b/pkg/dart2wasm/lib/ffi_native_transformer.dart index c9c7e64baa1..b85f93d6325 100644 --- a/pkg/dart2wasm/lib/ffi_native_transformer.dart +++ b/pkg/dart2wasm/lib/ffi_native_transformer.dart @@ -117,7 +117,7 @@ class WasmFfiNativeTransformer extends FfiNativeTransformer { @override visitProcedure(Procedure node) { // Only transform functions that are external and have Native annotation: - // @Native('Math_sqrt') + // @Native(symbol: 'Math_sqrt') // external double _square_root(double x); final nativeAnnotation = tryGetNativeAnnotation(node); if (nativeAnnotation == null) { diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml index 6bbd1112b42..57b3b3b9221 100644 --- a/pkg/front_end/messages.yaml +++ b/pkg/front_end/messages.yaml @@ -5149,12 +5149,12 @@ FfiLeafCallMustNotReturnHandle: FfiNativeUnexpectedNumberOfParametersWithReceiver: # Used by dart:ffi - problemMessage: "Unexpected number of FfiNative annotation parameters. Expected #count but has #count2. FfiNative instance method annotation must have receiver as first argument." + problemMessage: "Unexpected number of Native annotation parameters. Expected #count but has #count2. Native instance method annotation must have receiver as first argument." external: test/ffi_test.dart FfiNativeUnexpectedNumberOfParameters: # Used by dart:ffi - problemMessage: "Unexpected number of FfiNative annotation parameters. Expected #count but has #count2." + problemMessage: "Unexpected number of Native annotation parameters. Expected #count but has #count2." external: test/ffi_test.dart FfiNativeOnlyNativeFieldWrapperClassCanBePointer: @@ -5164,7 +5164,7 @@ FfiNativeOnlyNativeFieldWrapperClassCanBePointer: FfiNativeMustBeExternal: # Used by dart:ffi - problemMessage: "FfiNative functions must be marked external." + problemMessage: "Native functions must be marked external." external: test/ffi_test.dart SpreadTypeMismatch: diff --git a/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.1.expect b/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.1.expect index e1883397305..2276d018511 100644 --- a/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.1.expect +++ b/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.1.expect @@ -57,7 +57,6 @@ additionalExports = (ffi::Abi, ffi::DoublePointer, ffi::DynamicLibrary, ffi::DynamicLibraryExtension, - ffi::FfiNative, ffi::Finalizable, ffi::Float, ffi::FloatArray, @@ -154,7 +153,6 @@ additionalExports = (ffi::Abi, ffi::DoublePointer, ffi::DynamicLibrary, ffi::DynamicLibraryExtension, - ffi::FfiNative, ffi::Finalizable, ffi::Float, ffi::FloatArray, diff --git a/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.2.expect b/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.2.expect index 073d1d032f9..a0b0d030611 100644 --- a/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.2.expect +++ b/pkg/front_end/testcases/incremental/no_outline_change_50_ffi.yaml.world.2.expect @@ -57,7 +57,6 @@ additionalExports = (ffi::Abi, ffi::DoublePointer, ffi::DynamicLibrary, ffi::DynamicLibraryExtension, - ffi::FfiNative, ffi::Finalizable, ffi::Float, ffi::FloatArray, @@ -154,7 +153,6 @@ additionalExports = (ffi::Abi, ffi::DoublePointer, ffi::DynamicLibrary, ffi::DynamicLibraryExtension, - ffi::FfiNative, ffi::Finalizable, ffi::Float, ffi::FloatArray, diff --git a/pkg/mmap/lib/src/mmap_impl.dart b/pkg/mmap/lib/src/mmap_impl.dart index 083ca3caf99..51563e40ee9 100644 --- a/pkg/mmap/lib/src/mmap_impl.dart +++ b/pkg/mmap/lib/src/mmap_impl.dart @@ -2,9 +2,6 @@ // 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. -// File is compiled with checked in SDK, update [FfiNative]s to [Native] when -// SDK is rolled. - // ignore_for_file: camel_case_types // ignore_for_file: deprecated_member_use // ignore_for_file: non_constant_identifier_names @@ -25,14 +22,12 @@ external int close(int fd); // void* mmap(void* addr, size_t length, // int prot, int flags, // int fd, off_t offset) -@FfiNative< - Pointer Function( - Pointer, Size, Int, Int, Int, IntPtr)>("mmap") +@Native Function(Pointer, Size, Int, Int, Int, IntPtr)>() external Pointer mmap( Pointer address, int len, int prot, int flags, int fd, int offset); // int munmap(void *addr, size_t length) -@Native address, Size len)>(symbol: "munmap") +@Native address, Size len)>() external int munmap(Pointer address, int len); final DynamicLibrary processSymbols = DynamicLibrary.process(); diff --git a/pkg/vm/lib/transformations/ffi/common.dart b/pkg/vm/lib/transformations/ffi/common.dart index a4af32c3200..1444f55debb 100644 --- a/pkg/vm/lib/transformations/ffi/common.dart +++ b/pkg/vm/lib/transformations/ffi/common.dart @@ -186,7 +186,6 @@ class FfiTransformer extends Transformer { final Class abiSpecificIntegerClass; final Class abiSpecificIntegerMappingClass; final Class varArgsClass; - final Class ffiNativeClass; final Class nativeFieldWrapperClass1Class; final Class ffiStructLayoutClass; final Field ffiStructLayoutTypesField; @@ -358,7 +357,6 @@ class FfiTransformer extends Transformer { abiSpecificIntegerMappingClass = index.getClass('dart:ffi', 'AbiSpecificIntegerMapping'), varArgsClass = index.getClass('dart:ffi', 'VarArgs'), - ffiNativeClass = index.getClass('dart:ffi', 'FfiNative'), nativeFieldWrapperClass1Class = index.getClass('dart:nativewrappers', 'NativeFieldWrapperClass1'), ffiStructLayoutClass = index.getClass('dart:ffi', '_FfiStructLayout'), diff --git a/pkg/vm/lib/transformations/ffi/native.dart b/pkg/vm/lib/transformations/ffi/native.dart index 24be003df04..aa6da7d8bb6 100644 --- a/pkg/vm/lib/transformations/ffi/native.dart +++ b/pkg/vm/lib/transformations/ffi/native.dart @@ -38,7 +38,7 @@ void transformLibraries( 'dart:isolate' ]); // Skip if dart:ffi isn't loaded (e.g. during incremental compile). - if (index.tryGetClass('dart:ffi', 'FfiNative') == null) { + if (index.tryGetClass('dart:ffi', 'Native') == null) { return; } final transformer = FfiNativeTransformer( @@ -50,15 +50,12 @@ class FfiNativeTransformer extends FfiTransformer { final DiagnosticReporter diagnosticReporter; final ReferenceFromIndex? referenceFromIndex; final Class assetClass; - final Class ffiNativeClass; final Class nativeClass; final Class nativeFunctionClass; final Field assetAssetField; final Field nativeSymbolField; - final Field ffiNativeNameField; final Field nativeAssetField; final Field nativeIsLeafField; - final Field ffiNativeIsLeafField; final Field resolverField; StringConstant? currentAsset; @@ -75,16 +72,11 @@ class FfiNativeTransformer extends FfiTransformer { this.referenceFromIndex) : assetClass = index.getClass('dart:ffi', 'DefaultAsset'), nativeClass = index.getClass('dart:ffi', 'Native'), - ffiNativeClass = index.getClass('dart:ffi', 'FfiNative'), nativeFunctionClass = index.getClass('dart:ffi', 'NativeFunction'), assetAssetField = index.getField('dart:ffi', 'DefaultAsset', 'id'), nativeSymbolField = index.getField('dart:ffi', 'Native', 'symbol'), - ffiNativeNameField = - index.getField('dart:ffi', 'FfiNative', 'nativeName'), nativeAssetField = index.getField('dart:ffi', 'Native', 'assetId'), nativeIsLeafField = index.getField('dart:ffi', 'Native', 'isLeaf'), - ffiNativeIsLeafField = - index.getField('dart:ffi', 'FfiNative', 'isLeaf'), resolverField = index.getTopLevelField('dart:ffi', '_ffi_resolver'), super(index, coreTypes, hierarchy, diagnosticReporter, referenceFromIndex); @@ -122,9 +114,6 @@ class FfiNativeTransformer extends FfiTransformer { ConstantExpression? tryGetAssetAnnotation(Library node) => tryGetAnnotation(node, [assetClass]); - ConstantExpression? tryGetFfiNativeAnnotation(Member node) => - tryGetAnnotation(node, [ffiNativeClass]); - ConstantExpression? tryGetNativeAnnotation(Member node) => tryGetAnnotation(node, [nativeClass]); @@ -186,7 +175,7 @@ class FfiNativeTransformer extends FfiTransformer { // Create field holding the resolved native function pointer. // // For: - // @FfiNative)>('DoXYZ', isLeaf:true) + // @Native)>('DoXYZ', isLeaf:true) // external int doXyz(NativeFieldWrapperClass1 obj); // // Create: @@ -333,10 +322,10 @@ class FfiNativeTransformer extends FfiTransformer { return VariableGet(temporary); } - // FfiNative calls that pass objects extending NativeFieldWrapperClass1 + // Native calls that pass objects extending NativeFieldWrapperClass1 // should be passed as Pointer instead so we don't have the overhead of // converting Handles. - // If we find a NativeFieldWrapperClass1 object being passed to an FfiNative + // If we find a NativeFieldWrapperClass1 object being passed to an Native // signature taking a Pointer, we automatically wrap the argument in a call to // `Pointer.fromAddress(_getNativeField(obj))`. // @@ -522,13 +511,13 @@ class FfiNativeTransformer extends FfiTransformer { node.fileUri, ); - // Add field to the parent the FfiNative function belongs to. + // Add field to the parent the Native function belongs to. if (parent is Class) { parent.addField(resolvedField); } else if (parent is Library) { parent.addField(resolvedField); } else { - throw 'Unexpected parent of @FfiNative function. ' + throw 'Unexpected parent of @Native function. ' 'Expected Class or Library, but found ${parent}.'; } @@ -556,10 +545,10 @@ class FfiNativeTransformer extends FfiTransformer { return node; } - // Transform FfiNative instance methods. + // Transform Native instance methods. // Example: // class MyNativeClass extends NativeFieldWrapperClass1 { - // @FfiNative, IntPtr)>('MyClass_MyMethod') + // @Native, IntPtr)>('MyClass_MyMethod') // external int myMethod(int x); // } // Becomes, roughly: @@ -608,9 +597,9 @@ class FfiNativeTransformer extends FfiTransformer { ); } - // Transform FfiNative static functions. + // Transform Native static functions. // Example: - // @FfiNative, IntPtr)>('MyFunction') + // @Native, IntPtr)>('MyFunction') // external int myFunction(MyNativeClass obj, int x); // Becomes, roughly: // static final _myFunction$FfiNative$Ptr = ... @@ -647,11 +636,10 @@ class FfiNativeTransformer extends FfiTransformer { @override visitProcedure(Procedure node) { - // Only transform functions that are external and have FfiNative annotation: - // @FfiNative('Math_sqrt') + // Only transform functions that are external and have Native annotation: + // @Native(symbol: 'Math_sqrt') // external double _square_root(double x); - final ffiNativeAnnotation = - tryGetNativeAnnotation(node) ?? tryGetFfiNativeAnnotation(node); + final ffiNativeAnnotation = tryGetNativeAnnotation(node); if (ffiNativeAnnotation == null) { return node; } @@ -678,8 +666,7 @@ class FfiNativeTransformer extends FfiTransformer { } final ffiFunctionType = ffiConstant.typeArguments[0] as FunctionType; final nativeFunctionConst = - (ffiConstant.fieldValues[nativeSymbolField.fieldReference] ?? - ffiConstant.fieldValues[ffiNativeNameField.fieldReference]); + (ffiConstant.fieldValues[nativeSymbolField.fieldReference]); final nativeFunctionName = nativeFunctionConst is StringConstant ? nativeFunctionConst : StringConstant(node.name.text); @@ -687,9 +674,7 @@ class FfiNativeTransformer extends FfiTransformer { ffiConstant.fieldValues[nativeAssetField.fieldReference]; final assetName = assetConstant is StringConstant ? assetConstant : currentAsset; - final isLeaf = ((ffiConstant - .fieldValues[nativeIsLeafField.fieldReference] ?? - ffiConstant.fieldValues[ffiNativeIsLeafField.fieldReference]) + final isLeaf = ((ffiConstant.fieldValues[nativeIsLeafField.fieldReference]) as BoolConstant) .value; diff --git a/pkg/vm/testcases/transformations/ffi/ffinative.dart b/pkg/vm/testcases/transformations/ffi/ffinative.dart index f8ba423fa28..060087270c7 100644 --- a/pkg/vm/testcases/transformations/ffi/ffinative.dart +++ b/pkg/vm/testcases/transformations/ffi/ffinative.dart @@ -2,7 +2,7 @@ // 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. -// Tests for @FfiNative related transformations. +// Tests for @Native related transformations. // ignore_for_file: deprecated_member_use @@ -11,43 +11,44 @@ import 'dart:ffi'; import 'dart:nativewrappers'; -@FfiNative('ReturnIntPtr') +@Native(symbol: 'ReturnIntPtr') external int returnIntPtr(int x); -@FfiNative('ReturnIntPtr', isLeaf: true) +@Native(symbol: 'ReturnIntPtr', isLeaf: true) external int returnIntPtrLeaf(int x); class Classy { - @FfiNative('ReturnIntPtr') + @Native(symbol: 'ReturnIntPtr') external static int returnIntPtrStatic(int x); } class NativeClassy extends NativeFieldWrapperClass1 { - @FfiNative, IntPtr)>('doesntmatter') + @Native, IntPtr)>(symbol: 'doesntmatter') external void goodHasReceiverPointer(int v); - @FfiNative('doesntmatter') + @Native(symbol: 'doesntmatter') external void goodHasReceiverHandle(int v); - @FfiNative)>('doesntmatter') + @Native)>(symbol: 'doesntmatter') external void goodHasReceiverHandleAndPtr(NativeClassy v); - @FfiNative('doesntmatter') + @Native(symbol: 'doesntmatter') external void goodHasReceiverHandleAndHandle(NativeClassy v); - @FfiNative, Handle)>('doesntmatter') + @Native, Handle)>(symbol: 'doesntmatter') external void goodHasReceiverPtrAndHandle(NativeClassy v); - @FfiNative, Bool)>('doesntmatter') + @Native, Bool)>(symbol: 'doesntmatter') external String? meh(bool blah); - @FfiNative)>('doesntmatter') + @Native)>(symbol: 'doesntmatter') external bool blah(); - @FfiNative)>('doesntmatter', isLeaf: true) + @Native)>(symbol: 'doesntmatter', isLeaf: true) external bool get myField; - @FfiNative, Bool)>('doesntmatter', isLeaf: true) + @Native, Bool)>( + symbol: 'doesntmatter', isLeaf: true) external set myField(bool value); } diff --git a/runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc b/runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc index 964a2bb94e0..6f0a4c233ac 100644 --- a/runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc +++ b/runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc @@ -1125,7 +1125,7 @@ DART_EXPORT void SetArgumentTo42(void* token) { } //////////////////////////////////////////////////////////////////////////////// -// Functions for testing @FfiNative. +// Functions for testing @Native. DART_EXPORT Dart_Handle GetRootLibraryUrl() { Dart_Handle root_lib = Dart_RootLibrary(); @@ -1312,7 +1312,7 @@ DART_EXPORT void Regress216834909_SetAtExit(int64_t install) { Regress216834909_hang_at_exit = false; } } -#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID) || +#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID) || \ // defined(DART_HOST_OS_MACOS) DART_EXPORT bool IsNull(Dart_Handle object) { diff --git a/runtime/vm/compiler/frontend/kernel_to_il.cc b/runtime/vm/compiler/frontend/kernel_to_il.cc index c5b4b503029..009b34710d5 100644 --- a/runtime/vm/compiler/frontend/kernel_to_il.cc +++ b/runtime/vm/compiler/frontend/kernel_to_il.cc @@ -1659,7 +1659,7 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfRecognizedMethod( // the GC. // As an alternative design we could introduce an ExchangeNativeFieldInstr // that uses the same machine code as std::atomic::exchange. Or we could - // use an FfiNative to do that in C. + // use an Native to do that in C. body += LoadLocal(parsed_function_->RawParameterVariable(0)); // No GC from here til StoreNativeField. body += LoadNativeField(Slot::FinalizerBase_entries_collected()); diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 11b94225e4f..ab3c03615b8 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -4573,7 +4573,7 @@ TEST_CASE(DartAPI_NativeFieldAccess) { external void _keepSecret(int secret); } // Argument auto-conversion will wrap `o` in `_getNativeField()`. - @FfiNative)>('returnPtrAsInt') + @Native)>(symbol: 'returnPtrAsInt') external int returnPtrAsInt(NativeFieldWrapperClass1 o); main() => returnPtrAsInt(SecretKeeper(321)); )"; @@ -4605,7 +4605,7 @@ TEST_CASE(DartAPI_NativeFieldAccess_Throws) { ForgetfulSecretKeeper(int secret) { /* Forget to init. native field. */ } } // Argument auto-conversion will wrap `o` in `_getNativeField()`. - @FfiNative)>('returnPtrAsInt') + @Native)>(symbol: 'returnPtrAsInt') external int returnPtrAsInt(NativeFieldWrapperClass1 o); main() => returnPtrAsInt(ForgetfulSecretKeeper(321)); )"; @@ -10439,7 +10439,7 @@ static void* FfiNativeResolver(const char* name, uintptr_t args_n) { TEST_CASE(Dart_SetFfiNativeResolver) { const char* kScriptChars = R"( import 'dart:ffi'; - @FfiNative('EchoInt', isLeaf:true) + @Native(symbol: 'EchoInt', isLeaf:true) external int echoInt(double x); main() => echoInt(7.0); )"; @@ -10461,7 +10461,7 @@ TEST_CASE(Dart_SetFfiNativeResolver) { TEST_CASE(Dart_SetFfiNativeResolver_MissingResolver) { const char* kScriptChars = R"( import 'dart:ffi'; - @FfiNative('EchoInt', isLeaf:true) + @Native(symbol: 'EchoInt', isLeaf:true) external int echoInt(double x); main() => echoInt(7.0); )"; @@ -10482,7 +10482,7 @@ static void* NopResolver(const char* name, uintptr_t args_n) { TEST_CASE(Dart_SetFfiNativeResolver_DoesNotResolve) { const char* kScriptChars = R"( import 'dart:ffi'; - @FfiNative('DoesNotResolve') + @Native(symbol: 'DoesNotResolve') external void doesNotResolve(); main() => doesNotResolve(); )"; @@ -10564,8 +10564,7 @@ static void HeapSamplingDelete(void* data) { free(data); } -void HeapSamplingReport(void* context, - void* data) { +void HeapSamplingReport(void* context, void* data) { last_allocation_context = context; if (strcmp(reinterpret_cast(data), expected_allocation_cls) == 0) { found_allocation = true; diff --git a/sdk/lib/ffi/ffi.dart b/sdk/lib/ffi/ffi.dart index 7235d5977d1..8196c12c8c8 100644 --- a/sdk/lib/ffi/ffi.dart +++ b/sdk/lib/ffi/ffi.dart @@ -1117,45 +1117,6 @@ abstract final class NativeApi { external static Pointer get initializeApiDLData; } -/// Annotation to be used for marking an external function as FFI native. -/// -/// Example: -/// -/// ```dart template:top -/// @Native(symbol: 'FfiNative_Sum', isLeaf:true) -/// external int sum(int a, int b); -/// ``` -/// -/// Calling such functions will throw an exception if no resolver -/// was set on the library or the resolver failed to resolve the name. -/// -/// See `Dart_SetFfiNativeResolver` in `dart_api.h` -/// -/// NOTE: This experimental feature is replaced by [Native]. -@Since('2.14') -@Deprecated('Use Native instead.') -final class FfiNative { - final String nativeName; - - /// Whether the function is a leaf function. - /// - /// Leaf functions are small, short-running, non-blocking functions which are - /// not allowed to call back into Dart or use any Dart VM APIs. Leaf functions - /// are invoked bypassing some of the heavier parts of the standard - /// Dart-to-Native calling sequence which reduces the invocation overhead, - /// making leaf calls faster than non-leaf calls. However, this implies that a - /// thread executing a leaf function can't cooperate with the Dart runtime. A - /// long running or blocking leaf function will delay any operation which - /// requires synchronization between all threads associated with an isolate - /// group until after the leaf function returns. For example, if one isolate - /// in a group is trying to perform a GC and a second isolate is blocked in a - /// leaf call, then the first isolate will have to pause and wait until this - /// leaf call returns. - final bool isLeaf; - - const FfiNative(this.nativeName, {this.isLeaf = false}); -} - /// Annotation specifying how to bind an external function to native code. /// /// The annotation applies only to `external` function declarations. diff --git a/tests/ffi/ffi_native_test.dart b/tests/ffi/ffi_native_test.dart index 0ed8f9b56f2..58bb85a45bc 100644 --- a/tests/ffi/ffi_native_test.dart +++ b/tests/ffi/ffi_native_test.dart @@ -6,33 +6,33 @@ import 'dart:ffi'; import 'dart:nativewrappers'; class Classy { - @FfiNative('ReturnIntPtr') + @Native(symbol: 'ReturnIntPtr') external static int returnIntPtrStatic(int x); - @FfiNative('doesntmatter') + @Native(symbol: 'doesntmatter') external void goodHasReceiverHandle(int v); } base class NativeClassy extends NativeFieldWrapperClass1 { - @FfiNative('ReturnIntPtr') + @Native(symbol: 'ReturnIntPtr') external static int returnIntPtrStatic(int x); - @FfiNative, IntPtr)>('doesntmatter') + @Native, IntPtr)>(symbol: 'doesntmatter') external void goodHasReceiverPointer(int v); - @FfiNative('doesntmatter') + @Native(symbol: 'doesntmatter') external void goodHasReceiverHandle(int v); } -// Regression test: Ensure same-name FfiNative functions don't collide in the +// Regression test: Ensure same-name Native functions don't collide in the // top-level namespace, but instead live under their parent (Library, Class). class A { - @FfiNative('nop') + @Native(symbol: 'nop') external static void foo(); } class B { - @FfiNative('nop') + @Native(symbol: 'nop') external static void foo(); } diff --git a/tests/ffi/native_assets/asset_absolute_test.dart b/tests/ffi/native_assets/asset_absolute_test.dart index f9b93a17de7..7d80df7964e 100644 --- a/tests/ffi/native_assets/asset_absolute_test.dart +++ b/tests/ffi/native_assets/asset_absolute_test.dart @@ -68,16 +68,10 @@ Future runTests() async { testNonExistingFunction(); } -@FfiNative('SumPlus42') -external int sumPlus42(int a, int b); - @Native() external int SumPlus42(int a, int b); void testFfiTestfunctionsDll() { - final result = sumPlus42(2, 3); - Expect.equals(2 + 3 + 42, result); - final result2 = SumPlus42(2, 3); Expect.equals(2 + 3 + 42, result2); } diff --git a/tests/ffi/native_assets/asset_executable_test.dart b/tests/ffi/native_assets/asset_executable_test.dart index 71ebb2695fb..b49eb6e5d7a 100644 --- a/tests/ffi/native_assets/asset_executable_test.dart +++ b/tests/ffi/native_assets/asset_executable_test.dart @@ -63,27 +63,23 @@ Future runTests() async { testNonExistingFunction(); } -@FfiNative('Dart_PostInteger') -external bool dartPostInteger(int port, int message); - @Native() external bool Dart_PostInteger(int port, int message); Future testExecutable() async { - for (final postInteger in [dartPostInteger, Dart_PostInteger]) { - const int message = 1337 * 42; + const int message = 1337 * 42; - final completer = Completer(); + final completer = Completer(); - final receivePort = ReceivePort() - ..listen((receivedMessage) => completer.complete(receivedMessage)); + final receivePort = ReceivePort() + ..listen((receivedMessage) => completer.complete(receivedMessage)); - final bool success = postInteger(receivePort.sendPort.nativePort, message); - Expect.isTrue(success); + final bool success = + Dart_PostInteger(receivePort.sendPort.nativePort, message); + Expect.isTrue(success); - final postedMessage = await completer.future; - Expect.equals(message, postedMessage); + final postedMessage = await completer.future; + Expect.equals(message, postedMessage); - receivePort.close(); - } + receivePort.close(); } diff --git a/tests/ffi/native_assets/asset_process_test.dart b/tests/ffi/native_assets/asset_process_test.dart index 66d54234981..e62602a9a63 100644 --- a/tests/ffi/native_assets/asset_process_test.dart +++ b/tests/ffi/native_assets/asset_process_test.dart @@ -68,16 +68,16 @@ Future runTests() async { testNonExistingFunction(); } -@FfiNative('malloc') +@Native(symbol: 'malloc') external Pointer posixMalloc(int size); -@FfiNative('free') +@Native(symbol: 'free') external void posixFree(Pointer pointer); -@FfiNative('CoTaskMemAlloc') +@Native(symbol: 'CoTaskMemAlloc') external Pointer winCoTaskMemAlloc(int cb); -@FfiNative('CoTaskMemFree') +@Native(symbol: 'CoTaskMemFree') external void winCoTaskMemFree(Pointer pv); @Native() diff --git a/tests/ffi/native_assets/asset_relative_test.dart b/tests/ffi/native_assets/asset_relative_test.dart index 2fb4d0626ce..02a6e872cb0 100644 --- a/tests/ffi/native_assets/asset_relative_test.dart +++ b/tests/ffi/native_assets/asset_relative_test.dart @@ -122,16 +122,10 @@ Future runTests() async { testNonExistingFunction(); } -@FfiNative('SumPlus42') -external int sumPlus42(int a, int b); - @Native() external int SumPlus42(int a, int b); void testFfiTestfunctionsDll() { - final result = sumPlus42(2, 3); - Expect.equals(2 + 3 + 42, result); - final result2 = SumPlus42(2, 3); Expect.equals(2 + 3 + 42, result2); } diff --git a/tests/ffi/native_assets/asset_system_test.dart b/tests/ffi/native_assets/asset_system_test.dart index 53f6adf483a..3e9542be0e4 100644 --- a/tests/ffi/native_assets/asset_system_test.dart +++ b/tests/ffi/native_assets/asset_system_test.dart @@ -76,18 +76,6 @@ Future runTests() async { testNonExistingFunction(); } -@FfiNative('malloc') -external Pointer posixMalloc(int size); - -@FfiNative('free') -external void posixFree(Pointer pointer); - -@FfiNative('CoTaskMemAlloc') -external Pointer winCoTaskMemAlloc(int cb); - -@FfiNative('CoTaskMemFree') -external void winCoTaskMemFree(Pointer pv); - @Native() external Pointer malloc(int size); @@ -102,16 +90,10 @@ external void CoTaskMemFree(Pointer pv); void testProcessOrSystem() { if (Platform.isWindows) { - final pointer = winCoTaskMemAlloc(8); - Expect.notEquals(nullptr, pointer); - winCoTaskMemFree(pointer); final pointer2 = CoTaskMemAlloc(8); Expect.notEquals(nullptr, pointer2); CoTaskMemFree(pointer2); } else { - final pointer = posixMalloc(8); - Expect.notEquals(nullptr, pointer); - posixFree(pointer); final pointer2 = malloc(8); Expect.notEquals(nullptr, pointer2); free(pointer2); diff --git a/tests/ffi/native_assets/helpers.dart b/tests/ffi/native_assets/helpers.dart index 8d998097d0f..27edd82aeac 100644 --- a/tests/ffi/native_assets/helpers.dart +++ b/tests/ffi/native_assets/helpers.dart @@ -73,12 +73,13 @@ Future withTempDir( String prefix = 'tests_ffi_native_assets_', }) async { final tempDir = await Directory.systemTemp.createTemp(prefix); + final tempDirResolved = Directory(await tempDir.resolveSymbolicLinks()); try { - await fun(tempDir.uri); + await fun(tempDirResolved.uri); } finally { if (!Platform.environment.containsKey(keepTempKey) || Platform.environment[keepTempKey]!.isEmpty) { - await tempDir.delete(recursive: true); + await tempDirResolved.delete(recursive: true); } } } @@ -344,7 +345,7 @@ Future testIsolateSpawn(Future Function() fun) async { /// _with_ a native asset mapping. /// 2. The [doOnProcessInvocation]. In this, we know that we have a snapshot /// from the outer invocation and are in the corresponding Dart runtime. -/// This means we have an asset mapping and can use `@FfiNative` bindings. +/// This means we have an asset mapping and can use `@Native` bindings. /// In this invocation, we can call [Isolate.spawn] which should then reuse /// native asset mapping, because this mapping is shared among the isolate /// group. @@ -404,18 +405,10 @@ Future Function(List args, Object? message) selfInvokingTest({ const doesNotExistName = 'doesnotexist92304'; -@FfiNative(doesNotExistName) -external int doesNotExist(int a, int b); - @Native() external int doesnotexist92304(int a, int b); void testNonExistingFunction() { - final argumentError = Expect.throws(() { - doesNotExist(2, 3); - }); - Expect.contains(doesNotExistName, argumentError.message); - final argumentError2 = Expect.throws(() { doesnotexist92304(2, 3); }); diff --git a/tests/ffi/native_assets/infer_native_assets_yaml_dart_kernel_snapshot_helper.dart b/tests/ffi/native_assets/infer_native_assets_yaml_dart_kernel_snapshot_helper.dart index 1eafa320c93..9fac2f421d5 100644 --- a/tests/ffi/native_assets/infer_native_assets_yaml_dart_kernel_snapshot_helper.dart +++ b/tests/ffi/native_assets/infer_native_assets_yaml_dart_kernel_snapshot_helper.dart @@ -19,5 +19,5 @@ void main() { print('run done'); } -@FfiNative('SumPlus42') +@Native(symbol: 'SumPlus42') external int sumPlus42(int a, int b); diff --git a/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_2_helper_2.dart b/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_2_helper_2.dart index 983a96b8a37..d819ded4353 100644 --- a/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_2_helper_2.dart +++ b/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_2_helper_2.dart @@ -19,5 +19,5 @@ void main(List args, Object? message) { print('run done'); } -@FfiNative('SumPlus42') +@Native(symbol: 'SumPlus42') external int sumPlus42(int a, int b); diff --git a/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_3_helper.dart b/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_3_helper.dart index f950e4edca2..5d3d348848b 100644 --- a/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_3_helper.dart +++ b/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_3_helper.dart @@ -27,5 +27,5 @@ void main(List args, Object? message) { print('run done'); } -@FfiNative('SumPlus42') +@Native(symbol: 'SumPlus42') external int sumPlus42(int a, int b); diff --git a/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_helper.dart b/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_helper.dart index f950e4edca2..5d3d348848b 100644 --- a/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_helper.dart +++ b/tests/ffi/native_assets/infer_native_assets_yaml_isolate_spawnuri_helper.dart @@ -27,5 +27,5 @@ void main(List args, Object? message) { print('run done'); } -@FfiNative('SumPlus42') +@Native(symbol: 'SumPlus42') external int sumPlus42(int a, int b); diff --git a/tests/ffi/native_assets/infer_native_assets_yaml_process_run_helper.dart b/tests/ffi/native_assets/infer_native_assets_yaml_process_run_helper.dart index 1eafa320c93..9fac2f421d5 100644 --- a/tests/ffi/native_assets/infer_native_assets_yaml_process_run_helper.dart +++ b/tests/ffi/native_assets/infer_native_assets_yaml_process_run_helper.dart @@ -19,5 +19,5 @@ void main() { print('run done'); } -@FfiNative('SumPlus42') +@Native(symbol: 'SumPlus42') external int sumPlus42(int a, int b); diff --git a/tests/ffi/native_assets/process_test.dart b/tests/ffi/native_assets/process_test.dart index 2fcae54f9b4..4cf5d7c29bb 100644 --- a/tests/ffi/native_assets/process_test.dart +++ b/tests/ffi/native_assets/process_test.dart @@ -22,19 +22,19 @@ void testSuccess() { malloc.free(p1); } -@FfiNative('malloc') +@Native(symbol: 'malloc') external Pointer posixMalloc(int size); -@FfiNative('calloc') +@Native(symbol: 'calloc') external Pointer posixCalloc(int num, int size); -@FfiNative('free') +@Native(symbol: 'free') external void posixFree(Pointer pointer); -@FfiNative('CoTaskMemAlloc') +@Native(symbol: 'CoTaskMemAlloc') external Pointer winCoTaskMemAlloc(int cb); -@FfiNative('CoTaskMemFree') +@Native(symbol: 'CoTaskMemFree') external void winCoTaskMemFree(Pointer pv); class _MallocAllocator implements Allocator { @@ -87,5 +87,5 @@ void testFailure() { } } -@FfiNative('symbol_is_not_defined_29903211') +@Native(symbol: 'symbol_is_not_defined_29903211') external void symbolIsNotDefined(); diff --git a/tests/ffi/regress_49684_test.dart b/tests/ffi/regress_49684_test.dart index 33df684c4d5..a2b43f2de75 100644 --- a/tests/ffi/regress_49684_test.dart +++ b/tests/ffi/regress_49684_test.dart @@ -5,24 +5,23 @@ import 'dart:ffi'; void main() { - // Does nothing, FfiNative aren't resolved. + // Does nothing, Native's aren't resolved. } -@FfiNative, Int)>('subtract') +@Native, Int)>() external int subtract( Pointer a, int b, ); -@FfiNative Function(Pointer, Pointer)>( - 'dividePrecision') +@Native Function(Pointer, Pointer)>() external Pointer dividePrecision( Pointer a, Pointer b, ); -@FfiNative('free') +@Native(symbol: 'free') external void posixFree(Pointer pointer); -@FfiNative('CoTaskMemFree') +@Native(symbol: 'CoTaskMemFree') external void winCoTaskMemFree(Pointer pv); diff --git a/tests/ffi/vmspecific_ffi_native_test.dart b/tests/ffi/vmspecific_ffi_native_test.dart index 1ad52da3928..0f10ca593c0 100644 --- a/tests/ffi/vmspecific_ffi_native_test.dart +++ b/tests/ffi/vmspecific_ffi_native_test.dart @@ -20,26 +20,26 @@ final setFfiNativeResolverForTest = nativeLib.lookupFunction( 'SetFfiNativeResolverForTest'); -@FfiNative( - 'Dart_SetNativeInstanceField') +@Native( + symbol: 'Dart_SetNativeInstanceField') external Object setNativeInstanceField(Object obj, int index, int ptr); -// Basic FfiNative test functions. +// Basic Native test functions. -@FfiNative('ReturnIntPtr') +@Native(symbol: 'ReturnIntPtr') external int returnIntPtr(int x); -@FfiNative('ReturnIntPtr', isLeaf: true) +@Native(symbol: 'ReturnIntPtr', isLeaf: true) external int returnIntPtrLeaf(int x); -@FfiNative('IsThreadInGenerated') +@Native(symbol: 'IsThreadInGenerated') external int isThreadInGenerated(); -@FfiNative('IsThreadInGenerated', isLeaf: true) +@Native(symbol: 'IsThreadInGenerated', isLeaf: true) external int isThreadInGeneratedLeaf(); class Classy { - @FfiNative('ReturnIntPtr') + @Native(symbol: 'ReturnIntPtr') external static int returnIntPtrStatic(int x); } @@ -53,46 +53,49 @@ base class ClassWithNativeField extends NativeFieldWrapperClass1 { // Instance methods implicitly pass a 'self' reference as the first argument. // Passed as Pointer if the native function takes that (and the class can be // converted). - @FfiNative, IntPtr)>('AddPtrAndInt') + @Native, IntPtr)>(symbol: 'AddPtrAndInt') external int addSelfPtrAndIntMethod(int x); // Instance methods implicitly pass a 'self' reference as the first argument. // Passed as Handle if the native function takes that. - @FfiNative('AddHandleFieldAndInt') + @Native(symbol: 'AddHandleFieldAndInt') external int addSelfHandleFieldAndIntMethod(int x); - @FfiNative, Pointer)>('AddPtrAndPtr') + @Native, Pointer)>(symbol: 'AddPtrAndPtr') external int addSelfPtrAndPtrMethod(ClassWithNativeField other); - @FfiNative)>('AddHandleFieldAndPtr') + @Native)>( + symbol: 'AddHandleFieldAndPtr') external int addSelfHandleFieldAndPtrMethod(ClassWithNativeField other); - @FfiNative('AddHandleFieldAndHandleField') + @Native( + symbol: 'AddHandleFieldAndHandleField') external int addSelfHandleFieldAndHandleFieldMethod( ClassWithNativeField other); - @FfiNative, Handle)>('AddPtrAndHandleField') + @Native, Handle)>( + symbol: 'AddPtrAndHandleField') external int addselfPtrAndHandleFieldMethod(ClassWithNativeField other); } class ClassWithoutNativeField { // Instance methods implicitly pass their handle as the first arg. - @FfiNative('ReturnIntPtrMethod') + @Native(symbol: 'ReturnIntPtrMethod') external int returnIntPtrMethod(int x); } // Native function takes a Handle, so a Handle is passed as-is. -@FfiNative('PassAsHandle') +@Native(symbol: 'PassAsHandle') external int passAsHandle(NativeFieldWrapperClass1 obj); // FFI signature takes Pointer, Dart signature takes NativeFieldWrapperClass1. // This implies automatic conversion. -@FfiNative)>('PassAsPointer') +@Native)>(symbol: 'PassAsPointer') external int passAsPointer(NativeFieldWrapperClass1 obj); // Pass Pointer automatically, and return value. -@FfiNative, IntPtr)>('PassAsPointerAndValue') +@Native, IntPtr)>(symbol: 'PassAsPointerAndValue') external int passAsPointerAndValue(NativeFieldWrapperClass1 obj, int value); // Pass Pointer automatically, and return value. -@FfiNative)>('PassAsValueAndPointer') +@Native)>(symbol: 'PassAsValueAndPointer') external int passAsValueAndPointer(int value, NativeFieldWrapperClass1 obj); // Helpers for testing argument evaluation order is preserved. @@ -113,19 +116,19 @@ void main() { // Register test resolver for top-level functions above. setFfiNativeResolverForTest(getRootLibraryUrl()); - // Test we can call FfiNative functions. + // Test we can call Native functions. Expect.equals(123, returnIntPtr(123)); Expect.equals(123, returnIntPtrLeaf(123)); Expect.equals(123, Classy.returnIntPtrStatic(123)); - // Test FfiNative leaf calls remain in generated code. + // Test Native leaf calls remain in generated code. // Regular calls should transition generated -> native. Expect.equals(0, isThreadInGenerated()); // Leaf calls should remain in generated state. Expect.equals(1, isThreadInGeneratedLeaf()); // Test that objects extending NativeFieldWrapperClass1 can be passed to - // FfiNative functions that take Pointer. + // Native functions that take Pointer. // Such objects should automatically be converted and pass as Pointer. { final cwnf = ClassWithNativeField(123456); diff --git a/tests/ffi/vmspecific_static_checks_ffinative_test.dart b/tests/ffi/vmspecific_static_checks_ffinative_test.dart index de292ff1f4c..7120a13fda8 100644 --- a/tests/ffi/vmspecific_static_checks_ffinative_test.dart +++ b/tests/ffi/vmspecific_static_checks_ffinative_test.dart @@ -10,65 +10,65 @@ void main() { } // Error: FFI leaf call must not have Handle return type. -@FfiNative("foo", isLeaf: true) //# 01: compile-time error +@Native(symbol: "foo", isLeaf: true) //# 01: compile-time error external Object foo(); //# 01: compile-time error // Error: FFI leaf call must not have Handle argument types. -@FfiNative("bar", //# 02: compile-time error +@Native(symbol: "bar", //# 02: compile-time error isLeaf: true) //# 02: compile-time error external void bar(Object); //# 02: compile-time error class Classy { - // Error: Missing receiver in FfiNative annotation. - @FfiNative('doesntmatter') //# 03: compile-time error + // Error: Missing receiver in Native annotation. + @Native(symbol: 'doesntmatter') //# 03: compile-time error external void badMissingReceiver(int v); //# 03: compile-time error // Error: Class doesn't extend NativeFieldWrapperClass1 - can't be converted // to Pointer. - @FfiNative, IntPtr)>(//# 04: compile-time error - 'doesntmatter') //# 04: compile-time error + @Native, IntPtr)>(//# 04: compile-time error + symbol: 'doesntmatter') //# 04: compile-time error external void badHasReceiverPointer(int v); //# 04: compile-time error } base class NativeClassy extends NativeFieldWrapperClass1 { - // Error: Missing receiver in FfiNative annotation. - @FfiNative('doesntmatter') //# 05: compile-time error + // Error: Missing receiver in Native annotation. + @Native(symbol: 'doesntmatter') //# 05: compile-time error external void badMissingReceiver(int v); //# 05: compile-time error // Error: wrong return type. - @FfiNative, Uint32, Uint32, Handle)>('doesntmatter') //# 49471: compile-time error + @Native, Uint32, Uint32, Handle)>(symbol: 'doesntmatter') //# 49471: compile-time error external void toImageSync(int width, int height, Object outImage); //# 49471: compile-time error } -// Error: Too many FfiNative parameters. -@FfiNative(//# 06: compile-time error - 'doesntmatter') //# 06: compile-time error +// Error: Too many Native parameters. +@Native(//# 06: compile-time error + symbol: 'doesntmatter') //# 06: compile-time error external Object badTooManyFfiParameter(int v); //# 06: compile-time error -// Error: Too few FfiNative parameters. -@FfiNative('doesntmatter') //# 07: compile-time error +// Error: Too few Native parameters. +@Native(symbol: 'doesntmatter') //# 07: compile-time error external Object badTooFewFfiParameter(int v, int v2); //# 07: compile-time error -// Error: FfiNatives must be marked external (and by extension have no body). -@FfiNative('doesntmatter') //# 08: compile-time error +// Error: Natives must be marked external (and by extension have no body). +@Native(symbol: 'doesntmatter') //# 08: compile-time error void mustBeMarkedExternal() {} //# 08: compile-time error -// Error: 'FfiNative' can't be declared with optional parameters. -@FfiNative('doesntmatter') //# 12: compile-time error +// Error: 'Native' can't be declared with optional parameters. +@Native(symbol: 'doesntmatter') //# 12: compile-time error external static int badOptParam(); //# 12: compile-time error -// Error: 'FfiNative' can't be declared with named parameters. -@FfiNative('doesntmatter') //# 13: compile-time error +// Error: 'Native' can't be declared with named parameters. +@Native(symbol: 'doesntmatter') //# 13: compile-time error external static int badNamedParam(); //# 13: compile-time error -@FfiNative('doesntmatter') //# 14: compile-time error +@Native(symbol: 'doesntmatter') //# 14: compile-time error external int wrongFfiParameter(int v); //# 14: compile-time error -@FfiNative('doesntmatter') //# 15: compile-time error +@Native(symbol: 'doesntmatter') //# 15: compile-time error external double wrongFfiReturnType(int v); //# 15: compile-time error -@FfiNative('doesntmatter') //# 16: compile-time error +@Native(symbol: 'doesntmatter') //# 16: compile-time error external int nonFfiParameter(int v); //# 16: compile-time error -@FfiNative('doesntmatter') //# 17: compile-time error +@Native(symbol: 'doesntmatter') //# 17: compile-time error external double nonFfiReturnType(int v); //# 17: compile-time error