Skip to content

Commit

Permalink
Put inline functions in only one CGU
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Jul 27, 2023
1 parent e7d6ce3 commit 0424a16
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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 All @@ -9,7 +8,6 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::ItemId;
use rustc_index::Idx;
use rustc_query_system::ich::StableHashingContext;
use rustc_session::config::OptLevel;
use rustc_span::source_map::Span;
use rustc_span::symbol::Symbol;
use std::fmt;
Expand Down Expand Up @@ -96,13 +94,9 @@ impl<'tcx> MonoItem<'tcx> {
}

pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
let generate_cgu_internal_copies = tcx
.sess
.opts
.unstable_opts
.inline_in_all_cgus
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
&& !tcx.sess.link_dead_code();
let generate_cgu_internal_copies =
tcx.sess.opts.unstable_opts.inline_in_all_cgus.unwrap_or(false)
&& !tcx.sess.link_dead_code();

match *self {
MonoItem::Fn(ref instance) => {
Expand All @@ -123,15 +117,7 @@ impl<'tcx> MonoItem<'tcx> {
return InstantiationMode::LocalCopy;
}

// 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 },
}
return InstantiationMode::GloballyShared { may_conflict: true };
}
MonoItem::Static(..) | MonoItem::GlobalAsm(..) => {
InstantiationMode::GloballyShared { may_conflict: false }
Expand Down

0 comments on commit 0424a16

Please sign in to comment.