diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-07-08 11:47:17 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-08 11:47:17 +0000 |
commit | e1293ae35777427e1c87659ae21f9bca5f6395d6 (patch) | |
tree | 362332a85d7d4e27ed53f91a2f8293817fafc856 /gcc/rust/resolve | |
parent | 33eb5c938ac41ff5e65c3a8d947d033b32d31ace (diff) | |
parent | fb27d1452b31d5485b1fce692f14279472cf0baf (diff) | |
download | gcc-e1293ae35777427e1c87659ae21f9bca5f6395d6.zip gcc-e1293ae35777427e1c87659ae21f9bca5f6395d6.tar.gz gcc-e1293ae35777427e1c87659ae21f9bca5f6395d6.tar.bz2 |
Merge #1366
1366: Refactor mappings class and HIR lowering to be consistent r=philberty a=philberty
In order to support loading extern crates and use statements we needed to
clarify the usage of NodeId and HirId within gccrs. Each of these id's were
nested behind the CrateNum but the type resolution, linting and code-gen
passes do not support that level of nesting.
In order to get metadata exports and imports working lets focus on gccrs
supporting compilation of a single crate at a time. This means the crate
prefix only matters for imports and limits the complexity here. Down the
line there might be a way to leverage DefId's for all Path resolution
which could solve this problem but significant refactoring would be
required here to do this properly and its not nessecary for a basic working
rust compiler.
The mappings changes here will help us resolve issues like #1361 much more
easily.
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-implitem.h | 12 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 54 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-stmt.h | 30 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-toplevel.h | 93 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.cc | 3 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.h | 3 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-name-resolver.cc | 23 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-name-resolver.h | 2 |
8 files changed, 121 insertions, 99 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index 192ecaf..29dbe34 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -147,8 +147,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - function.get_node_id (), cpath); + mappings->insert_canonical_path (function.get_node_id (), cpath); } void visit (AST::TraitItemMethod &method) override @@ -166,8 +165,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - method.get_node_id (), cpath); + mappings->insert_canonical_path (method.get_node_id (), cpath); } void visit (AST::TraitItemConst &constant) override @@ -185,8 +183,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - constant.get_node_id (), cpath); + mappings->insert_canonical_path (constant.get_node_id (), cpath); } void visit (AST::TraitItemType &type) override @@ -204,8 +201,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - type.get_node_id (), cpath); + mappings->insert_canonical_path (type.get_node_id (), cpath); } private: diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 62518b6..244bf64 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -46,8 +46,7 @@ ResolveTraitItems::visit (AST::TraitItemType &type) = CanonicalPath::new_seg (type.get_node_id (), type.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - type.get_node_id (), cpath); + mappings->insert_canonical_path (type.get_node_id (), cpath); for (auto &bound : type.get_type_param_bounds ()) ResolveTypeBound::go (bound.get ()); @@ -60,8 +59,7 @@ ResolveTraitItems::visit (AST::TraitItemFunc &func) func.get_node_id (), func.get_trait_function_decl ().get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - func.get_node_id (), cpath); + mappings->insert_canonical_path (func.get_node_id (), cpath); NodeId scope_node_id = func.get_node_id (); resolver->get_name_scope ().push (scope_node_id); @@ -107,8 +105,7 @@ ResolveTraitItems::visit (AST::TraitItemMethod &func) func.get_trait_method_decl ().get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - func.get_node_id (), cpath); + mappings->insert_canonical_path (func.get_node_id (), cpath); NodeId scope_node_id = func.get_node_id (); resolver->get_name_scope ().push (scope_node_id); @@ -170,8 +167,7 @@ ResolveTraitItems::visit (AST::TraitItemConst &constant) constant.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - constant.get_node_id (), cpath); + mappings->insert_canonical_path (constant.get_node_id (), cpath); ResolveType::go (constant.get_type ().get ()); @@ -199,8 +195,7 @@ ResolveItem::visit (AST::TypeAlias &alias) = CanonicalPath::new_seg (alias.get_node_id (), alias.get_new_type_name ()); auto path = prefix.append (talias); auto cpath = canonical_prefix.append (talias); - mappings->insert_canonical_path (mappings->get_current_crate (), - alias.get_node_id (), cpath); + mappings->insert_canonical_path (alias.get_node_id (), cpath); NodeId scope_node_id = alias.get_node_id (); resolver->get_type_scope ().push (scope_node_id); @@ -223,8 +218,7 @@ ResolveItem::visit (AST::Module &module) auto mod = CanonicalPath::new_seg (module.get_node_id (), module.get_name ()); auto path = prefix.append (mod); auto cpath = canonical_prefix.append (mod); - mappings->insert_canonical_path (mappings->get_current_crate (), - module.get_node_id (), cpath); + mappings->insert_canonical_path (module.get_node_id (), cpath); resolve_visibility (module.get_visibility ()); @@ -259,8 +253,7 @@ ResolveItem::visit (AST::TupleStruct &struct_decl) struct_decl.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - struct_decl.get_node_id (), cpath); + mappings->insert_canonical_path (struct_decl.get_node_id (), cpath); resolve_visibility (struct_decl.get_visibility ()); @@ -294,8 +287,7 @@ ResolveItem::visit (AST::Enum &enum_decl) enum_decl.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - enum_decl.get_node_id (), cpath); + mappings->insert_canonical_path (enum_decl.get_node_id (), cpath); resolve_visibility (enum_decl.get_visibility ()); @@ -327,8 +319,7 @@ ResolveItem::visit (AST::EnumItem &item) = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); } void @@ -338,8 +329,7 @@ ResolveItem::visit (AST::EnumItemTuple &item) = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); for (auto &field : item.get_tuple_fields ()) { @@ -357,8 +347,7 @@ ResolveItem::visit (AST::EnumItemStruct &item) = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); for (auto &field : item.get_struct_fields ()) { @@ -377,8 +366,7 @@ ResolveItem::visit (AST::EnumItemDiscriminant &item) auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); } void @@ -388,8 +376,7 @@ ResolveItem::visit (AST::StructStruct &struct_decl) struct_decl.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - struct_decl.get_node_id (), cpath); + mappings->insert_canonical_path (struct_decl.get_node_id (), cpath); resolve_visibility (struct_decl.get_visibility ()); @@ -423,8 +410,7 @@ ResolveItem::visit (AST::Union &union_decl) union_decl.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - union_decl.get_node_id (), cpath); + mappings->insert_canonical_path (union_decl.get_node_id (), cpath); resolve_visibility (union_decl.get_visibility ()); @@ -456,8 +442,7 @@ ResolveItem::visit (AST::StaticItem &var) = CanonicalPath::new_seg (var.get_node_id (), var.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - var.get_node_id (), cpath); + mappings->insert_canonical_path (var.get_node_id (), cpath); ResolveType::go (var.get_type ().get ()); ResolveExpr::go (var.get_expr ().get (), path, cpath); @@ -470,8 +455,7 @@ ResolveItem::visit (AST::ConstantItem &constant) constant.get_identifier ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - constant.get_node_id (), cpath); + mappings->insert_canonical_path (constant.get_node_id (), cpath); resolve_visibility (constant.get_visibility ()); @@ -487,8 +471,7 @@ ResolveItem::visit (AST::Function &function) auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - function.get_node_id (), cpath); + mappings->insert_canonical_path (function.get_node_id (), cpath); resolve_visibility (function.get_visibility ()); @@ -614,8 +597,7 @@ ResolveItem::visit (AST::Method &method) = CanonicalPath::new_seg (method.get_node_id (), method.get_method_name ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - method.get_node_id (), cpath); + mappings->insert_canonical_path (method.get_node_id (), cpath); NodeId scope_node_id = method.get_node_id (); diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 8867845..6f21bc3 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -60,8 +60,7 @@ public: constant.get_identifier ()); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - constant.get_node_id (), cpath); + mappings->insert_canonical_path (constant.get_node_id (), cpath); resolver->get_name_scope ().insert ( path, constant.get_node_id (), constant.get_locus (), false, @@ -94,8 +93,7 @@ public: struct_decl.get_identifier ()); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - struct_decl.get_node_id (), cpath); + mappings->insert_canonical_path (struct_decl.get_node_id (), cpath); resolver->get_type_scope ().insert ( path, struct_decl.get_node_id (), struct_decl.get_locus (), false, @@ -126,8 +124,7 @@ public: enum_decl.get_identifier ()); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - enum_decl.get_node_id (), cpath); + mappings->insert_canonical_path (enum_decl.get_node_id (), cpath); resolver->get_type_scope ().insert ( path, enum_decl.get_node_id (), enum_decl.get_locus (), false, @@ -158,8 +155,7 @@ public: CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ())); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); resolver->get_type_scope ().insert ( path, item.get_node_id (), item.get_locus (), false, @@ -178,8 +174,7 @@ public: CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ())); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); resolver->get_type_scope ().insert ( path, item.get_node_id (), item.get_locus (), false, @@ -204,8 +199,7 @@ public: CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ())); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); resolver->get_type_scope ().insert ( path, item.get_node_id (), item.get_locus (), false, @@ -230,8 +224,7 @@ public: CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ())); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); resolver->get_type_scope ().insert ( path, item.get_node_id (), item.get_locus (), false, @@ -250,8 +243,7 @@ public: struct_decl.get_identifier ()); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - struct_decl.get_node_id (), cpath); + mappings->insert_canonical_path (struct_decl.get_node_id (), cpath); resolver->get_type_scope ().insert ( path, struct_decl.get_node_id (), struct_decl.get_locus (), false, @@ -287,8 +279,7 @@ public: union_decl.get_identifier ()); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - union_decl.get_node_id (), cpath); + mappings->insert_canonical_path (union_decl.get_node_id (), cpath); resolver->get_type_scope ().insert ( path, union_decl.get_node_id (), union_decl.get_locus (), false, @@ -322,8 +313,7 @@ public: function.get_function_name ()); auto path = decl; // this ensures we have the correct relative resolution auto cpath = canonical_prefix.append (decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - function.get_node_id (), cpath); + mappings->insert_canonical_path (function.get_node_id (), cpath); resolver->get_name_scope ().insert ( path, function.get_node_id (), function.get_locus (), false, diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 7aacc0a..352faac 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -24,6 +24,7 @@ #include "rust-ast-resolve-implitem.h" #include "rust-ast-full.h" #include "rust-name-resolver.h" +#include "rust-session-manager.h" namespace Rust { namespace Resolver { @@ -72,8 +73,7 @@ public: resolver->pop_module_scope (); - mappings->insert_canonical_path (mappings->get_current_crate (), - module.get_node_id (), cpath); + mappings->insert_canonical_path (module.get_node_id (), cpath); } void visit (AST::TypeAlias &alias) override @@ -93,8 +93,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, talias); - mappings->insert_canonical_path (mappings->get_current_crate (), - alias.get_node_id (), cpath); + mappings->insert_canonical_path (alias.get_node_id (), cpath); } void visit (AST::TupleStruct &struct_decl) override @@ -114,8 +113,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - struct_decl.get_node_id (), cpath); + mappings->insert_canonical_path (struct_decl.get_node_id (), cpath); } void visit (AST::Enum &enum_decl) override @@ -138,8 +136,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - enum_decl.get_node_id (), cpath); + mappings->insert_canonical_path (enum_decl.get_node_id (), cpath); } void visit (AST::EnumItem &item) override @@ -157,8 +154,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); } void visit (AST::EnumItemTuple &item) override @@ -176,8 +172,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); } void visit (AST::EnumItemStruct &item) override @@ -195,8 +190,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); } void visit (AST::EnumItemDiscriminant &item) override @@ -214,8 +208,7 @@ public: rust_error_at (r, "redefined multiple times"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - item.get_node_id (), cpath); + mappings->insert_canonical_path (item.get_node_id (), cpath); } void visit (AST::StructStruct &struct_decl) override @@ -235,8 +228,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - struct_decl.get_node_id (), cpath); + mappings->insert_canonical_path (struct_decl.get_node_id (), cpath); } void visit (AST::Union &union_decl) override @@ -256,8 +248,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - union_decl.get_node_id (), cpath); + mappings->insert_canonical_path (union_decl.get_node_id (), cpath); } void visit (AST::StaticItem &var) override @@ -277,8 +268,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - var.get_node_id (), cpath); + mappings->insert_canonical_path (var.get_node_id (), cpath); } void visit (AST::ConstantItem &constant) override @@ -298,8 +288,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - constant.get_node_id (), cpath); + mappings->insert_canonical_path (constant.get_node_id (), cpath); } void visit (AST::Function &function) override @@ -319,8 +308,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - function.get_node_id (), cpath); + mappings->insert_canonical_path (function.get_node_id (), cpath); } void visit (AST::InherentImpl &impl_block) override @@ -385,8 +373,7 @@ public: NodeId current_module = resolver->peek_current_module_scope (); mappings->insert_module_child_item (current_module, decl); - mappings->insert_canonical_path (mappings->get_current_crate (), - trait.get_node_id (), cpath); + mappings->insert_canonical_path (trait.get_node_id (), cpath); } void visit (AST::ExternBlock &extern_block) override @@ -397,6 +384,56 @@ public: } } + void visit (AST::ExternCrate &extern_crate) override + { + if (extern_crate.is_marked_for_strip ()) + return; + + NodeId resolved_crate = UNKNOWN_NODEID; + if (extern_crate.references_self ()) + { + // FIXME + // then this resolves to current crate_node_id + // need to expose on the session object a reference to the current + // AST::Crate& to get node_id + gcc_unreachable (); + return; + } + else + { + rust_debug_loc (extern_crate.get_locus (), "load extern crate: [%s]", + extern_crate.as_string ().c_str ()); + + Session &session = Session::get_instance (); + resolved_crate + = session.load_extern_crate (extern_crate.get_referenced_crate ()); + } + + if (resolved_crate == UNKNOWN_NODEID) + { + rust_error_at (extern_crate.get_locus (), "failed to resolve crate"); + return; + } + + // mark the node as resolved + resolver->insert_resolved_name (extern_crate.get_node_id (), + resolved_crate); + + // does it has an as clause + if (extern_crate.has_as_clause ()) + { + auto decl = CanonicalPath::new_seg (extern_crate.get_node_id (), + extern_crate.get_as_clause ()); + resolver->get_type_scope ().insert ( + decl, extern_crate.get_node_id (), extern_crate.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { + RichLocation r (extern_crate.get_locus ()); + r.add_range (locus); + rust_error_at (r, "redefined multiple times"); + }); + } + } + private: ResolveTopLevel (const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index e875688..8e85889 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -371,8 +371,7 @@ ResolveTypeToCanonicalPath::visit (AST::TypePath &path) return; const CanonicalPath *type_path = nullptr; - if (mappings->lookup_canonical_path (mappings->get_current_crate (), - resolved_node, &type_path)) + if (mappings->lookup_canonical_path (resolved_node, &type_path)) { auto &final_seg = path.get_segments ().back (); switch (final_seg->get_type ()) diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index f933d1e..1679831 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -184,8 +184,7 @@ public: rust_error_at (locus, "was defined here"); }); - mappings->insert_canonical_path (mappings->get_current_crate (), - param.get_node_id (), seg); + mappings->insert_canonical_path (param.get_node_id (), seg); } private: diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index a788914..fb70874 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -34,11 +34,10 @@ _R.push_back (builtin_type); \ tyctx->insert_builtin (_TY->get_ref (), builtin_type->get_node_id (), \ _TY); \ - mappings->insert_node_to_hir (mappings->get_current_crate (), \ - builtin_type->get_node_id (), \ + mappings->insert_node_to_hir (builtin_type->get_node_id (), \ _TY->get_ref ()); \ mappings->insert_canonical_path ( \ - mappings->get_current_crate (), builtin_type->get_node_id (), \ + builtin_type->get_node_id (), \ CanonicalPath::new_seg (builtin_type->get_node_id (), _X)); \ } \ while (0) @@ -129,6 +128,24 @@ Rib::decl_was_declared_here (NodeId def) const return false; } +void +Rib::debug () const +{ + fprintf (stderr, "%s\n", debug_str ().c_str ()); +} + +std::string +Rib::debug_str () const +{ + std::string buffer; + for (const auto &it : path_mappings) + { + buffer += it.first.get () + "=" + std::to_string (it.second); + buffer += ","; + } + return "{" + buffer + "}"; +} + Scope::Scope (CrateNum crate_num) : crate_num (crate_num) {} void diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index e9f7c62..014628a 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -45,6 +45,8 @@ public: void append_reference_for_def (NodeId def, NodeId ref); bool have_references_for_node (NodeId def) const; bool decl_was_declared_here (NodeId def) const; + void debug () const; + std::string debug_str () const; CrateNum get_crate_num () const { return crate_num; } NodeId get_node_id () const { return node_id; } |