From 8c9cc860763f871604ffb77209a167e6f9fe4bea Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 1 Aug 2022 15:19:54 +0000 Subject: [PATCH] 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 Commit-Queue: Ben Clayton Reviewed-by: Dan Sinclair --- src/tint/resolver/resolver.cc | 24 ++++++++++++++++++++++-- src/tint/resolver/validator.cc | 29 +++++++++++------------------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 7eb4d28fad..da6cfe29fa 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -1592,7 +1592,17 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { return builder_->create(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(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); diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index d854447f0f..c7df529ad1 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -1495,28 +1495,21 @@ bool Validator::Call(const sem::Call* call, sem::Statement* current_statement) c bool is_call_stmt = current_statement && Is(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,