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:
parent
9c4d0c9410
commit
8c9cc86076
|
@ -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);
|
||||
|
|
|
@ -1495,30 +1495,23 @@ 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; });
|
||||
|
||||
if (is_call_stmt) {
|
||||
return Switch(
|
||||
call->Target(), //
|
||||
[&](const sem::TypeConversion*) {
|
||||
if (is_call_stmt) {
|
||||
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; });
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Validator::DiscardStatement(const sem::Statement* stmt,
|
||||
sem::Statement* current_statement) const {
|
||||
if (auto* continuing = ClosestContinuing(/*stop_at_loop*/ false, current_statement)) {
|
||||
|
|
Loading…
Reference in New Issue