From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 906AA38582B9; Tue, 27 Sep 2022 15:50:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 906AA38582B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664293818; bh=ddZ4n7rN0sQ7WDCaoiMtbBbgcJ2AHE/ZVnG78q7sbmw=; h=From:To:Subject:Date:From; b=VkDODiJCHi7HzZB9UvQk0jfteCs94xF2TA+roEuKiulk4BXl7CRGRIrK4IVarQoUY e4dRuXU8DblZtXiBvp0za4oSjvAKlBmetTUK/3WQedOvX2+BwdLBSjAoQvgMn4hL6b bygrCrzJngnxLtBV+inaaB5CEqOm6VoFMD0irLi8= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Merge #1545 X-Act-Checkin: gcc X-Git-Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com> X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: cecd314884a285957a110560bbd141a5f39ad7d3 X-Git-Newrev: b71e3dc02a8fd3141080419b7fb1a24d2c4133d0 Message-Id: <20220927155018.906AA38582B9@sourceware.org> Date: Tue, 27 Sep 2022 15:50:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b71e3dc02a8fd3141080419b7fb1a24d2c4133d0 commit b71e3dc02a8fd3141080419b7fb1a24d2c4133d0 Merge: cecd314884a b17e69852ea Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com> Date: Tue Sep 27 14:06:08 2022 +0000 Merge #1545 1545: Refactor TypeResolution to be a simple query based system r=philberty a=philberty This patch refactors the type resolution system to introduce a new interface bool query_type (HirId, TyTy::BaseType** result) This is needed in order to properly support forward declared items. Our name resolution system has two parts: 1. Toplevel scan 2. Item resolution The toplevel scan gathers all the nesseacry 'names' into their respective namespace by doing a full toplevel scan and generate canonical paths for each item. The second pass is responsible for drilling down into each structure or function to resolve each field or variable etc. This means our name resolution system supports forward decalred items but our type resolution system did not. This patch removes the toplevel scan from our type resolution pass which is not able to handle all cases such as a function with return type and the type is decalred after the fact or a type alias to a type declared after the fact. The name resolution mappings are resolved so when errors occured here we got errors such as unable to lookup HirId 1234, which meant yes we have 'resolved' this reference to this HirId but we are unable to find any type information for it. This means we needed a new way to figure out the type in a query based way. This is where the new query_type inferface comes in so when we have an HirId we want to resolve the mappings class allows us to figure out what item this is such as: 1. HIR::Item (normal HIR::Function, Struct, TypeAlias, ...) 2. HIR::ImplItem (function, constant, ... within an impl-block) 3. HIR::ImplBlock (Self type on an impl-block) 4. HIR::ExternalItem (extern-block item) The mappings class allows us to simply lookup these HIR nodes and then call the relevant resolver class to compute the type. This patch does not add support for self-referencial types but is the starting point to be able to support such types. Fixes #1455 Fixes #1006 Fixes #1073 Fixes #1272 Co-authored-by: Philip Herron Diff: gcc/rust/Make-lang.in | 2 +- gcc/rust/backend/rust-compile-context.h | 21 +- gcc/rust/backend/rust-compile-expr.h | 17 +- gcc/rust/backend/rust-compile-item.cc | 14 +- gcc/rust/backend/rust-constexpr.cc | 16 +- gcc/rust/checks/lints/rust-lint-marklive.cc | 7 +- gcc/rust/resolve/rust-name-resolver.cc | 20 + gcc/rust/resolve/rust-name-resolver.h | 6 + gcc/rust/typecheck/rust-hir-dot-operator.cc | 8 +- gcc/rust/typecheck/rust-hir-dot-operator.h | 6 +- gcc/rust/typecheck/rust-hir-path-probe.cc | 46 ++ gcc/rust/typecheck/rust-hir-path-probe.h | 24 +- gcc/rust/typecheck/rust-hir-type-check-base.cc | 76 +++ gcc/rust/typecheck/rust-hir-type-check-base.h | 2 + gcc/rust/typecheck/rust-hir-type-check-expr.cc | 3 + gcc/rust/typecheck/rust-hir-type-check-implitem.cc | 181 +++---- gcc/rust/typecheck/rust-hir-type-check-implitem.h | 42 +- gcc/rust/typecheck/rust-hir-type-check-item.cc | 554 +++++++++++++++++---- gcc/rust/typecheck/rust-hir-type-check-item.h | 47 +- gcc/rust/typecheck/rust-hir-type-check-path.cc | 9 +- gcc/rust/typecheck/rust-hir-type-check-stmt.cc | 387 ++------------ gcc/rust/typecheck/rust-hir-type-check-stmt.h | 62 +-- gcc/rust/typecheck/rust-hir-type-check-toplevel.cc | 378 -------------- gcc/rust/typecheck/rust-hir-type-check-toplevel.h | 56 --- gcc/rust/typecheck/rust-hir-type-check-type.cc | 110 ++-- gcc/rust/typecheck/rust-hir-type-check.cc | 9 +- gcc/rust/typecheck/rust-hir-type-check.h | 41 ++ gcc/rust/typecheck/rust-substitution-mapper.h | 2 +- gcc/rust/typecheck/rust-tyty-bounds.cc | 24 +- gcc/rust/typecheck/rust-tyty-cmp.h | 2 + gcc/rust/typecheck/rust-tyty.cc | 45 +- gcc/rust/typecheck/rust-tyty.h | 34 +- gcc/rust/util/rust-hir-map.cc | 13 + gcc/rust/util/rust-hir-map.h | 2 + gcc/testsuite/rust/compile/const_generics_5.rs | 13 +- gcc/testsuite/rust/compile/issue-1006.rs | 10 + gcc/testsuite/rust/compile/issue-1073.rs | 4 + gcc/testsuite/rust/compile/issue-1272.rs | 8 + .../rust/compile/unconstrained_type_param.rs | 2 + 39 files changed, 1058 insertions(+), 1245 deletions(-)