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] Ensure we support generic arguments on mangled type-paths Date: Thu, 30 Jun 2022 18:50:48 +0000 (GMT) [thread overview] Message-ID: <20220630185048.05D3E383EC6C@sourceware.org> (raw) https://gcc.gnu.org/g:1282974cf899f9486c62054bcbadf41346915dd5 commit 1282974cf899f9486c62054bcbadf41346915dd5 Author: Philip Herron <philip.herron@embecosm.com> Date: Wed Jun 29 12:01:05 2022 +0100 Ensure we support generic arguments on mangled type-paths This allows us to have the generic arguments within type paths for mangled symbols such as those in impl-blocks. This also updates our symbol managling to mangle comma's to $C$. Diff: --- gcc/rust/backend/rust-mangle.cc | 6 ++++ gcc/rust/resolve/rust-ast-resolve-type.cc | 47 ++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc index c0aea0286af..4d202078a70 100644 --- a/gcc/rust/backend/rust-mangle.cc +++ b/gcc/rust/backend/rust-mangle.cc @@ -14,6 +14,7 @@ static const std::string kMangledPtr = "$BP$"; static const std::string kMangledLeftSqParen = "$u5b$"; // [ static const std::string kMangledRightSqParen = "$u5d$"; // ] static const std::string kQualPathBegin = "_" + kMangledSubstBegin; +static const std::string kMangledComma = "$C$"; namespace Rust { namespace Compile { @@ -39,6 +40,9 @@ legacy_mangle_name (const std::string &name) // // example::Foo<T>::new: // _ZN7example12Foo$LT$T$GT$3new17h9a2aacb7fd783515E: + // + // <example::Identity as example::FnLike<&T,&T>>::call + // _ZN74_$LT$example..Identity$u20$as$u20$example..FnLike$LT$$RF$T$C$$RF$T$GT$$GT$4call17ha9ee58935895acb3E std::string buffer; for (size_t i = 0; i < name.size (); i++) @@ -62,6 +66,8 @@ legacy_mangle_name (const std::string &name) m = kMangledLeftSqParen; else if (c == ']') m = kMangledRightSqParen; + else if (c == ',') + m = kMangledComma; else if (c == ':') { rust_assert (i + 1 < name.size ()); diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index 5d0ceb536d5..a823543e18d 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -356,7 +356,52 @@ ResolveTypeToCanonicalPath::visit (AST::TypePath &path) if (mappings->lookup_canonical_path (mappings->get_current_crate (), resolved_node, &type_path)) { - result = *type_path; + auto &final_seg = path.get_segments ().back (); + switch (final_seg->get_type ()) + { + case AST::TypePathSegment::SegmentType::GENERIC: { + AST::TypePathSegmentGeneric *s + = static_cast<AST::TypePathSegmentGeneric *> (final_seg.get ()); + + std::vector<CanonicalPath> args; + if (s->has_generic_args ()) + { + for (auto > : s->get_generic_args ().get_type_args ()) + { + CanonicalPath arg = CanonicalPath::create_empty (); + bool ok = ResolveTypeToCanonicalPath::go (gt.get (), arg); + if (ok) + args.push_back (std::move (arg)); + } + } + + result = *type_path; + if (!args.empty ()) + { + // append this onto the path + std::string buf; + for (size_t i = 0; i < args.size (); i++) + { + bool has_next = (i + 1) < args.size (); + const auto &arg = args.at (i); + + buf += arg.get (); + if (has_next) + buf += ", "; + } + + std::string arg_seg = "<" + buf + ">"; + CanonicalPath argument_seg + = CanonicalPath::new_seg (s->get_node_id (), arg_seg); + result = result.append (argument_seg); + } + } + break; + + default: + result = *type_path; + break; + } } }
reply other threads:[~2022-06-30 18:50 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=20220630185048.05D3E383EC6C@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).