Skip to content

Commit

Permalink
lang-items: Store NodeId mappings for lang items
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* util/rust-hir-map.h: Keep a NodeId mappings for lang items.
	* util/rust-hir-map.cc (Mappings::insert_lang_item_node): New function.
	(Mappings::lookup_lang_item_node): Likewise.
  • Loading branch information
CohenArthur committed Nov 28, 2024
1 parent af0ca06 commit f8e0b86
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,9 @@ Mappings::lookup_builtin_marker ()
return builtinMarker;
}

// FIXME: Before merging: Should we remove the `locus` parameter here? since
// lang items are looked up mostly for code generation, it doesn't make sense to
// error out on the locus of the node trying to access an inexistant lang item
DefId
Mappings::get_lang_item (LangItem::Kind item_type, location_t locus)
{
Expand Down Expand Up @@ -1277,5 +1280,24 @@ Mappings::lookup_lang_item (LangItem::Kind item_type)
return it->second;
}

void
Mappings::insert_lang_item_node (LangItem::Kind item_type, NodeId node_id)
{
auto it = lang_item_nodes.find (item_type);
rust_assert (it == lang_item_nodes.end ());

lang_item_nodes.insert ({item_type, node_id});
}

tl::optional<NodeId &>
Mappings::lookup_lang_item_node (LangItem::Kind item_type)
{
auto it = lang_item_nodes.find (item_type);
if (it == lang_item_nodes.end ())
return tl::nullopt;

return it->second;
}

} // namespace Analysis
} // namespace Rust
8 changes: 8 additions & 0 deletions gcc/rust/util/rust-hir-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ class Mappings
void insert_lang_item (LangItem::Kind item_type, DefId id);
tl::optional<DefId &> lookup_lang_item (LangItem::Kind item_type);

void insert_lang_item_node (LangItem::Kind item_type, NodeId node_id);
tl::optional<NodeId &> lookup_lang_item_node (LangItem::Kind item_type);

// This will fatal_error when this lang item does not exist
DefId get_lang_item (LangItem::Kind item_type, location_t locus);

Expand Down Expand Up @@ -375,7 +378,12 @@ class Mappings
std::map<HirId, HIR::GenericParam *> hirGenericParamMappings;
std::map<HirId, HIR::Trait *> hirTraitItemsToTraitMappings;
std::map<HirId, HIR::Pattern *> hirPatternMappings;

// We need to have two maps here, as lang-items need to be used for both AST
// passes and HIR passes. Thus those two maps are created at different times.
std::map<LangItem::Kind, DefId> lang_item_mappings;
std::map<LangItem::Kind, NodeId> lang_item_nodes;

std::map<NodeId, Resolver::CanonicalPath> paths;
std::map<NodeId, location_t> locations;
std::map<NodeId, HirId> nodeIdToHirMappings;
Expand Down

0 comments on commit f8e0b86

Please sign in to comment.