tint/resolver: Simplify / optimize Validator::Call()

The resolver has sensible places to dispatch to ArrayConstructor() and
StructureConstructor(), so don't do additional, unnecessary type
dispatches.

Change-Id: Id4edb1fc0dedf431d94507b1c3378bca164746a4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97588
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2022-08-01 15:19:54 +00:00 committed by Dawn LUCI CQ
parent 9c4d0c9410
commit 8c9cc86076
2 changed files with 33 additions and 20 deletions

View File

@ -1592,7 +1592,17 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
return builder_->create<sem::TypeConstructor>(arr, std::move(params),
args_stage);
});
return arr_or_str_ctor(arr, call_target);
auto* call = arr_or_str_ctor(arr, call_target);
if (!call) {
return nullptr;
}
// Validation must occur after argument materialization in arr_or_str_ctor().
if (!validator_.ArrayConstructor(expr, arr)) {
return nullptr;
}
return call;
},
[&](const sem::Struct* str) -> sem::Call* {
auto* call_target = utils::GetOrCreate(
@ -1611,7 +1621,17 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
return builder_->create<sem::TypeConstructor>(str, std::move(params),
args_stage);
});
return arr_or_str_ctor(str, call_target);
auto* call = arr_or_str_ctor(str, call_target);
if (!call) {
return nullptr;
}
// Validation must occur after argument materialization in arr_or_str_ctor().
if (!validator_.StructureConstructor(expr, str)) {
return nullptr;
}
return call;
},
[&](Default) {
AddError("type is not constructible", expr->source);

View File

@ -1495,28 +1495,21 @@ bool Validator::Call(const sem::Call* call, sem::Statement* current_statement) c
bool is_call_stmt =
current_statement && Is<ast::CallStatement>(current_statement->Declaration(),
[&](auto* stmt) { return stmt->expr == expr; });
return Switch(
call->Target(), //
[&](const sem::TypeConversion*) {
if (is_call_stmt) {
if (is_call_stmt) {
return Switch(
call->Target(), //
[&](const sem::TypeConversion*) {
AddError("type conversion evaluated but not used", call->Declaration()->source);
return false;
}
return true;
},
[&](const sem::TypeConstructor* ctor) {
if (is_call_stmt) {
},
[&](const sem::TypeConstructor*) {
AddError("type constructor evaluated but not used", call->Declaration()->source);
return false;
}
return Switch(
ctor->ReturnType(), //
[&](const sem::Array* arr) { return ArrayConstructor(expr, arr); },
[&](const sem::Struct* str) { return StructureConstructor(expr, str); },
[&](Default) { return true; });
},
[&](Default) { return true; });
},
[&](Default) { return true; });
}
return true;
}
bool Validator::DiscardStatement(const sem::Statement* stmt,