Skip to content

Commit 205b90f

Browse files
sjindel-googlecommit-bot@chromium.org
authored andcommitted
Take 3 for '[vm/ffi] Implement FFI callbacks on AOT for ELF and Asm snapshots (excl. blobs).'
Fixes the changes to assembly snapshot writer in SIMARM_X64 mode. This unfortunately can't be tested until the ELF loader is available. Take 2 is in patchset 1. Change-Id: Ib8b067dd4f09dcba3b142705e9cb4dfbf4e3eb53 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117726 Commit-Queue: Samir Jindel <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent 3731cfd commit 205b90f

Some content is hidden

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

58 files changed

+2119
-361
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
@@ -3754,6 +3754,81 @@ Message _withArgumentsFfiDartTypeMismatch(DartType _type, DartType _type2) {
37543754
arguments: {'type': _type, 'type2': _type2});
37553755
}
37563756

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

37903865
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -3800,7 +3875,7 @@ Message _withArgumentsFfiFieldAnnotation(String name) {
38003875
name = demangleMixinApplicationName(name);
38013876
return new Message(codeFfiFieldAnnotation,
38023877
message:
3803-
"""Field '${name}' requires exactly one annotation to declare its C++ type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields.""",
3878+
"""Field '${name}' requires exactly one annotation to declare its native type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields.""",
38043879
arguments: {'name': name});
38053880
}
38063881

@@ -3836,7 +3911,7 @@ const Template<
38363911
name)> templateFfiFieldNoAnnotation = const Template<
38373912
Message Function(String name)>(
38383913
messageTemplate:
3839-
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++.""",
3914+
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.""",
38403915
withArguments: _withArgumentsFfiFieldNoAnnotation);
38413916

38423917
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -3852,7 +3927,7 @@ Message _withArgumentsFfiFieldNoAnnotation(String name) {
38523927
name = demangleMixinApplicationName(name);
38533928
return new Message(codeFfiFieldNoAnnotation,
38543929
message:
3855-
"""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++.""",
3930+
"""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.""",
38563931
arguments: {'name': name});
38573932
}
38583933

@@ -3861,7 +3936,7 @@ const Template<
38613936
Message Function(String name)> templateFfiNotStatic = const Template<
38623937
Message Function(String name)>(
38633938
messageTemplate:
3864-
r"""#name expects a static function as parameter. dart:ffi only supports calling static Dart functions from c.""",
3939+
r"""#name expects a static function as parameter. dart:ffi only supports calling static Dart functions from native code.""",
38653940
withArguments: _withArgumentsFfiNotStatic);
38663941

38673942
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -3877,7 +3952,7 @@ Message _withArgumentsFfiNotStatic(String name) {
38773952
name = demangleMixinApplicationName(name);
38783953
return new Message(codeFfiNotStatic,
38793954
message:
3880-
"""${name} expects a static function as parameter. dart:ffi only supports calling static Dart functions from c.""",
3955+
"""${name} expects a static function as parameter. dart:ffi only supports calling static Dart functions from native code.""",
38813956
arguments: {'name': name});
38823957
}
38833958

pkg/front_end/messages.status

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

pkg/front_end/messages.yaml

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

34943494
FfiFieldAnnotation:
34953495
# Used by dart:ffi
3496-
template: "Field '#name' requires exactly one annotation to declare its C++ type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields."
3496+
template: "Field '#name' requires exactly one annotation to declare its native type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields."
34973497
external: test/ffi_test.dart
34983498

34993499
FfiFieldNoAnnotation:
35003500
# Used by dart:ffi
3501-
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++."
3501+
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."
35023502
external: test/ffi_test.dart
35033503

35043504
FfiNotStatic:
35053505
# Used by dart:ffi
3506-
template: "#name expects a static function as parameter. dart:ffi only supports calling static Dart functions from c."
3506+
template: "#name expects a static function as parameter. dart:ffi only supports calling static Dart functions from native code."
35073507
external: test/ffi_test.dart
35083508

35093509
FfiFieldInitializer:
@@ -3531,6 +3531,26 @@ FfiDartTypeMismatch:
35313531
template: "Expected '#type' to be a subtype of '#type2'."
35323532
external: test/ffi_test.dart
35333533

3534+
FfiExpectedExceptionalReturn:
3535+
# Used by dart:ffi
3536+
template: "Expected an exceptional return value for a native callback returning '#type'."
3537+
external: test/ffi_test.dart
3538+
3539+
FfiExpectedNoExceptionalReturn:
3540+
# Used by dart:ffi
3541+
template: "Exceptional return value cannot be provided for a native callback returning '#type'."
3542+
external: test/ffi_test.dart
3543+
3544+
FfiExpectedConstant:
3545+
# Used by dart:ffi
3546+
template: "Exceptional return value must be a constant."
3547+
external: test/ffi_test.dart
3548+
3549+
FfiExceptionalReturnNull:
3550+
# Used by dart:ffi
3551+
template: "Exceptional return value must not be null."
3552+
external: test/ffi_test.dart
3553+
35343554
SpreadTypeMismatch:
35353555
template: "Unexpected type '#type' of a spread. Expected 'dynamic' or an Iterable."
35363556
script:

pkg/front_end/test/spell_checking_list_common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ examples
942942
exceeded
943943
except
944944
exception
945+
exceptional
945946
exceptions
946947
exclamation
947948
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)