public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Handle generic Slices and Arrays Date: Wed, 8 Jun 2022 12:17:33 +0000 (GMT) [thread overview] Message-ID: <20220608121733.EF4223AAA061@sourceware.org> (raw) https://gcc.gnu.org/g:894e9d29adadc13e9841f43df32a07939480846d commit 894e9d29adadc13e9841f43df32a07939480846d Author: Philip Herron <philip.herron@embecosm.com> 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<ArrayType *> (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<SliceType *> (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; };
reply other threads:[~2022-06-08 12:17 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608121733.EF4223AAA061@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).