Skip to content

Commit

Permalink
Reland "[vm/ffi] Implement FFI callbacks on AOT for ELF and Asm snaps…
Browse files Browse the repository at this point in the history
…hots (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 <sjindel@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
  • Loading branch information
sjindel-google authored and commit-bot@chromium.org committed Sep 5, 2019
1 parent 6a8c988 commit c219a76
Show file tree
Hide file tree
Showing 57 changed files with 2,131 additions and 375 deletions.
16 changes: 10 additions & 6 deletions pkg/front_end/lib/src/api_unstable/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,23 @@ export '../fasta/fasta_codes.dart'
show
LocatedMessage,
messageBytecodeLimitExceededTooManyArguments,
messageFfiExceptionalReturnNull,
messageFfiExpectedConstant,
noLength,
templateFfiDartTypeMismatch,
templateFfiExpectedExceptionalReturn,
templateFfiExpectedNoExceptionalReturn,
templateFfiExtendsOrImplementsSealedClass,
templateFfiFieldAnnotation,
templateFfiFieldInitializer,
templateFfiFieldNoAnnotation,
templateFfiNotStatic,
templateFfiStructGeneric,
templateFfiTypeInvalid,
templateFfiTypeMismatch,
templateFfiTypeUnsized,
templateFfiFieldInitializer,
templateIllegalRecursiveType,
templateFfiDartTypeMismatch,
templateFfiExtendsOrImplementsSealedClass,
templateFfiStructGeneric,
templateFfiWrongStructInheritance;
templateFfiWrongStructInheritance,
templateIllegalRecursiveType;

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

Expand Down
87 changes: 81 additions & 6 deletions pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,81 @@ Message _withArgumentsFfiDartTypeMismatch(DartType _type, DartType _type2) {
arguments: {'type': _type, 'type2': _type2});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeFfiExceptionalReturnNull = messageFfiExceptionalReturnNull;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageFfiExceptionalReturnNull = const MessageCode(
"FfiExceptionalReturnNull",
message: r"""Exceptional return value must not be null.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeFfiExpectedConstant = messageFfiExpectedConstant;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageFfiExpectedConstant = const MessageCode(
"FfiExpectedConstant",
message: r"""Exceptional return value must be a constant.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<
Message Function(
DartType
_type)> templateFfiExpectedExceptionalReturn = const Template<
Message Function(DartType _type)>(
messageTemplate:
r"""Expected an exceptional return value for a native callback returning '#type'.""",
withArguments: _withArgumentsFfiExpectedExceptionalReturn);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Message Function(DartType _type)> codeFfiExpectedExceptionalReturn =
const Code<Message Function(DartType _type)>(
"FfiExpectedExceptionalReturn",
templateFfiExpectedExceptionalReturn,
);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Message _withArgumentsFfiExpectedExceptionalReturn(DartType _type) {
TypeLabeler labeler = new TypeLabeler();
List<Object> typeParts = labeler.labelType(_type);
String type = typeParts.join();
return new Message(codeFfiExpectedExceptionalReturn,
message:
"""Expected an exceptional return value for a native callback returning '${type}'.""" +
labeler.originMessages,
arguments: {'type': _type});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<
Message Function(
DartType
_type)> templateFfiExpectedNoExceptionalReturn = const Template<
Message Function(DartType _type)>(
messageTemplate:
r"""Exceptional return value cannot be provided for a native callback returning '#type'.""",
withArguments: _withArgumentsFfiExpectedNoExceptionalReturn);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Message Function(DartType _type)>
codeFfiExpectedNoExceptionalReturn =
const Code<Message Function(DartType _type)>(
"FfiExpectedNoExceptionalReturn",
templateFfiExpectedNoExceptionalReturn,
);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Message _withArgumentsFfiExpectedNoExceptionalReturn(DartType _type) {
TypeLabeler labeler = new TypeLabeler();
List<Object> typeParts = labeler.labelType(_type);
String type = typeParts.join();
return new Message(codeFfiExpectedNoExceptionalReturn,
message:
"""Exceptional return value cannot be provided for a native callback returning '${type}'.""" +
labeler.originMessages,
arguments: {'type': _type});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<Message Function(String name)>
templateFfiExtendsOrImplementsSealedClass =
Expand Down Expand Up @@ -3773,7 +3848,7 @@ const Template<
Message Function(String name)> templateFfiFieldAnnotation = const Template<
Message Function(String name)>(
messageTemplate:
r"""Field '#name' requires exactly one annotation to declare its C++ type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields.""",
r"""Field '#name' requires exactly one annotation to declare its native type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields.""",
withArguments: _withArgumentsFfiFieldAnnotation);

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

Expand Down Expand Up @@ -3825,7 +3900,7 @@ const Template<
name)> templateFfiFieldNoAnnotation = const Template<
Message Function(String name)>(
messageTemplate:
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++.""",
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.""",
withArguments: _withArgumentsFfiFieldNoAnnotation);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Expand All @@ -3841,7 +3916,7 @@ Message _withArgumentsFfiFieldNoAnnotation(String name) {
name = demangleMixinApplicationName(name);
return new Message(codeFfiFieldNoAnnotation,
message:
"""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++.""",
"""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.""",
arguments: {'name': name});
}

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

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

Expand Down
4 changes: 4 additions & 0 deletions pkg/front_end/messages.status
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ FfiDartTypeMismatch/analyzerCode: Fail
FfiExtendsOrImplementsSealedClass/analyzerCode: Fail
FfiStructGeneric/analyzerCode: Fail
FfiWrongStructInheritance/analyzerCode: Fail
FfiExpectedExceptionalReturn/analyzerCode: Fail
FfiExpectedNoExceptionalReturn/analyzerCode: Fail
FfiExpectedConstant/analyzerCode: Fail
FfiExceptionalReturnNull/analyzerCode: Fail
FieldInitializedOutsideDeclaringClass/part_wrapped_script1: Fail
FieldInitializedOutsideDeclaringClass/script1: Fail
FieldInitializerOutsideConstructor/part_wrapped_script1: Fail
Expand Down
26 changes: 23 additions & 3 deletions pkg/front_end/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3478,17 +3478,17 @@ FfiTypeUnsized:

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

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

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

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

FfiExpectedExceptionalReturn:
# Used by dart:ffi
template: "Expected an exceptional return value for a native callback returning '#type'."
external: test/ffi_test.dart

FfiExpectedNoExceptionalReturn:
# Used by dart:ffi
template: "Exceptional return value cannot be provided for a native callback returning '#type'."
external: test/ffi_test.dart

FfiExpectedConstant:
# Used by dart:ffi
template: "Exceptional return value must be a constant."
external: test/ffi_test.dart

FfiExceptionalReturnNull:
# Used by dart:ffi
template: "Exceptional return value must not be null."
external: test/ffi_test.dart

SpreadTypeMismatch:
template: "Unexpected type '#type' of a spread. Expected 'dynamic' or an Iterable."
script:
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/test/spell_checking_list_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ examples
exceeded
except
exception
exceptional
exceptions
exclamation
exclude
Expand Down
6 changes: 6 additions & 0 deletions pkg/vm/lib/transformations/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class FfiTransformer extends Transformer {
final Constructor structFromPointer;
final Procedure libraryLookupMethod;
final Procedure abiMethod;
final Procedure pointerFromFunctionProcedure;
final Procedure nativeCallbackFunctionProcedure;

/// Classes corresponding to [NativeType], indexed by [NativeType].
final List<Class> nativeTypesClasses;
Expand Down Expand Up @@ -220,6 +222,10 @@ class FfiTransformer extends Transformer {
libraryLookupMethod =
index.getMember('dart:ffi', 'DynamicLibrary', 'lookup'),
abiMethod = index.getTopLevelMember('dart:ffi', '_abi'),
pointerFromFunctionProcedure =
index.getTopLevelMember('dart:ffi', '_pointerFromFunction'),
nativeCallbackFunctionProcedure =
index.getTopLevelMember('dart:ffi', '_nativeCallbackFunction'),
nativeTypesClasses = nativeTypeClassNames
.map((name) => index.getClass('dart:ffi', name))
.toList();
Expand Down
Loading

0 comments on commit c219a76

Please sign in to comment.