Have TypesBuilder::u32() return ast::U32

Bug: tint:724
Change-Id: I23a26dadcb6037e3eb2b4c46e727da37e84c1fc1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49342
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-05-19 17:47:11 +00:00
parent dffb68e49d
commit 58dec17828
8 changed files with 33 additions and 32 deletions

View File

@ -53,13 +53,14 @@ TEST_F(IntrinsicTableTest, MismatchF32) {
}
TEST_F(IntrinsicTableTest, MatchU32) {
auto result = table->Lookup(*this, IntrinsicType::kUnpack2x16Float,
{ty.u32()}, Source{});
auto* u32 = create<sem::U32>();
auto result =
table->Lookup(*this, IntrinsicType::kUnpack2x16Float, {u32}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
ASSERT_EQ(result.diagnostics.str(), "");
EXPECT_THAT(result.intrinsic->Type(), IntrinsicType::kUnpack2x16Float);
EXPECT_THAT(result.intrinsic->ReturnType(), ty.vec2<f32>());
EXPECT_THAT(result.intrinsic->Parameters(), ElementsAre(Parameter{ty.u32()}));
EXPECT_THAT(result.intrinsic->Parameters(), ElementsAre(Parameter{u32}));
}
TEST_F(IntrinsicTableTest, MismatchU32) {
@ -102,13 +103,14 @@ TEST_F(IntrinsicTableTest, MatchIU32AsI32) {
}
TEST_F(IntrinsicTableTest, MatchIU32AsU32) {
auto* u32 = create<sem::U32>();
auto result =
table->Lookup(*this, IntrinsicType::kCountOneBits, {ty.u32()}, Source{});
table->Lookup(*this, IntrinsicType::kCountOneBits, {u32}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
ASSERT_EQ(result.diagnostics.str(), "");
EXPECT_THAT(result.intrinsic->Type(), IntrinsicType::kCountOneBits);
EXPECT_THAT(result.intrinsic->ReturnType(), ty.u32());
EXPECT_THAT(result.intrinsic->Parameters(), ElementsAre(Parameter{ty.u32()}));
EXPECT_THAT(result.intrinsic->ReturnType(), u32);
EXPECT_THAT(result.intrinsic->Parameters(), ElementsAre(Parameter{u32}));
}
TEST_F(IntrinsicTableTest, MismatchIU32) {
@ -131,15 +133,15 @@ TEST_F(IntrinsicTableTest, MatchFIU32AsI32) {
}
TEST_F(IntrinsicTableTest, MatchFIU32AsU32) {
auto result = table->Lookup(*this, IntrinsicType::kClamp,
{ty.u32(), ty.u32(), ty.u32()}, Source{});
auto* u32 = create<sem::U32>();
auto result =
table->Lookup(*this, IntrinsicType::kClamp, {u32, u32, u32}, Source{});
ASSERT_NE(result.intrinsic, nullptr);
ASSERT_EQ(result.diagnostics.str(), "");
EXPECT_THAT(result.intrinsic->Type(), IntrinsicType::kClamp);
EXPECT_THAT(result.intrinsic->ReturnType(), ty.u32());
EXPECT_THAT(result.intrinsic->ReturnType(), u32);
EXPECT_THAT(result.intrinsic->Parameters(),
ElementsAre(Parameter{ty.u32()}, Parameter{ty.u32()},
Parameter{ty.u32()}));
ElementsAre(Parameter{u32}, Parameter{u32}, Parameter{u32}));
}
TEST_F(IntrinsicTableTest, MatchFIU32AsF32) {
@ -208,7 +210,7 @@ TEST_F(IntrinsicTableTest, MatchArray) {
ASSERT_NE(result.intrinsic, nullptr);
ASSERT_EQ(result.diagnostics.str(), "");
EXPECT_THAT(result.intrinsic->Type(), IntrinsicType::kArrayLength);
EXPECT_THAT(result.intrinsic->ReturnType(), ty.u32());
EXPECT_TRUE(result.intrinsic->ReturnType()->Is<sem::U32>());
ASSERT_EQ(result.intrinsic->Parameters().size(), 1u);
EXPECT_TRUE(result.intrinsic->Parameters()[0].type->Is<sem::Array>());
}
@ -371,8 +373,9 @@ TEST_F(IntrinsicTableTest, MatchOpenType) {
}
TEST_F(IntrinsicTableTest, MismatchOpenType) {
auto* u32 = create<sem::U32>();
auto result = table->Lookup(*this, IntrinsicType::kClamp,
{ty.f32(), ty.u32(), ty.f32()}, Source{});
{ty.f32(), u32, ty.f32()}, Source{});
ASSERT_EQ(result.intrinsic, nullptr);
ASSERT_THAT(result.diagnostics.str(), HasSubstr("no matching call"));
}
@ -391,9 +394,9 @@ TEST_F(IntrinsicTableTest, MatchOpenSizeVector) {
}
TEST_F(IntrinsicTableTest, MismatchOpenSizeVector) {
auto result =
table->Lookup(*this, IntrinsicType::kClamp,
{ty.vec2<f32>(), ty.vec2<u32>(), ty.vec2<f32>()}, Source{});
auto* u32 = create<sem::U32>();
auto result = table->Lookup(*this, IntrinsicType::kClamp,
{ty.vec2<f32>(), u32, ty.vec2<f32>()}, Source{});
ASSERT_EQ(result.intrinsic, nullptr);
ASSERT_THAT(result.diagnostics.str(), HasSubstr("no matching call"));
}

View File

@ -388,14 +388,12 @@ class ProgramBuilder {
}
/// @returns a u32 type
typ::U32 u32() const {
return {builder->create<ast::U32>(), builder->create<sem::U32>()};
}
typ::U32 u32() const { return builder->create<ast::U32>(); }
/// @param source the Source of the node
/// @returns a u32 type
typ::U32 u32(const Source& source) const {
return {builder->create<ast::U32>(source), builder->create<sem::U32>()};
return builder->create<ast::U32>(source);
}
/// @returns a void type

View File

@ -33,7 +33,7 @@ TEST_F(ResolverIsHostShareable, Bool) {
TEST_F(ResolverIsHostShareable, NumericScalar) {
EXPECT_TRUE(r()->IsHostShareable(ty.i32()));
EXPECT_TRUE(r()->IsHostShareable(ty.u32()));
EXPECT_TRUE(r()->IsHostShareable(create<sem::U32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.f32()));
}
@ -41,9 +41,9 @@ TEST_F(ResolverIsHostShareable, NumericVector) {
EXPECT_TRUE(r()->IsHostShareable(ty.vec2<i32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec3<i32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec4<i32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec2<u32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec3<u32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec4<u32>()));
EXPECT_TRUE(r()->IsHostShareable(create<sem::Vector>(create<sem::U32>(), 2)));
EXPECT_TRUE(r()->IsHostShareable(create<sem::Vector>(create<sem::U32>(), 3)));
EXPECT_TRUE(r()->IsHostShareable(create<sem::Vector>(create<sem::U32>(), 4)));
EXPECT_TRUE(r()->IsHostShareable(ty.vec2<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec3<f32>()));
EXPECT_TRUE(r()->IsHostShareable(ty.vec4<f32>()));

View File

@ -30,7 +30,7 @@ TEST_F(ResolverIsStorableTest, Void) {
TEST_F(ResolverIsStorableTest, Scalar) {
EXPECT_TRUE(r()->IsStorable(ty.bool_()));
EXPECT_TRUE(r()->IsStorable(ty.i32()));
EXPECT_TRUE(r()->IsStorable(ty.u32()));
EXPECT_TRUE(r()->IsStorable(create<sem::U32>()));
EXPECT_TRUE(r()->IsStorable(ty.f32()));
}
@ -38,9 +38,9 @@ TEST_F(ResolverIsStorableTest, Vector) {
EXPECT_TRUE(r()->IsStorable(ty.vec2<i32>()));
EXPECT_TRUE(r()->IsStorable(ty.vec3<i32>()));
EXPECT_TRUE(r()->IsStorable(ty.vec4<i32>()));
EXPECT_TRUE(r()->IsStorable(ty.vec2<u32>()));
EXPECT_TRUE(r()->IsStorable(ty.vec3<u32>()));
EXPECT_TRUE(r()->IsStorable(ty.vec4<u32>()));
EXPECT_TRUE(r()->IsStorable(create<sem::Vector>(create<sem::U32>(), 2)));
EXPECT_TRUE(r()->IsStorable(create<sem::Vector>(create<sem::U32>(), 3)));
EXPECT_TRUE(r()->IsStorable(create<sem::Vector>(create<sem::U32>(), 4)));
EXPECT_TRUE(r()->IsStorable(ty.vec2<f32>()));
EXPECT_TRUE(r()->IsStorable(ty.vec3<f32>()));
EXPECT_TRUE(r()->IsStorable(ty.vec4<f32>()));

View File

@ -761,7 +761,7 @@ TEST_F(ResolverTest, Function_Parameters) {
EXPECT_EQ(func_sem->Parameters().size(), 3u);
EXPECT_EQ(func_sem->Parameters()[0]->Type(), ty.f32());
EXPECT_EQ(func_sem->Parameters()[1]->Type(), ty.i32());
EXPECT_EQ(func_sem->Parameters()[2]->Type(), ty.u32());
EXPECT_TRUE(func_sem->Parameters()[2]->Type()->Is<sem::U32>());
EXPECT_EQ(func_sem->Parameters()[0]->Declaration(), param_a);
EXPECT_EQ(func_sem->Parameters()[1]->Declaration(), param_b);
EXPECT_EQ(func_sem->Parameters()[2]->Declaration(), param_c);

View File

@ -252,10 +252,11 @@ using SampledTexture = TypePair<ast::SampledTexture, sem::SampledTexture>;
using StorageTexture = TypePair<ast::StorageTexture, sem::StorageTexture>;
using Struct = TypePair<ast::Struct, sem::Struct>;
using Texture = TypePair<ast::Texture, sem::Texture>;
using U32 = TypePair<ast::U32, sem::U32>;
using Vector = TypePair<ast::Vector, sem::Vector>;
using Void = TypePair<ast::Void, sem::Void>;
using U32 = Ptr<ast::U32>;
// Helpers
/// Makes a type pair, deducing the return type from input args

View File

@ -282,7 +282,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) {
auto u32 = ty.u32();
auto* u32 = create<sem::U32>();
GeneratorImpl& gen = Build();

View File

@ -276,7 +276,6 @@ struct S {
TEST_F(WgslGeneratorImplTest, EmitType_U32) {
auto u32 = ty.u32();
AST().AddConstructedType(ty.alias("make_type_reachable", u32));
GeneratorImpl& gen = Build();