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] Track the cratenum for the respective canonical path Date: Wed, 8 Jun 2022 12:02:29 +0000 (GMT) [thread overview] Message-ID: <20220608120229.E50B73AA980C@sourceware.org> (raw) https://gcc.gnu.org/g:2fbf9cb25e930e2df86d05e0f7f707e69bae2b1f commit 2fbf9cb25e930e2df86d05e0f7f707e69bae2b1f Author: Philip Herron <philip.herron@embecosm.com> Date: Sat Jan 29 14:55:51 2022 +0000 Track the cratenum for the respective canonical path This means we can get the crate name to squash the warning in the V0 symbol mangling scheme. Diff: --- gcc/rust/backend/rust-mangle.cc | 10 +++++++--- gcc/rust/resolve/rust-ast-resolve.cc | 9 +++++---- gcc/rust/util/rust-canonical-path.h | 33 +++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc index 2c864888964..eaf78146464 100644 --- a/gcc/rust/backend/rust-mangle.cc +++ b/gcc/rust/backend/rust-mangle.cc @@ -252,12 +252,16 @@ legacy_mangle_item (const TyTy::BaseType *ty, static std::string v0_mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path) { - std::string mangled; + // we can get this from the canonical_path + auto mappings = Analysis::Mappings::get (); + std::string crate_name; + bool ok = mappings->get_crate_name (path.get_crate_num (), crate_name); + rust_assert (ok); + std::string mangled; // FIXME: Add real algorithm once all pieces are implemented auto ty_prefix = v0_type_prefix (ty); - // crate name must be assumed to be part of the canonical path - // v0_add_identifier (mangled, crate_name); + v0_add_identifier (mangled, crate_name); v0_add_disambiguator (mangled, 62); gcc_unreachable (); diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 5e29e25f230..96524d254ff 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -314,9 +314,9 @@ void NameResolution::go (AST::Crate &crate) { // lookup current crate name + CrateNum cnum = mappings->get_current_crate (); std::string crate_name; - bool ok - = mappings->get_crate_name (mappings->get_current_crate (), crate_name); + bool ok = mappings->get_crate_name (cnum, crate_name); rust_assert (ok); // setup the ribs @@ -331,10 +331,11 @@ NameResolution::go (AST::Crate &crate) // get the root segment CanonicalPath crate_prefix = CanonicalPath::new_seg (scope_node_id, crate_name); + crate_prefix.set_crate_num (cnum); // first gather the top-level namespace names then we drill down so this - // allows for resolving forward declarations since an impl block might have a - // Self type Foo which is defined after the impl block for example. + // allows for resolving forward declarations since an impl block might have + // a Self type Foo which is defined after the impl block for example. for (auto it = crate.items.begin (); it != crate.items.end (); it++) ResolveTopLevel::go (it->get (), CanonicalPath::create_empty (), crate_prefix); diff --git a/gcc/rust/util/rust-canonical-path.h b/gcc/rust/util/rust-canonical-path.h index 6ac8968afcc..9b340750bba 100644 --- a/gcc/rust/util/rust-canonical-path.h +++ b/gcc/rust/util/rust-canonical-path.h @@ -57,7 +57,8 @@ public: static CanonicalPath new_seg (NodeId id, const std::string &path) { rust_assert (!path.empty ()); - return CanonicalPath ({std::pair<NodeId, std::string> (id, path)}); + return CanonicalPath ({std::pair<NodeId, std::string> (id, path)}, + UNKNOWN_CREATENUM); } std::string get () const @@ -77,7 +78,10 @@ public: return CanonicalPath::new_seg (id, "Self"); } - static CanonicalPath create_empty () { return CanonicalPath ({}); } + static CanonicalPath create_empty () + { + return CanonicalPath ({}, UNKNOWN_CREATENUM); + } bool is_empty () const { return segs.size () == 0; } @@ -85,13 +89,13 @@ public: { rust_assert (!other.is_empty ()); if (is_empty ()) - return CanonicalPath (other.segs); + return CanonicalPath (other.segs, crate_num); std::vector<std::pair<NodeId, std::string>> copy (segs); for (auto &s : other.segs) copy.push_back (s); - return CanonicalPath (copy); + return CanonicalPath (copy, crate_num); } // if we have the path A::B::C this will give a callback for each segment @@ -110,7 +114,7 @@ public: for (auto &seg : segs) { buf.push_back (seg); - if (!cb (CanonicalPath (buf))) + if (!cb (CanonicalPath (buf, crate_num))) return; } } @@ -131,7 +135,7 @@ public: { std::vector<std::pair<NodeId, std::string>> buf; buf.push_back ({seg.first, seg.second}); - if (!cb (CanonicalPath (buf))) + if (!cb (CanonicalPath (buf, crate_num))) return; } } @@ -150,14 +154,17 @@ public: return segs.at (index); } - static bool segment_is_qualified_path (const std::string &seg) + bool is_equal (const CanonicalPath &b) const { - return seg.find (" as ") != std::string::npos; + return get ().compare (b.get ()) == 0; } - bool is_equal (const CanonicalPath &b) const + void set_crate_num (CrateNum n) { crate_num = n; } + + CrateNum get_crate_num () const { - return get ().compare (b.get ()) == 0; + rust_assert (crate_num != UNKNOWN_CREATENUM); + return crate_num; } bool operator== (const CanonicalPath &b) const { return is_equal (b); } @@ -165,11 +172,13 @@ public: bool operator< (const CanonicalPath &b) const { return get () < b.get (); } private: - explicit CanonicalPath (std::vector<std::pair<NodeId, std::string>> path) - : segs (path) + explicit CanonicalPath (std::vector<std::pair<NodeId, std::string>> path, + CrateNum crate_num) + : segs (path), crate_num (crate_num) {} std::vector<std::pair<NodeId, std::string>> segs; + CrateNum crate_num; }; } // namespace Resolver
reply other threads:[~2022-06-08 12:02 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=20220608120229.E50B73AA980C@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).