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 { ...@@ -193,7 +193,7 @@ namespace v8 {
class CTypeInfo { class CTypeInfo {
public: public:
enum class Type : char { enum class Type : uint8_t {
kVoid, kVoid,
kBool, kBool,
kInt32, kInt32,
...@@ -205,57 +205,31 @@ class CTypeInfo { ...@@ -205,57 +205,31 @@ class CTypeInfo {
kV8Value, 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 { enum class ArgFlags : uint8_t {
kNone = 0, kNone = 0,
kIsArrayBit = 1 << 0, // This argument is first in an array of values.
}; };
static CTypeInfo FromWrapperType(ArgFlags flags = ArgFlags::kNone) { explicit constexpr CTypeInfo(Type type, ArgFlags flags = ArgFlags::kNone)
return CTypeInfo(static_cast<int>(flags) | kIsWrapperTypeBit); : type_(type), flags_(flags) {}
}
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));
}
const void* GetWrapperInfo() const;
constexpr Type GetType() const { constexpr Type GetType() const { return type_; }
if (payload_ & kIsWrapperTypeBit) {
return Type::kV8Value;
}
return static_cast<Type>((payload_ & kTypeMask) >> kTypeOffset);
}
constexpr bool IsArray() const { constexpr ArgFlags GetFlags() const { return flags_; }
return payload_ & static_cast<int>(ArgFlags::kIsArrayBit);
}
static const CTypeInfo& Invalid() { static const CTypeInfo& Invalid() {
static CTypeInfo invalid = CTypeInfo(0); static CTypeInfo invalid = CTypeInfo(kInvalidType);
return invalid; return invalid;
} }
private: private:
explicit constexpr CTypeInfo(uintptr_t payload) : payload_(payload) {} Type type_;
ArgFlags flags_;
// 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_;
}; };
class CFunctionInfo { class CFunctionInfo {
...@@ -299,18 +273,14 @@ struct FastApiCallbackOptions { ...@@ -299,18 +273,14 @@ struct FastApiCallbackOptions {
namespace internal { namespace internal {
template <typename T> template <typename T>
struct GetCType { struct GetCType;
static constexpr CTypeInfo Get() {
return CTypeInfo::FromCType(CTypeInfo::Type::kV8Value); #define SPECIALIZE_GET_C_TYPE_FOR(ctype, ctypeinfo) \
} template <> \
}; struct GetCType<ctype> { \
static constexpr CTypeInfo Get() { \
#define SPECIALIZE_GET_C_TYPE_FOR(ctype, ctypeinfo) \ return CTypeInfo(CTypeInfo::Type::ctypeinfo); \
template <> \ } \
struct GetCType<ctype> { \
static constexpr CTypeInfo Get() { \
return CTypeInfo::FromCType(CTypeInfo::Type::ctypeinfo); \
} \
}; };
#define SUPPORTED_C_TYPES(V) \ #define SUPPORTED_C_TYPES(V) \
...@@ -326,41 +296,13 @@ struct GetCType { ...@@ -326,41 +296,13 @@ struct GetCType {
SUPPORTED_C_TYPES(SPECIALIZE_GET_C_TYPE_FOR) SUPPORTED_C_TYPES(SPECIALIZE_GET_C_TYPE_FOR)
// T* where T is a primitive (array of primitives). template <>
template <typename T, typename = void> struct GetCType<FastApiCallbackOptions&> {
struct GetCTypePointerImpl {
static constexpr CTypeInfo Get() { static constexpr CTypeInfo Get() {
return CTypeInfo::FromCType(GetCType<T>::Get().GetType(), return CTypeInfo(CTypeInfo::kCallbackOptionsType);
CTypeInfo::ArgFlags::kIsArrayBit);
} }
}; };
// 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` // Helper to count the number of occurances of `T` in `List`
template <typename T, typename... List> template <typename T, typename... List>
struct count : std::integral_constant<int, 0> {}; struct count : std::integral_constant<int, 0> {};
......
...@@ -9963,32 +9963,10 @@ void EmbedderHeapTracer::ResetHandleInNonTracingGC( ...@@ -9963,32 +9963,10 @@ void EmbedderHeapTracer::ResetHandleInNonTracingGC(
UNREACHABLE(); 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) CFunction::CFunction(const void* address, const CFunctionInfo* type_info)
: address_(address), type_info_(type_info) { : address_(address), type_info_(type_info) {
CHECK_NOT_NULL(address_); CHECK_NOT_NULL(address_);
CHECK_NOT_NULL(type_info_); 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() RegisterState::RegisterState()
......
...@@ -27934,7 +27934,7 @@ void CallWithUnexpectedObjectType(v8::Local<v8::Value> receiver) { ...@@ -27934,7 +27934,7 @@ void CallWithUnexpectedObjectType(v8::Local<v8::Value> receiver) {
class TestCFunctionInfo : public v8::CFunctionInfo { class TestCFunctionInfo : public v8::CFunctionInfo {
const v8::CTypeInfo& ReturnInfo() const override { const v8::CTypeInfo& ReturnInfo() const override {
static v8::CTypeInfo return_info = static v8::CTypeInfo return_info =
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kVoid); v8::CTypeInfo(v8::CTypeInfo::Type::kVoid);
return return_info; return return_info;
} }
...@@ -27942,9 +27942,8 @@ class TestCFunctionInfo : public v8::CFunctionInfo { ...@@ -27942,9 +27942,8 @@ class TestCFunctionInfo : public v8::CFunctionInfo {
const v8::CTypeInfo& ArgumentInfo(unsigned int index) const override { const v8::CTypeInfo& ArgumentInfo(unsigned int index) const override {
static v8::CTypeInfo type_info0 = static v8::CTypeInfo type_info0 =
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kV8Value); v8::CTypeInfo(v8::CTypeInfo::Type::kV8Value);
static v8::CTypeInfo type_info1 = static v8::CTypeInfo type_info1 = v8::CTypeInfo(v8::CTypeInfo::Type::kBool);
v8::CTypeInfo::FromCType(v8::CTypeInfo::Type::kBool);
switch (index) { switch (index) {
case 0: case 0:
return type_info0; return type_info0;
...@@ -3922,10 +3922,12 @@ namespace { ...@@ -3922,10 +3922,12 @@ namespace {
struct FastApiReceiver { struct FastApiReceiver {
static void FastCallback(v8::ApiObject receiver, int argument, 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); v8::Object* receiver_obj = reinterpret_cast<v8::Object*>(&receiver);
if (!IsValidUnwrapObject(receiver_obj)) { if (!IsValidUnwrapObject(receiver_obj)) {
*fallback = 1; options.fallback = 1;
return; return;
} }
FastApiReceiver* receiver_ptr = 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