diag: Add System enumerator to all diagnostics

Describes what Tint system raised the diagnostic.

Use this information in the fuzzers to distinguish between expected and unexpected failure cases in the Transform fuzzer tests.

Fixed: chromium:1206407
Fixed: chromium:1207154
Change-Id: I3b807acafe384a2fc363d2a4165a29693450b3cf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/55254
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
Ben Clayton
2021-06-24 11:27:36 +00:00
committed by Tint LUCI CQ
parent 261643bb9f
commit ffd28e2e1a
94 changed files with 1005 additions and 902 deletions

View File

@@ -38,6 +38,7 @@ Output ArrayLengthFromUniform::Run(const Program* in, const DataMap& data) {
auto* cfg = data.Get<Config>();
if (cfg == nullptr) {
out.Diagnostics().add_error(
diag::System::Transform,
"missing transform data for ArrayLengthFromUniform");
return Output(Program(std::move(out)));
}
@@ -95,13 +96,13 @@ Output ArrayLengthFromUniform::Run(const Program* in, const DataMap& data) {
// have been run before this transform.
auto* param = call_expr->params()[0]->As<ast::UnaryOpExpression>();
if (!param || param->op() != ast::UnaryOp::kAddressOf) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "expected form of arrayLength argument to be &resource.array";
break;
}
auto* accessor = param->expr()->As<ast::MemberAccessorExpression>();
if (!accessor) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "expected form of arrayLength argument to be &resource.array";
break;
}
@@ -109,7 +110,7 @@ Output ArrayLengthFromUniform::Run(const Program* in, const DataMap& data) {
auto* storage_buffer_sem =
sem.Get(storage_buffer_expr)->As<sem::VariableUser>();
if (!storage_buffer_sem) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "expected form of arrayLength argument to be &resource.array";
break;
}
@@ -119,9 +120,10 @@ Output ArrayLengthFromUniform::Run(const Program* in, const DataMap& data) {
auto idx_itr = cfg->bindpoint_to_size_index.find(binding);
if (idx_itr == cfg->bindpoint_to_size_index.end()) {
ctx.dst->Diagnostics().add_error(
diag::System::Transform,
"missing size index mapping for binding point (" +
std::to_string(binding.group) + "," +
std::to_string(binding.binding) + ")");
std::to_string(binding.group) + "," +
std::to_string(binding.binding) + ")");
continue;
}

View File

@@ -45,6 +45,7 @@ Output BindingRemapper::Run(const Program* in, const DataMap& datamap) {
auto* remappings = datamap.Get<Remappings>();
if (!remappings) {
out.Diagnostics().add_error(
diag::System::Transform,
"BindingRemapper did not find the remapping data");
return Output(Program(std::move(out)));
}

View File

@@ -74,7 +74,8 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
auto* limit = b.Sub(arr_len, b.Expr(1u));
new_idx = b.Call("min", b.Construct<u32>(ctx->Clone(old_idx)), limit);
} else {
diags.add_error("invalid 0 size", expr->source());
diags.add_error(diag::System::Transform, "invalid 0 size",
expr->source());
return nullptr;
}
} else if (auto* c = old_idx->As<ast::ScalarConstructorExpression>()) {
@@ -86,7 +87,8 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
} else if (auto* uint = lit->As<ast::UintLiteral>()) {
new_idx = b.Expr(std::min(uint->value(), size - 1));
} else {
diags.add_error("unknown scalar constructor type for accessor",
diags.add_error(diag::System::Transform,
"unknown scalar constructor type for accessor",
expr->source());
return nullptr;
}

View File

@@ -134,7 +134,7 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
auto* arg = call_expr->params()[0];
auto* address_of = arg->As<ast::UnaryOpExpression>();
if (!address_of || address_of->op() != ast::UnaryOp::kAddressOf) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "arrayLength() expected pointer to member access, got "
<< address_of->TypeInfo().name;
}
@@ -142,7 +142,7 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
auto* accessor = array_expr->As<ast::MemberAccessorExpression>();
if (!accessor) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "arrayLength() expected pointer to member access, got "
"pointer to "
<< array_expr->TypeInfo().name;
@@ -158,7 +158,7 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
auto buffer_size = get_buffer_size_intrinsic(storage_buffer_type);
if (!storage_buffer_type) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "arrayLength(X.Y) expected X to be sem::Struct, got "
<< storage_buffer_type->FriendlyName(ctx.src->Symbols());
break;

View File

@@ -69,6 +69,7 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap& data) {
auto* cfg = data.Get<Config>();
if (cfg == nullptr) {
out.Diagnostics().add_error(
diag::System::Transform,
"missing transform data for CanonicalizeEntryPointIO");
return Output(Program(std::move(out)));
}
@@ -146,7 +147,8 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap& data) {
ast::ExpressionList init_values;
for (auto* member : str->Members()) {
if (member->Type()->Is<sem::Struct>()) {
TINT_ICE(ctx.dst->Diagnostics()) << "nested pipeline IO struct";
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "nested pipeline IO struct";
}
if (cfg->builtin_style == BuiltinStyle::kParameter &&
@@ -239,7 +241,8 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap& data) {
// Rebuild struct with only the entry point IO attributes.
for (auto* member : str->Members()) {
if (member->Type()->Is<sem::Struct>()) {
TINT_ICE(ctx.dst->Diagnostics()) << "nested pipeline IO struct";
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "nested pipeline IO struct";
}
ast::DecorationList new_decorations = RemoveDecorations(

View File

@@ -352,7 +352,7 @@ DecomposeMemoryAccess::Intrinsic* IntrinsicAtomicFor(ProgramBuilder* builder,
op = DecomposeMemoryAccess::Intrinsic::Op::kAtomicCompareExchangeWeak;
break;
default:
TINT_ICE(builder->Diagnostics())
TINT_ICE(Transform, builder->Diagnostics())
<< "invalid IntrinsicType for DecomposeMemoryAccess::Intrinsic: "
<< ty->type_name();
break;
@@ -435,7 +435,7 @@ struct DecomposeMemoryAccess::State {
/// @param expr the expression that performs the access
/// @param access the access
void AddAccess(ast::Expression* expr, BufferAccess&& access) {
TINT_ASSERT(access.type);
TINT_ASSERT(Transform, access.type);
accesses.emplace(expr, std::move(access));
expression_order.emplace_back(expr);
}
@@ -672,7 +672,7 @@ struct DecomposeMemoryAccess::State {
auto* atomic = IntrinsicAtomicFor(ctx.dst, op, el_ty);
if (atomic == nullptr) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "IntrinsicAtomicFor() returned nullptr for op " << op
<< " and type " << el_ty->type_name();
}

View File

@@ -58,7 +58,7 @@ Output ExternalTextureTransform::Run(const Program* in, const DataMap&) {
->Is<sem::ExternalTexture>()) {
if (intrinsic->Type() == sem::IntrinsicType::kTextureLoad &&
call_expr->params().size() != 2) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "expected textureLoad call with a texture_external to "
"have 2 parameters, found "
<< call_expr->params().size() << " parameters";
@@ -67,7 +67,7 @@ Output ExternalTextureTransform::Run(const Program* in, const DataMap&) {
if (intrinsic->Type() ==
sem::IntrinsicType::kTextureSampleLevel &&
call_expr->params().size() != 3) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "expected textureSampleLevel call with a "
"texture_external to have 3 parameters, found "
<< call_expr->params().size() << " parameters";

View File

@@ -67,7 +67,7 @@ struct Value {
operator bool() const { return Valid(); }
void Append(const Value& value) {
TINT_ASSERT(value.type == type);
TINT_ASSERT(Transform, value.type == type);
elems.insert(elems.end(), value.elems.begin(), value.elems.end());
}
@@ -89,7 +89,7 @@ struct Value {
return func(elems[index].bool_);
}
}
TINT_ASSERT(false && "Unreachable");
TINT_ASSERT(Transform, false && "Unreachable");
return func(~0);
}
};
@@ -105,7 +105,7 @@ Value::Type AstToValueType(ast::Type* t) {
} else if (t->Is<ast::Bool>()) {
return Value::Type::bool_;
}
TINT_ASSERT(false && "Invalid type");
TINT_ASSERT(Transform, false && "Invalid type");
return {};
}
@@ -193,7 +193,7 @@ Value Fold(const ast::ScalarConstructorExpression* scalar_ctor) {
if (auto* lit = literal->As<ast::BoolLiteral>()) {
return {lit->IsTrue()};
}
TINT_ASSERT(false && "Unreachable");
TINT_ASSERT(Transform, false && "Unreachable");
return {};
}

View File

@@ -52,7 +52,7 @@ Output PromoteInitializersToConstVar::Run(const Program* in, const DataMap&) {
if (auto* src_init = src_node->As<ast::TypeConstructorExpression>()) {
auto* src_sem_expr = ctx.src->Sem().Get(src_init);
if (!src_sem_expr) {
TINT_ICE(ctx.dst->Diagnostics())
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "ast::TypeConstructorExpression has no semantic expression node";
continue;
}

View File

@@ -857,7 +857,7 @@ Output Renamer::Run(const Program* in, const DataMap&) {
if (auto* member = node->As<ast::MemberAccessorExpression>()) {
auto* sem = in->Sem().Get(member);
if (!sem) {
TINT_ICE(out.Diagnostics())
TINT_ICE(Transform, out.Diagnostics())
<< "MemberAccessorExpression has no semantic info";
continue;
}
@@ -867,7 +867,8 @@ Output Renamer::Run(const Program* in, const DataMap&) {
} else if (auto* call = node->As<ast::CallExpression>()) {
auto* sem = in->Sem().Get(call);
if (!sem) {
TINT_ICE(out.Diagnostics()) << "CallExpression has no semantic info";
TINT_ICE(Transform, out.Diagnostics())
<< "CallExpression has no semantic info";
continue;
}
if (sem->Target()->Is<sem::Intrinsic>()) {

View File

@@ -35,7 +35,8 @@ Output SingleEntryPoint::Run(const Program* in, const DataMap& data) {
auto* cfg = data.Get<Config>();
if (cfg == nullptr) {
out.Diagnostics().add_error("missing transform data for SingleEntryPoint");
out.Diagnostics().add_error(diag::System::Transform,
"missing transform data for SingleEntryPoint");
return Output(Program(std::move(out)));
}
@@ -51,8 +52,9 @@ Output SingleEntryPoint::Run(const Program* in, const DataMap& data) {
}
}
if (entry_point == nullptr) {
out.Diagnostics().add_error("entry point '" + cfg->entry_point_name +
"' not found");
out.Diagnostics().add_error(
diag::System::Transform,
"entry point '" + cfg->entry_point_name + "' not found");
return Output(Program(std::move(out)));
}
@@ -81,7 +83,7 @@ Output SingleEntryPoint::Run(const Program* in, const DataMap& data) {
out.AST().AddFunction(ctx.Clone(func));
}
} else {
TINT_UNREACHABLE(out.Diagnostics())
TINT_UNREACHABLE(Transform, out.Diagnostics())
<< "unhandled global declaration: " << decl->TypeInfo().name;
return Output(Program(std::move(out)));
}

View File

@@ -134,7 +134,7 @@ ast::Type* Transform::CreateASTTypeFor(CloneContext* ctx, const sem::Type* ty) {
if (auto* s = ty->As<sem::Sampler>()) {
return ctx->dst->create<ast::Sampler>(s->kind());
}
TINT_UNREACHABLE(ctx->dst->Diagnostics())
TINT_UNREACHABLE(Transform, ctx->dst->Diagnostics())
<< "Unhandled type: " << ty->TypeInfo().name;
return nullptr;
}

View File

@@ -304,7 +304,8 @@ struct State {
}
new_function_parameters.push_back(ctx.Clone(param));
} else {
TINT_ICE(ctx.dst->Diagnostics()) << "Invalid entry point parameter";
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "Invalid entry point parameter";
}
}
@@ -346,7 +347,8 @@ struct State {
}
members_to_clone.push_back(member);
} else {
TINT_ICE(ctx.dst->Diagnostics()) << "Invalid entry point parameter";
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "Invalid entry point parameter";
}
}
@@ -466,7 +468,8 @@ Output VertexPulling::Run(const Program* in, const DataMap& data) {
auto* func = in->AST().Functions().Find(
in->Symbols().Get(cfg.entry_point_name), ast::PipelineStage::kVertex);
if (func == nullptr) {
out.Diagnostics().add_error("Vertex stage entry point not found");
out.Diagnostics().add_error(diag::System::Transform,
"Vertex stage entry point not found");
return Output(Program(std::move(out)));
}

View File

@@ -78,7 +78,7 @@ struct ZeroInitWorkgroupMemory::State {
return;
}
TINT_UNREACHABLE(ctx.dst->Diagnostics())
TINT_UNREACHABLE(Transform, ctx.dst->Diagnostics())
<< "could not zero workgroup type: " << ty->type_name();
}