diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-11-23 11:29:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 11:29:35 +0000 |
commit | a60de84632f5df6e4d54e2736bb7e04f9655af6a (patch) | |
tree | 893244e2b2d779d34877c6535a97147e969755d3 /gcc | |
parent | 87da9922e66d64e2ef307d33076da86b8486bea0 (diff) | |
parent | 0216a1a9a04c1efa19851aa4b049be3bcb4ff72c (diff) | |
download | gcc-a60de84632f5df6e4d54e2736bb7e04f9655af6a.zip gcc-a60de84632f5df6e4d54e2736bb7e04f9655af6a.tar.gz gcc-a60de84632f5df6e4d54e2736bb7e04f9655af6a.tar.bz2 |
Merge #812
812: Remove implicit paths hack r=philberty a=philberty
The name resolver also created a bunch of duplicates Self::associated_type
paths in the name resolver so associated types paths of this kind could be resolved
at name resolve time.
Addresses #739
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-implitem.h | 8 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.h | 32 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 20 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-name-resolver.h | 65 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-type.cc | 4 |
5 files changed, 51 insertions, 78 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index e9ee75e..ef75505 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -54,9 +54,6 @@ public: r.add_range (locus); rust_error_at (r, "redefined multiple times"); }); - resolver->insert_new_definition (type.get_node_id (), - Definition{type.get_node_id (), - type.get_node_id ()}); } void visit (AST::ConstantItem &constant) override @@ -181,16 +178,13 @@ public: { auto path = prefix.append (ResolveTraitItemTypeToCanonicalPath::resolve (type)); - resolver->get_name_scope ().insert ( + resolver->get_type_scope ().insert ( path, type.get_node_id (), type.get_locus (), false, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (type.get_locus ()); r.add_range (locus); rust_error_at (r, "redefined multiple times"); }); - resolver->insert_new_definition (type.get_node_id (), - Definition{type.get_node_id (), - type.get_node_id ()}); } private: diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index f60732c..a4bf261 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -453,7 +453,7 @@ public: for (auto &impl_item : impl_block.get_impl_items ()) { - resolve_impl_item (impl_item.get (), Self); + resolve_impl_item (impl_item.get ()); } resolver->get_type_scope ().peek ()->clear_name ( @@ -584,7 +584,7 @@ public: for (auto &impl_item : impl_block.get_impl_items ()) { - resolve_impl_item (impl_item.get (), Self); + resolve_impl_item (impl_item.get ()); } resolver->get_type_scope ().peek ()->clear_name ( @@ -646,9 +646,8 @@ public: } protected: - void resolve_impl_item (AST::TraitImplItem *item, const CanonicalPath &self); - void resolve_impl_item (AST::InherentImplItem *item, - const CanonicalPath &self); + void resolve_impl_item (AST::TraitImplItem *item); + void resolve_impl_item (AST::InherentImplItem *item); void resolve_extern_item (AST::ExternalItem *item); ResolveItem () : ResolverBase (UNKNOWN_NODEID) {} @@ -659,15 +658,15 @@ class ResolveImplItems : public ResolveItem using Rust::Resolver::ResolveItem::visit; public: - static void go (AST::InherentImplItem *item, const CanonicalPath &self) + static void go (AST::InherentImplItem *item) { - ResolveImplItems resolver (self); + ResolveImplItems resolver; item->accept_vis (resolver); }; - static void go (AST::TraitImplItem *item, const CanonicalPath &self) + static void go (AST::TraitImplItem *item) { - ResolveImplItems resolver (self); + ResolveImplItems resolver; item->accept_vis (resolver); }; @@ -675,26 +674,13 @@ public: { ResolveItem::visit (alias); - auto path - = self.append (CanonicalPath::new_seg (alias.get_node_id (), - alias.get_new_type_name ())); - resolver->get_type_scope ().insert ( - path, alias.get_node_id (), alias.get_locus (), false, - [&] (const CanonicalPath &, NodeId, Location locus) -> void { - RichLocation r (alias.get_locus ()); - r.add_range (locus); - rust_error_at (r, "redefined multiple times"); - }); - // FIXME this stops the erronious unused decls which will be fixed later on resolver->get_type_scope ().append_reference_for_def (alias.get_node_id (), alias.get_node_id ()); } private: - ResolveImplItems (const CanonicalPath &self) : ResolveItem (), self (self) {} - - const CanonicalPath &self; + ResolveImplItems () : ResolveItem () {} }; class ResolveExternItem : public ResolverBase diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 9a0d349..39e8ee4 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -313,14 +313,12 @@ NameResolution::Resolve (AST::Crate &crate) void NameResolution::go (AST::Crate &crate) { - // setup parent scoping for names - resolver->get_name_scope ().push (crate.get_node_id ()); + NodeId scope_node_id = crate.get_node_id (); + resolver->get_name_scope ().push (scope_node_id); + resolver->get_type_scope ().push (scope_node_id); + resolver->get_label_scope ().push (scope_node_id); resolver->push_new_name_rib (resolver->get_name_scope ().peek ()); - // setup parent scoping for new types - resolver->get_type_scope ().push (mappings->get_next_node_id ()); resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); - // setup label scope - resolver->get_label_scope ().push (mappings->get_next_node_id ()); resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); // first gather the top-level namespace names then we drill down @@ -773,17 +771,15 @@ ResolveType::visit (AST::TraitObjectType &type) // rust-ast-resolve-item.h void -ResolveItem::resolve_impl_item (AST::TraitImplItem *item, - const CanonicalPath &self) +ResolveItem::resolve_impl_item (AST::TraitImplItem *item) { - ResolveImplItems::go (item, self); + ResolveImplItems::go (item); } void -ResolveItem::resolve_impl_item (AST::InherentImplItem *item, - const CanonicalPath &self) +ResolveItem::resolve_impl_item (AST::InherentImplItem *item) { - ResolveImplItems::go (item, self); + ResolveImplItems::go (item); } void diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index d5703ed..f03fe06 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -33,7 +33,8 @@ public: // Rust uses local_def_ids assigned by def_collector on the AST // lets use NodeId instead Rib (CrateNum crateNum, NodeId node_id) - : crate_num (crateNum), node_id (node_id) + : crate_num (crateNum), node_id (node_id), + mappings (Analysis::Mappings::get ()) {} ~Rib () {} @@ -42,35 +43,30 @@ public: const CanonicalPath &path, NodeId id, Location locus, bool shadow, std::function<void (const CanonicalPath &, NodeId, Location)> dup_cb) { - auto it = mappings.find (path); - bool already_exists = it != mappings.end (); - if (already_exists && !shadow) + auto it = path_mappings.find (path); + bool path_already_exists = it != path_mappings.end (); + if (path_already_exists && !shadow) { - for (auto &decl : decls_within_rib) - { - if (decl.first == it->second) - { - dup_cb (path, it->second, decl.second); - return; - } - } - dup_cb (path, it->second, locus); + const auto &decl = decls_within_rib.find (it->second); + if (decl != decls_within_rib.end ()) + dup_cb (path, it->second, decl->second); + else + dup_cb (path, it->second, locus); + return; } - mappings[path] = id; - reverse_mappings.insert (std::pair<NodeId, CanonicalPath> (id, path)); + path_mappings[path] = id; + reverse_path_mappings.insert (std::pair<NodeId, CanonicalPath> (id, path)); decls_within_rib.insert (std::pair<NodeId, Location> (id, locus)); references[id] = {}; - - auto mappings = Analysis::Mappings::get (); mappings->insert_canonical_path (mappings->get_current_crate (), id, path); } bool lookup_name (const CanonicalPath &ident, NodeId *id) { - auto it = mappings.find (ident); - if (it == mappings.end ()) + auto it = path_mappings.find (ident); + if (it == path_mappings.end ()) return false; *id = it->second; @@ -79,8 +75,8 @@ public: bool lookup_canonical_path (const NodeId &id, CanonicalPath *ident) { - auto it = reverse_mappings.find (id); - if (it == reverse_mappings.end ()) + auto it = reverse_path_mappings.find (id); + if (it == reverse_path_mappings.end ()) return false; *ident = it->second; @@ -89,17 +85,17 @@ public: void clear_name (const CanonicalPath &ident, NodeId id) { - mappings.erase (ident); - reverse_mappings.erase (id); + auto ii = path_mappings.find (ident); + if (ii != path_mappings.end ()) + path_mappings.erase (ii); - for (auto &it : decls_within_rib) - { - if (it.first == id) - { - decls_within_rib.erase (it); - break; - } - } + auto ij = reverse_path_mappings.find (id); + if (ij != reverse_path_mappings.end ()) + reverse_path_mappings.erase (ij); + + auto ik = decls_within_rib.find (id); + if (ik != decls_within_rib.end ()) + decls_within_rib.erase (ik); } CrateNum get_crate_num () const { return crate_num; } @@ -154,10 +150,11 @@ public: private: CrateNum crate_num; NodeId node_id; - std::map<CanonicalPath, NodeId> mappings; - std::map<NodeId, CanonicalPath> reverse_mappings; - std::set<std::pair<NodeId, Location>> decls_within_rib; + std::map<CanonicalPath, NodeId> path_mappings; + std::map<NodeId, CanonicalPath> reverse_path_mappings; + std::map<NodeId, Location> decls_within_rib; std::map<NodeId, std::set<NodeId>> references; + Analysis::Mappings *mappings; }; class Scope diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index f1dbb6b..391ea40 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -220,7 +220,7 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) bool fully_resolved = path.get_segments ().empty (); if (fully_resolved) { - resolver->insert_resolved_name (path.get_mappings ().get_nodeid (), + resolver->insert_resolved_type (path.get_mappings ().get_nodeid (), root_resolved_node_id); context->insert_receiver (path.get_mappings ().get_hirid (), root); return; @@ -517,7 +517,7 @@ TypeCheckType::resolve_segments ( } else { - resolver->insert_resolved_name (expr_mappings.get_nodeid (), + resolver->insert_resolved_type (expr_mappings.get_nodeid (), resolved_node_id); } |