Commit dff140dd authored by Maya Lekova's avatar Maya Lekova Committed by V8 LUCI CQ

[fastcall] Expose CTypeInfoBuilder publicly

This CL exposes the helper class publicly to facilitate sequences
implementation, as discussed in
https://chromium-review.googlesource.com/c/chromium/src/+/3111815.

Bug: chromium:1052746
Change-Id: I3f3c24412c022014fc15b563201a63ee0691f6bc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3236549
Auto-Submit: Maya Lekova <mslekova@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77568}
parent 1ca9a770
...@@ -678,17 +678,19 @@ struct TypeInfoHelper<FastApiCallbackOptions&> { ...@@ -678,17 +678,19 @@ struct TypeInfoHelper<FastApiCallbackOptions&> {
#define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG) \ #define STATIC_ASSERT_IMPLIES(COND, ASSERTION, MSG) \
static_assert(((COND) == 0) || (ASSERTION), MSG) static_assert(((COND) == 0) || (ASSERTION), MSG)
} // namespace internal
template <typename T, CTypeInfo::Flags... Flags> template <typename T, CTypeInfo::Flags... Flags>
class CTypeInfoBuilder { class V8_EXPORT CTypeInfoBuilder {
public: public:
using BaseType = T; using BaseType = T;
static constexpr CTypeInfo Build() { static constexpr CTypeInfo Build() {
constexpr CTypeInfo::Flags kFlags = constexpr CTypeInfo::Flags kFlags =
MergeFlags(TypeInfoHelper<T>::Flags(), Flags...); MergeFlags(internal::TypeInfoHelper<T>::Flags(), Flags...);
constexpr CTypeInfo::Type kType = TypeInfoHelper<T>::Type(); constexpr CTypeInfo::Type kType = internal::TypeInfoHelper<T>::Type();
constexpr CTypeInfo::SequenceType kSequenceType = constexpr CTypeInfo::SequenceType kSequenceType =
TypeInfoHelper<T>::SequenceType(); internal::TypeInfoHelper<T>::SequenceType();
STATIC_ASSERT_IMPLIES( STATIC_ASSERT_IMPLIES(
uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kAllowSharedBit), uint8_t(kFlags) & uint8_t(CTypeInfo::Flags::kAllowSharedBit),
...@@ -716,8 +718,8 @@ class CTypeInfoBuilder { ...@@ -716,8 +718,8 @@ class CTypeInfoBuilder {
"TypedArrays are only supported from primitive types or void."); "TypedArrays are only supported from primitive types or void.");
// Return the same type with the merged flags. // Return the same type with the merged flags.
return CTypeInfo(TypeInfoHelper<T>::Type(), return CTypeInfo(internal::TypeInfoHelper<T>::Type(),
TypeInfoHelper<T>::SequenceType(), kFlags); internal::TypeInfoHelper<T>::SequenceType(), kFlags);
} }
private: private:
...@@ -729,6 +731,7 @@ class CTypeInfoBuilder { ...@@ -729,6 +731,7 @@ class CTypeInfoBuilder {
static constexpr CTypeInfo::Flags MergeFlags() { return CTypeInfo::Flags(0); } static constexpr CTypeInfo::Flags MergeFlags() { return CTypeInfo::Flags(0); }
}; };
namespace internal {
template <typename RetBuilder, typename... ArgBuilders> template <typename RetBuilder, typename... ArgBuilders>
class CFunctionBuilderWithFunction { class CFunctionBuilderWithFunction {
public: public:
...@@ -858,24 +861,28 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer( ...@@ -858,24 +861,28 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer(
Local<Array> src, T* dst, uint32_t max_length); Local<Array> src, T* dst, uint32_t max_length);
template <> template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< bool V8_EXPORT V8_WARN_UNUSED_RESULT
internal::CTypeInfoBuilder<int32_t>::Build().GetId(), int32_t>( TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<int32_t>::Build().GetId(),
Local<Array> src, int32_t* dst, uint32_t max_length); int32_t>(Local<Array> src, int32_t* dst,
uint32_t max_length);
template <> template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< bool V8_EXPORT V8_WARN_UNUSED_RESULT
internal::CTypeInfoBuilder<uint32_t>::Build().GetId(), uint32_t>( TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<uint32_t>::Build().GetId(),
Local<Array> src, uint32_t* dst, uint32_t max_length); uint32_t>(Local<Array> src, uint32_t* dst,
uint32_t max_length);
template <> template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< bool V8_EXPORT V8_WARN_UNUSED_RESULT
internal::CTypeInfoBuilder<float>::Build().GetId(), float>( TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<float>::Build().GetId(),
Local<Array> src, float* dst, uint32_t max_length); float>(Local<Array> src, float* dst,
uint32_t max_length);
template <> template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< bool V8_EXPORT V8_WARN_UNUSED_RESULT
internal::CTypeInfoBuilder<double>::Build().GetId(), double>( TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<double>::Build().GetId(),
Local<Array> src, double* dst, uint32_t max_length); double>(Local<Array> src, double* dst,
uint32_t max_length);
} // namespace v8 } // namespace v8
......
...@@ -10531,9 +10531,10 @@ bool ConvertDouble(double d) { ...@@ -10531,9 +10531,10 @@ bool ConvertDouble(double d) {
} // namespace internal } // namespace internal
template <> template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< bool V8_EXPORT V8_WARN_UNUSED_RESULT
internal::CTypeInfoBuilder<int32_t>::Build().GetId(), int32_t>( TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<int32_t>::Build().GetId(),
Local<Array> src, int32_t* dst, uint32_t max_length) { int32_t>(Local<Array> src, int32_t* dst,
uint32_t max_length) {
return CopyAndConvertArrayToCppBuffer< return CopyAndConvertArrayToCppBuffer<
CTypeInfo(CTypeInfo::Type::kInt32, CTypeInfo::SequenceType::kIsSequence) CTypeInfo(CTypeInfo::Type::kInt32, CTypeInfo::SequenceType::kIsSequence)
.GetId(), .GetId(),
...@@ -10541,9 +10542,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< ...@@ -10541,9 +10542,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
} }
template <> template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< bool V8_EXPORT V8_WARN_UNUSED_RESULT
internal::CTypeInfoBuilder<uint32_t>::Build().GetId(), uint32_t>( TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<uint32_t>::Build().GetId(),
Local<Array> src, uint32_t* dst, uint32_t max_length) { uint32_t>(Local<Array> src, uint32_t* dst,
uint32_t max_length) {
return CopyAndConvertArrayToCppBuffer< return CopyAndConvertArrayToCppBuffer<
CTypeInfo(CTypeInfo::Type::kUint32, CTypeInfo::SequenceType::kIsSequence) CTypeInfo(CTypeInfo::Type::kUint32, CTypeInfo::SequenceType::kIsSequence)
.GetId(), .GetId(),
...@@ -10551,9 +10553,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< ...@@ -10551,9 +10553,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
} }
template <> template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< bool V8_EXPORT V8_WARN_UNUSED_RESULT
internal::CTypeInfoBuilder<float>::Build().GetId(), float>( TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<float>::Build().GetId(),
Local<Array> src, float* dst, uint32_t max_length) { float>(Local<Array> src, float* dst,
uint32_t max_length) {
return CopyAndConvertArrayToCppBuffer< return CopyAndConvertArrayToCppBuffer<
CTypeInfo(CTypeInfo::Type::kFloat32, CTypeInfo::SequenceType::kIsSequence) CTypeInfo(CTypeInfo::Type::kFloat32, CTypeInfo::SequenceType::kIsSequence)
.GetId(), .GetId(),
...@@ -10561,9 +10564,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< ...@@ -10561,9 +10564,10 @@ bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer<
} }
template <> template <>
bool V8_EXPORT V8_WARN_UNUSED_RESULT TryToCopyAndConvertArrayToCppBuffer< bool V8_EXPORT V8_WARN_UNUSED_RESULT
internal::CTypeInfoBuilder<double>::Build().GetId(), double>( TryToCopyAndConvertArrayToCppBuffer<CTypeInfoBuilder<double>::Build().GetId(),
Local<Array> src, double* dst, uint32_t max_length) { double>(Local<Array> src, double* dst,
uint32_t max_length) {
return CopyAndConvertArrayToCppBuffer< return CopyAndConvertArrayToCppBuffer<
CTypeInfo(CTypeInfo::Type::kFloat64, CTypeInfo::SequenceType::kIsSequence) CTypeInfo(CTypeInfo::Type::kFloat64, CTypeInfo::SequenceType::kIsSequence)
.GetId(), .GetId(),
......
...@@ -120,8 +120,7 @@ class FastCApiObject { ...@@ -120,8 +120,7 @@ class FastCApiObject {
Type buffer[1024]; Type buffer[1024];
bool result = TryToCopyAndConvertArrayToCppBuffer< bool result = TryToCopyAndConvertArrayToCppBuffer<
i::CTypeInfoBuilder<Type>::Build().GetId(), Type>(seq_arg, buffer, CTypeInfoBuilder<Type>::Build().GetId(), Type>(seq_arg, buffer, 1024);
1024);
if (!result) { if (!result) {
options.fallback = 1; options.fallback = 1;
return 0; return 0;
......
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