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:
parent
6ac51c1c57
commit
1545ca191b
|
@ -17,6 +17,6 @@
|
|||
|
||||
#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_
|
||||
|
|
|
@ -134,19 +134,6 @@ const type::Type* Program::TypeOf(const ast::TypeDecl* type_decl) const {
|
|||
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 {
|
||||
TINT_ASSERT(Program, !moved_);
|
||||
}
|
||||
|
|
|
@ -151,19 +151,6 @@ class Program {
|
|||
/// the type declaration has no resolved type.
|
||||
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
|
||||
using Printer = std::string (*)(const Program*);
|
||||
|
||||
|
|
|
@ -113,19 +113,6 @@ const type::Type* ProgramBuilder::TypeOf(const ast::TypeDecl* type_decl) const {
|
|||
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) {}
|
||||
|
||||
const ast::Statement* ProgramBuilder::WrapInStatement(const ast::Expression* expr) {
|
||||
|
|
|
@ -3919,19 +3919,6 @@ class ProgramBuilder {
|
|||
/// the type declaration has no resolved type.
|
||||
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
|
||||
/// construct a partial AST and require the Resolver to reach these
|
||||
/// nodes.
|
||||
|
|
|
@ -128,12 +128,12 @@ type::Struct* CreateModfResult(ProgramBuilder& b, const type::Type* ty) {
|
|||
},
|
||||
[&](Default) {
|
||||
TINT_ICE(Resolver, b.Diagnostics())
|
||||
<< "unhandled modf type: " << b.FriendlyName(ty);
|
||||
<< "unhandled modf type: " << ty->FriendlyName();
|
||||
return nullptr;
|
||||
});
|
||||
},
|
||||
[&](Default) {
|
||||
TINT_ICE(Resolver, b.Diagnostics()) << "unhandled modf type: " << b.FriendlyName(ty);
|
||||
TINT_ICE(Resolver, b.Diagnostics()) << "unhandled modf type: " << ty->FriendlyName();
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
@ -208,12 +208,12 @@ type::Struct* CreateFrexpResult(ProgramBuilder& b, const type::Type* ty) {
|
|||
},
|
||||
[&](Default) {
|
||||
TINT_ICE(Resolver, b.Diagnostics())
|
||||
<< "unhandled frexp type: " << b.FriendlyName(ty);
|
||||
<< "unhandled frexp type: " << ty->FriendlyName();
|
||||
return nullptr;
|
||||
});
|
||||
},
|
||||
[&](Default) {
|
||||
TINT_ICE(Resolver, b.Diagnostics()) << "unhandled frexp type: " << b.FriendlyName(ty);
|
||||
TINT_ICE(Resolver, b.Diagnostics()) << "unhandled frexp type: " << ty->FriendlyName();
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ type::Struct* CreateAtomicCompareExchangeResult(ProgramBuilder& b, const type::T
|
|||
},
|
||||
[&](Default) {
|
||||
TINT_ICE(Resolver, b.Diagnostics())
|
||||
<< "unhandled atomic_compare_exchange type: " << b.FriendlyName(ty);
|
||||
<< "unhandled atomic_compare_exchange type: " << ty->FriendlyName();
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ ConstEval::Result ScalarConvert(const constant::Scalar<T>* scalar,
|
|||
// --- Below this point are the failure cases ---
|
||||
} else if constexpr (IsAbstract<FROM>) {
|
||||
// [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) {
|
||||
builder.Diagnostics().add_warning(tint::diag::System::Resolver, msg, source);
|
||||
switch (conv.Failure()) {
|
||||
|
@ -287,7 +287,7 @@ ConstEval::Result ScalarConvert(const constant::Scalar<T>* scalar,
|
|||
} else if constexpr (IsFloatingPoint<TO>) {
|
||||
// [x -> floating-point] - number not exactly representable
|
||||
// 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) {
|
||||
builder.Diagnostics().add_warning(tint::diag::System::Resolver, msg, source);
|
||||
switch (conv.Failure()) {
|
||||
|
@ -534,7 +534,7 @@ ConstEval::Result ConstEval::CreateScalar(const Source& source, const type::Type
|
|||
|
||||
if constexpr (IsFloatingPoint<T>) {
|
||||
if (!std::isfinite(v.value)) {
|
||||
AddError(OverflowErrorMessage(v, builder.FriendlyName(t)), source);
|
||||
AddError(OverflowErrorMessage(v, t->FriendlyName()), source);
|
||||
if (use_runtime_semantics_) {
|
||||
return ZeroValue(t);
|
||||
} else {
|
||||
|
@ -2689,7 +2689,7 @@ ConstEval::Result ConstEval::frexp(const type::Type* ty,
|
|||
[&](Default) {
|
||||
TINT_ICE(Resolver, builder.Diagnostics())
|
||||
<< "unhandled element type for frexp() const-eval: "
|
||||
<< builder.FriendlyName(s->Type());
|
||||
<< s->Type()->FriendlyName();
|
||||
return FractExp{utils::Failure, utils::Failure};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -75,8 +75,6 @@ static std::ostream& operator<<(std::ostream& o, Expectation m) {
|
|||
template <typename CASE>
|
||||
class MaterializeTest : public resolver::ResolverTestWithParam<CASE> {
|
||||
protected:
|
||||
using ProgramBuilder::FriendlyName;
|
||||
|
||||
void CheckTypesAndValues(const sem::ValueExpression* expr,
|
||||
const tint::type::Type* expected_sem_ty,
|
||||
const std::variant<AInt, AFloat>& expected_value) {
|
||||
|
|
|
@ -921,9 +921,8 @@ sem::Statement* Resolver::ConstAssert(const ast::ConstAssert* assertion) {
|
|||
}
|
||||
auto* cond = expr->ConstantValue();
|
||||
if (auto* ty = cond->Type(); !ty->Is<type::Bool>()) {
|
||||
AddError(
|
||||
"const assertion condition must be a bool, got '" + builder_->FriendlyName(ty) + "'",
|
||||
assertion->condition->source);
|
||||
AddError("const assertion condition must be a bool, got '" + ty->FriendlyName() + "'",
|
||||
assertion->condition->source);
|
||||
return nullptr;
|
||||
}
|
||||
if (!cond->ValueAs<bool>()) {
|
||||
|
@ -1833,8 +1832,8 @@ const sem::ValueExpression* Resolver::Materialize(const sem::ValueExpression* ex
|
|||
materialized_val = val.Get();
|
||||
if (TINT_UNLIKELY(!materialized_val)) {
|
||||
TINT_ICE(Resolver, diagnostics_)
|
||||
<< decl->source << "ConvertValue(" << builder_->FriendlyName(expr_val->Type())
|
||||
<< " -> " << builder_->FriendlyName(concrete_ty) << ") returned invalid value";
|
||||
<< decl->source << "ConvertValue(" << expr_val->Type()->FriendlyName() << " -> "
|
||||
<< concrete_ty->FriendlyName() << ") returned invalid value";
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -2590,7 +2589,7 @@ type::Type* Resolver::BuiltinType(builtin::Builtin builtin_ty, const ast::Identi
|
|||
}
|
||||
if (!ApplyAddressSpaceUsageToType(address_space, store_ty,
|
||||
store_ty_expr->Declaration()->source)) {
|
||||
AddNote("while instantiating " + builder_->FriendlyName(out), ident->source);
|
||||
AddNote("while instantiating " + out->FriendlyName(), ident->source);
|
||||
return nullptr;
|
||||
}
|
||||
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()) {
|
||||
AddError("array count must evaluate to a constant integer expression, but is type '" +
|
||||
builder_->FriendlyName(ty) + "'",
|
||||
ty->FriendlyName() + "'",
|
||||
count_expr->source);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -593,7 +593,7 @@ struct BuiltinPolyfill::State {
|
|||
if (TINT_UNLIKELY(((!type::Type::DeepestElementOf(ty)->IsAnyOf<type::I32, type::U32>())))) {
|
||||
TINT_ICE(Transform, b.Diagnostics())
|
||||
<< "insertBits polyfill only support i32, u32, and vector of i32 or u32, got "
|
||||
<< b.FriendlyName(ty);
|
||||
<< ty->FriendlyName();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@ struct Robustness::State {
|
|||
[&](Default) -> const ast::Expression* {
|
||||
TINT_ICE(Transform, b.Diagnostics())
|
||||
<< "unhandled object type in robustness of array index: "
|
||||
<< src->FriendlyName(obj_type->UnwrapRef());
|
||||
<< obj_type->UnwrapRef()->FriendlyName();
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -414,7 +414,7 @@ struct Std140::State {
|
|||
auto std140_mat = std140_mats.GetOrCreate(mat, [&] {
|
||||
auto name = b.Symbols().New("mat" + std::to_string(mat->columns()) + "x" +
|
||||
std::to_string(mat->rows()) + "_" +
|
||||
src->FriendlyName(mat->type()));
|
||||
mat->type()->FriendlyName());
|
||||
auto members =
|
||||
DecomposedMatrixStructMembers(mat, "col", mat->Align(), mat->Size());
|
||||
b.Structure(name, members);
|
||||
|
@ -652,7 +652,7 @@ struct Std140::State {
|
|||
[&](const type::F16*) { return "f16"; },
|
||||
[&](Default) {
|
||||
TINT_ICE(Transform, b.Diagnostics())
|
||||
<< "unhandled type for conversion name: " << src->FriendlyName(ty);
|
||||
<< "unhandled type for conversion name: " << ty->FriendlyName();
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
@ -728,7 +728,7 @@ struct Std140::State {
|
|||
stmts.Push(b.Return(b.Call(mat_ty, std::move(mat_args))));
|
||||
} else {
|
||||
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) {
|
||||
|
@ -758,7 +758,7 @@ struct Std140::State {
|
|||
},
|
||||
[&](Default) {
|
||||
TINT_ICE(Transform, b.Diagnostics())
|
||||
<< "unhandled type for conversion: " << src->FriendlyName(ty);
|
||||
<< "unhandled type for conversion: " << ty->FriendlyName();
|
||||
});
|
||||
|
||||
// Generate the function
|
||||
|
@ -1104,7 +1104,7 @@ struct Std140::State {
|
|||
}, //
|
||||
[&](Default) -> ExprTypeName {
|
||||
TINT_ICE(Transform, b.Diagnostics())
|
||||
<< "unhandled type for access chain: " << src->FriendlyName(ty);
|
||||
<< "unhandled type for access chain: " << ty->FriendlyName();
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
@ -1125,7 +1125,7 @@ struct Std140::State {
|
|||
}, //
|
||||
[&](Default) -> ExprTypeName {
|
||||
TINT_ICE(Transform, b.Diagnostics())
|
||||
<< "unhandled type for access chain: " << src->FriendlyName(ty);
|
||||
<< "unhandled type for access chain: " << ty->FriendlyName();
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
@ -1154,7 +1154,7 @@ struct Std140::State {
|
|||
}, //
|
||||
[&](Default) -> ExprTypeName {
|
||||
TINT_ICE(Transform, b.Diagnostics())
|
||||
<< "unhandled type for access chain: " << src->FriendlyName(ty);
|
||||
<< "unhandled type for access chain: " << ty->FriendlyName();
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
|
|
@ -124,8 +124,8 @@ Transform::ApplyResult VectorizeMatrixConversions::Apply(const Program* src,
|
|||
utils::GetOrCreate(matrix_convs, HelperFunctionKey{{src_type, dst_type}}, [&] {
|
||||
auto name = b.Symbols().New(
|
||||
"convert_mat" + std::to_string(src_type->columns()) + "x" +
|
||||
std::to_string(src_type->rows()) + "_" + b.FriendlyName(src_type->type()) +
|
||||
"_" + b.FriendlyName(dst_type->type()));
|
||||
std::to_string(src_type->rows()) + "_" + src_type->type()->FriendlyName() +
|
||||
"_" + dst_type->type()->FriendlyName());
|
||||
b.Func(name,
|
||||
utils::Vector{
|
||||
b.Param("value", CreateASTTypeFor(ctx, src_type)),
|
||||
|
|
|
@ -45,15 +45,15 @@ using TestParamHelper = TestHelperBase<testing::TestWithParam<T>>;
|
|||
} // namespace tint::type
|
||||
|
||||
/// Helper macro for testing that a type was as expected
|
||||
#define EXPECT_TYPE(GOT, EXPECT) \
|
||||
do { \
|
||||
const type::Type* got = GOT; \
|
||||
const type::Type* expect = EXPECT; \
|
||||
if (got != expect) { \
|
||||
ADD_FAILURE() << #GOT " != " #EXPECT "\n" \
|
||||
<< " " #GOT ": " << FriendlyName(got) << "\n" \
|
||||
<< " " #EXPECT ": " << FriendlyName(expect); \
|
||||
} \
|
||||
#define EXPECT_TYPE(GOT, EXPECT) \
|
||||
do { \
|
||||
const type::Type* got = GOT; \
|
||||
const type::Type* expect = EXPECT; \
|
||||
if (got != expect) { \
|
||||
ADD_FAILURE() << #GOT " != " #EXPECT "\n" \
|
||||
<< " " #GOT ": " << (got ? got->FriendlyName() : "<null>") << "\n" \
|
||||
<< " " #EXPECT ": " << (expect ? expect->FriendlyName() : "<null>"); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#endif // SRC_TINT_TYPE_TEST_HELPER_H_
|
||||
|
|
|
@ -2148,9 +2148,8 @@ void GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
|||
}
|
||||
},
|
||||
[&](Default) {
|
||||
diagnostics_.add_error(
|
||||
diag::System::Writer,
|
||||
"unhandled constant type: " + builder_.FriendlyName(constant->Type()));
|
||||
diagnostics_.add_error(diag::System::Writer,
|
||||
"unhandled constant type: " + constant->Type()->FriendlyName());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3482,9 +3482,8 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out,
|
|||
return true;
|
||||
},
|
||||
[&](Default) {
|
||||
diagnostics_.add_error(
|
||||
diag::System::Writer,
|
||||
"unhandled constant type: " + builder_.FriendlyName(constant->Type()));
|
||||
diagnostics_.add_error(diag::System::Writer,
|
||||
"unhandled constant type: " + constant->Type()->FriendlyName());
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1788,9 +1788,8 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value
|
|||
return true;
|
||||
},
|
||||
[&](Default) {
|
||||
diagnostics_.add_error(
|
||||
diag::System::Writer,
|
||||
"unhandled constant type: " + builder_.FriendlyName(constant->Type()));
|
||||
diagnostics_.add_error(diag::System::Writer,
|
||||
"unhandled constant type: " + constant->Type()->FriendlyName());
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1717,7 +1717,7 @@ uint32_t Builder::GenerateConstantIfNeeded(const constant::Value* constant) {
|
|||
},
|
||||
[&](const type::Struct* s) { return composite(s->Members().Length()); },
|
||||
[&](Default) {
|
||||
error_ = "unhandled constant type: " + builder_.FriendlyName(ty);
|
||||
error_ = "unhandled constant type: " + ty->FriendlyName();
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue