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>
diff --git a/src/dawn/native/d3d12/d3d12_platform.h b/src/dawn/native/d3d12/d3d12_platform.h
index cc6d611..5b9d7cf 100644
--- a/src/dawn/native/d3d12/d3d12_platform.h
+++ b/src/dawn/native/d3d12/d3d12_platform.h
@@ -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_
diff --git a/src/tint/program.cc b/src/tint/program.cc
index c8466f5..a1cf5c8 100644
--- a/src/tint/program.cc
+++ b/src/tint/program.cc
@@ -134,19 +134,6 @@
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_);
}
diff --git a/src/tint/program.h b/src/tint/program.h
index 1c57fe0..ae46acd 100644
--- a/src/tint/program.h
+++ b/src/tint/program.h
@@ -151,19 +151,6 @@
/// 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*);
diff --git a/src/tint/program_builder.cc b/src/tint/program_builder.cc
index 4181f96..fc2e795 100644
--- a/src/tint/program_builder.cc
+++ b/src/tint/program_builder.cc
@@ -113,19 +113,6 @@
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) {
diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h
index 49b14fc..b944e21 100644
--- a/src/tint/program_builder.h
+++ b/src/tint/program_builder.h
@@ -3919,19 +3919,6 @@
/// 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.
diff --git a/src/tint/resolver/builtin_structs.cc b/src/tint/resolver/builtin_structs.cc
index 4e45c16..2b8c117 100644
--- a/src/tint/resolver/builtin_structs.cc
+++ b/src/tint/resolver/builtin_structs.cc
@@ -128,12 +128,12 @@
},
[&](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 @@
},
[&](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 @@
},
[&](Default) {
TINT_ICE(Resolver, b.Diagnostics())
- << "unhandled atomic_compare_exchange type: " << b.FriendlyName(ty);
+ << "unhandled atomic_compare_exchange type: " << ty->FriendlyName();
return nullptr;
});
}
diff --git a/src/tint/resolver/const_eval.cc b/src/tint/resolver/const_eval.cc
index 2aa755a..792a2fb 100644
--- a/src/tint/resolver/const_eval.cc
+++ b/src/tint/resolver/const_eval.cc
@@ -271,7 +271,7 @@
// --- 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 @@
} 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 @@
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 @@
[&](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};
});
};
diff --git a/src/tint/resolver/materialize_test.cc b/src/tint/resolver/materialize_test.cc
index 94d916c..696f279 100644
--- a/src/tint/resolver/materialize_test.cc
+++ b/src/tint/resolver/materialize_test.cc
@@ -75,8 +75,6 @@
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) {
diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc
index de29692..a65d825 100644
--- a/src/tint/resolver/resolver.cc
+++ b/src/tint/resolver/resolver.cc
@@ -921,9 +921,8 @@
}
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 @@
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 @@
}
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 @@
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;
}
diff --git a/src/tint/transform/builtin_polyfill.cc b/src/tint/transform/builtin_polyfill.cc
index 9cbb65f..4014b21 100644
--- a/src/tint/transform/builtin_polyfill.cc
+++ b/src/tint/transform/builtin_polyfill.cc
@@ -593,7 +593,7 @@
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 {};
}
diff --git a/src/tint/transform/robustness.cc b/src/tint/transform/robustness.cc
index c25bcac..3860de4 100644
--- a/src/tint/transform/robustness.cc
+++ b/src/tint/transform/robustness.cc
@@ -251,7 +251,7 @@
[&](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;
});
}
diff --git a/src/tint/transform/std140.cc b/src/tint/transform/std140.cc
index fa4fade..fed3943 100644
--- a/src/tint/transform/std140.cc
+++ b/src/tint/transform/std140.cc
@@ -414,7 +414,7 @@
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 @@
[&](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 @@
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 @@
},
[&](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 @@
}, //
[&](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 @@
}, //
[&](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 @@
}, //
[&](Default) -> ExprTypeName {
TINT_ICE(Transform, b.Diagnostics())
- << "unhandled type for access chain: " << src->FriendlyName(ty);
+ << "unhandled type for access chain: " << ty->FriendlyName();
return {};
});
}
diff --git a/src/tint/transform/vectorize_matrix_conversions.cc b/src/tint/transform/vectorize_matrix_conversions.cc
index 748346e..97e4d3c 100644
--- a/src/tint/transform/vectorize_matrix_conversions.cc
+++ b/src/tint/transform/vectorize_matrix_conversions.cc
@@ -124,8 +124,8 @@
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)),
diff --git a/src/tint/type/test_helper.h b/src/tint/type/test_helper.h
index 45ff61a..95827b0 100644
--- a/src/tint/type/test_helper.h
+++ b/src/tint/type/test_helper.h
@@ -45,15 +45,15 @@
} // 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_
diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc
index 181bce8..85644e2 100644
--- a/src/tint/writer/glsl/generator_impl.cc
+++ b/src/tint/writer/glsl/generator_impl.cc
@@ -2148,9 +2148,8 @@
}
},
[&](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());
});
}
diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc
index fefd424..e8b697b 100644
--- a/src/tint/writer/hlsl/generator_impl.cc
+++ b/src/tint/writer/hlsl/generator_impl.cc
@@ -3482,9 +3482,8 @@
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;
});
}
diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc
index 14288ee..d955d78 100644
--- a/src/tint/writer/msl/generator_impl.cc
+++ b/src/tint/writer/msl/generator_impl.cc
@@ -1788,9 +1788,8 @@
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;
});
}
diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc
index 972ba7c..b3ae005 100644
--- a/src/tint/writer/spirv/builder.cc
+++ b/src/tint/writer/spirv/builder.cc
@@ -1717,7 +1717,7 @@
},
[&](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;
});
}