tint: Use `const-expression` and `override-expression` terms

Fixed: tint:1601
Change-Id: I72827df7c83dbb8f5dc69a8803fbe955b1a2421d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105622
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2022-10-13 13:47:39 +00:00 committed by Dawn LUCI CQ
parent 92264f8bb2
commit f10a57908a
18 changed files with 41 additions and 40 deletions

View File

@ -67,7 +67,7 @@ TEST_F(ResolverBuiltinTest, ModuleScopeUsage) {
// TODO(crbug.com/tint/1581): Once 'abs' is implemented as @const, this will no longer be an // TODO(crbug.com/tint/1581): Once 'abs' is implemented as @const, this will no longer be an
// error. // error.
EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be constant expression)"); EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be const-expression)");
} }
// Tests for Logical builtins // Tests for Logical builtins

View File

@ -327,7 +327,7 @@ TEST_P(BuiltinTextureConstExprArgValidationTest, GlobalConst) {
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
std::stringstream err; std::stringstream err;
err << "12:34 error: the " << param.name << " argument must be a const_expression"; err << "12:34 error: the " << param.name << " argument must be a const-expression";
EXPECT_EQ(r()->error(), err.str()); EXPECT_EQ(r()->error(), err.str());
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(

View File

@ -38,7 +38,7 @@ class Type;
namespace tint::resolver { namespace tint::resolver {
/// ConstEval performs shader creation-time (constant expression) expression evaluation. /// ConstEval performs shader creation-time (const-expression) expression evaluation.
/// Methods are called from the resolver, either directly or via member-function pointers indexed by /// Methods are called from the resolver, either directly or via member-function pointers indexed by
/// the IntrinsicTable. All child-expression nodes are guaranteed to have been already resolved /// the IntrinsicTable. All child-expression nodes are guaranteed to have been already resolved
/// before calling a method to evaluate an expression's value. /// before calling a method to evaluate an expression's value.

View File

@ -672,7 +672,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_Literal_BadType) {
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
r()->error(), r()->error(),
"12:34 error: workgroup_size argument must be a constant or override expression of type " "12:34 error: workgroup_size argument must be a constant or override-expression of type "
"abstract-integer, i32 or u32"); "abstract-integer, i32 or u32");
} }
@ -718,7 +718,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_Const_BadType) {
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ( EXPECT_EQ(
r()->error(), r()->error(),
"12:34 error: workgroup_size argument must be a constant or override expression of type " "12:34 error: workgroup_size argument must be a constant or override-expression of type "
"abstract-integer, i32 or u32"); "abstract-integer, i32 or u32");
} }
@ -851,7 +851,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_NonConst) {
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: workgroup_size argument must be a constant or override expression of " "12:34 error: workgroup_size argument must be a constant or override-expression of "
"type abstract-integer, i32 or u32"); "type abstract-integer, i32 or u32");
} }
@ -866,7 +866,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_x) {
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: workgroup_size argument must be a constant or override expression of " "12:34 error: workgroup_size argument must be a constant or override-expression of "
"type abstract-integer, i32 or u32"); "type abstract-integer, i32 or u32");
} }
@ -881,7 +881,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_y) {
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: workgroup_size argument must be a constant or override expression of " "12:34 error: workgroup_size argument must be a constant or override-expression of "
"type abstract-integer, i32 or u32"); "type abstract-integer, i32 or u32");
} }
@ -896,7 +896,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_z) {
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: workgroup_size argument must be a constant or override expression of " "12:34 error: workgroup_size argument must be a constant or override-expression of "
"type abstract-integer, i32 or u32"); "type abstract-integer, i32 or u32");
} }

View File

@ -511,7 +511,7 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) {
const auto value = rhs->ConstantValue(); const auto value = rhs->ConstantValue();
if (!value) { if (!value) {
AddError("'const' initializer must be constant expression", c->constructor->source); AddError("'const' initializer must be const-expression", c->constructor->source);
return nullptr; return nullptr;
} }
@ -864,7 +864,7 @@ sem::Statement* Resolver::StaticAssert(const ast::StaticAssert* assertion) {
} }
auto* cond = expr->ConstantValue(); auto* cond = expr->ConstantValue();
if (!cond) { if (!cond) {
AddError("static assertion condition must be a constant expression", AddError("static assertion condition must be a const-expression",
assertion->condition->source); assertion->condition->source);
return nullptr; return nullptr;
} }
@ -1068,12 +1068,12 @@ bool Resolver::WorkgroupSize(const ast::Function* func) {
utils::Vector<const sem::Type*, 3> arg_tys; utils::Vector<const sem::Type*, 3> arg_tys;
constexpr const char* kErrBadExpr = constexpr const char* kErrBadExpr =
"workgroup_size argument must be a constant or override expression of type " "workgroup_size argument must be a constant or override-expression of type "
"abstract-integer, i32 or u32"; "abstract-integer, i32 or u32";
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
// Each argument to this attribute can either be a literal, an identifier for a module-scope // Each argument to this attribute can either be a literal, an identifier for a module-scope
// constants, a constant expression, or nullptr if not specified. // constants, a const-expression, or nullptr if not specified.
auto* value = values[i]; auto* value = values[i];
if (!value) { if (!value) {
break; break;
@ -2824,7 +2824,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
} }
auto const_value = materialized->ConstantValue(); auto const_value = materialized->ConstantValue();
if (!const_value) { if (!const_value) {
AddError("'offset' must be constant expression", o->expr->source); AddError("'offset' must be const-expression", o->expr->source);
return nullptr; return nullptr;
} }
offset = const_value->As<uint64_t>(); offset = const_value->As<uint64_t>();
@ -2847,7 +2847,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
auto const_value = materialized->ConstantValue(); auto const_value = materialized->ConstantValue();
if (!const_value) { if (!const_value) {
AddError("'align' must be constant expression", a->source); AddError("'align' must be const-expression", a->source);
return nullptr; return nullptr;
} }
auto value = const_value->As<AInt>(); auto value = const_value->As<AInt>();
@ -2865,7 +2865,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) {
} }
auto const_value = materialized->ConstantValue(); auto const_value = materialized->ConstantValue();
if (!const_value) { if (!const_value) {
AddError("'size' must be constant expression", s->expr->source); AddError("'size' must be const-expression", s->expr->source);
return nullptr; return nullptr;
} }
auto value = const_value->As<uint64_t>(); auto value = const_value->As<uint64_t>();

View File

@ -88,7 +88,7 @@ TEST_F(ResolverStaticAssertTest, Local_NonConst) {
WrapInFunction(StaticAssert(Expr(Source{{12, 34}}, "V"))); WrapInFunction(StaticAssert(Expr(Source{{12, 34}}, "V")));
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), EXPECT_EQ(r()->error(),
"12:34 error: static assertion condition must be a constant expression"); "12:34 error: static assertion condition must be a const-expression");
} }
TEST_F(ResolverStaticAssertTest, Local_LessThan_Pass) { TEST_F(ResolverStaticAssertTest, Local_LessThan_Pass) {

View File

@ -593,7 +593,7 @@ bool Validator::GlobalVariable(
[&](const ast::Var* var) { [&](const ast::Var* var) {
if (auto* init = global->Constructor(); if (auto* init = global->Constructor();
init && init->Stage() > sem::EvaluationStage::kOverride) { init && init->Stage() > sem::EvaluationStage::kOverride) {
AddError("module-scope 'var' initializer must be a constant or override expression", AddError("module-scope 'var' initializer must be a constant or override-expression",
init->Declaration()->source); init->Declaration()->source);
return false; return false;
} }
@ -795,7 +795,7 @@ bool Validator::Override(
auto* storage_ty = v->Type()->UnwrapRef(); auto* storage_ty = v->Type()->UnwrapRef();
if (auto* init = v->Constructor(); init && init->Stage() > sem::EvaluationStage::kOverride) { if (auto* init = v->Constructor(); init && init->Stage() > sem::EvaluationStage::kOverride) {
AddError("'override' initializer must be an override expression", AddError("'override' initializer must be an override-expression",
init->Declaration()->source); init->Declaration()->source);
return false; return false;
} }
@ -1708,7 +1708,7 @@ bool Validator::TextureBuiltinFunction(const sem::Call* call) const {
return true; return true;
} }
} }
AddError("the " + name + " argument must be a const_expression", AddError("the " + name + " argument must be a const-expression",
arg->Declaration()->source); arg->Declaration()->source);
return false; return false;
}; };
@ -1902,7 +1902,7 @@ bool Validator::ArrayConstructor(const ast::CallExpression* ctor,
} }
if (array_type->IsOverrideSized()) { if (array_type->IsOverrideSized()) {
AddError("cannot construct an array that has an override expression count", ctor->source); AddError("cannot construct an array that has an override-expression count", ctor->source);
return false; return false;
} }

View File

@ -423,7 +423,7 @@ TEST_F(ResolverVariableValidationTest, ConstInitWithVar) {
WrapInFunction(v, c); WrapInFunction(v, c);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be constant expression)"); EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be const-expression)");
} }
TEST_F(ResolverVariableValidationTest, ConstInitWithOverride) { TEST_F(ResolverVariableValidationTest, ConstInitWithOverride) {
@ -432,7 +432,7 @@ TEST_F(ResolverVariableValidationTest, ConstInitWithOverride) {
WrapInFunction(c); WrapInFunction(c);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be constant expression)"); EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be const-expression)");
} }
TEST_F(ResolverVariableValidationTest, ConstInitWithLet) { TEST_F(ResolverVariableValidationTest, ConstInitWithLet) {
@ -441,7 +441,7 @@ TEST_F(ResolverVariableValidationTest, ConstInitWithLet) {
WrapInFunction(l, c); WrapInFunction(l, c);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be constant expression)"); EXPECT_EQ(r()->error(), R"(12:34 error: 'const' initializer must be const-expression)");
} }
} // namespace } // namespace

View File

@ -31,7 +31,7 @@ class GlobalVariable;
namespace tint::sem { namespace tint::sem {
/// The variant of an ArrayCount when the array is a constant expression. /// The variant of an ArrayCount when the array is a const-expression.
/// Example: /// Example:
/// ``` /// ```
/// const N = 123; /// const N = 123;
@ -144,7 +144,7 @@ class Array final : public Castable<Array, Type> {
/// @returns the number of elements in the array. /// @returns the number of elements in the array.
const ArrayCount& Count() const { return count_; } const ArrayCount& Count() const { return count_; }
/// @returns the array count if the count is a constant expression, otherwise returns nullopt. /// @returns the array count if the count is a const-expression, otherwise returns nullopt.
inline std::optional<uint32_t> ConstantCount() const { inline std::optional<uint32_t> ConstantCount() const {
if (auto* count = std::get_if<ConstantArrayCount>(&count_)) { if (auto* count = std::get_if<ConstantArrayCount>(&count_)) {
return count->value; return count->value;
@ -175,7 +175,7 @@ class Array final : public Castable<Array, Type> {
/// natural stride /// natural stride
bool IsStrideImplicit() const { return stride_ == implicit_stride_; } bool IsStrideImplicit() const { return stride_ == implicit_stride_; }
/// @returns true if this array is sized using an constant expression /// @returns true if this array is sized using an const-expression
bool IsConstantSized() const { return std::holds_alternative<ConstantArrayCount>(count_); } bool IsConstantSized() const { return std::holds_alternative<ConstantArrayCount>(count_); }
/// @returns true if this array is sized using an override variable /// @returns true if this array is sized using an override variable

View File

@ -40,8 +40,9 @@ class Variable;
namespace tint::sem { namespace tint::sem {
/// WorkgroupSize is a three-dimensional array of WorkgroupDimensions. /// WorkgroupSize is a three-dimensional array of WorkgroupDimensions.
/// Each dimension is a std::optional as a workgroup size can be a constant or override expression. /// Each dimension is a std::optional as a workgroup size can be a const-expression or
/// Override expressions are not known at compilation time, so these will be std::nullopt. /// override-expression. Override expressions are not known at compilation time, so these will be
/// std::nullopt.
using WorkgroupSize = std::array<std::optional<uint32_t>, 3>; using WorkgroupSize = std::array<std::optional<uint32_t>, 3>;
/// Function holds the semantic information for function nodes. /// Function holds the semantic information for function nodes.

View File

@ -77,7 +77,7 @@ void SubstituteOverride::Run(CloneContext& ctx, const DataMap& config, DataMap&)
if (!ctor) { if (!ctor) {
ctx.dst->Diagnostics().add_error(diag::System::Transform, ctx.dst->Diagnostics().add_error(diag::System::Transform,
"Failed to create override expression"); "Failed to create override-expression");
return nullptr; return nullptr;
} }

View File

@ -1887,7 +1887,7 @@ bool GeneratorImpl::EmitGlobalVariable(const ast::Variable* global) {
[&](const ast::Override*) { [&](const ast::Override*) {
// Override is removed with SubstituteOverride // Override is removed with SubstituteOverride
diagnostics_.add_error(diag::System::Writer, diagnostics_.add_error(diag::System::Writer,
"override expressions should have been removed with the " "override-expressions should have been removed with the "
"SubstituteOverride transform"); "SubstituteOverride transform");
return false; return false;
}, },
@ -2109,7 +2109,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
if (!wgsize[i].has_value()) { if (!wgsize[i].has_value()) {
diagnostics_.add_error( diagnostics_.add_error(
diag::System::Writer, diag::System::Writer,
"override expressions should have been removed with the SubstituteOverride " "override-expressions should have been removed with the SubstituteOverride "
"transform"); "transform");
return false; return false;
} }

View File

@ -799,7 +799,7 @@ TEST_F(GlslGeneratorImplTest_Function,
EXPECT_FALSE(gen.Generate()) << gen.error(); EXPECT_FALSE(gen.Generate()) << gen.error();
EXPECT_EQ( EXPECT_EQ(
gen.error(), gen.error(),
R"(error: override expressions should have been removed with the SubstituteOverride transform)"); R"(error: override-expressions should have been removed with the SubstituteOverride transform)");
} }
TEST_F(GlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { TEST_F(GlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {

View File

@ -2837,7 +2837,7 @@ bool GeneratorImpl::EmitGlobalVariable(const ast::Variable* global) {
[&](const ast::Override*) { [&](const ast::Override*) {
// Override is removed with SubstituteOverride // Override is removed with SubstituteOverride
diagnostics_.add_error(diag::System::Writer, diagnostics_.add_error(diag::System::Writer,
"override expressions should have been removed with the " "override-expressions should have been removed with the "
"SubstituteOverride transform"); "SubstituteOverride transform");
return false; return false;
}, },
@ -3044,7 +3044,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) {
if (!wgsize[i].has_value()) { if (!wgsize[i].has_value()) {
diagnostics_.add_error( diagnostics_.add_error(
diag::System::Writer, diag::System::Writer,
"override expressions should have been removed with the SubstituteOverride " "override-expressions should have been removed with the SubstituteOverride "
"transform"); "transform");
return false; return false;
} }

View File

@ -728,7 +728,7 @@ TEST_F(HlslGeneratorImplTest_Function,
EXPECT_FALSE(gen.Generate()) << gen.error(); EXPECT_FALSE(gen.Generate()) << gen.error();
EXPECT_EQ( EXPECT_EQ(
gen.error(), gen.error(),
R"(error: override expressions should have been removed with the SubstituteOverride transform)"); R"(error: override-expressions should have been removed with the SubstituteOverride transform)");
} }
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {

View File

@ -301,7 +301,7 @@ bool GeneratorImpl::Generate() {
[&](const ast::Override*) { [&](const ast::Override*) {
// Override is removed with SubstituteOverride // Override is removed with SubstituteOverride
diagnostics_.add_error(diag::System::Writer, diagnostics_.add_error(diag::System::Writer,
"override expressions should have been removed with the " "override-expressions should have been removed with the "
"SubstituteOverride transform."); "SubstituteOverride transform.");
return false; return false;
}, },

View File

@ -509,7 +509,7 @@ bool Builder::GenerateExecutionModes(const ast::Function* func, uint32_t id) {
// Check if the workgroup_size uses pipeline-overridable constants. // Check if the workgroup_size uses pipeline-overridable constants.
if (!wgsize[0].has_value() || !wgsize[1].has_value() || !wgsize[2].has_value()) { if (!wgsize[0].has_value() || !wgsize[1].has_value() || !wgsize[2].has_value()) {
error_ = error_ =
"override expressions should have been removed with the SubstituteOverride " "override-expressions should have been removed with the SubstituteOverride "
"transform"; "transform";
return false; return false;
} }

View File

@ -164,7 +164,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_OverridableConst) {
EXPECT_FALSE(b.GenerateExecutionModes(func, 3)) << b.error(); EXPECT_FALSE(b.GenerateExecutionModes(func, 3)) << b.error();
EXPECT_EQ( EXPECT_EQ(
b.error(), b.error(),
R"(override expressions should have been removed with the SubstituteOverride transform)"); R"(override-expressions should have been removed with the SubstituteOverride transform)");
} }
TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_LiteralAndConst) { TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_LiteralAndConst) {
@ -181,7 +181,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_LiteralAndConst) {
EXPECT_FALSE(b.GenerateExecutionModes(func, 3)) << b.error(); EXPECT_FALSE(b.GenerateExecutionModes(func, 3)) << b.error();
EXPECT_EQ( EXPECT_EQ(
b.error(), b.error(),
R"(override expressions should have been removed with the SubstituteOverride transform)"); R"(override-expressions should have been removed with the SubstituteOverride transform)");
} }
TEST_F(BuilderTest, Decoration_ExecutionMode_MultipleFragment) { TEST_F(BuilderTest, Decoration_ExecutionMode_MultipleFragment) {