Skip to content

Commit d052156

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[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: #38648 Bug: #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 <[email protected]> Commit-Queue: Daco Harkes <[email protected]>
1 parent 98d5ecb commit d052156

File tree

3 files changed

+5
-52
lines changed

3 files changed

+5
-52
lines changed

pkg/vm/lib/transformations/ffi.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ class FfiTransformer extends Transformer {
237237
final Map<NativeType, Procedure> loadMethods;
238238
final Map<NativeType, Procedure> storeMethods;
239239
final Map<NativeType, Procedure> elementAtMethods;
240-
final Procedure loadStructMethod;
241240
final Procedure memCopy;
242241
final Procedure allocationTearoff;
243242
final Procedure asFunctionTearoff;
@@ -322,7 +321,6 @@ class FfiTransformer extends Transformer {
322321
final name = nativeTypeClassNames[t.index];
323322
return index.getTopLevelMember('dart:ffi', "_elementAt$name");
324323
}),
325-
loadStructMethod = index.getTopLevelMember('dart:ffi', '_loadStruct'),
326324
memCopy = index.getTopLevelMember('dart:ffi', '_memCopy'),
327325
allocationTearoff = index.getMember(
328326
'dart:ffi', 'AllocatorAlloc', LibraryIndex.tearoffPrefix + 'call'),

runtime/lib/ffi.cc

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -88,45 +88,8 @@ DEFINE_NATIVE_ENTRY(Ffi_loadPointer, 1, 2) {
8888
UNREACHABLE();
8989
}
9090

91-
static ObjectPtr LoadValueStruct(Zone* zone,
92-
const Pointer& target,
93-
const AbstractType& instance_type_arg) {
94-
// Result is a struct class -- find <class name>.#fromTypedDataBase
95-
// constructor and call it.
96-
const Class& cls = Class::Handle(zone, instance_type_arg.type_class());
97-
const Function& constructor =
98-
Function::Handle(cls.LookupFunctionAllowPrivate(String::Handle(
99-
String::Concat(String::Handle(String::Concat(
100-
String::Handle(cls.Name()), Symbols::Dot())),
101-
Symbols::StructFromTypedDataBase()))));
102-
ASSERT(!constructor.IsNull());
103-
ASSERT(constructor.IsGenerativeConstructor());
104-
ASSERT(!Object::Handle(constructor.VerifyCallEntryPoint()).IsError());
105-
const Instance& new_object = Instance::Handle(Instance::New(cls));
106-
ASSERT(cls.is_allocated() || Dart::vm_snapshot_kind() != Snapshot::kFullAOT);
107-
const Array& args = Array::Handle(zone, Array::New(2));
108-
args.SetAt(0, new_object);
109-
args.SetAt(1, target);
110-
const Object& constructorResult =
111-
Object::Handle(DartEntry::InvokeFunction(constructor, args));
112-
ASSERT(!constructorResult.IsError());
113-
return new_object.ptr();
114-
}
115-
11691
DEFINE_NATIVE_ENTRY(Ffi_loadStruct, 0, 2) {
117-
GET_NON_NULL_NATIVE_ARGUMENT(Pointer, pointer, arguments->NativeArgAt(0));
118-
const AbstractType& pointer_type_arg =
119-
AbstractType::Handle(arguments->NativeTypeArgAt(0));
120-
GET_NON_NULL_NATIVE_ARGUMENT(Integer, index, arguments->NativeArgAt(1));
121-
122-
// TODO(36370): Make representation consistent with kUnboxedFfiIntPtr.
123-
const size_t address =
124-
pointer.NativeAddress() + static_cast<intptr_t>(index.AsInt64Value()) *
125-
SizeOf(zone, pointer_type_arg);
126-
const Pointer& pointer_offset =
127-
Pointer::Handle(zone, Pointer::New(pointer_type_arg, address));
128-
129-
return LoadValueStruct(zone, pointer_offset, pointer_type_arg);
92+
UNREACHABLE();
13093
}
13194

13295
#define DEFINE_NATIVE_ENTRY_STORE(type) \

sdk/lib/_internal/vm/lib/ffi_patch.dart

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,6 @@ double _loadDouble(Pointer pointer, int offsetInBytes) native "Ffi_loadDouble";
204204
Pointer<S> _loadPointer<S extends NativeType>(
205205
Pointer pointer, int offsetInBytes) native "Ffi_loadPointer";
206206

207-
S _loadStructNoStruct<S extends Struct>(Pointer<S> pointer, int index) {
208-
if (S == Struct) {
209-
throw ArgumentError("S should be a subtype of Struct.");
210-
}
211-
return _loadStruct(pointer, index);
212-
}
213-
214-
S _loadStruct<S extends Struct>(Pointer<S> pointer, int index)
215-
native "Ffi_loadStruct";
216-
217207
@pragma("vm:recognized", "other")
218208
void _storeInt8(Pointer pointer, int offsetInBytes, int value)
219209
native "Ffi_storeInt8";
@@ -518,10 +508,12 @@ extension PointerPointer<T extends NativeType> on Pointer<Pointer<T>> {
518508

519509
extension StructPointer<T extends Struct> on Pointer<T> {
520510
@patch
521-
T get ref => _loadStructNoStruct(this, 0);
511+
T get ref =>
512+
throw "UNREACHABLE: This case should have been rewritten in the CFE.";
522513

523514
@patch
524-
T operator [](int index) => _loadStructNoStruct(this, index);
515+
T operator [](int index) =>
516+
throw "UNREACHABLE: This case should have been rewritten in the CFE.";
525517
}
526518

527519
extension NativePort on SendPort {

0 commit comments

Comments
 (0)