Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup lang items mappings #3273

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1258,5 +1258,24 @@ Mappings::lookup_trait_item_lang_item (LangItem::Kind item, location_t locus)
return lookup_trait_item_defid (trait_item_id);
}

void
Mappings::insert_lang_item (LangItem::Kind item_type, DefId id)
{
auto it = lang_item_mappings.find (item_type);
rust_assert (it == lang_item_mappings.end ());

lang_item_mappings[item_type] = id;
}

tl::optional<DefId &>
Mappings::lookup_lang_item (LangItem::Kind item_type)
{
auto it = lang_item_mappings.find (item_type);
if (it == lang_item_mappings.end ())
return tl::nullopt;

return it->second;
}

} // namespace Analysis
} // namespace Rust
18 changes: 2 additions & 16 deletions gcc/rust/util/rust-hir-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,8 @@ class Mappings
return it->second;
}

void insert_lang_item (LangItem::Kind item_type, DefId id)
{
auto it = lang_item_mappings.find (item_type);
rust_assert (it == lang_item_mappings.end ());

lang_item_mappings[item_type] = id;
}

tl::optional<DefId &> lookup_lang_item (LangItem::Kind item_type)
{
auto it = lang_item_mappings.find (item_type);
if (it == lang_item_mappings.end ())
return tl::nullopt;

return it->second;
}
void insert_lang_item (LangItem::Kind item_type, DefId id);
tl::optional<DefId &> lookup_lang_item (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
2 changes: 1 addition & 1 deletion gcc/rust/util/rust-lang-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

namespace Rust {

// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
class LangItem
{
public:
enum class Kind
{
// https://github.com/rust-lang/rust/blob/master/library/core/src/ops/arith.rs
ADD,
SUBTRACT,
MULTIPLY,
Expand Down
Loading