diff --git a/src/intrinsic_table_test.cc b/src/intrinsic_table_test.cc index d689681110..7ee87e8a35 100644 --- a/src/intrinsic_table_test.cc +++ b/src/intrinsic_table_test.cc @@ -168,23 +168,24 @@ TEST_F(IntrinsicTableTest, MatchFIU32AsF32) { } TEST_F(IntrinsicTableTest, MismatchFIU32) { + auto* bool_ = create(); 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(); - auto result = table->Lookup(*this, IntrinsicType::kSelect, - {f32, f32, ty.bool_()}, Source{}); + auto* bool_ = create(); + 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(); 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(); 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 a8083569c5..186d6f9525 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -355,14 +355,12 @@ class ProgramBuilder { } /// @returns a boolean type - typ::Bool bool_() const { - return {builder->create(), builder->create()}; - } + typ::Bool bool_() const { return {builder->create()}; } /// @param source the Source of the node /// @returns a boolean type typ::Bool bool_(const Source& source) const { - return {builder->create(source), builder->create()}; + return {builder->create(source)}; } /// @returns a f32 type diff --git a/src/resolver/is_host_shareable_test.cc b/src/resolver/is_host_shareable_test.cc index 5ef5f48f02..0af2e5a9e3 100644 --- a/src/resolver/is_host_shareable_test.cc +++ b/src/resolver/is_host_shareable_test.cc @@ -28,7 +28,7 @@ TEST_F(ResolverIsHostShareable, Void) { } TEST_F(ResolverIsHostShareable, Bool) { - EXPECT_FALSE(r()->IsHostShareable(ty.bool_())); + EXPECT_FALSE(r()->IsHostShareable(create())); } TEST_F(ResolverIsHostShareable, NumericScalar) { @@ -50,15 +50,24 @@ TEST_F(ResolverIsHostShareable, NumericVector) { } TEST_F(ResolverIsHostShareable, BoolVector) { - EXPECT_FALSE(r()->IsHostShareable(ty.vec2())); - EXPECT_FALSE(r()->IsHostShareable(ty.vec3())); - EXPECT_FALSE(r()->IsHostShareable(ty.vec4())); - EXPECT_FALSE(r()->IsHostShareable(ty.vec2())); - EXPECT_FALSE(r()->IsHostShareable(ty.vec3())); - EXPECT_FALSE(r()->IsHostShareable(ty.vec4())); - EXPECT_FALSE(r()->IsHostShareable(ty.vec2())); - EXPECT_FALSE(r()->IsHostShareable(ty.vec3())); - EXPECT_FALSE(r()->IsHostShareable(ty.vec4())); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 2))); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 3))); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 4))); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 2))); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 3))); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 4))); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 2))); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 3))); + EXPECT_FALSE( + r()->IsHostShareable(create(create(), 4))); } TEST_F(ResolverIsHostShareable, Matrix) { diff --git a/src/resolver/is_storeable_test.cc b/src/resolver/is_storeable_test.cc index 064c28acc8..55d3a7801a 100644 --- a/src/resolver/is_storeable_test.cc +++ b/src/resolver/is_storeable_test.cc @@ -28,7 +28,7 @@ TEST_F(ResolverIsStorableTest, Void) { } TEST_F(ResolverIsStorableTest, Scalar) { - EXPECT_TRUE(r()->IsStorable(ty.bool_())); + EXPECT_TRUE(r()->IsStorable(create())); EXPECT_TRUE(r()->IsStorable(create())); EXPECT_TRUE(r()->IsStorable(create())); EXPECT_TRUE(r()->IsStorable(create())); diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index fcfc908077..b2f589f791 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -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()) { 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()) { 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 52f0065920..c8844b0828 100644 --- a/src/typepair.h +++ b/src/typepair.h @@ -238,7 +238,6 @@ bool operator!=(std::nullptr_t, const TypePair& rhs) { using Type = TypePair; using Array = TypePair; -using Bool = TypePair; using DepthTexture = TypePair; using ExternalTexture = TypePair; using Matrix = TypePair; @@ -253,6 +252,7 @@ using Texture = TypePair; using Vector = TypePair; using Void = TypePair; +using Bool = Ptr; using U32 = Ptr; using I32 = Ptr; using F32 = Ptr; diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index b57fe5b91e..908c2a2849 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, DISABLED_EmitType_RuntimeArray) { } TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) { - auto bool_ = ty.bool_(); + auto* bool_ = create(); GeneratorImpl& gen = Build(); diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index 340eb27d45..9e282ab0cc 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_RuntimeArray) { } TEST_F(MslGeneratorImplTest, EmitType_Bool) { - auto bool_ = ty.bool_(); + auto* bool_ = create(); GeneratorImpl& gen = Build(); diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 8da9b7a50c..51cb38e4ff 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, ReturnsGeneratedArray) { } TEST_F(BuilderTest_Type, GenerateBool) { - auto bool_ = ty.bool_(); + auto* bool_ = create(); 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(); auto* i32 = create(); spirv::Builder& b = Build();