Skip to content
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
6 changes: 3 additions & 3 deletions compiler/rustc_hir/src/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ use crate::def_id::DefId;
use crate::{lang_items, LangItem, LanguageItems};

use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_map::StableMap;
use rustc_span::symbol::{sym, Symbol};

use std::lazy::SyncLazy;

macro_rules! weak_lang_items {
($($name:ident, $item:ident, $sym:ident;)*) => (

pub static WEAK_ITEMS_REFS: SyncLazy<FxHashMap<Symbol, LangItem>> = SyncLazy::new(|| {
let mut map = FxHashMap::default();
pub static WEAK_ITEMS_REFS: SyncLazy<StableMap<Symbol, LangItem>> = SyncLazy::new(|| {
let mut map = StableMap::default();
$(map.insert(sym::$name, LangItem::$item);)*
map
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) {
}
}

for (name, &item) in WEAK_ITEMS_REFS.iter() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WEAK_ITEMS_REFS is already a StableMap now, do you need to sort it? The only reason I am commenting on it is that I am slightly saddened by the new .clone() (but I'll get over it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is the one turning it into a StableMap, and the sort is necessary to normalize the order, right?

(That is: If we don't normalize the order, then we don't get the benefit of this change, right?)

To be clear: I too am saddened by the .clone(), and you might talk me into just using a different structure entirely. This seemed like the simplest fix, and if we're going to balk at doing it in this scenario, then maybe we should remove StableMap entirely and figure out a different way to discourage people from using FxHashMap?

for (name, item) in WEAK_ITEMS_REFS.clone().into_sorted_vector().into_iter() {
if missing.contains(&item) && required(tcx, item) && items.require(item).is_err() {
if item == LangItem::PanicImpl {
tcx.sess.err("`#[panic_handler]` function required, but not found");
Expand Down