From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id EF4223AAA061; Wed, 8 Jun 2022 12:17:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF4223AAA061 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] Handle generic Slices and Arrays X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: a620a228c1d79d4725efd5d6ed5f0ebe398e6787 X-Git-Newrev: 894e9d29adadc13e9841f43df32a07939480846d Message-Id: <20220608121733.EF4223AAA061@sourceware.org> Date: Wed, 8 Jun 2022 12:17:33 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 12:17:34 -0000 https://gcc.gnu.org/g:894e9d29adadc13e9841f43df32a07939480846d commit 894e9d29adadc13e9841f43df32a07939480846d Author: Philip Herron Date: Thu Mar 10 16:17:52 2022 +0000 Handle generic Slices and Arrays Slices and Arrays are covariant types which means they can contain elements which bind generics such as ADT or FnTypes. This means substitutions can be recursive and this gives the typechecker a chance to handle this recursion on these types. Diff: --- gcc/rust/typecheck/rust-substitution-mapper.h | 12 ++++++++-- gcc/rust/typecheck/rust-tyty.cc | 32 +++++++++++++++++++++++++++ gcc/rust/typecheck/rust-tyty.h | 4 ++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h index 0d48bd2532c..5f1781635cc 100644 --- a/gcc/rust/typecheck/rust-substitution-mapper.h +++ b/gcc/rust/typecheck/rust-substitution-mapper.h @@ -221,11 +221,19 @@ public: resolved = type.handle_substitions (mappings); } + void visit (TyTy::ArrayType &type) override + { + resolved = type.handle_substitions (mappings); + } + + void visit (TyTy::SliceType &type) override + { + resolved = type.handle_substitions (mappings); + } + // nothing to do for these void visit (TyTy::InferType &) override { gcc_unreachable (); } void visit (TyTy::FnPtr &) override { gcc_unreachable (); } - void visit (TyTy::ArrayType &) override { gcc_unreachable (); } - void visit (TyTy::SliceType &) override { gcc_unreachable (); } void visit (TyTy::BoolType &) override { gcc_unreachable (); } void visit (TyTy::IntType &) override { gcc_unreachable (); } void visit (TyTy::UintType &) override { gcc_unreachable (); } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 0a296445d59..8d5cc5e511a 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -1508,6 +1508,22 @@ ArrayType::clone () const element_type, get_combined_refs ()); } +ArrayType * +ArrayType::handle_substitions (SubstitutionArgumentMappings mappings) +{ + auto mappings_table = Analysis::Mappings::get (); + + ArrayType *ref = static_cast (clone ()); + ref->set_ty_ref (mappings_table->get_next_hir_id ()); + + // might be &T or &ADT so this needs to be recursive + auto base = ref->get_element_type (); + BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings); + ref->element_type = TyVar (concrete->get_ty_ref ()); + + return ref; +} + void SliceType::accept_vis (TyVisitor &vis) { @@ -1581,6 +1597,22 @@ SliceType::clone () const get_combined_refs ()); } +SliceType * +SliceType::handle_substitions (SubstitutionArgumentMappings mappings) +{ + auto mappings_table = Analysis::Mappings::get (); + + SliceType *ref = static_cast (clone ()); + ref->set_ty_ref (mappings_table->get_next_hir_id ()); + + // might be &T or &ADT so this needs to be recursive + auto base = ref->get_element_type (); + BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings); + ref->element_type = TyVar (concrete->get_ty_ref ()); + + return ref; +} + void BoolType::accept_vis (TyVisitor &vis) { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index bf4110baf76..82262abab09 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1665,6 +1665,8 @@ public: HIR::Expr &get_capacity_expr () const { return capacity_expr; } + ArrayType *handle_substitions (SubstitutionArgumentMappings mappings); + private: TyVar element_type; HIR::Expr &capacity_expr; @@ -1710,6 +1712,8 @@ public: return get_element_type ()->is_concrete (); } + SliceType *handle_substitions (SubstitutionArgumentMappings mappings); + private: TyVar element_type; };