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),
|
return builder_->create<sem::TypeConstructor>(arr, std::move(params),
|
||||||
args_stage);
|
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* {
|
[&](const sem::Struct* str) -> sem::Call* {
|
||||||
auto* call_target = utils::GetOrCreate(
|
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),
|
return builder_->create<sem::TypeConstructor>(str, std::move(params),
|
||||||
args_stage);
|
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) {
|
[&](Default) {
|
||||||
AddError("type is not constructible", expr->source);
|
AddError("type is not constructible", expr->source);
|
||||||
|
|
|
@ -1495,28 +1495,21 @@ bool Validator::Call(const sem::Call* call, sem::Statement* current_statement) c
|
||||||
bool is_call_stmt =
|
bool is_call_stmt =
|
||||||
current_statement && Is<ast::CallStatement>(current_statement->Declaration(),
|
current_statement && Is<ast::CallStatement>(current_statement->Declaration(),
|
||||||
[&](auto* stmt) { return stmt->expr == expr; });
|
[&](auto* stmt) { return stmt->expr == expr; });
|
||||||
|
if (is_call_stmt) {
|
||||||
return Switch(
|
return Switch(
|
||||||
call->Target(), //
|
call->Target(), //
|
||||||
[&](const sem::TypeConversion*) {
|
[&](const sem::TypeConversion*) {
|
||||||
if (is_call_stmt) {
|
|
||||||
AddError("type conversion evaluated but not used", call->Declaration()->source);
|
AddError("type conversion evaluated but not used", call->Declaration()->source);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
[&](const sem::TypeConstructor* ctor) {
|
[&](const sem::TypeConstructor*) {
|
||||||
if (is_call_stmt) {
|
|
||||||
AddError("type constructor evaluated but not used", call->Declaration()->source);
|
AddError("type constructor evaluated but not used", call->Declaration()->source);
|
||||||
return false;
|
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,
|
bool Validator::DiscardStatement(const sem::Statement* stmt,
|
||||||
|
|
Loading…
Reference in New Issue