Commit 6c5d7c2a authored by Austin Eng's avatar Austin Eng Committed by Commit Bot

[fastcall] Remove unused / unsupported APIs from the interface

- Remove unused type inference paths which will be replaced
  with more explicit structs.
- Removes the tagged pointer from CTypeInfo since the embedder
  will perform the type check for API objects.

Bug: chromium:1052746
Change-Id: I47a5f5ae35b06845b01b68cb089c67f76a7fb05e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2686685
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72848}
parent 44ee4a9f
......@@ -193,7 +193,7 @@ namespace v8 {
class CTypeInfo {
public:
enum class Type : char {
enum class Type : uint8_t {
kVoid,
kBool,
kInt32,
......@@ -205,57 +205,31 @@ class CTypeInfo {
kV8Value,
};
// kCallbackOptionsType and kInvalidType are not part of the Type enum
// because they are only used internally. Use values 255 and 254 that
// are larger than any valid Type enum.
static constexpr Type kCallbackOptionsType = Type(255);
static constexpr Type kInvalidType = Type(254);
enum class ArgFlags : uint8_t {
kNone = 0,
kIsArrayBit = 1 << 0, // This argument is first in an array of values.
};
static CTypeInfo FromWrapperType(ArgFlags flags = ArgFlags::kNone) {
return CTypeInfo(static_cast<int>(flags) | kIsWrapperTypeBit);
}
static constexpr CTypeInfo FromCType(Type ctype,
ArgFlags flags = ArgFlags::kNone) {
// TODO(mslekova): Refactor the manual bit manipulations to use
// PointerWithPayload instead.
// ctype cannot be Type::kV8Value.
return CTypeInfo(
((static_cast<uintptr_t>(ctype) << kTypeOffset) & kTypeMask) |
static_cast<int>(flags));
}
explicit constexpr CTypeInfo(Type type, ArgFlags flags = ArgFlags::kNone)
: type_(type), flags_(flags) {}
const void* GetWrapperInfo() const;
constexpr Type GetType() const {
if (payload_ & kIsWrapperTypeBit) {
return Type::kV8Value;
}
return static_cast<Type>((payload_ & kTypeMask) >> kTypeOffset);
}
constexpr Type GetType() const { return type_; }
constexpr bool IsArray() const {
return payload_ & static_cast<int>(ArgFlags::kIsArrayBit);
}
constexpr ArgFlags GetFlags() const { return flags_; }
static const CTypeInfo& Invalid() {
static CTypeInfo invalid = CTypeInfo(0);
static CTypeInfo invalid = CTypeInfo(kInvalidType);
return invalid;
}
private:
explicit constexpr CTypeInfo(uintptr_t payload) : payload_(payload) {}
// That must be the last bit after ArgFlags.
static constexpr uintptr_t kIsWrapperTypeBit = 1 << 1;
static constexpr uintptr_t kWrapperTypeInfoMask = static_cast<uintptr_t>(~0)
<< 2;
static constexpr unsigned int kTypeOffset = kIsWrapperTypeBit;
static constexpr unsigned int kTypeSize = 8 - kTypeOffset;
static constexpr uintptr_t kTypeMask =
(~(static_cast<uintptr_t>(~0) << kTypeSize)) << kTypeOffset;
const uintptr_t payload_;
Type type_;
ArgFlags flags_;
};
class CFunctionInfo {
......@@ -299,17 +273,13 @@ struct FastApiCallbackOptions {
namespace internal {
template <typename T>
struct GetCType {
static constexpr CTypeInfo Get() {
return CTypeInfo::FromCType(CTypeInfo::Type::kV8Value);
}
};
struct GetCType;
#define SPECIALIZE_GET_C_TYPE_FOR(ctype, ctypeinfo) \
template <> \
struct GetCType<ctype> { \
static constexpr CTypeInfo Get() { \
return CTypeInfo::FromCType(CTypeInfo::Type::ctypeinfo); \
return CTypeInfo(CTypeInfo::Type::ctypeinfo); \
} \
};
......@@ -326,41 +296,13 @@ struct GetCType {
SUPPORTED_C_TYPES(SPECIALIZE_GET_C_TYPE_FOR)
// T* where T is a primitive (array of primitives).
template <typename T, typename = void>
struct GetCTypePointerImpl {
template <>
struct GetCType<FastApiCallbackOptions&> {
static constexpr CTypeInfo Get() {
return CTypeInfo::FromCType(GetCType<T>::Get().GetType(),
CTypeInfo::ArgFlags::kIsArrayBit);
return CTypeInfo(CTypeInfo::kCallbackOptionsType);
}
};
// T* where T is an API object.
template <typename T>
struct GetCTypePointerImpl<T, void> {
static constexpr CTypeInfo Get() { return CTypeInfo::FromWrapperType(); }
};
// T** where T is a primitive. Not allowed.
template <typename T, typename = void>
struct GetCTypePointerPointerImpl {
static_assert(sizeof(T**) != sizeof(T**), "Unsupported type");
};
// T** where T is an API object (array of API objects).
template <typename T>
struct GetCTypePointerPointerImpl<T, void> {
static constexpr CTypeInfo Get() {
return CTypeInfo::FromWrapperType(CTypeInfo::ArgFlags::kIsArrayBit);
}
};
template <typename T>
struct GetCType<T**> : public GetCTypePointerPointerImpl<T> {};
template <typename T>
struct GetCType<T*> : public GetCTypePointerImpl<T> {};
// Helper to count the number of occurances of `T` in `List`
template <typename T, typename... List>
struct count : std::integral_constant<int, 0> {};
......
......@@ -9963,32 +9963,10 @@ void EmbedderHeapTracer::ResetHandleInNonTracingGC(
UNREACHABLE();
}
const void* CTypeInfo::GetWrapperInfo() const {
DCHECK(payload_ & kWrapperTypeInfoMask);
return reinterpret_cast<const void*>(payload_ & kWrapperTypeInfoMask);
}
CFunction::CFunction(const void* address, const CFunctionInfo* type_info)
: address_(address), type_info_(type_info) {
CHECK_NOT_NULL(address_);
CHECK_NOT_NULL(type_info_);
for (unsigned int i = 0; i < type_info_->ArgumentCount(); ++i) {
if (type_info_->ArgumentInfo(i).IsArray()) {
// Array args require an integer passed for their length
// as the next argument.
DCHECK_LT(i + 1, type_info_->ArgumentCount());
switch (type_info_->ArgumentInfo(i + 1).GetType()) {
case CTypeInfo::Type::kInt32:
case CTypeInfo::Type::kUint32:
case CTypeInfo::Type::kInt64:
case CTypeInfo::Type::kUint64:
break;
default:
UNREACHABLE();
break;
}
}
}
}
RegisterState::RegisterState()
......
......@@ -27934,7 +27934,7 @@ void CallWithUnexpectedObjectType(v8::Local<v8::Value> receiver) {
class TestCFunctionInfo : public v8::CFunctionInfo {
const v8::CTypeInfo& ReturnInfo() const override {
static v8::CTypeInfo return_info =
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kVoid);
v8::CTypeInfo(v8::CTypeInfo::Type::kVoid);
return return_info;
}
......@@ -27942,9 +27942,8 @@ class TestCFunctionInfo : public v8::CFunctionInfo {
const v8::CTypeInfo& ArgumentInfo(unsigned int index) const override {
static v8::CTypeInfo type_info0 =
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kV8Value);
static v8::CTypeInfo type_info1 =
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kBool);
v8::CTypeInfo(v8::CTypeInfo::Type::kV8Value);
static v8::CTypeInfo type_info1 = v8::CTypeInfo(v8::CTypeInfo::Type::kBool);
switch (index) {
case 0:
return type_info0;
......@@ -3922,10 +3922,12 @@ namespace {
struct FastApiReceiver {
static void FastCallback(v8::ApiObject receiver, int argument,
int* fallback) {
v8::FastApiCallbackOptions& options) {
// TODO(mslekova): The fallback is not used by the test. Replace this
// with a CHECK.
v8::Object* receiver_obj = reinterpret_cast<v8::Object*>(&receiver);
if (!IsValidUnwrapObject(receiver_obj)) {
*fallback = 1;
options.fallback = 1;
return;
}
FastApiReceiver* receiver_ptr =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment