Skip to content

Commit

Permalink
Keep inline(always) in multiple CGUs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Jul 27, 2023
1 parent 0424a16 commit e2789cb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::dep_graph::{DepNode, WorkProduct, WorkProductId};
use crate::ty::{GenericArgs, Instance, InstanceDef, SymbolName, TyCtxt};
use rustc_attr::InlineAttr;
use rustc_data_structures::base_n;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -117,7 +118,15 @@ impl<'tcx> MonoItem<'tcx> {
return InstantiationMode::LocalCopy;
}

return InstantiationMode::GloballyShared { may_conflict: true };
// Finally, if this is `#[inline(always)]` we're sure to respect
// that with an inline copy per CGU, but otherwise we'll be
// creating one copy of this `#[inline]` function which may
// conflict with upstream crates as it could be an exported
// symbol.
match tcx.codegen_fn_attrs(instance.def_id()).inline {
InlineAttr::Always => InstantiationMode::LocalCopy,
_ => InstantiationMode::GloballyShared { may_conflict: true },
}
}
MonoItem::Static(..) | MonoItem::GlobalAsm(..) => {
InstantiationMode::GloballyShared { may_conflict: false }
Expand Down

0 comments on commit e2789cb

Please sign in to comment.