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>
diff --git a/src/intrinsic_table_test.cc b/src/intrinsic_table_test.cc
index d689681..7ee87e8 100644
--- a/src/intrinsic_table_test.cc
+++ b/src/intrinsic_table_test.cc
@@ -168,23 +168,24 @@
}
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, 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, 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)
diff --git a/src/program_builder.h b/src/program_builder.h
index a808356..186d6f9 100644
--- a/src/program_builder.h
+++ b/src/program_builder.h
@@ -355,14 +355,12 @@
}
/// @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
diff --git a/src/resolver/is_host_shareable_test.cc b/src/resolver/is_host_shareable_test.cc
index 5ef5f48..0af2e5a 100644
--- a/src/resolver/is_host_shareable_test.cc
+++ b/src/resolver/is_host_shareable_test.cc
@@ -28,7 +28,7 @@
}
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, 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) {
diff --git a/src/resolver/is_storeable_test.cc b/src/resolver/is_storeable_test.cc
index 064c28a..55d3a78 100644
--- a/src/resolver/is_storeable_test.cc
+++ b/src/resolver/is_storeable_test.cc
@@ -28,7 +28,7 @@
}
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>()));
diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc
index fcfc908..b2f589f 100644
--- a/src/resolver/resolver.cc
+++ b/src/resolver/resolver.cc
@@ -1458,7 +1458,7 @@
}
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 @@
}
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()),
diff --git a/src/typepair.h b/src/typepair.h
index 52f0065..c8844b0 100644
--- a/src/typepair.h
+++ b/src/typepair.h
@@ -238,7 +238,6 @@
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 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>;
diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc
index b57fe5b..908c2a2 100644
--- a/src/writer/hlsl/generator_impl_type_test.cc
+++ b/src/writer/hlsl/generator_impl_type_test.cc
@@ -106,7 +106,7 @@
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
- auto bool_ = ty.bool_();
+ auto* bool_ = create<sem::Bool>();
GeneratorImpl& gen = Build();
diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc
index 340eb27..9e282ab 100644
--- a/src/writer/msl/generator_impl_type_test.cc
+++ b/src/writer/msl/generator_impl_type_test.cc
@@ -123,7 +123,7 @@
}
TEST_F(MslGeneratorImplTest, EmitType_Bool) {
- auto bool_ = ty.bool_();
+ auto* bool_ = create<sem::Bool>();
GeneratorImpl& gen = Build();
diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc
index 8da9b7a..51cb38e 100644
--- a/src/writer/spirv/builder_type_test.cc
+++ b/src/writer/spirv/builder_type_test.cc
@@ -125,7 +125,7 @@
}
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, ReturnsGeneratedBool) {
- auto bool_ = ty.bool_();
+ auto* bool_ = create<sem::Bool>();
auto* i32 = create<sem::I32>();
spirv::Builder& b = Build();