Have TypesBuilder::bool_() return ast::Bool

Bug: tint:724
Change-Id: I7b5b1d0633f5ba654829502eaceee1ffa3ee4cd2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51660
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-05-20 14:22:28 +00:00 committed by Tint LUCI CQ
parent 9e32b20096
commit c03d3bdc94
9 changed files with 40 additions and 30 deletions

View File

@ -168,23 +168,24 @@ TEST_F(IntrinsicTableTest, MatchFIU32AsF32) {
}
TEST_F(IntrinsicTableTest, MismatchFIU32) {
auto* bool_ = create<sem::Bool>();
auto result = table->Lookup(*this, IntrinsicType::kClamp,
{ty.bool_(), ty.bool_(), ty.bool_()}, Source{});
{bool_, bool_, bool_}, Source{});
ASSERT_EQ(result.intrinsic, nullptr);
ASSERT_THAT(result.diagnostics.str(), HasSubstr("no matching call"));
}
TEST_F(IntrinsicTableTest, MatchBool) {
auto* f32 = create<sem::F32>();
auto result = table->Lookup(*this, IntrinsicType::kSelect,
{f32, f32, ty.bool_()}, Source{});
auto* bool_ = create<sem::Bool>();
auto result =
table->Lookup(*this, IntrinsicType::kSelect, {f32, f32, bool_}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
ASSERT_EQ(result.diagnostics.str(), "");
EXPECT_THAT(result.intrinsic->Type(), IntrinsicType::kSelect);
EXPECT_THAT(result.intrinsic->ReturnType(), f32);
EXPECT_THAT(
result.intrinsic->Parameters(),
ElementsAre(Parameter{f32}, Parameter{f32}, Parameter{ty.bool_()}));
EXPECT_THAT(result.intrinsic->Parameters(),
ElementsAre(Parameter{f32}, Parameter{f32}, Parameter{bool_}));
}
TEST_F(IntrinsicTableTest, MismatchBool) {
@ -472,8 +473,9 @@ TEST_F(IntrinsicTableTest, MismatchOpenSizeMatrix) {
TEST_F(IntrinsicTableTest, OverloadOrderByNumberOfParameters) {
// None of the arguments match, so expect the overloads with 2 parameters to
// come first
auto* bool_ = create<sem::Bool>();
auto result = table->Lookup(*this, IntrinsicType::kTextureDimensions,
{ty.bool_(), ty.bool_()}, Source{});
{bool_, bool_}, Source{});
ASSERT_EQ(result.diagnostics.str(),
R"(error: no matching call to textureDimensions(bool, bool)
@ -509,8 +511,9 @@ TEST_F(IntrinsicTableTest, OverloadOrderByNumberOfParameters) {
TEST_F(IntrinsicTableTest, OverloadOrderByMatchingParameter) {
auto tex = ty.depth_texture(ast::TextureDimension::k2d);
auto* bool_ = create<sem::Bool>();
auto result = table->Lookup(*this, IntrinsicType::kTextureDimensions,
{tex, ty.bool_()}, Source{});
{tex, bool_}, Source{});
ASSERT_EQ(
result.diagnostics.str(),
R"(error: no matching call to textureDimensions(texture_depth_2d, bool)

View File

@ -355,14 +355,12 @@ class ProgramBuilder {
}
/// @returns a boolean type
typ::Bool bool_() const {
return {builder->create<ast::Bool>(), builder->create<sem::Bool>()};
}
typ::Bool bool_() const { return {builder->create<ast::Bool>()}; }
/// @param source the Source of the node
/// @returns a boolean type
typ::Bool bool_(const Source& source) const {
return {builder->create<ast::Bool>(source), builder->create<sem::Bool>()};
return {builder->create<ast::Bool>(source)};
}
/// @returns a f32 type

View File

@ -28,7 +28,7 @@ TEST_F(ResolverIsHostShareable, Void) {
}
TEST_F(ResolverIsHostShareable, Bool) {
EXPECT_FALSE(r()->IsHostShareable(ty.bool_()));
EXPECT_FALSE(r()->IsHostShareable(create<sem::Bool>()));
}
TEST_F(ResolverIsHostShareable, NumericScalar) {
@ -50,15 +50,24 @@ TEST_F(ResolverIsHostShareable, NumericVector) {
}
TEST_F(ResolverIsHostShareable, BoolVector) {
EXPECT_FALSE(r()->IsHostShareable(ty.vec2<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec3<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec4<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec2<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec3<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec4<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec2<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec3<bool>()));
EXPECT_FALSE(r()->IsHostShareable(ty.vec4<bool>()));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 2)));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 3)));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 4)));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 2)));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 3)));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 4)));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 2)));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 3)));
EXPECT_FALSE(
r()->IsHostShareable(create<sem::Vector>(create<sem::Bool>(), 4)));
}
TEST_F(ResolverIsHostShareable, Matrix) {

View File

@ -28,7 +28,7 @@ TEST_F(ResolverIsStorableTest, Void) {
}
TEST_F(ResolverIsStorableTest, Scalar) {
EXPECT_TRUE(r()->IsStorable(ty.bool_()));
EXPECT_TRUE(r()->IsStorable(create<sem::Bool>()));
EXPECT_TRUE(r()->IsStorable(create<sem::I32>()));
EXPECT_TRUE(r()->IsStorable(create<sem::U32>()));
EXPECT_TRUE(r()->IsStorable(create<sem::F32>()));

View File

@ -1458,7 +1458,7 @@ bool Resolver::IfStatement(ast::IfStatement* stmt) {
}
auto* cond_type = TypeOf(stmt->condition())->UnwrapRef();
if (cond_type != builder_->ty.bool_()) {
if (!cond_type->Is<sem::Bool>()) {
diagnostics_.add_error("if statement condition must be bool, got " +
cond_type->FriendlyName(builder_->Symbols()),
stmt->condition()->source());
@ -1490,7 +1490,7 @@ bool Resolver::IfStatement(ast::IfStatement* stmt) {
}
auto* else_cond_type = TypeOf(cond)->UnwrapRef();
if (else_cond_type != builder_->ty.bool_()) {
if (!else_cond_type->Is<sem::Bool>()) {
diagnostics_.add_error(
"else statement condition must be bool, got " +
else_cond_type->FriendlyName(builder_->Symbols()),

View File

@ -238,7 +238,6 @@ bool operator!=(std::nullptr_t, const TypePair<AST, SEM>& rhs) {
using Type = TypePair<ast::Type, sem::Type>;
using Array = TypePair<ast::Array, sem::Array>;
using Bool = TypePair<ast::Bool, sem::Bool>;
using DepthTexture = TypePair<ast::DepthTexture, sem::DepthTexture>;
using ExternalTexture = TypePair<ast::ExternalTexture, sem::ExternalTexture>;
using Matrix = TypePair<ast::Matrix, sem::Matrix>;
@ -253,6 +252,7 @@ using Texture = TypePair<ast::Texture, sem::Texture>;
using Vector = TypePair<ast::Vector, sem::Vector>;
using Void = TypePair<ast::Void, sem::Void>;
using Bool = Ptr<ast::Bool>;
using U32 = Ptr<ast::U32>;
using I32 = Ptr<ast::I32>;
using F32 = Ptr<ast::F32>;

View File

@ -106,7 +106,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_RuntimeArray) {
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
auto bool_ = ty.bool_();
auto* bool_ = create<sem::Bool>();
GeneratorImpl& gen = Build();

View File

@ -123,7 +123,7 @@ TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) {
}
TEST_F(MslGeneratorImplTest, EmitType_Bool) {
auto bool_ = ty.bool_();
auto* bool_ = create<sem::Bool>();
GeneratorImpl& gen = Build();

View File

@ -125,7 +125,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedArray) {
}
TEST_F(BuilderTest_Type, GenerateBool) {
auto bool_ = ty.bool_();
auto* bool_ = create<sem::Bool>();
spirv::Builder& b = Build();
@ -139,7 +139,7 @@ TEST_F(BuilderTest_Type, GenerateBool) {
}
TEST_F(BuilderTest_Type, ReturnsGeneratedBool) {
auto bool_ = ty.bool_();
auto* bool_ = create<sem::Bool>();
auto* i32 = create<sem::I32>();
spirv::Builder& b = Build();