tint/resolver: Fix intrinsic table matching of AInt as AFloat
An AInt argument can be passed to a parameter of type AFloat. Fix the matcher for AFloat so that it includes AInts. Change-Id: I6aeebb567b6176b146920a2035f09cd07c11c014 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100780 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
ef8b50f9d2
commit
54bcbdbbf3
|
@ -105,8 +105,8 @@ enum texel_format {
|
|||
|
||||
// https://gpuweb.github.io/gpuweb/wgsl/#plain-types-section
|
||||
type bool
|
||||
@precedence(5) @display("abstract-float") type fa
|
||||
@precedence(4) @display("abstract-int") type ia
|
||||
@precedence(5) @display("abstract-int") type ia
|
||||
@precedence(4) @display("abstract-float") type fa
|
||||
@precedence(3) type i32
|
||||
@precedence(2) type u32
|
||||
@precedence(1) type f32
|
||||
|
|
|
@ -349,7 +349,7 @@ const sem::AbstractFloat* build_fa(MatchState& state) {
|
|||
}
|
||||
|
||||
bool match_fa(const sem::Type* ty) {
|
||||
return ty->IsAnyOf<Any, sem::AbstractFloat>();
|
||||
return ty->IsAnyOf<Any, sem::AbstractNumeric>();
|
||||
}
|
||||
|
||||
const sem::AbstractInt* build_ia(MatchState& state) {
|
||||
|
|
|
@ -48,34 +48,6 @@ std::string Bool::String(MatchState*) const {
|
|||
return "bool";
|
||||
}
|
||||
|
||||
/// TypeMatcher for 'type fa'
|
||||
class Fa : public TypeMatcher {
|
||||
public:
|
||||
/// Checks whether the given type matches the matcher rules.
|
||||
/// Match may define and refine the template types and numbers in state.
|
||||
/// @param state the MatchState
|
||||
/// @param type the type to match
|
||||
/// @returns the canonicalized type on match, otherwise nullptr
|
||||
const sem::Type* Match(MatchState& state,
|
||||
const sem::Type* type) const override;
|
||||
/// @param state the MatchState
|
||||
/// @return a string representation of the matcher.
|
||||
std::string String(MatchState* state) const override;
|
||||
};
|
||||
|
||||
const sem::Type* Fa::Match(MatchState& state, const sem::Type* ty) const {
|
||||
if (!match_fa(ty)) {
|
||||
return nullptr;
|
||||
}
|
||||
return build_fa(state);
|
||||
}
|
||||
|
||||
std::string Fa::String(MatchState*) const {
|
||||
std::stringstream ss;
|
||||
ss << "abstract-float";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/// TypeMatcher for 'type ia'
|
||||
class Ia : public TypeMatcher {
|
||||
public:
|
||||
|
@ -104,6 +76,34 @@ std::string Ia::String(MatchState*) const {
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
/// TypeMatcher for 'type fa'
|
||||
class Fa : public TypeMatcher {
|
||||
public:
|
||||
/// Checks whether the given type matches the matcher rules.
|
||||
/// Match may define and refine the template types and numbers in state.
|
||||
/// @param state the MatchState
|
||||
/// @param type the type to match
|
||||
/// @returns the canonicalized type on match, otherwise nullptr
|
||||
const sem::Type* Match(MatchState& state,
|
||||
const sem::Type* type) const override;
|
||||
/// @param state the MatchState
|
||||
/// @return a string representation of the matcher.
|
||||
std::string String(MatchState* state) const override;
|
||||
};
|
||||
|
||||
const sem::Type* Fa::Match(MatchState& state, const sem::Type* ty) const {
|
||||
if (!match_fa(ty)) {
|
||||
return nullptr;
|
||||
}
|
||||
return build_fa(state);
|
||||
}
|
||||
|
||||
std::string Fa::String(MatchState*) const {
|
||||
std::stringstream ss;
|
||||
ss << "abstract-float";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/// TypeMatcher for 'type i32'
|
||||
class I32 : public TypeMatcher {
|
||||
public:
|
||||
|
@ -1567,12 +1567,12 @@ class AbstractOrScalar : public TypeMatcher {
|
|||
};
|
||||
|
||||
const sem::Type* AbstractOrScalar::Match(MatchState& state, const sem::Type* ty) const {
|
||||
if (match_fa(ty)) {
|
||||
return build_fa(state);
|
||||
}
|
||||
if (match_ia(ty)) {
|
||||
return build_ia(state);
|
||||
}
|
||||
if (match_fa(ty)) {
|
||||
return build_fa(state);
|
||||
}
|
||||
if (match_i32(ty)) {
|
||||
return build_i32(state);
|
||||
}
|
||||
|
@ -1859,12 +1859,12 @@ class FiaFiu32F16 : public TypeMatcher {
|
|||
};
|
||||
|
||||
const sem::Type* FiaFiu32F16::Match(MatchState& state, const sem::Type* ty) const {
|
||||
if (match_fa(ty)) {
|
||||
return build_fa(state);
|
||||
}
|
||||
if (match_ia(ty)) {
|
||||
return build_ia(state);
|
||||
}
|
||||
if (match_fa(ty)) {
|
||||
return build_fa(state);
|
||||
}
|
||||
if (match_i32(ty)) {
|
||||
return build_i32(state);
|
||||
}
|
||||
|
@ -1905,12 +1905,12 @@ class FiaFi32F16 : public TypeMatcher {
|
|||
};
|
||||
|
||||
const sem::Type* FiaFi32F16::Match(MatchState& state, const sem::Type* ty) const {
|
||||
if (match_fa(ty)) {
|
||||
return build_fa(state);
|
||||
}
|
||||
if (match_ia(ty)) {
|
||||
return build_ia(state);
|
||||
}
|
||||
if (match_fa(ty)) {
|
||||
return build_fa(state);
|
||||
}
|
||||
if (match_i32(ty)) {
|
||||
return build_i32(state);
|
||||
}
|
||||
|
@ -1948,12 +1948,12 @@ class FiaFiu32 : public TypeMatcher {
|
|||
};
|
||||
|
||||
const sem::Type* FiaFiu32::Match(MatchState& state, const sem::Type* ty) const {
|
||||
if (match_fa(ty)) {
|
||||
return build_fa(state);
|
||||
}
|
||||
if (match_ia(ty)) {
|
||||
return build_ia(state);
|
||||
}
|
||||
if (match_fa(ty)) {
|
||||
return build_fa(state);
|
||||
}
|
||||
if (match_i32(ty)) {
|
||||
return build_i32(state);
|
||||
}
|
||||
|
@ -2533,8 +2533,8 @@ class Matchers {
|
|||
TemplateNumberMatcher template_number_1_{1};
|
||||
TemplateNumberMatcher template_number_2_{2};
|
||||
Bool Bool_;
|
||||
Fa Fa_;
|
||||
Ia Ia_;
|
||||
Fa Fa_;
|
||||
I32 I32_;
|
||||
U32 U32_;
|
||||
F32 F32_;
|
||||
|
@ -2619,8 +2619,8 @@ class Matchers {
|
|||
/* [0] */ &template_type_0_,
|
||||
/* [1] */ &template_type_1_,
|
||||
/* [2] */ &Bool_,
|
||||
/* [3] */ &Fa_,
|
||||
/* [4] */ &Ia_,
|
||||
/* [3] */ &Ia_,
|
||||
/* [4] */ &Fa_,
|
||||
/* [5] */ &I32_,
|
||||
/* [6] */ &U32_,
|
||||
/* [7] */ &F32_,
|
||||
|
|
|
@ -767,6 +767,22 @@ TEST_F(IntrinsicTableTest, MismatchTypeConstructorExplicit) {
|
|||
)");
|
||||
}
|
||||
|
||||
TEST_F(IntrinsicTableTest, MatchTypeConstructorImplicitMatFromVec) {
|
||||
auto* af = create<sem::AbstractFloat>();
|
||||
auto* vec2_ai = create<sem::Vector>(create<sem::AbstractInt>(), 2u);
|
||||
auto* vec2_af = create<sem::Vector>(af, 2u);
|
||||
auto* mat2x2_af = create<sem::Matrix>(vec2_af, 2u);
|
||||
auto result = table->Lookup(CtorConvIntrinsic::kMat2x2, nullptr,
|
||||
utils::Vector{vec2_ai, vec2_ai}, Source{{12, 34}});
|
||||
ASSERT_NE(result.target, nullptr);
|
||||
EXPECT_TYPE(result.target->ReturnType(), mat2x2_af);
|
||||
EXPECT_TRUE(result.target->Is<sem::TypeConstructor>());
|
||||
ASSERT_EQ(result.target->Parameters().Length(), 2u);
|
||||
EXPECT_TYPE(result.target->Parameters()[0]->Type(), vec2_af);
|
||||
EXPECT_TYPE(result.target->Parameters()[1]->Type(), vec2_af);
|
||||
EXPECT_NE(result.const_eval_fn, nullptr);
|
||||
}
|
||||
|
||||
TEST_F(IntrinsicTableTest, MatchTypeConversion) {
|
||||
auto* i32 = create<sem::I32>();
|
||||
auto* vec3_i32 = create<sem::Vector>(i32, 3u);
|
||||
|
|
Loading…
Reference in New Issue