tint: Remove Program|ProgramBuilder::FriendlyName()

Now that we don't need the symbol table to get the names of the types, we can just call FriendlyName() on the type directly.

Change-Id: I39478f5b8847ee032e77c15fd0de0665ddbf4811
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130220
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2023-05-03 16:26:40 +00:00 committed by Dawn LUCI CQ
parent 6ac51c1c57
commit 1545ca191b
18 changed files with 43 additions and 101 deletions

View File

@ -17,6 +17,6 @@
#include "dawn/native/d3d/d3d_platform.h" #include "dawn/native/d3d/d3d_platform.h"
#include <d3d12.h> // NOLINT(build/include_order) #include <d3d12.h> // NOLINT(build/include_order)
#endif // SRC_DAWN_NATIVE_D3D12_D3D12_PLATFORM_H_ #endif // SRC_DAWN_NATIVE_D3D12_D3D12_PLATFORM_H_

View File

@ -134,19 +134,6 @@ const type::Type* Program::TypeOf(const ast::TypeDecl* type_decl) const {
return Sem().Get(type_decl); return Sem().Get(type_decl);
} }
std::string Program::FriendlyName(ast::Type type) const {
TINT_ASSERT_PROGRAM_IDS_EQUAL(Program, type, ID());
return type ? type->identifier->symbol.Name() : "<null>";
}
std::string Program::FriendlyName(const type::Type* type) const {
return type ? type->FriendlyName() : "<null>";
}
std::string Program::FriendlyName(std::nullptr_t) const {
return "<null>";
}
void Program::AssertNotMoved() const { void Program::AssertNotMoved() const {
TINT_ASSERT(Program, !moved_); TINT_ASSERT(Program, !moved_);
} }

View File

@ -151,19 +151,6 @@ class Program {
/// the type declaration has no resolved type. /// the type declaration has no resolved type.
const type::Type* TypeOf(const ast::TypeDecl* type_decl) const; const type::Type* TypeOf(const ast::TypeDecl* type_decl) const;
/// @param type a type
/// @returns the name for `type` that closely resembles how it would be declared in WGSL.
std::string FriendlyName(ast::Type type) const;
/// @param type a type
/// @returns the name for `type` that closely resembles how it would be declared in WGSL.
std::string FriendlyName(const type::Type* type) const;
/// Overload of FriendlyName, which removes an ambiguity when passing nullptr.
/// Simplifies test code.
/// @returns "<null>"
std::string FriendlyName(std::nullptr_t) const;
/// A function that can be used to print a program /// A function that can be used to print a program
using Printer = std::string (*)(const Program*); using Printer = std::string (*)(const Program*);

View File

@ -113,19 +113,6 @@ const type::Type* ProgramBuilder::TypeOf(const ast::TypeDecl* type_decl) const {
return Sem().Get(type_decl); return Sem().Get(type_decl);
} }
std::string ProgramBuilder::FriendlyName(ast::Type type) const {
TINT_ASSERT_PROGRAM_IDS_EQUAL(ProgramBuilder, type, ID());
return type.expr ? type->identifier->symbol.Name() : "<null>";
}
std::string ProgramBuilder::FriendlyName(const type::Type* type) const {
return type ? type->FriendlyName() : "<null>";
}
std::string ProgramBuilder::FriendlyName(std::nullptr_t) const {
return "<null>";
}
ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {} ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {}
const ast::Statement* ProgramBuilder::WrapInStatement(const ast::Expression* expr) { const ast::Statement* ProgramBuilder::WrapInStatement(const ast::Expression* expr) {

View File

@ -3919,19 +3919,6 @@ class ProgramBuilder {
/// the type declaration has no resolved type. /// the type declaration has no resolved type.
const type::Type* TypeOf(const ast::TypeDecl* type_decl) const; const type::Type* TypeOf(const ast::TypeDecl* type_decl) const;
/// @param type a type
/// @returns the name for `type` that closely resembles how it would be declared in WGSL.
std::string FriendlyName(ast::Type type) const;
/// @param type a type
/// @returns the name for `type` that closely resembles how it would be declared in WGSL.
std::string FriendlyName(const type::Type* type) const;
/// Overload of FriendlyName, which removes an ambiguity when passing nullptr.
/// Simplifies test code.
/// @returns "<null>"
std::string FriendlyName(std::nullptr_t) const;
/// Wraps the ast::Expression in a statement. This is used by tests that /// Wraps the ast::Expression in a statement. This is used by tests that
/// construct a partial AST and require the Resolver to reach these /// construct a partial AST and require the Resolver to reach these
/// nodes. /// nodes.

View File

@ -128,12 +128,12 @@ type::Struct* CreateModfResult(ProgramBuilder& b, const type::Type* ty) {
}, },
[&](Default) { [&](Default) {
TINT_ICE(Resolver, b.Diagnostics()) TINT_ICE(Resolver, b.Diagnostics())
<< "unhandled modf type: " << b.FriendlyName(ty); << "unhandled modf type: " << ty->FriendlyName();
return nullptr; return nullptr;
}); });
}, },
[&](Default) { [&](Default) {
TINT_ICE(Resolver, b.Diagnostics()) << "unhandled modf type: " << b.FriendlyName(ty); TINT_ICE(Resolver, b.Diagnostics()) << "unhandled modf type: " << ty->FriendlyName();
return nullptr; return nullptr;
}); });
} }
@ -208,12 +208,12 @@ type::Struct* CreateFrexpResult(ProgramBuilder& b, const type::Type* ty) {
}, },
[&](Default) { [&](Default) {
TINT_ICE(Resolver, b.Diagnostics()) TINT_ICE(Resolver, b.Diagnostics())
<< "unhandled frexp type: " << b.FriendlyName(ty); << "unhandled frexp type: " << ty->FriendlyName();
return nullptr; return nullptr;
}); });
}, },
[&](Default) { [&](Default) {
TINT_ICE(Resolver, b.Diagnostics()) << "unhandled frexp type: " << b.FriendlyName(ty); TINT_ICE(Resolver, b.Diagnostics()) << "unhandled frexp type: " << ty->FriendlyName();
return nullptr; return nullptr;
}); });
} }
@ -231,7 +231,7 @@ type::Struct* CreateAtomicCompareExchangeResult(ProgramBuilder& b, const type::T
}, },
[&](Default) { [&](Default) {
TINT_ICE(Resolver, b.Diagnostics()) TINT_ICE(Resolver, b.Diagnostics())
<< "unhandled atomic_compare_exchange type: " << b.FriendlyName(ty); << "unhandled atomic_compare_exchange type: " << ty->FriendlyName();
return nullptr; return nullptr;
}); });
} }

View File

@ -271,7 +271,7 @@ ConstEval::Result ScalarConvert(const constant::Scalar<T>* scalar,
// --- Below this point are the failure cases --- // --- Below this point are the failure cases ---
} else if constexpr (IsAbstract<FROM>) { } else if constexpr (IsAbstract<FROM>) {
// [abstract-numeric -> x] - materialization failure // [abstract-numeric -> x] - materialization failure
auto msg = OverflowErrorMessage(scalar->value, builder.FriendlyName(target_ty)); auto msg = OverflowErrorMessage(scalar->value, target_ty->FriendlyName());
if (use_runtime_semantics) { if (use_runtime_semantics) {
builder.Diagnostics().add_warning(tint::diag::System::Resolver, msg, source); builder.Diagnostics().add_warning(tint::diag::System::Resolver, msg, source);
switch (conv.Failure()) { switch (conv.Failure()) {
@ -287,7 +287,7 @@ ConstEval::Result ScalarConvert(const constant::Scalar<T>* scalar,
} else if constexpr (IsFloatingPoint<TO>) { } else if constexpr (IsFloatingPoint<TO>) {
// [x -> floating-point] - number not exactly representable // [x -> floating-point] - number not exactly representable
// https://www.w3.org/TR/WGSL/#floating-point-conversion // https://www.w3.org/TR/WGSL/#floating-point-conversion
auto msg = OverflowErrorMessage(scalar->value, builder.FriendlyName(target_ty)); auto msg = OverflowErrorMessage(scalar->value, target_ty->FriendlyName());
if (use_runtime_semantics) { if (use_runtime_semantics) {
builder.Diagnostics().add_warning(tint::diag::System::Resolver, msg, source); builder.Diagnostics().add_warning(tint::diag::System::Resolver, msg, source);
switch (conv.Failure()) { switch (conv.Failure()) {
@ -534,7 +534,7 @@ ConstEval::Result ConstEval::CreateScalar(const Source& source, const type::Type
if constexpr (IsFloatingPoint<T>) { if constexpr (IsFloatingPoint<T>) {
if (!std::isfinite(v.value)) { if (!std::isfinite(v.value)) {
AddError(OverflowErrorMessage(v, builder.FriendlyName(t)), source); AddError(OverflowErrorMessage(v, t->FriendlyName()), source);
if (use_runtime_semantics_) { if (use_runtime_semantics_) {
return ZeroValue(t); return ZeroValue(t);
} else { } else {
@ -2689,7 +2689,7 @@ ConstEval::Result ConstEval::frexp(const type::Type* ty,
[&](Default) { [&](Default) {
TINT_ICE(Resolver, builder.Diagnostics()) TINT_ICE(Resolver, builder.Diagnostics())
<< "unhandled element type for frexp() const-eval: " << "unhandled element type for frexp() const-eval: "
<< builder.FriendlyName(s->Type()); << s->Type()->FriendlyName();
return FractExp{utils::Failure, utils::Failure}; return FractExp{utils::Failure, utils::Failure};
}); });
}; };

View File

@ -75,8 +75,6 @@ static std::ostream& operator<<(std::ostream& o, Expectation m) {
template <typename CASE> template <typename CASE>
class MaterializeTest : public resolver::ResolverTestWithParam<CASE> { class MaterializeTest : public resolver::ResolverTestWithParam<CASE> {
protected: protected:
using ProgramBuilder::FriendlyName;
void CheckTypesAndValues(const sem::ValueExpression* expr, void CheckTypesAndValues(const sem::ValueExpression* expr,
const tint::type::Type* expected_sem_ty, const tint::type::Type* expected_sem_ty,
const std::variant<AInt, AFloat>& expected_value) { const std::variant<AInt, AFloat>& expected_value) {

View File

@ -921,9 +921,8 @@ sem::Statement* Resolver::ConstAssert(const ast::ConstAssert* assertion) {
} }
auto* cond = expr->ConstantValue(); auto* cond = expr->ConstantValue();
if (auto* ty = cond->Type(); !ty->Is<type::Bool>()) { if (auto* ty = cond->Type(); !ty->Is<type::Bool>()) {
AddError( AddError("const assertion condition must be a bool, got '" + ty->FriendlyName() + "'",
"const assertion condition must be a bool, got '" + builder_->FriendlyName(ty) + "'", assertion->condition->source);
assertion->condition->source);
return nullptr; return nullptr;
} }
if (!cond->ValueAs<bool>()) { if (!cond->ValueAs<bool>()) {
@ -1833,8 +1832,8 @@ const sem::ValueExpression* Resolver::Materialize(const sem::ValueExpression* ex
materialized_val = val.Get(); materialized_val = val.Get();
if (TINT_UNLIKELY(!materialized_val)) { if (TINT_UNLIKELY(!materialized_val)) {
TINT_ICE(Resolver, diagnostics_) TINT_ICE(Resolver, diagnostics_)
<< decl->source << "ConvertValue(" << builder_->FriendlyName(expr_val->Type()) << decl->source << "ConvertValue(" << expr_val->Type()->FriendlyName() << " -> "
<< " -> " << builder_->FriendlyName(concrete_ty) << ") returned invalid value"; << concrete_ty->FriendlyName() << ") returned invalid value";
return nullptr; return nullptr;
} }
} }
@ -2590,7 +2589,7 @@ type::Type* Resolver::BuiltinType(builtin::Builtin builtin_ty, const ast::Identi
} }
if (!ApplyAddressSpaceUsageToType(address_space, store_ty, if (!ApplyAddressSpaceUsageToType(address_space, store_ty,
store_ty_expr->Declaration()->source)) { store_ty_expr->Declaration()->source)) {
AddNote("while instantiating " + builder_->FriendlyName(out), ident->source); AddNote("while instantiating " + out->FriendlyName(), ident->source);
return nullptr; return nullptr;
} }
return out; return out;
@ -3837,7 +3836,7 @@ const type::ArrayCount* Resolver::ArrayCount(const ast::Expression* count_expr)
if (auto* ty = count_val->Type(); !ty->is_integer_scalar()) { if (auto* ty = count_val->Type(); !ty->is_integer_scalar()) {
AddError("array count must evaluate to a constant integer expression, but is type '" + AddError("array count must evaluate to a constant integer expression, but is type '" +
builder_->FriendlyName(ty) + "'", ty->FriendlyName() + "'",
count_expr->source); count_expr->source);
return nullptr; return nullptr;
} }

View File

@ -593,7 +593,7 @@ struct BuiltinPolyfill::State {
if (TINT_UNLIKELY(((!type::Type::DeepestElementOf(ty)->IsAnyOf<type::I32, type::U32>())))) { if (TINT_UNLIKELY(((!type::Type::DeepestElementOf(ty)->IsAnyOf<type::I32, type::U32>())))) {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "insertBits polyfill only support i32, u32, and vector of i32 or u32, got " << "insertBits polyfill only support i32, u32, and vector of i32 or u32, got "
<< b.FriendlyName(ty); << ty->FriendlyName();
return {}; return {};
} }

View File

@ -251,7 +251,7 @@ struct Robustness::State {
[&](Default) -> const ast::Expression* { [&](Default) -> const ast::Expression* {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "unhandled object type in robustness of array index: " << "unhandled object type in robustness of array index: "
<< src->FriendlyName(obj_type->UnwrapRef()); << obj_type->UnwrapRef()->FriendlyName();
return nullptr; return nullptr;
}); });
} }

View File

@ -414,7 +414,7 @@ struct Std140::State {
auto std140_mat = std140_mats.GetOrCreate(mat, [&] { auto std140_mat = std140_mats.GetOrCreate(mat, [&] {
auto name = b.Symbols().New("mat" + std::to_string(mat->columns()) + "x" + auto name = b.Symbols().New("mat" + std::to_string(mat->columns()) + "x" +
std::to_string(mat->rows()) + "_" + std::to_string(mat->rows()) + "_" +
src->FriendlyName(mat->type())); mat->type()->FriendlyName());
auto members = auto members =
DecomposedMatrixStructMembers(mat, "col", mat->Align(), mat->Size()); DecomposedMatrixStructMembers(mat, "col", mat->Align(), mat->Size());
b.Structure(name, members); b.Structure(name, members);
@ -652,7 +652,7 @@ struct Std140::State {
[&](const type::F16*) { return "f16"; }, [&](const type::F16*) { return "f16"; },
[&](Default) { [&](Default) {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "unhandled type for conversion name: " << src->FriendlyName(ty); << "unhandled type for conversion name: " << ty->FriendlyName();
return ""; return "";
}); });
} }
@ -728,7 +728,7 @@ struct Std140::State {
stmts.Push(b.Return(b.Call(mat_ty, std::move(mat_args)))); stmts.Push(b.Return(b.Call(mat_ty, std::move(mat_args))));
} else { } else {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "failed to find std140 matrix info for: " << src->FriendlyName(ty); << "failed to find std140 matrix info for: " << ty->FriendlyName();
} }
}, // }, //
[&](const type::Array* arr) { [&](const type::Array* arr) {
@ -758,7 +758,7 @@ struct Std140::State {
}, },
[&](Default) { [&](Default) {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "unhandled type for conversion: " << src->FriendlyName(ty); << "unhandled type for conversion: " << ty->FriendlyName();
}); });
// Generate the function // Generate the function
@ -1104,7 +1104,7 @@ struct Std140::State {
}, // }, //
[&](Default) -> ExprTypeName { [&](Default) -> ExprTypeName {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "unhandled type for access chain: " << src->FriendlyName(ty); << "unhandled type for access chain: " << ty->FriendlyName();
return {}; return {};
}); });
} }
@ -1125,7 +1125,7 @@ struct Std140::State {
}, // }, //
[&](Default) -> ExprTypeName { [&](Default) -> ExprTypeName {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "unhandled type for access chain: " << src->FriendlyName(ty); << "unhandled type for access chain: " << ty->FriendlyName();
return {}; return {};
}); });
} }
@ -1154,7 +1154,7 @@ struct Std140::State {
}, // }, //
[&](Default) -> ExprTypeName { [&](Default) -> ExprTypeName {
TINT_ICE(Transform, b.Diagnostics()) TINT_ICE(Transform, b.Diagnostics())
<< "unhandled type for access chain: " << src->FriendlyName(ty); << "unhandled type for access chain: " << ty->FriendlyName();
return {}; return {};
}); });
} }

View File

@ -124,8 +124,8 @@ Transform::ApplyResult VectorizeMatrixConversions::Apply(const Program* src,
utils::GetOrCreate(matrix_convs, HelperFunctionKey{{src_type, dst_type}}, [&] { utils::GetOrCreate(matrix_convs, HelperFunctionKey{{src_type, dst_type}}, [&] {
auto name = b.Symbols().New( auto name = b.Symbols().New(
"convert_mat" + std::to_string(src_type->columns()) + "x" + "convert_mat" + std::to_string(src_type->columns()) + "x" +
std::to_string(src_type->rows()) + "_" + b.FriendlyName(src_type->type()) + std::to_string(src_type->rows()) + "_" + src_type->type()->FriendlyName() +
"_" + b.FriendlyName(dst_type->type())); "_" + dst_type->type()->FriendlyName());
b.Func(name, b.Func(name,
utils::Vector{ utils::Vector{
b.Param("value", CreateASTTypeFor(ctx, src_type)), b.Param("value", CreateASTTypeFor(ctx, src_type)),

View File

@ -45,15 +45,15 @@ using TestParamHelper = TestHelperBase<testing::TestWithParam<T>>;
} // namespace tint::type } // namespace tint::type
/// Helper macro for testing that a type was as expected /// Helper macro for testing that a type was as expected
#define EXPECT_TYPE(GOT, EXPECT) \ #define EXPECT_TYPE(GOT, EXPECT) \
do { \ do { \
const type::Type* got = GOT; \ const type::Type* got = GOT; \
const type::Type* expect = EXPECT; \ const type::Type* expect = EXPECT; \
if (got != expect) { \ if (got != expect) { \
ADD_FAILURE() << #GOT " != " #EXPECT "\n" \ ADD_FAILURE() << #GOT " != " #EXPECT "\n" \
<< " " #GOT ": " << FriendlyName(got) << "\n" \ << " " #GOT ": " << (got ? got->FriendlyName() : "<null>") << "\n" \
<< " " #EXPECT ": " << FriendlyName(expect); \ << " " #EXPECT ": " << (expect ? expect->FriendlyName() : "<null>"); \
} \ } \
} while (false) } while (false)
#endif // SRC_TINT_TYPE_TEST_HELPER_H_ #endif // SRC_TINT_TYPE_TEST_HELPER_H_

View File

@ -2148,9 +2148,8 @@ void GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
} }
}, },
[&](Default) { [&](Default) {
diagnostics_.add_error( diagnostics_.add_error(diag::System::Writer,
diag::System::Writer, "unhandled constant type: " + constant->Type()->FriendlyName());
"unhandled constant type: " + builder_.FriendlyName(constant->Type()));
}); });
} }

View File

@ -3482,9 +3482,8 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out,
return true; return true;
}, },
[&](Default) { [&](Default) {
diagnostics_.add_error( diagnostics_.add_error(diag::System::Writer,
diag::System::Writer, "unhandled constant type: " + constant->Type()->FriendlyName());
"unhandled constant type: " + builder_.FriendlyName(constant->Type()));
return false; return false;
}); });
} }

View File

@ -1788,9 +1788,8 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
return true; return true;
}, },
[&](Default) { [&](Default) {
diagnostics_.add_error( diagnostics_.add_error(diag::System::Writer,
diag::System::Writer, "unhandled constant type: " + constant->Type()->FriendlyName());
"unhandled constant type: " + builder_.FriendlyName(constant->Type()));
return false; return false;
}); });
} }

View File

@ -1717,7 +1717,7 @@ uint32_t Builder::GenerateConstantIfNeeded(const constant::Value* constant) {
}, },
[&](const type::Struct* s) { return composite(s->Members().Length()); }, [&](const type::Struct* s) { return composite(s->Members().Length()); },
[&](Default) { [&](Default) {
error_ = "unhandled constant type: " + builder_.FriendlyName(ty); error_ = "unhandled constant type: " + ty->FriendlyName();
return 0; return 0;
}); });
} }