Commit deca6529 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

Make FixedSizeSignature<T, 0, 0> constexpr

This allows to hold a constexpr (empty) "builder" object instead of
creating it for every use.

R=ahaas@chromium.org

Bug: v8:11384
Change-Id: Ib5e13c58e81a950bb5dd0e8eefe4021bc77d8b64
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2773801
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73548}
parent 282c2c30
......@@ -127,11 +127,6 @@ size_t hash_value(const Signature<T>& sig) {
template <typename T, size_t kNumReturns = 0, size_t kNumParams = 0>
class FixedSizeSignature : public Signature<T> {
public:
explicit FixedSizeSignature(std::array<T, kNumReturns + kNumParams> reps)
: Signature<T>(kNumReturns, kNumParams, reps_) {
std::copy(reps.begin(), reps.end(), reps_);
}
// Add return types to this signature (only allowed if there are none yet).
template <typename... ReturnTypes>
auto Returns(ReturnTypes... return_types) const {
......@@ -162,6 +157,27 @@ class FixedSizeSignature : public Signature<T> {
T reps_[kNumReturns + kNumParams];
};
// Specialization for zero-sized signatures.
template <typename T>
class FixedSizeSignature<T, 0, 0> : public Signature<T> {
public:
constexpr FixedSizeSignature() : Signature<T>(0, 0, nullptr) {}
// Add return types.
template <typename... ReturnTypes>
static auto Returns(ReturnTypes... return_types) {
return FixedSizeSignature<T, sizeof...(ReturnTypes), 0>{
std::initializer_list<T>{return_types...}.begin(), nullptr};
}
// Add parameters.
template <typename... ParamTypes>
static auto Params(ParamTypes... param_types) {
return FixedSizeSignature<T, 0, sizeof...(ParamTypes)>{
nullptr, std::initializer_list<T>{param_types...}.begin()};
}
};
} // namespace internal
} // namespace v8
......
This diff is collapsed.
......@@ -68,10 +68,8 @@ constexpr size_t kMaxByteSizedLeb128 = 127;
using F = std::pair<ValueType, bool>;
// Used to construct fixed-size signatures: MakeSig().Returns(...).Params(...);
FixedSizeSignature<ValueType> MakeSig() {
return FixedSizeSignature<ValueType>{{}};
}
// Used to construct fixed-size signatures: MakeSig::Returns(...).Params(...);
using MakeSig = FixedSizeSignature<ValueType>;
enum MemoryType { kMemory32, kMemory64 };
......@@ -5022,9 +5020,9 @@ TEST_P(FunctionBodyDecoderTestOnBothMemoryTypes, MemoryGrow) {
// memory.grow is i64->i64 memory32.
Validate(is_memory64(), sigs.l_l(), {WASM_MEMORY_GROW(WASM_LOCAL_GET(0))});
// any other combination always fails.
auto sig_l_i = MakeSig().Returns(kWasmI64).Params(kWasmI32);
auto sig_l_i = MakeSig::Returns(kWasmI64).Params(kWasmI32);
ExpectFailure(&sig_l_i, {WASM_MEMORY_GROW(WASM_LOCAL_GET(0))});
auto sig_i_l = MakeSig().Returns(kWasmI32).Params(kWasmI64);
auto sig_i_l = MakeSig::Returns(kWasmI32).Params(kWasmI64);
ExpectFailure(&sig_i_l, {WASM_MEMORY_GROW(WASM_LOCAL_GET(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