Skip to content

Commit c219a76

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
Reland "[vm/ffi] Implement FFI callbacks on AOT for ELF and Asm snapshots (excl. blobs)."
The original change is in Patchset 1. The dependency contains the fix for the non-bare-instructions bot. Change-Id: Iab02ab0736a2ee9144b667d2777ca526341b2a36 Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-android-release-arm-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-bare-linux-release-x64-try,vm-kernel-precomp-mac-debug-simarm_x64-try,vm-kernel-precomp-win-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115241 Commit-Queue: Samir Jindel <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent 6a8c988 commit c219a76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2131
-375
lines changed

pkg/front_end/lib/src/api_unstable/vm.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,23 @@ export '../fasta/fasta_codes.dart'
4040
show
4141
LocatedMessage,
4242
messageBytecodeLimitExceededTooManyArguments,
43+
messageFfiExceptionalReturnNull,
44+
messageFfiExpectedConstant,
4345
noLength,
46+
templateFfiDartTypeMismatch,
47+
templateFfiExpectedExceptionalReturn,
48+
templateFfiExpectedNoExceptionalReturn,
49+
templateFfiExtendsOrImplementsSealedClass,
4450
templateFfiFieldAnnotation,
51+
templateFfiFieldInitializer,
4552
templateFfiFieldNoAnnotation,
4653
templateFfiNotStatic,
54+
templateFfiStructGeneric,
4755
templateFfiTypeInvalid,
4856
templateFfiTypeMismatch,
4957
templateFfiTypeUnsized,
50-
templateFfiFieldInitializer,
51-
templateIllegalRecursiveType,
52-
templateFfiDartTypeMismatch,
53-
templateFfiExtendsOrImplementsSealedClass,
54-
templateFfiStructGeneric,
55-
templateFfiWrongStructInheritance;
58+
templateFfiWrongStructInheritance,
59+
templateIllegalRecursiveType;
5660

5761
export '../fasta/hybrid_file_system.dart' show HybridFileSystem;
5862

pkg/front_end/lib/src/fasta/fasta_codes_generated.dart

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,6 +3743,81 @@ Message _withArgumentsFfiDartTypeMismatch(DartType _type, DartType _type2) {
37433743
arguments: {'type': _type, 'type2': _type2});
37443744
}
37453745

3746+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3747+
const Code<Null> codeFfiExceptionalReturnNull = messageFfiExceptionalReturnNull;
3748+
3749+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3750+
const MessageCode messageFfiExceptionalReturnNull = const MessageCode(
3751+
"FfiExceptionalReturnNull",
3752+
message: r"""Exceptional return value must not be null.""");
3753+
3754+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3755+
const Code<Null> codeFfiExpectedConstant = messageFfiExpectedConstant;
3756+
3757+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3758+
const MessageCode messageFfiExpectedConstant = const MessageCode(
3759+
"FfiExpectedConstant",
3760+
message: r"""Exceptional return value must be a constant.""");
3761+
3762+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3763+
const Template<
3764+
Message Function(
3765+
DartType
3766+
_type)> templateFfiExpectedExceptionalReturn = const Template<
3767+
Message Function(DartType _type)>(
3768+
messageTemplate:
3769+
r"""Expected an exceptional return value for a native callback returning '#type'.""",
3770+
withArguments: _withArgumentsFfiExpectedExceptionalReturn);
3771+
3772+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3773+
const Code<Message Function(DartType _type)> codeFfiExpectedExceptionalReturn =
3774+
const Code<Message Function(DartType _type)>(
3775+
"FfiExpectedExceptionalReturn",
3776+
templateFfiExpectedExceptionalReturn,
3777+
);
3778+
3779+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3780+
Message _withArgumentsFfiExpectedExceptionalReturn(DartType _type) {
3781+
TypeLabeler labeler = new TypeLabeler();
3782+
List<Object> typeParts = labeler.labelType(_type);
3783+
String type = typeParts.join();
3784+
return new Message(codeFfiExpectedExceptionalReturn,
3785+
message:
3786+
"""Expected an exceptional return value for a native callback returning '${type}'.""" +
3787+
labeler.originMessages,
3788+
arguments: {'type': _type});
3789+
}
3790+
3791+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3792+
const Template<
3793+
Message Function(
3794+
DartType
3795+
_type)> templateFfiExpectedNoExceptionalReturn = const Template<
3796+
Message Function(DartType _type)>(
3797+
messageTemplate:
3798+
r"""Exceptional return value cannot be provided for a native callback returning '#type'.""",
3799+
withArguments: _withArgumentsFfiExpectedNoExceptionalReturn);
3800+
3801+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3802+
const Code<Message Function(DartType _type)>
3803+
codeFfiExpectedNoExceptionalReturn =
3804+
const Code<Message Function(DartType _type)>(
3805+
"FfiExpectedNoExceptionalReturn",
3806+
templateFfiExpectedNoExceptionalReturn,
3807+
);
3808+
3809+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3810+
Message _withArgumentsFfiExpectedNoExceptionalReturn(DartType _type) {
3811+
TypeLabeler labeler = new TypeLabeler();
3812+
List<Object> typeParts = labeler.labelType(_type);
3813+
String type = typeParts.join();
3814+
return new Message(codeFfiExpectedNoExceptionalReturn,
3815+
message:
3816+
"""Exceptional return value cannot be provided for a native callback returning '${type}'.""" +
3817+
labeler.originMessages,
3818+
arguments: {'type': _type});
3819+
}
3820+
37463821
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
37473822
const Template<Message Function(String name)>
37483823
templateFfiExtendsOrImplementsSealedClass =
@@ -3773,7 +3848,7 @@ const Template<
37733848
Message Function(String name)> templateFfiFieldAnnotation = const Template<
37743849
Message Function(String name)>(
37753850
messageTemplate:
3776-
r"""Field '#name' requires exactly one annotation to declare its C++ type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields.""",
3851+
r"""Field '#name' requires exactly one annotation to declare its native type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields.""",
37773852
withArguments: _withArgumentsFfiFieldAnnotation);
37783853

37793854
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -3789,7 +3864,7 @@ Message _withArgumentsFfiFieldAnnotation(String name) {
37893864
name = demangleMixinApplicationName(name);
37903865
return new Message(codeFfiFieldAnnotation,
37913866
message:
3792-
"""Field '${name}' requires exactly one annotation to declare its C++ type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields.""",
3867+
"""Field '${name}' requires exactly one annotation to declare its native type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields.""",
37933868
arguments: {'name': name});
37943869
}
37953870

@@ -3825,7 +3900,7 @@ const Template<
38253900
name)> templateFfiFieldNoAnnotation = const Template<
38263901
Message Function(String name)>(
38273902
messageTemplate:
3828-
r"""Field '#name' requires no annotation to declare its C++ type, it is a Pointer which is represented by the same type in Dart and C++.""",
3903+
r"""Field '#name' requires no annotation to declare its native type, it is a Pointer which is represented by the same type in Dart and native code.""",
38293904
withArguments: _withArgumentsFfiFieldNoAnnotation);
38303905

38313906
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -3841,7 +3916,7 @@ Message _withArgumentsFfiFieldNoAnnotation(String name) {
38413916
name = demangleMixinApplicationName(name);
38423917
return new Message(codeFfiFieldNoAnnotation,
38433918
message:
3844-
"""Field '${name}' requires no annotation to declare its C++ type, it is a Pointer which is represented by the same type in Dart and C++.""",
3919+
"""Field '${name}' requires no annotation to declare its native type, it is a Pointer which is represented by the same type in Dart and native code.""",
38453920
arguments: {'name': name});
38463921
}
38473922

@@ -3850,7 +3925,7 @@ const Template<
38503925
Message Function(String name)> templateFfiNotStatic = const Template<
38513926
Message Function(String name)>(
38523927
messageTemplate:
3853-
r"""#name expects a static function as parameter. dart:ffi only supports calling static Dart functions from c.""",
3928+
r"""#name expects a static function as parameter. dart:ffi only supports calling static Dart functions from native code.""",
38543929
withArguments: _withArgumentsFfiNotStatic);
38553930

38563931
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -3866,7 +3941,7 @@ Message _withArgumentsFfiNotStatic(String name) {
38663941
name = demangleMixinApplicationName(name);
38673942
return new Message(codeFfiNotStatic,
38683943
message:
3869-
"""${name} expects a static function as parameter. dart:ffi only supports calling static Dart functions from c.""",
3944+
"""${name} expects a static function as parameter. dart:ffi only supports calling static Dart functions from native code.""",
38703945
arguments: {'name': name});
38713946
}
38723947

pkg/front_end/messages.status

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ FfiDartTypeMismatch/analyzerCode: Fail
264264
FfiExtendsOrImplementsSealedClass/analyzerCode: Fail
265265
FfiStructGeneric/analyzerCode: Fail
266266
FfiWrongStructInheritance/analyzerCode: Fail
267+
FfiExpectedExceptionalReturn/analyzerCode: Fail
268+
FfiExpectedNoExceptionalReturn/analyzerCode: Fail
269+
FfiExpectedConstant/analyzerCode: Fail
270+
FfiExceptionalReturnNull/analyzerCode: Fail
267271
FieldInitializedOutsideDeclaringClass/part_wrapped_script1: Fail
268272
FieldInitializedOutsideDeclaringClass/script1: Fail
269273
FieldInitializerOutsideConstructor/part_wrapped_script1: Fail

pkg/front_end/messages.yaml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,17 +3478,17 @@ FfiTypeUnsized:
34783478

34793479
FfiFieldAnnotation:
34803480
# Used by dart:ffi
3481-
template: "Field '#name' requires exactly one annotation to declare its C++ type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields."
3481+
template: "Field '#name' requires exactly one annotation to declare its native type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields."
34823482
external: test/ffi_test.dart
34833483

34843484
FfiFieldNoAnnotation:
34853485
# Used by dart:ffi
3486-
template: "Field '#name' requires no annotation to declare its C++ type, it is a Pointer which is represented by the same type in Dart and C++."
3486+
template: "Field '#name' requires no annotation to declare its native type, it is a Pointer which is represented by the same type in Dart and native code."
34873487
external: test/ffi_test.dart
34883488

34893489
FfiNotStatic:
34903490
# Used by dart:ffi
3491-
template: "#name expects a static function as parameter. dart:ffi only supports calling static Dart functions from c."
3491+
template: "#name expects a static function as parameter. dart:ffi only supports calling static Dart functions from native code."
34923492
external: test/ffi_test.dart
34933493

34943494
FfiFieldInitializer:
@@ -3516,6 +3516,26 @@ FfiDartTypeMismatch:
35163516
template: "Expected '#type' to be a subtype of '#type2'."
35173517
external: test/ffi_test.dart
35183518

3519+
FfiExpectedExceptionalReturn:
3520+
# Used by dart:ffi
3521+
template: "Expected an exceptional return value for a native callback returning '#type'."
3522+
external: test/ffi_test.dart
3523+
3524+
FfiExpectedNoExceptionalReturn:
3525+
# Used by dart:ffi
3526+
template: "Exceptional return value cannot be provided for a native callback returning '#type'."
3527+
external: test/ffi_test.dart
3528+
3529+
FfiExpectedConstant:
3530+
# Used by dart:ffi
3531+
template: "Exceptional return value must be a constant."
3532+
external: test/ffi_test.dart
3533+
3534+
FfiExceptionalReturnNull:
3535+
# Used by dart:ffi
3536+
template: "Exceptional return value must not be null."
3537+
external: test/ffi_test.dart
3538+
35193539
SpreadTypeMismatch:
35203540
template: "Unexpected type '#type' of a spread. Expected 'dynamic' or an Iterable."
35213541
script:

pkg/front_end/test/spell_checking_list_common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ examples
939939
exceeded
940940
except
941941
exception
942+
exceptional
942943
exceptions
943944
exclamation
944945
exclude

pkg/vm/lib/transformations/ffi.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class FfiTransformer extends Transformer {
186186
final Constructor structFromPointer;
187187
final Procedure libraryLookupMethod;
188188
final Procedure abiMethod;
189+
final Procedure pointerFromFunctionProcedure;
190+
final Procedure nativeCallbackFunctionProcedure;
189191

190192
/// Classes corresponding to [NativeType], indexed by [NativeType].
191193
final List<Class> nativeTypesClasses;
@@ -220,6 +222,10 @@ class FfiTransformer extends Transformer {
220222
libraryLookupMethod =
221223
index.getMember('dart:ffi', 'DynamicLibrary', 'lookup'),
222224
abiMethod = index.getTopLevelMember('dart:ffi', '_abi'),
225+
pointerFromFunctionProcedure =
226+
index.getTopLevelMember('dart:ffi', '_pointerFromFunction'),
227+
nativeCallbackFunctionProcedure =
228+
index.getTopLevelMember('dart:ffi', '_nativeCallbackFunction'),
223229
nativeTypesClasses = nativeTypeClassNames
224230
.map((name) => index.getClass('dart:ffi', name))
225231
.toList();

0 commit comments

Comments
 (0)