mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Rename Constant::As to Constant::ValueAs.
This CL updates Constant::As to be Constant::ValueAs. Now that Constant inherits from CastableBase, there is already an As method on CastableBase. This makes the override inside Constant confusing and potentially incorrect. Bug: tint:1718 Change-Id: I4f73971801e95225a99a5a993124c04194d0d7d6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114360 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
35842190ef
commit
5addefb148
@@ -64,8 +64,8 @@ template <typename F, typename... CONSTANTS>
|
||||
auto Dispatch_iu32(F&& f, CONSTANTS&&... cs) {
|
||||
return Switch(
|
||||
First(cs...)->Type(), //
|
||||
[&](const type::I32*) { return f(cs->template As<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template As<u32>()...); });
|
||||
[&](const type::I32*) { return f(cs->template ValueAs<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template ValueAs<u32>()...); });
|
||||
}
|
||||
|
||||
/// Helper that calls `f` passing in the value of all `cs`.
|
||||
@@ -74,9 +74,9 @@ template <typename F, typename... CONSTANTS>
|
||||
auto Dispatch_ia_iu32(F&& f, CONSTANTS&&... cs) {
|
||||
return Switch(
|
||||
First(cs...)->Type(), //
|
||||
[&](const type::AbstractInt*) { return f(cs->template As<AInt>()...); },
|
||||
[&](const type::I32*) { return f(cs->template As<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template As<u32>()...); });
|
||||
[&](const type::AbstractInt*) { return f(cs->template ValueAs<AInt>()...); },
|
||||
[&](const type::I32*) { return f(cs->template ValueAs<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template ValueAs<u32>()...); });
|
||||
}
|
||||
|
||||
/// Helper that calls `f` passing in the value of all `cs`.
|
||||
@@ -85,10 +85,10 @@ template <typename F, typename... CONSTANTS>
|
||||
auto Dispatch_ia_iu32_bool(F&& f, CONSTANTS&&... cs) {
|
||||
return Switch(
|
||||
First(cs...)->Type(), //
|
||||
[&](const type::AbstractInt*) { return f(cs->template As<AInt>()...); },
|
||||
[&](const type::I32*) { return f(cs->template As<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template As<u32>()...); },
|
||||
[&](const type::Bool*) { return f(cs->template As<bool>()...); });
|
||||
[&](const type::AbstractInt*) { return f(cs->template ValueAs<AInt>()...); },
|
||||
[&](const type::I32*) { return f(cs->template ValueAs<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template ValueAs<u32>()...); },
|
||||
[&](const type::Bool*) { return f(cs->template ValueAs<bool>()...); });
|
||||
}
|
||||
|
||||
/// Helper that calls `f` passing in the value of all `cs`.
|
||||
@@ -97,11 +97,11 @@ template <typename F, typename... CONSTANTS>
|
||||
auto Dispatch_fia_fi32_f16(F&& f, CONSTANTS&&... cs) {
|
||||
return Switch(
|
||||
First(cs...)->Type(), //
|
||||
[&](const type::AbstractInt*) { return f(cs->template As<AInt>()...); },
|
||||
[&](const type::AbstractFloat*) { return f(cs->template As<AFloat>()...); },
|
||||
[&](const type::F32*) { return f(cs->template As<f32>()...); },
|
||||
[&](const type::I32*) { return f(cs->template As<i32>()...); },
|
||||
[&](const type::F16*) { return f(cs->template As<f16>()...); });
|
||||
[&](const type::AbstractInt*) { return f(cs->template ValueAs<AInt>()...); },
|
||||
[&](const type::AbstractFloat*) { return f(cs->template ValueAs<AFloat>()...); },
|
||||
[&](const type::F32*) { return f(cs->template ValueAs<f32>()...); },
|
||||
[&](const type::I32*) { return f(cs->template ValueAs<i32>()...); },
|
||||
[&](const type::F16*) { return f(cs->template ValueAs<f16>()...); });
|
||||
}
|
||||
|
||||
/// Helper that calls `f` passing in the value of all `cs`.
|
||||
@@ -110,12 +110,12 @@ template <typename F, typename... CONSTANTS>
|
||||
auto Dispatch_fia_fiu32_f16(F&& f, CONSTANTS&&... cs) {
|
||||
return Switch(
|
||||
First(cs...)->Type(), //
|
||||
[&](const type::AbstractInt*) { return f(cs->template As<AInt>()...); },
|
||||
[&](const type::AbstractFloat*) { return f(cs->template As<AFloat>()...); },
|
||||
[&](const type::F32*) { return f(cs->template As<f32>()...); },
|
||||
[&](const type::I32*) { return f(cs->template As<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template As<u32>()...); },
|
||||
[&](const type::F16*) { return f(cs->template As<f16>()...); });
|
||||
[&](const type::AbstractInt*) { return f(cs->template ValueAs<AInt>()...); },
|
||||
[&](const type::AbstractFloat*) { return f(cs->template ValueAs<AFloat>()...); },
|
||||
[&](const type::F32*) { return f(cs->template ValueAs<f32>()...); },
|
||||
[&](const type::I32*) { return f(cs->template ValueAs<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template ValueAs<u32>()...); },
|
||||
[&](const type::F16*) { return f(cs->template ValueAs<f16>()...); });
|
||||
}
|
||||
|
||||
/// Helper that calls `f` passing in the value of all `cs`.
|
||||
@@ -124,13 +124,13 @@ template <typename F, typename... CONSTANTS>
|
||||
auto Dispatch_fia_fiu32_f16_bool(F&& f, CONSTANTS&&... cs) {
|
||||
return Switch(
|
||||
First(cs...)->Type(), //
|
||||
[&](const type::AbstractInt*) { return f(cs->template As<AInt>()...); },
|
||||
[&](const type::AbstractFloat*) { return f(cs->template As<AFloat>()...); },
|
||||
[&](const type::F32*) { return f(cs->template As<f32>()...); },
|
||||
[&](const type::I32*) { return f(cs->template As<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template As<u32>()...); },
|
||||
[&](const type::F16*) { return f(cs->template As<f16>()...); },
|
||||
[&](const type::Bool*) { return f(cs->template As<bool>()...); });
|
||||
[&](const type::AbstractInt*) { return f(cs->template ValueAs<AInt>()...); },
|
||||
[&](const type::AbstractFloat*) { return f(cs->template ValueAs<AFloat>()...); },
|
||||
[&](const type::F32*) { return f(cs->template ValueAs<f32>()...); },
|
||||
[&](const type::I32*) { return f(cs->template ValueAs<i32>()...); },
|
||||
[&](const type::U32*) { return f(cs->template ValueAs<u32>()...); },
|
||||
[&](const type::F16*) { return f(cs->template ValueAs<f16>()...); },
|
||||
[&](const type::Bool*) { return f(cs->template ValueAs<bool>()...); });
|
||||
}
|
||||
|
||||
/// Helper that calls `f` passing in the value of all `cs`.
|
||||
@@ -139,16 +139,16 @@ template <typename F, typename... CONSTANTS>
|
||||
auto Dispatch_fa_f32_f16(F&& f, CONSTANTS&&... cs) {
|
||||
return Switch(
|
||||
First(cs...)->Type(), //
|
||||
[&](const type::AbstractFloat*) { return f(cs->template As<AFloat>()...); },
|
||||
[&](const type::F32*) { return f(cs->template As<f32>()...); },
|
||||
[&](const type::F16*) { return f(cs->template As<f16>()...); });
|
||||
[&](const type::AbstractFloat*) { return f(cs->template ValueAs<AFloat>()...); },
|
||||
[&](const type::F32*) { return f(cs->template ValueAs<f32>()...); },
|
||||
[&](const type::F16*) { return f(cs->template ValueAs<f16>()...); });
|
||||
}
|
||||
|
||||
/// Helper that calls `f` passing in the value of all `cs`.
|
||||
/// Calls `f` with all constants cast to the type of the first `cs` argument.
|
||||
template <typename F, typename... CONSTANTS>
|
||||
auto Dispatch_bool(F&& f, CONSTANTS&&... cs) {
|
||||
return f(cs->template As<bool>()...);
|
||||
return f(cs->template ValueAs<bool>()...);
|
||||
}
|
||||
|
||||
/// ZeroTypeDispatch is a helper for calling the function `f`, passing a single zero-value argument
|
||||
@@ -1373,7 +1373,7 @@ ConstEval::Result ConstEval::Index(const sem::Expression* obj_expr,
|
||||
uint32_t el_count = 0;
|
||||
type::Type::ElementOf(obj_expr->Type()->UnwrapRef(), &el_count);
|
||||
|
||||
AInt idx = idx_val->As<AInt>();
|
||||
AInt idx = idx_val->ValueAs<AInt>();
|
||||
if (idx < 0 || (el_count > 0 && idx >= el_count)) {
|
||||
std::string range;
|
||||
if (el_count > 0) {
|
||||
@@ -1761,7 +1761,7 @@ ConstEval::Result ConstEval::OpLogicalAnd(const type::Type* ty,
|
||||
const Source& source) {
|
||||
// Note: Due to short-circuiting, this function is only called if lhs is true, so we could
|
||||
// technically only return the value of the rhs.
|
||||
return CreateScalar(builder, source, ty, args[0]->As<bool>() && args[1]->As<bool>());
|
||||
return CreateScalar(builder, source, ty, args[0]->ValueAs<bool>() && args[1]->ValueAs<bool>());
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::OpLogicalOr(const type::Type* ty,
|
||||
@@ -1769,7 +1769,7 @@ ConstEval::Result ConstEval::OpLogicalOr(const type::Type* ty,
|
||||
const Source& source) {
|
||||
// Note: Due to short-circuiting, this function is only called if lhs is false, so we could
|
||||
// technically only return the value of the rhs.
|
||||
return CreateScalar(builder, source, ty, args[1]->As<bool>());
|
||||
return CreateScalar(builder, source, ty, args[1]->ValueAs<bool>());
|
||||
}
|
||||
|
||||
ConstEval::Result ConstEval::OpAnd(const type::Type* ty,
|
||||
@@ -2408,8 +2408,8 @@ ConstEval::Result ConstEval::extractBits(const type::Type* ty,
|
||||
using NumberUT = Number<UT>;
|
||||
|
||||
// Read args that are always scalar
|
||||
NumberUT in_offset = args[1]->As<NumberUT>();
|
||||
NumberUT in_count = args[2]->As<NumberUT>();
|
||||
NumberUT in_offset = args[1]->ValueAs<NumberUT>();
|
||||
NumberUT in_count = args[2]->ValueAs<NumberUT>();
|
||||
|
||||
// Cast all to unsigned
|
||||
UT e = static_cast<UT>(in_e);
|
||||
@@ -2606,7 +2606,7 @@ ConstEval::Result ConstEval::frexp(const type::Type* ty,
|
||||
|
||||
auto scalar = [&](const constant::Constant* s) {
|
||||
int exp = 0;
|
||||
double fract = std::frexp(s->As<AFloat>(), &exp);
|
||||
double fract = std::frexp(s->ValueAs<AFloat>(), &exp);
|
||||
return Switch(
|
||||
s->Type(),
|
||||
[&](const type::F32*) {
|
||||
@@ -2678,8 +2678,8 @@ ConstEval::Result ConstEval::insertBits(const type::Type* ty,
|
||||
using NumberUT = Number<UT>;
|
||||
|
||||
// Read args that are always scalar
|
||||
NumberUT in_offset = args[2]->As<NumberUT>();
|
||||
NumberUT in_count = args[3]->As<NumberUT>();
|
||||
NumberUT in_offset = args[2]->ValueAs<NumberUT>();
|
||||
NumberUT in_count = args[3]->ValueAs<NumberUT>();
|
||||
|
||||
// Cast all to unsigned
|
||||
UT e = static_cast<UT>(in_e);
|
||||
@@ -2831,9 +2831,9 @@ ConstEval::Result ConstEval::mix(const type::Type* ty,
|
||||
NumberT e3;
|
||||
auto* c2 = args[2];
|
||||
if (c2->Type()->Is<type::Vector>()) {
|
||||
e3 = c2->Index(index)->As<NumberT>();
|
||||
e3 = c2->Index(index)->ValueAs<NumberT>();
|
||||
} else {
|
||||
e3 = c2->As<NumberT>();
|
||||
e3 = c2->ValueAs<NumberT>();
|
||||
}
|
||||
// Implement as `e1 * (1 - e3) + e2 * e3)` instead of as `e1 + e3 * (e2 - e1)` to avoid
|
||||
// float precision loss when e1 and e2 significantly differ in magnitude.
|
||||
@@ -2929,12 +2929,12 @@ ConstEval::Result ConstEval::pack2x16float(const type::Type* ty,
|
||||
};
|
||||
|
||||
auto* e = args[0];
|
||||
auto e0 = convert(e->Index(0)->As<f32>());
|
||||
auto e0 = convert(e->Index(0)->ValueAs<f32>());
|
||||
if (!e0) {
|
||||
return utils::Failure;
|
||||
}
|
||||
|
||||
auto e1 = convert(e->Index(1)->As<f32>());
|
||||
auto e1 = convert(e->Index(1)->ValueAs<f32>());
|
||||
if (!e1) {
|
||||
return utils::Failure;
|
||||
}
|
||||
@@ -2953,8 +2953,8 @@ ConstEval::Result ConstEval::pack2x16snorm(const type::Type* ty,
|
||||
};
|
||||
|
||||
auto* e = args[0];
|
||||
auto e0 = calc(e->Index(0)->As<f32>());
|
||||
auto e1 = calc(e->Index(1)->As<f32>());
|
||||
auto e0 = calc(e->Index(0)->ValueAs<f32>());
|
||||
auto e1 = calc(e->Index(1)->ValueAs<f32>());
|
||||
|
||||
u32 ret = u32((e0 & 0x0000'ffff) | (e1 << 16));
|
||||
return CreateScalar(builder, source, ty, ret);
|
||||
@@ -2969,8 +2969,8 @@ ConstEval::Result ConstEval::pack2x16unorm(const type::Type* ty,
|
||||
};
|
||||
|
||||
auto* e = args[0];
|
||||
auto e0 = calc(e->Index(0)->As<f32>());
|
||||
auto e1 = calc(e->Index(1)->As<f32>());
|
||||
auto e0 = calc(e->Index(0)->ValueAs<f32>());
|
||||
auto e1 = calc(e->Index(1)->ValueAs<f32>());
|
||||
|
||||
u32 ret = u32((e0 & 0x0000'ffff) | (e1 << 16));
|
||||
return CreateScalar(builder, source, ty, ret);
|
||||
@@ -2986,10 +2986,10 @@ ConstEval::Result ConstEval::pack4x8snorm(const type::Type* ty,
|
||||
};
|
||||
|
||||
auto* e = args[0];
|
||||
auto e0 = calc(e->Index(0)->As<f32>());
|
||||
auto e1 = calc(e->Index(1)->As<f32>());
|
||||
auto e2 = calc(e->Index(2)->As<f32>());
|
||||
auto e3 = calc(e->Index(3)->As<f32>());
|
||||
auto e0 = calc(e->Index(0)->ValueAs<f32>());
|
||||
auto e1 = calc(e->Index(1)->ValueAs<f32>());
|
||||
auto e2 = calc(e->Index(2)->ValueAs<f32>());
|
||||
auto e3 = calc(e->Index(3)->ValueAs<f32>());
|
||||
|
||||
uint32_t mask = 0x0000'00ff;
|
||||
u32 ret = u32((e0 & mask) | ((e1 & mask) << 8) | ((e2 & mask) << 16) | ((e3 & mask) << 24));
|
||||
@@ -3005,10 +3005,10 @@ ConstEval::Result ConstEval::pack4x8unorm(const type::Type* ty,
|
||||
};
|
||||
|
||||
auto* e = args[0];
|
||||
auto e0 = calc(e->Index(0)->As<f32>());
|
||||
auto e1 = calc(e->Index(1)->As<f32>());
|
||||
auto e2 = calc(e->Index(2)->As<f32>());
|
||||
auto e3 = calc(e->Index(3)->As<f32>());
|
||||
auto e0 = calc(e->Index(0)->ValueAs<f32>());
|
||||
auto e1 = calc(e->Index(1)->ValueAs<f32>());
|
||||
auto e2 = calc(e->Index(2)->ValueAs<f32>());
|
||||
auto e3 = calc(e->Index(3)->ValueAs<f32>());
|
||||
|
||||
uint32_t mask = 0x0000'00ff;
|
||||
u32 ret = u32((e0 & mask) | ((e1 & mask) << 8) | ((e2 & mask) << 16) | ((e3 & mask) << 24));
|
||||
@@ -3173,7 +3173,7 @@ ConstEval::Result ConstEval::refract(const type::Type* ty,
|
||||
}
|
||||
|
||||
// If k < 0.0, returns the refraction vector 0.0
|
||||
if (k.Get()->As<AFloat>() < 0) {
|
||||
if (k.Get()->ValueAs<AFloat>() < 0) {
|
||||
return ZeroValue(builder, ty);
|
||||
}
|
||||
|
||||
@@ -3279,7 +3279,7 @@ ConstEval::Result ConstEval::saturate(const type::Type* ty,
|
||||
ConstEval::Result ConstEval::select_bool(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
auto cond = args[2]->As<bool>();
|
||||
auto cond = args[2]->ValueAs<bool>();
|
||||
auto transform = [&](const constant::Constant* c0, const constant::Constant* c1) {
|
||||
auto create = [&](auto f, auto t) -> ConstEval::Result {
|
||||
return CreateScalar(builder, source, type::Type::DeepestElementOf(ty), cond ? t : f);
|
||||
@@ -3296,7 +3296,7 @@ ConstEval::Result ConstEval::select_boolvec(const type::Type* ty,
|
||||
auto transform = [&](const constant::Constant* c0, const constant::Constant* c1, size_t index) {
|
||||
auto create = [&](auto f, auto t) -> ConstEval::Result {
|
||||
// Get corresponding bool value at the current vector value index
|
||||
auto cond = args[2]->Index(index)->As<bool>();
|
||||
auto cond = args[2]->Index(index)->ValueAs<bool>();
|
||||
return CreateScalar(builder, source, type::Type::DeepestElementOf(ty), cond ? t : f);
|
||||
};
|
||||
return Dispatch_fia_fiu32_f16_bool(create, c0, c1);
|
||||
@@ -3490,7 +3490,7 @@ ConstEval::Result ConstEval::unpack2x16float(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
auto* inner_ty = type::Type::DeepestElementOf(ty);
|
||||
auto e = args[0]->As<u32>().value;
|
||||
auto e = args[0]->ValueAs<u32>().value;
|
||||
|
||||
utils::Vector<const constant::Constant*, 2> els;
|
||||
els.Reserve(2);
|
||||
@@ -3514,7 +3514,7 @@ ConstEval::Result ConstEval::unpack2x16snorm(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
auto* inner_ty = type::Type::DeepestElementOf(ty);
|
||||
auto e = args[0]->As<u32>().value;
|
||||
auto e = args[0]->ValueAs<u32>().value;
|
||||
|
||||
utils::Vector<const constant::Constant*, 2> els;
|
||||
els.Reserve(2);
|
||||
@@ -3534,7 +3534,7 @@ ConstEval::Result ConstEval::unpack2x16unorm(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
auto* inner_ty = type::Type::DeepestElementOf(ty);
|
||||
auto e = args[0]->As<u32>().value;
|
||||
auto e = args[0]->ValueAs<u32>().value;
|
||||
|
||||
utils::Vector<const constant::Constant*, 2> els;
|
||||
els.Reserve(2);
|
||||
@@ -3553,7 +3553,7 @@ ConstEval::Result ConstEval::unpack4x8snorm(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
auto* inner_ty = type::Type::DeepestElementOf(ty);
|
||||
auto e = args[0]->As<u32>().value;
|
||||
auto e = args[0]->ValueAs<u32>().value;
|
||||
|
||||
utils::Vector<const constant::Constant*, 4> els;
|
||||
els.Reserve(4);
|
||||
@@ -3573,7 +3573,7 @@ ConstEval::Result ConstEval::unpack4x8unorm(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
auto* inner_ty = type::Type::DeepestElementOf(ty);
|
||||
auto e = args[0]->As<u32>().value;
|
||||
auto e = args[0]->ValueAs<u32>().value;
|
||||
|
||||
utils::Vector<const constant::Constant*, 4> els;
|
||||
els.Reserve(4);
|
||||
@@ -3592,7 +3592,7 @@ ConstEval::Result ConstEval::quantizeToF16(const type::Type* ty,
|
||||
utils::VectorRef<const constant::Constant*> args,
|
||||
const Source& source) {
|
||||
auto transform = [&](const constant::Constant* c) -> ConstEval::Result {
|
||||
auto value = c->As<f32>();
|
||||
auto value = c->ValueAs<f32>();
|
||||
auto conv = CheckedConvert<f32>(f16(value));
|
||||
if (!conv) {
|
||||
AddError(OverflowErrorMessage(value, "f16"), source);
|
||||
|
||||
@@ -903,7 +903,7 @@ TEST_F(ResolverConstEvalTest, NotAndOrOfVecs) {
|
||||
|
||||
ForEachElemPair(value, expected_value,
|
||||
[&](const constant::Constant* a, const constant::Constant* b) {
|
||||
EXPECT_EQ(a->As<bool>(), b->As<bool>());
|
||||
EXPECT_EQ(a->ValueAs<bool>(), b->ValueAs<bool>());
|
||||
return HasFailure() ? Action::kStop : Action::kContinue;
|
||||
});
|
||||
}
|
||||
@@ -1377,7 +1377,7 @@ static void ValidateAnd(const sem::Info& sem, const ast::BinaryExpression* binar
|
||||
|
||||
auto* lhs_sem = sem.Get(lhs);
|
||||
ASSERT_TRUE(lhs_sem->ConstantValue());
|
||||
EXPECT_EQ(lhs_sem->ConstantValue()->As<bool>(), false);
|
||||
EXPECT_EQ(lhs_sem->ConstantValue()->ValueAs<bool>(), false);
|
||||
EXPECT_EQ(lhs_sem->Stage(), sem::EvaluationStage::kConstant);
|
||||
|
||||
auto* rhs_sem = sem.Get(rhs);
|
||||
@@ -1386,7 +1386,7 @@ static void ValidateAnd(const sem::Info& sem, const ast::BinaryExpression* binar
|
||||
|
||||
auto* binary_sem = sem.Get(binary);
|
||||
ASSERT_TRUE(binary_sem->ConstantValue());
|
||||
EXPECT_EQ(binary_sem->ConstantValue()->As<bool>(), false);
|
||||
EXPECT_EQ(binary_sem->ConstantValue()->ValueAs<bool>(), false);
|
||||
EXPECT_EQ(binary_sem->Stage(), sem::EvaluationStage::kConstant);
|
||||
}
|
||||
|
||||
@@ -1397,7 +1397,7 @@ static void ValidateOr(const sem::Info& sem, const ast::BinaryExpression* binary
|
||||
|
||||
auto* lhs_sem = sem.Get(lhs);
|
||||
ASSERT_TRUE(lhs_sem->ConstantValue());
|
||||
EXPECT_EQ(lhs_sem->ConstantValue()->As<bool>(), true);
|
||||
EXPECT_EQ(lhs_sem->ConstantValue()->ValueAs<bool>(), true);
|
||||
EXPECT_EQ(lhs_sem->Stage(), sem::EvaluationStage::kConstant);
|
||||
|
||||
auto* rhs_sem = sem.Get(rhs);
|
||||
@@ -1406,7 +1406,7 @@ static void ValidateOr(const sem::Info& sem, const ast::BinaryExpression* binary
|
||||
|
||||
auto* binary_sem = sem.Get(binary);
|
||||
ASSERT_TRUE(binary_sem->ConstantValue());
|
||||
EXPECT_EQ(binary_sem->ConstantValue()->As<bool>(), true);
|
||||
EXPECT_EQ(binary_sem->ConstantValue()->ValueAs<bool>(), true);
|
||||
EXPECT_EQ(binary_sem->Stage(), sem::EvaluationStage::kConstant);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -242,17 +242,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_f32_to_i32) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<AInt>(), 1);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AInt>(), 1);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<AInt>(), 2);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AInt>(), 2);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<AInt>(), 3);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AInt>(), 3);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Convert_u32_to_f32) {
|
||||
@@ -275,17 +275,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_u32_to_f32) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<AFloat>(), 10.f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AFloat>(), 10.f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<AFloat>(), 20.f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AFloat>(), 20.f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<AFloat>(), 30.f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AFloat>(), 30.f);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Convert_f16_to_i32) {
|
||||
@@ -310,17 +310,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_f16_to_i32) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<AInt>(), 1_i);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AInt>(), 1_i);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<AInt>(), 2_i);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AInt>(), 2_i);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<AInt>(), 3_i);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AInt>(), 3_i);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Convert_u32_to_f16) {
|
||||
@@ -345,17 +345,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_u32_to_f16) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<AFloat>(), 10.f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AFloat>(), 10.f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<AFloat>(), 20.f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AFloat>(), 20.f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<AFloat>(), 30.f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AFloat>(), 30.f);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Convert_Large_f32_to_i32) {
|
||||
@@ -378,17 +378,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_Large_f32_to_i32) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<AInt>(), i32::Highest());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AInt>(), i32::Highest());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<AInt>(), i32::Lowest());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AInt>(), i32::Lowest());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<AInt>(), i32::Highest());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AInt>(), i32::Highest());
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Convert_Large_f32_to_u32) {
|
||||
@@ -411,17 +411,17 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_Large_f32_to_u32) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<AInt>(), u32::Highest());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AInt>(), u32::Highest());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<AInt>(), u32::Lowest());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AInt>(), u32::Lowest());
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<AInt>(), u32::Highest());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AInt>(), u32::Highest());
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Convert_Large_f32_to_f16) {
|
||||
@@ -456,20 +456,20 @@ TEST_F(ResolverConstEvalTest, Vec3_Convert_Small_f32_to_f16) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<AFloat>(), 0.0);
|
||||
EXPECT_FALSE(std::signbit(sem->ConstantValue()->Index(0)->As<AFloat>().value));
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<AFloat>(), 0.0);
|
||||
EXPECT_FALSE(std::signbit(sem->ConstantValue()->Index(0)->ValueAs<AFloat>().value));
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<AFloat>(), -0.0);
|
||||
EXPECT_TRUE(std::signbit(sem->ConstantValue()->Index(1)->As<AFloat>().value));
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<AFloat>(), -0.0);
|
||||
EXPECT_TRUE(std::signbit(sem->ConstantValue()->Index(1)->ValueAs<AFloat>().value));
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<AFloat>(), 0.0);
|
||||
EXPECT_FALSE(std::signbit(sem->ConstantValue()->Index(2)->As<AFloat>().value));
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<AFloat>(), 0.0);
|
||||
EXPECT_FALSE(std::signbit(sem->ConstantValue()->Index(2)->ValueAs<AFloat>().value));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -32,7 +32,7 @@ TEST_F(ResolverConstEvalTest, Vec3_Index) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->As<i32>(), 3_i);
|
||||
EXPECT_EQ(sem->ConstantValue()->ValueAs<i32>(), 3_i);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Index_OOB_High) {
|
||||
@@ -64,7 +64,7 @@ TEST_F(ResolverConstEvalTest, Vec3_Swizzle_Scalar) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->As<i32>(), 2_i);
|
||||
EXPECT_EQ(sem->ConstantValue()->ValueAs<i32>(), 2_i);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Swizzle_Vector) {
|
||||
@@ -83,12 +83,12 @@ TEST_F(ResolverConstEvalTest, Vec3_Swizzle_Vector) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<f32>(), 3._a);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<f32>(), 3._a);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<f32>(), 1._a);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<f32>(), 1._a);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Vec3_Swizzle_Chain) {
|
||||
@@ -105,7 +105,7 @@ TEST_F(ResolverConstEvalTest, Vec3_Swizzle_Chain) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->As<i32>(), 2_i);
|
||||
EXPECT_EQ(sem->ConstantValue()->ValueAs<i32>(), 2_i);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Mat3x2_Index) {
|
||||
@@ -125,12 +125,12 @@ TEST_F(ResolverConstEvalTest, Mat3x2_Index) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<f32>(), 5._a);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<f32>(), 5._a);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<f32>(), 6._a);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<f32>(), 6._a);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Mat3x2_Index_OOB_High) {
|
||||
@@ -172,17 +172,17 @@ TEST_F(ResolverConstEvalTest, Array_vec3_f32_Index) {
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->As<f32>(), 4_f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(0)->ValueAs<f32>(), 4_f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<f32>(), 5_f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(1)->ValueAs<f32>(), 5_f);
|
||||
|
||||
EXPECT_TRUE(sem->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(sem->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<f32>(), 6_f);
|
||||
EXPECT_EQ(sem->ConstantValue()->Index(2)->ValueAs<f32>(), 6_f);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Array_vec3_f32_Index_OOB_High) {
|
||||
@@ -245,32 +245,32 @@ TEST_F(ResolverConstEvalTest, ChainedIndex) {
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(0)->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(0)->Index(0)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(0)->As<f32>(), 7_f);
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(0)->ValueAs<f32>(), 7_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(1)->AllEqual());
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(1)->AnyZero());
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(1)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(1)->As<f32>(), 0_f);
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(1)->ValueAs<f32>(), 0_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(0)->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(0)->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(0)->Index(2)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(2)->As<f32>(), 9_f);
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(0)->Index(2)->ValueAs<f32>(), 9_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(1)->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(0)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(0)->As<f32>(), 10_f);
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(0)->ValueAs<f32>(), 10_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(1)->Index(1)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(1)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(1)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(1)->As<f32>(), 11_f);
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(1)->ValueAs<f32>(), 11_f);
|
||||
|
||||
EXPECT_TRUE(mat->ConstantValue()->Index(1)->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(mat->ConstantValue()->Index(1)->Index(2)->AllZero());
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(2)->As<f32>(), 12_f);
|
||||
EXPECT_EQ(mat->ConstantValue()->Index(1)->Index(2)->ValueAs<f32>(), 12_f);
|
||||
}
|
||||
{
|
||||
auto* vec = Sem().Get(vec_expr);
|
||||
@@ -287,17 +287,17 @@ TEST_F(ResolverConstEvalTest, ChainedIndex) {
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(0)->AllEqual());
|
||||
EXPECT_FALSE(vec->ConstantValue()->Index(0)->AnyZero());
|
||||
EXPECT_FALSE(vec->ConstantValue()->Index(0)->AllZero());
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(0)->As<f32>(), 7_f);
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(0)->ValueAs<f32>(), 7_f);
|
||||
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(1)->AllEqual());
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(1)->AnyZero());
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(1)->AllZero());
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(1)->As<f32>(), 0_f);
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(1)->ValueAs<f32>(), 0_f);
|
||||
|
||||
EXPECT_TRUE(vec->ConstantValue()->Index(2)->AllEqual());
|
||||
EXPECT_FALSE(vec->ConstantValue()->Index(2)->AnyZero());
|
||||
EXPECT_FALSE(vec->ConstantValue()->Index(2)->AllZero());
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(2)->As<f32>(), 9_f);
|
||||
EXPECT_EQ(vec->ConstantValue()->Index(2)->ValueAs<f32>(), 9_f);
|
||||
}
|
||||
{
|
||||
auto* f = Sem().Get(f32_expr);
|
||||
@@ -307,7 +307,7 @@ TEST_F(ResolverConstEvalTest, ChainedIndex) {
|
||||
EXPECT_TRUE(f->ConstantValue()->AllEqual());
|
||||
EXPECT_FALSE(f->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(f->ConstantValue()->AllZero());
|
||||
EXPECT_EQ(f->ConstantValue()->As<f32>(), 9_f);
|
||||
EXPECT_EQ(f->ConstantValue()->ValueAs<f32>(), 9_f);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -56,9 +56,9 @@ TEST_F(ResolverConstEvalTest, MemberAccess) {
|
||||
EXPECT_FALSE(o1->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(o1->ConstantValue()->AllZero());
|
||||
EXPECT_TRUE(o1->ConstantValue()->Type()->Is<sem::Struct>());
|
||||
EXPECT_EQ(o1->ConstantValue()->Index(0)->As<i32>(), 1_i);
|
||||
EXPECT_EQ(o1->ConstantValue()->Index(1)->As<u32>(), 2_u);
|
||||
EXPECT_EQ(o1->ConstantValue()->Index(2)->As<f32>(), 3_f);
|
||||
EXPECT_EQ(o1->ConstantValue()->Index(0)->ValueAs<i32>(), 1_i);
|
||||
EXPECT_EQ(o1->ConstantValue()->Index(1)->ValueAs<u32>(), 2_u);
|
||||
EXPECT_EQ(o1->ConstantValue()->Index(2)->ValueAs<f32>(), 3_f);
|
||||
|
||||
auto* i2 = Sem().Get(i2_expr);
|
||||
ASSERT_NE(i2->ConstantValue(), nullptr);
|
||||
@@ -66,7 +66,7 @@ TEST_F(ResolverConstEvalTest, MemberAccess) {
|
||||
EXPECT_FALSE(i2->ConstantValue()->AnyZero());
|
||||
EXPECT_FALSE(i2->ConstantValue()->AllZero());
|
||||
EXPECT_TRUE(i2->ConstantValue()->Type()->Is<type::U32>());
|
||||
EXPECT_EQ(i2->ConstantValue()->As<u32>(), 2_u);
|
||||
EXPECT_EQ(i2->ConstantValue()->ValueAs<u32>(), 2_u);
|
||||
}
|
||||
|
||||
TEST_F(ResolverConstEvalTest, Matrix_AFloat_Construct_From_AInt_Vectors) {
|
||||
|
||||
@@ -42,13 +42,13 @@ inline void CollectScalars(const constant::Constant* c,
|
||||
utils::Vector<builder::Scalar, N>& scalars) {
|
||||
Switch(
|
||||
c->Type(), //
|
||||
[&](const type::AbstractInt*) { scalars.Push(c->As<AInt>()); },
|
||||
[&](const type::AbstractFloat*) { scalars.Push(c->As<AFloat>()); },
|
||||
[&](const type::Bool*) { scalars.Push(c->As<bool>()); },
|
||||
[&](const type::I32*) { scalars.Push(c->As<i32>()); },
|
||||
[&](const type::U32*) { scalars.Push(c->As<u32>()); },
|
||||
[&](const type::F32*) { scalars.Push(c->As<f32>()); },
|
||||
[&](const type::F16*) { scalars.Push(c->As<f16>()); },
|
||||
[&](const type::AbstractInt*) { scalars.Push(c->ValueAs<AInt>()); },
|
||||
[&](const type::AbstractFloat*) { scalars.Push(c->ValueAs<AFloat>()); },
|
||||
[&](const type::Bool*) { scalars.Push(c->ValueAs<bool>()); },
|
||||
[&](const type::I32*) { scalars.Push(c->ValueAs<i32>()); },
|
||||
[&](const type::U32*) { scalars.Push(c->ValueAs<u32>()); },
|
||||
[&](const type::F32*) { scalars.Push(c->ValueAs<f32>()); },
|
||||
[&](const type::F16*) { scalars.Push(c->ValueAs<f16>()); },
|
||||
[&](Default) {
|
||||
size_t i = 0;
|
||||
while (auto* child = c->Index(i++)) {
|
||||
|
||||
@@ -159,7 +159,7 @@ TEST_F(ResolverConstEvalTest, UnaryNegateLowestAbstract) {
|
||||
(void)c;
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
auto* sem = Sem().Get(c);
|
||||
EXPECT_EQ(sem->ConstantValue()->As<AInt>(), 9223372036854775808_a);
|
||||
EXPECT_EQ(sem->ConstantValue()->ValueAs<AInt>(), 9223372036854775808_a);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(Not,
|
||||
|
||||
@@ -480,7 +480,7 @@ sem::Variable* Resolver::Override(const ast::Override* v) {
|
||||
}
|
||||
|
||||
auto const_value = materialized->ConstantValue();
|
||||
auto value = const_value->As<AInt>();
|
||||
auto value = const_value->ValueAs<AInt>();
|
||||
if (value < 0) {
|
||||
AddError("@id value must be non-negative", id_attr->source);
|
||||
return nullptr;
|
||||
@@ -660,7 +660,7 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) {
|
||||
}
|
||||
|
||||
auto const_value = materialized->ConstantValue();
|
||||
auto value = const_value->As<AInt>();
|
||||
auto value = const_value->ValueAs<AInt>();
|
||||
if (value < 0) {
|
||||
AddError("@binding value must be non-negative", attr->source);
|
||||
return nullptr;
|
||||
@@ -684,7 +684,7 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) {
|
||||
}
|
||||
|
||||
auto const_value = materialized->ConstantValue();
|
||||
auto value = const_value->As<AInt>();
|
||||
auto value = const_value->ValueAs<AInt>();
|
||||
if (value < 0) {
|
||||
AddError("@group value must be non-negative", attr->source);
|
||||
return nullptr;
|
||||
@@ -762,7 +762,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
|
||||
if (!materialized) {
|
||||
return nullptr;
|
||||
}
|
||||
binding_point.binding = materialized->ConstantValue()->As<uint32_t>();
|
||||
binding_point.binding = materialized->ConstantValue()->ValueAs<u32>();
|
||||
}
|
||||
{
|
||||
ExprEvalStageConstraint constraint{sem::EvaluationStage::kConstant, "@group value"};
|
||||
@@ -773,7 +773,7 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
|
||||
if (!materialized) {
|
||||
return nullptr;
|
||||
}
|
||||
binding_point.group = materialized->ConstantValue()->As<uint32_t>();
|
||||
binding_point.group = materialized->ConstantValue()->ValueAs<u32>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,7 +808,7 @@ utils::Result<uint32_t> Resolver::LocationAttribute(const ast::LocationAttribute
|
||||
}
|
||||
|
||||
auto const_value = materialized->ConstantValue();
|
||||
auto value = const_value->As<AInt>();
|
||||
auto value = const_value->ValueAs<AInt>();
|
||||
if (value < 0) {
|
||||
AddError("@location value must be non-negative", attr->source);
|
||||
return utils::Failure;
|
||||
@@ -946,7 +946,7 @@ sem::Statement* Resolver::StaticAssert(const ast::StaticAssert* assertion) {
|
||||
assertion->condition->source);
|
||||
return nullptr;
|
||||
}
|
||||
if (!cond->As<bool>()) {
|
||||
if (!cond->ValueAs<bool>()) {
|
||||
AddError("static assertion failed", assertion->source);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1181,11 +1181,11 @@ bool Resolver::WorkgroupSize(const ast::Function* func) {
|
||||
return false;
|
||||
}
|
||||
if (auto* value = materialized->ConstantValue()) {
|
||||
if (value->As<AInt>() < 1) {
|
||||
if (value->ValueAs<AInt>() < 1) {
|
||||
AddError("workgroup_size argument must be at least 1", values[i]->source);
|
||||
return false;
|
||||
}
|
||||
ws[i] = value->As<uint32_t>();
|
||||
ws[i] = value->ValueAs<u32>();
|
||||
} else {
|
||||
ws[i] = std::nullopt;
|
||||
}
|
||||
@@ -1571,7 +1571,7 @@ sem::Expression* Resolver::Expression(const ast::Expression* root) {
|
||||
// short-circuiting.
|
||||
if (sem_expr->ConstantValue()) {
|
||||
if (auto binary = logical_binary_lhs_to_parent_.Find(expr)) {
|
||||
const bool lhs_is_true = sem_expr->ConstantValue()->As<bool>();
|
||||
const bool lhs_is_true = sem_expr->ConstantValue()->ValueAs<bool>();
|
||||
if (((*binary)->IsLogicalAnd() && !lhs_is_true) ||
|
||||
((*binary)->IsLogicalOr() && lhs_is_true)) {
|
||||
// Mark entire expression tree to not const-evaluate
|
||||
@@ -3110,7 +3110,7 @@ const type::ArrayCount* Resolver::ArrayCount(const ast::Expression* count_expr)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int64_t count = count_val->As<AInt>();
|
||||
int64_t count = count_val->ValueAs<AInt>();
|
||||
if (count < 1) {
|
||||
AddError("array count (" + std::to_string(count) + ") must be greater than 0",
|
||||
count_expr->source);
|
||||
@@ -3270,7 +3270,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
|
||||
AddError("@offset must be constant expression", o->expr->source);
|
||||
return false;
|
||||
}
|
||||
offset = const_value->As<uint64_t>();
|
||||
offset = const_value->ValueAs<uint64_t>();
|
||||
|
||||
if (offset < struct_size) {
|
||||
AddError("offsets must be in ascending order", o->source);
|
||||
@@ -3297,7 +3297,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
|
||||
AddError("@align must be constant expression", a->source);
|
||||
return false;
|
||||
}
|
||||
auto value = const_value->As<AInt>();
|
||||
auto value = const_value->ValueAs<AInt>();
|
||||
|
||||
if (value <= 0 || !utils::IsPowerOfTwo(value)) {
|
||||
AddError("@align value must be a positive, power-of-two integer",
|
||||
@@ -3327,13 +3327,13 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
|
||||
return false;
|
||||
}
|
||||
{
|
||||
auto value = const_value->As<AInt>();
|
||||
auto value = const_value->ValueAs<AInt>();
|
||||
if (value <= 0) {
|
||||
AddError("@size must be a positive integer", s->source);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
auto value = const_value->As<uint64_t>();
|
||||
auto value = const_value->ValueAs<uint64_t>();
|
||||
if (value < size) {
|
||||
AddError("@size must be at least as big as the type's size (" +
|
||||
std::to_string(size) + ")",
|
||||
|
||||
@@ -1573,7 +1573,7 @@ bool Validator::TextureBuiltinFunction(const sem::Call* call) const {
|
||||
if (auto values = arg->ConstantValue()) {
|
||||
if (auto* vector = values->Type()->As<type::Vector>()) {
|
||||
for (size_t i = 0; i < vector->Width(); i++) {
|
||||
auto value = values->Index(i)->As<AInt>();
|
||||
auto value = values->Index(i)->ValueAs<AInt>();
|
||||
if (value < min || value > max) {
|
||||
AddError("each component of the " + name + " argument must be at least " +
|
||||
std::to_string(min) + " and at most " + std::to_string(max) +
|
||||
@@ -1584,7 +1584,7 @@ bool Validator::TextureBuiltinFunction(const sem::Call* call) const {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto value = values->As<AInt>();
|
||||
auto value = values->ValueAs<AInt>();
|
||||
if (value < min || value > max) {
|
||||
AddError("the " + name + " argument must be at least " + std::to_string(min) +
|
||||
" and at most " + std::to_string(max) + ". " + name + " is " +
|
||||
@@ -2239,7 +2239,7 @@ bool Validator::SwitchStatement(const ast::SwitchStatement* s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto value = selector->Value()->As<uint32_t>();
|
||||
auto value = selector->Value()->ValueAs<u32>();
|
||||
if (auto added = selectors.Add(value, selector->Declaration()->source); !added) {
|
||||
AddError("duplicate switch case '" +
|
||||
(decl_ty->IsAnyOf<type::I32, type::AbstractNumeric>()
|
||||
|
||||
@@ -1011,7 +1011,7 @@ TEST_F(ResolverVariableTest, LocalConst_PropagateConstValue) {
|
||||
|
||||
ASSERT_TRUE(TypeOf(c)->Is<type::I32>());
|
||||
|
||||
EXPECT_EQ(Sem().Get(c)->ConstantValue()->As<i32>(), 42_i);
|
||||
EXPECT_EQ(Sem().Get(c)->ConstantValue()->ValueAs<i32>(), 42_i);
|
||||
}
|
||||
|
||||
TEST_F(ResolverVariableTest, LocalConst_ConstEval) {
|
||||
@@ -1023,7 +1023,7 @@ TEST_F(ResolverVariableTest, LocalConst_ConstEval) {
|
||||
|
||||
ASSERT_TRUE(TypeOf(c)->Is<type::I32>());
|
||||
|
||||
EXPECT_EQ(Sem().Get(c)->ConstantValue()->As<i32>(), 3_i);
|
||||
EXPECT_EQ(Sem().Get(c)->ConstantValue()->ValueAs<i32>(), 3_i);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1178,7 +1178,7 @@ TEST_F(ResolverVariableTest, GlobalConst_PropagateConstValue) {
|
||||
|
||||
ASSERT_TRUE(TypeOf(c)->Is<type::I32>());
|
||||
|
||||
EXPECT_EQ(Sem().Get(c)->ConstantValue()->As<i32>(), 42_i);
|
||||
EXPECT_EQ(Sem().Get(c)->ConstantValue()->ValueAs<i32>(), 42_i);
|
||||
}
|
||||
|
||||
TEST_F(ResolverVariableTest, GlobalConst_ConstEval) {
|
||||
@@ -1188,7 +1188,7 @@ TEST_F(ResolverVariableTest, GlobalConst_ConstEval) {
|
||||
|
||||
ASSERT_TRUE(TypeOf(c)->Is<type::I32>());
|
||||
|
||||
EXPECT_EQ(Sem().Get(c)->ConstantValue()->As<i32>(), 3_i);
|
||||
EXPECT_EQ(Sem().Get(c)->ConstantValue()->ValueAs<i32>(), 3_i);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user