]> gcc.gnu.org Git - gcc.git/commit
Refactor TypeResolution to be a simple query based system
authorPhilip Herron <philip.herron@embecosm.com>
Tue, 27 Sep 2022 10:35:21 +0000 (11:35 +0100)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 27 Sep 2022 11:24:37 +0000 (12:24 +0100)
commit96c8baa8a7a8aa796450585c1ba2c1fe2428b6f4
tree62c5a2edc7a80705984b4051a3fd7dbc27674262
parent770a2449e8e3b7c9c8a9627ce5d57c3bcd99177c
Refactor TypeResolution to be a simple query based system

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
29 files changed:
gcc/rust/Make-lang.in
gcc/rust/typecheck/rust-hir-dot-operator.cc
gcc/rust/typecheck/rust-hir-dot-operator.h
gcc/rust/typecheck/rust-hir-path-probe.cc [new file with mode: 0644]
gcc/rust/typecheck/rust-hir-path-probe.h
gcc/rust/typecheck/rust-hir-type-check-base.cc
gcc/rust/typecheck/rust-hir-type-check-base.h
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/rust/typecheck/rust-hir-type-check-implitem.cc
gcc/rust/typecheck/rust-hir-type-check-implitem.h
gcc/rust/typecheck/rust-hir-type-check-item.cc
gcc/rust/typecheck/rust-hir-type-check-item.h
gcc/rust/typecheck/rust-hir-type-check-path.cc
gcc/rust/typecheck/rust-hir-type-check-stmt.cc
gcc/rust/typecheck/rust-hir-type-check-stmt.h
gcc/rust/typecheck/rust-hir-type-check-toplevel.cc [deleted file]
gcc/rust/typecheck/rust-hir-type-check-toplevel.h [deleted file]
gcc/rust/typecheck/rust-hir-type-check-type.cc
gcc/rust/typecheck/rust-hir-type-check.cc
gcc/rust/typecheck/rust-hir-type-check.h
gcc/rust/typecheck/rust-substitution-mapper.h
gcc/rust/typecheck/rust-tyty-bounds.cc
gcc/rust/typecheck/rust-tyty-cmp.h
gcc/rust/typecheck/rust-tyty.cc
gcc/rust/typecheck/rust-tyty.h
gcc/rust/util/rust-hir-map.cc
gcc/rust/util/rust-hir-map.h
gcc/testsuite/rust/compile/const_generics_5.rs
gcc/testsuite/rust/compile/unconstrained_type_param.rs
This page took 0.063901 seconds and 6 git commands to generate.