Skip to content

Commit e5732b1

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[vm/ffi] Remove VM sizeOf runtime entry
After changing `elementAt` and `sizeOf` to only accept static types (https://dart-review.googlesource.com/c/sdk/+/178200) and rewrite all the calls with static types in the CFE (https://dart-review.googlesource.com/c/sdk/+/182262), the runtime entry can now be removed. One less place where the runtime relies on `Struct` subtypes not being tree shaken. Issue: #38721 Because we're no longer using `NativeType`s in a RTE to calculate their size, these do no longer need to be available in the precompiled runtime. Closes: #42809 TEST=tests/ffi(_2)/* Change-Id: I8682a3bb4d2dc3ee71531cf71909e47489e96f12 Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64-try,vm-ffi-android-debug-arm-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185085 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Clement Skau <[email protected]>
1 parent 3593de9 commit e5732b1

File tree

3 files changed

+2
-50
lines changed

3 files changed

+2
-50
lines changed

runtime/lib/ffi.cc

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "vm/bootstrap_natives.h"
1212
#include "vm/class_finalizer.h"
1313
#include "vm/class_id.h"
14-
#include "vm/compiler/ffi/native_type.h"
1514
#include "vm/exceptions.h"
1615
#include "vm/flags.h"
1716
#include "vm/log.h"
@@ -30,45 +29,6 @@
3029

3130
namespace dart {
3231

33-
// The following functions are runtime checks on type arguments.
34-
// Some checks are also performed in kernel transformation, these are asserts.
35-
// Some checks are only performed at runtime to allow for generic code, these
36-
// throw ArgumentExceptions.
37-
38-
static void CheckSized(const AbstractType& type_arg) {
39-
const classid_t type_cid = type_arg.type_class_id();
40-
if (IsFfiNativeTypeTypeClassId(type_cid) || IsFfiTypeVoidClassId(type_cid) ||
41-
IsFfiTypeNativeFunctionClassId(type_cid)) {
42-
const String& error = String::Handle(String::NewFormatted(
43-
"%s does not have a predefined size (@unsized). "
44-
"Unsized NativeTypes do not support [sizeOf] because their size "
45-
"is unknown. "
46-
"Consequently, [allocate], [Pointer.load], [Pointer.store], and "
47-
"[Pointer.elementAt] are not available.",
48-
String::Handle(type_arg.UserVisibleName()).ToCString()));
49-
Exceptions::ThrowArgumentError(error);
50-
}
51-
}
52-
53-
// Calculate the size of a native type.
54-
//
55-
// You must check [IsConcreteNativeType] and [CheckSized] first to verify that
56-
// this type has a defined size.
57-
static size_t SizeOf(Zone* zone, const AbstractType& type) {
58-
if (IsFfiTypeClassId(type.type_class_id())) {
59-
return compiler::ffi::NativeType::FromAbstractType(zone, type)
60-
.SizeInBytes();
61-
} else {
62-
Class& struct_class = Class::Handle(type.type_class());
63-
Object& result = Object::Handle(
64-
struct_class.InvokeGetter(Symbols::SizeOfStructField(),
65-
/*throw_nsm_if_absent=*/false,
66-
/*respect_reflectable=*/false));
67-
ASSERT(!result.IsNull() && result.IsInteger());
68-
return Integer::Cast(result).AsInt64Value();
69-
}
70-
}
71-
7232
// The remainder of this file implements the dart:ffi native methods.
7333

7434
DEFINE_NATIVE_ENTRY(Ffi_fromAddress, 1, 1) {
@@ -101,13 +61,6 @@ DEFINE_NATIVE_ENTRY(Ffi_storePointer, 0, 3) {
10161
UNREACHABLE();
10262
}
10363

104-
DEFINE_NATIVE_ENTRY(Ffi_sizeOf, 1, 0) {
105-
GET_NATIVE_TYPE_ARGUMENT(type_arg, arguments->NativeTypeArgAt(0));
106-
CheckSized(type_arg);
107-
108-
return Integer::New(SizeOf(zone, type_arg));
109-
}
110-
11164
// Static invocations to this method are translated directly in streaming FGB.
11265
DEFINE_NATIVE_ENTRY(Ffi_asFunctionInternal, 2, 1) {
11366
UNREACHABLE();

runtime/vm/bootstrap_natives.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ namespace dart {
405405
V(Ffi_storePointer, 3) \
406406
V(Ffi_address, 1) \
407407
V(Ffi_fromAddress, 1) \
408-
V(Ffi_sizeOf, 0) \
409408
V(Ffi_asFunctionInternal, 1) \
410409
V(Ffi_nativeCallbackFunction, 2) \
411410
V(Ffi_pointerFromFunction, 1) \

runtime/vm/compiler/compiler_sources.gni

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ compiler_sources = [
107107
"ffi/native_calling_convention.h",
108108
"ffi/native_location.cc",
109109
"ffi/native_location.h",
110+
"ffi/native_type.cc",
111+
"ffi/native_type.h",
110112
"ffi/recognized_method.cc",
111113
"ffi/recognized_method.h",
112114
"frontend/base_flow_graph_builder.cc",
@@ -189,8 +191,6 @@ compiler_api_sources = [
189191
"api/print_filter.cc",
190192
"api/print_filter.h",
191193
"api/type_check_mode.h",
192-
"ffi/native_type.cc",
193-
"ffi/native_type.h",
194194
"jit/compiler.cc",
195195
"jit/compiler.h",
196196
"runtime_api.cc",

0 commit comments

Comments
 (0)