[vm/ffi] Remove `.ref` VM runtime entry
After https://dart-review.googlesource.com/c/sdk/+/180190 the runtime
entry has become dead code.
This CL keeps the runtime entry itself but makes it unreachable as was
the suggestion on previous a CL removing runtime entries:
https://dart-review.googlesource.com/c/sdk/+/169406
Bug: https://github.com/dart-lang/sdk/issues/38648
Bug: https://github.com/dart-lang/sdk/issues/38721
TEST=tests/ffi/vmspecific_static_checks_test.dart
TEST=tests/ffi/*struct*test_.dart
Change-Id: I84c5c925215b9dbd999826fb390df91d8050e1dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182627
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
diff --git a/pkg/vm/lib/transformations/ffi.dart b/pkg/vm/lib/transformations/ffi.dart
index 1c16b1b..5ead392 100644
--- a/pkg/vm/lib/transformations/ffi.dart
+++ b/pkg/vm/lib/transformations/ffi.dart
@@ -237,7 +237,6 @@
final Map<NativeType, Procedure> loadMethods;
final Map<NativeType, Procedure> storeMethods;
final Map<NativeType, Procedure> elementAtMethods;
- final Procedure loadStructMethod;
final Procedure memCopy;
final Procedure allocationTearoff;
final Procedure asFunctionTearoff;
@@ -322,7 +321,6 @@
final name = nativeTypeClassNames[t.index];
return index.getTopLevelMember('dart:ffi', "_elementAt$name");
}),
- loadStructMethod = index.getTopLevelMember('dart:ffi', '_loadStruct'),
memCopy = index.getTopLevelMember('dart:ffi', '_memCopy'),
allocationTearoff = index.getMember(
'dart:ffi', 'AllocatorAlloc', LibraryIndex.tearoffPrefix + 'call'),
diff --git a/runtime/lib/ffi.cc b/runtime/lib/ffi.cc
index 3a6bb40..0724681 100644
--- a/runtime/lib/ffi.cc
+++ b/runtime/lib/ffi.cc
@@ -88,45 +88,8 @@
UNREACHABLE();
}
-static ObjectPtr LoadValueStruct(Zone* zone,
- const Pointer& target,
- const AbstractType& instance_type_arg) {
- // Result is a struct class -- find <class name>.#fromTypedDataBase
- // constructor and call it.
- const Class& cls = Class::Handle(zone, instance_type_arg.type_class());
- const Function& constructor =
- Function::Handle(cls.LookupFunctionAllowPrivate(String::Handle(
- String::Concat(String::Handle(String::Concat(
- String::Handle(cls.Name()), Symbols::Dot())),
- Symbols::StructFromTypedDataBase()))));
- ASSERT(!constructor.IsNull());
- ASSERT(constructor.IsGenerativeConstructor());
- ASSERT(!Object::Handle(constructor.VerifyCallEntryPoint()).IsError());
- const Instance& new_object = Instance::Handle(Instance::New(cls));
- ASSERT(cls.is_allocated() || Dart::vm_snapshot_kind() != Snapshot::kFullAOT);
- const Array& args = Array::Handle(zone, Array::New(2));
- args.SetAt(0, new_object);
- args.SetAt(1, target);
- const Object& constructorResult =
- Object::Handle(DartEntry::InvokeFunction(constructor, args));
- ASSERT(!constructorResult.IsError());
- return new_object.ptr();
-}
-
DEFINE_NATIVE_ENTRY(Ffi_loadStruct, 0, 2) {
- GET_NON_NULL_NATIVE_ARGUMENT(Pointer, pointer, arguments->NativeArgAt(0));
- const AbstractType& pointer_type_arg =
- AbstractType::Handle(arguments->NativeTypeArgAt(0));
- GET_NON_NULL_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1));
-
- // TODO(36370): Make representation consistent with kUnboxedFfiIntPtr.
- const size_t address =
- pointer.NativeAddress() + static_cast<intptr_t>(index.AsInt64Value()) *
- SizeOf(zone, pointer_type_arg);
- const Pointer& pointer_offset =
- Pointer::Handle(zone, Pointer::New(pointer_type_arg, address));
-
- return LoadValueStruct(zone, pointer_offset, pointer_type_arg);
+ UNREACHABLE();
}
#define DEFINE_NATIVE_ENTRY_STORE(type) \
diff --git a/sdk/lib/_internal/vm/lib/ffi_patch.dart b/sdk/lib/_internal/vm/lib/ffi_patch.dart
index dd18559..3a43c2b 100644
--- a/sdk/lib/_internal/vm/lib/ffi_patch.dart
+++ b/sdk/lib/_internal/vm/lib/ffi_patch.dart
@@ -204,16 +204,6 @@
Pointer<S> _loadPointer<S extends NativeType>(
Pointer pointer, int offsetInBytes) native "Ffi_loadPointer";
-S _loadStructNoStruct<S extends Struct>(Pointer<S> pointer, int index) {
- if (S == Struct) {
- throw ArgumentError("S should be a subtype of Struct.");
- }
- return _loadStruct(pointer, index);
-}
-
-S _loadStruct<S extends Struct>(Pointer<S> pointer, int index)
- native "Ffi_loadStruct";
-
@pragma("vm:recognized", "other")
void _storeInt8(Pointer pointer, int offsetInBytes, int value)
native "Ffi_storeInt8";
@@ -518,10 +508,12 @@
extension StructPointer<T extends Struct> on Pointer<T> {
@patch
- T get ref => _loadStructNoStruct(this, 0);
+ T get ref =>
+ throw "UNREACHABLE: This case should have been rewritten in the CFE.";
@patch
- T operator [](int index) => _loadStructNoStruct(this, index);
+ T operator [](int index) =>
+ throw "UNREACHABLE: This case should have been rewritten in the CFE.";
}
extension NativePort on SendPort {