tint/resolver: Rename test field names, update comments

Try and make things a little clearer.

Change-Id: I66b051e71d4fc8366afe8b2b90067c7c0708d7cc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91844
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2022-05-27 22:06:26 +00:00 committed by Dawn LUCI CQ
parent eac0566718
commit 3aa0f8182b
1 changed files with 47 additions and 47 deletions

View File

@ -41,53 +41,53 @@ namespace MaterializeTests {
// How should the materialization occur? // How should the materialization occur?
enum class Method { enum class Method {
// var a : T = literal; // var a : target_type = abstract_expr;
kVar, kVar,
// let a : T = literal; // let a : target_type = abstract_expr;
kLet, kLet,
// fn F(v : T) {} // fn F(v : target_type) {}
// fn x() { // fn x() {
// F(literal); // F(abstract_expr);
// } // }
kFnArg, kFnArg,
// min(target_expr, literal); // min(target_expr, abstract_expr);
kBuiltinArg, kBuiltinArg,
// fn F() : T { // fn F() : target_type {
// return literal; // return abstract_expr;
// } // }
kReturn, kReturn,
// array<T, 1>(literal); // array<target_type, 1>(abstract_expr);
kArray, kArray,
// struct S { // struct S {
// v : T // v : target_type
// }; // };
// fn x() { // fn x() {
// _ = S(literal) // _ = S(abstract_expr)
// } // }
kStruct, kStruct,
// target_expr + literal // target_expr + abstract_expr
kBinaryOp, kBinaryOp,
// switch (literal) { // switch (abstract_expr) {
// case target_expr: {} // case target_expr: {}
// default: {} // default: {}
// } // }
kSwitchCond, kSwitchCond,
// switch (target_expr) { // switch (target_expr) {
// case literal: {} // case abstract_expr: {}
// default: {} // default: {}
// } // }
kSwitchCase, kSwitchCase,
// switch (literal) { // switch (abstract_expr) {
// case 123: {} // case 123: {}
// case target_expr: {} // case target_expr: {}
// default: {} // default: {}
@ -96,7 +96,7 @@ enum class Method {
// switch (target_expr) { // switch (target_expr) {
// case 123: {} // case 123: {}
// case literal: {} // case abstract_expr: {}
// default: {} // default: {}
// } // }
kSwitchCaseWithAbstractCase, kSwitchCaseWithAbstractCase,
@ -138,16 +138,16 @@ struct Data {
builder::ast_type_func_ptr target_ast_ty; builder::ast_type_func_ptr target_ast_ty;
builder::sem_type_func_ptr target_sem_ty; builder::sem_type_func_ptr target_sem_ty;
builder::ast_expr_func_ptr target_expr; builder::ast_expr_func_ptr target_expr;
std::string source_type_name; std::string abstract_type_name;
builder::ast_expr_func_ptr source_builder; builder::ast_expr_func_ptr abstract_expr;
std::variant<AInt, AFloat> materialized_value; std::variant<AInt, AFloat> materialized_value;
double literal_value; double literal_value;
}; };
template <typename TARGET_TYPE, typename SOURCE_TYPE, typename MATERIALIZED_TYPE> template <typename TARGET_TYPE, typename ABSTRACT_TYPE, typename MATERIALIZED_TYPE>
Data Types(MATERIALIZED_TYPE materialized_value, double literal_value) { Data Types(MATERIALIZED_TYPE materialized_value, double literal_value) {
using TargetDataType = builder::DataType<TARGET_TYPE>; using TargetDataType = builder::DataType<TARGET_TYPE>;
using SourceDataType = builder::DataType<SOURCE_TYPE>; using AbstractDataType = builder::DataType<ABSTRACT_TYPE>;
using TargetElementDataType = builder::DataType<typename TargetDataType::ElementType>; using TargetElementDataType = builder::DataType<typename TargetDataType::ElementType>;
return { return {
TargetDataType::Name(), // target_type_name TargetDataType::Name(), // target_type_name
@ -155,17 +155,17 @@ Data Types(MATERIALIZED_TYPE materialized_value, double literal_value) {
TargetDataType::AST, // target_ast_ty TargetDataType::AST, // target_ast_ty
TargetDataType::Sem, // target_sem_ty TargetDataType::Sem, // target_sem_ty
TargetDataType::Expr, // target_expr TargetDataType::Expr, // target_expr
SourceDataType::Name(), // literal_type_name AbstractDataType::Name(), // abstract_type_name
SourceDataType::Expr, // literal_builder AbstractDataType::Expr, // abstract_expr
materialized_value, materialized_value,
literal_value, literal_value,
}; };
} }
template <typename TARGET_TYPE, typename SOURCE_TYPE> template <typename TARGET_TYPE, typename ABSTRACT_TYPE>
Data Types() { Data Types() {
using TargetDataType = builder::DataType<TARGET_TYPE>; using TargetDataType = builder::DataType<TARGET_TYPE>;
using SourceDataType = builder::DataType<SOURCE_TYPE>; using AbstractDataType = builder::DataType<ABSTRACT_TYPE>;
using TargetElementDataType = builder::DataType<typename TargetDataType::ElementType>; using TargetElementDataType = builder::DataType<typename TargetDataType::ElementType>;
return { return {
TargetDataType::Name(), // target_type_name TargetDataType::Name(), // target_type_name
@ -173,8 +173,8 @@ Data Types() {
TargetDataType::AST, // target_ast_ty TargetDataType::AST, // target_ast_ty
TargetDataType::Sem, // target_sem_ty TargetDataType::Sem, // target_sem_ty
TargetDataType::Expr, // target_expr TargetDataType::Expr, // target_expr
SourceDataType::Name(), // literal_type_name AbstractDataType::Name(), // abstract_type_name
SourceDataType::Expr, // literal_builder AbstractDataType::Expr, // abstract_expr
0_a, 0_a,
0.0, 0.0,
}; };
@ -182,7 +182,7 @@ Data Types() {
static std::ostream& operator<<(std::ostream& o, const Data& c) { static std::ostream& operator<<(std::ostream& o, const Data& c) {
auto print_value = [&](auto&& v) { o << v; }; auto print_value = [&](auto&& v) { o << v; };
o << "[" << c.target_type_name << " <- " << c.source_type_name << "] ["; o << "[" << c.target_type_name << " <- " << c.abstract_type_name << "] [";
std::visit(print_value, c.materialized_value); std::visit(print_value, c.materialized_value);
o << " <- " << c.literal_value << "]"; o << " <- " << c.literal_value << "]";
return o; return o;
@ -223,54 +223,54 @@ TEST_P(MaterializeAbstractNumeric, Test) {
auto target_ty = [&] { return data.target_ast_ty(*this); }; auto target_ty = [&] { return data.target_ast_ty(*this); };
auto target_expr = [&] { return data.target_expr(*this, 42); }; auto target_expr = [&] { return data.target_expr(*this, 42); };
auto* literal = data.source_builder(*this, data.literal_value); auto* abstract_expr = data.abstract_expr(*this, data.literal_value);
switch (method) { switch (method) {
case Method::kVar: case Method::kVar:
WrapInFunction(Decl(Var("a", target_ty(), literal))); WrapInFunction(Decl(Var("a", target_ty(), abstract_expr)));
break; break;
case Method::kLet: case Method::kLet:
WrapInFunction(Decl(Let("a", target_ty(), literal))); WrapInFunction(Decl(Let("a", target_ty(), abstract_expr)));
break; break;
case Method::kFnArg: case Method::kFnArg:
Func("F", {Param("P", target_ty())}, ty.void_(), {}); Func("F", {Param("P", target_ty())}, ty.void_(), {});
WrapInFunction(CallStmt(Call("F", literal))); WrapInFunction(CallStmt(Call("F", abstract_expr)));
break; break;
case Method::kBuiltinArg: case Method::kBuiltinArg:
WrapInFunction(CallStmt(Call("min", target_expr(), literal))); WrapInFunction(CallStmt(Call("min", target_expr(), abstract_expr)));
break; break;
case Method::kReturn: case Method::kReturn:
Func("F", {}, target_ty(), {Return(literal)}); Func("F", {}, target_ty(), {Return(abstract_expr)});
break; break;
case Method::kArray: case Method::kArray:
WrapInFunction(Construct(ty.array(target_ty(), 1_i), literal)); WrapInFunction(Construct(ty.array(target_ty(), 1_i), abstract_expr));
break; break;
case Method::kStruct: case Method::kStruct:
Structure("S", {Member("v", target_ty())}); Structure("S", {Member("v", target_ty())});
WrapInFunction(Construct(ty.type_name("S"), literal)); WrapInFunction(Construct(ty.type_name("S"), abstract_expr));
break; break;
case Method::kBinaryOp: case Method::kBinaryOp:
WrapInFunction(Add(target_expr(), literal)); WrapInFunction(Add(target_expr(), abstract_expr));
break; break;
case Method::kSwitchCond: case Method::kSwitchCond:
WrapInFunction(Switch(literal, // WrapInFunction(Switch(abstract_expr, //
Case(target_expr()->As<ast::IntLiteralExpression>()), // Case(target_expr()->As<ast::IntLiteralExpression>()), //
DefaultCase())); DefaultCase()));
break; break;
case Method::kSwitchCase: case Method::kSwitchCase:
WrapInFunction(Switch(target_expr(), // WrapInFunction(Switch(target_expr(), //
Case(literal->As<ast::IntLiteralExpression>()), // Case(abstract_expr->As<ast::IntLiteralExpression>()), //
DefaultCase())); DefaultCase()));
break; break;
case Method::kSwitchCondWithAbstractCase: case Method::kSwitchCondWithAbstractCase:
WrapInFunction(Switch(literal, // WrapInFunction(Switch(abstract_expr, //
Case(Expr(123_a)), // Case(Expr(123_a)), //
Case(target_expr()->As<ast::IntLiteralExpression>()), // Case(target_expr()->As<ast::IntLiteralExpression>()), //
DefaultCase())); DefaultCase()));
break; break;
case Method::kSwitchCaseWithAbstractCase: case Method::kSwitchCaseWithAbstractCase:
WrapInFunction(Switch(target_expr(), // WrapInFunction(Switch(target_expr(), //
Case(Expr(123_a)), // Case(Expr(123_a)), //
Case(literal->As<ast::IntLiteralExpression>()), // Case(abstract_expr->As<ast::IntLiteralExpression>()), //
DefaultCase())); DefaultCase()));
break; break;
} }
@ -296,14 +296,14 @@ TEST_P(MaterializeAbstractNumeric, Test) {
switch (expectation) { switch (expectation) {
case Expectation::kMaterialize: { case Expectation::kMaterialize: {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* materialize = Sem().Get<sem::Materialize>(literal); auto* materialize = Sem().Get<sem::Materialize>(abstract_expr);
ASSERT_NE(materialize, nullptr); ASSERT_NE(materialize, nullptr);
check_types_and_values(materialize); check_types_and_values(materialize);
break; break;
} }
case Expectation::kNoMaterialize: { case Expectation::kNoMaterialize: {
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(literal); auto* sem = Sem().Get(abstract_expr);
ASSERT_NE(sem, nullptr); ASSERT_NE(sem, nullptr);
EXPECT_FALSE(sem->Is<sem::Materialize>()); EXPECT_FALSE(sem->Is<sem::Materialize>());
check_types_and_values(sem); check_types_and_values(sem);
@ -315,14 +315,14 @@ TEST_P(MaterializeAbstractNumeric, Test) {
switch (method) { switch (method) {
case Method::kBuiltinArg: case Method::kBuiltinArg:
expect = "error: no matching call to min(" + data.target_type_name + ", " + expect = "error: no matching call to min(" + data.target_type_name + ", " +
data.source_type_name + ")"; data.abstract_type_name + ")";
break; break;
case Method::kBinaryOp: case Method::kBinaryOp:
expect = "error: no matching overload for operator + (" + expect = "error: no matching overload for operator + (" +
data.target_type_name + ", " + data.source_type_name + ")"; data.target_type_name + ", " + data.abstract_type_name + ")";
break; break;
default: default:
expect = "error: cannot convert value of type '" + data.source_type_name + expect = "error: cannot convert value of type '" + data.abstract_type_name +
"' to type '" + data.target_type_name + "'"; "' to type '" + data.target_type_name + "'";
break; break;
} }