Skip to content

Commit 0424a16

Browse files
committed
Put inline functions in only one CGU
1 parent e7d6ce3 commit 0424a16

File tree

1 file changed

+4
-18
lines changed
  • compiler/rustc_middle/src/mir

1 file changed

+4
-18
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::dep_graph::{DepNode, WorkProduct, WorkProductId};
22
use crate::ty::{GenericArgs, Instance, InstanceDef, SymbolName, TyCtxt};
3-
use rustc_attr::InlineAttr;
43
use rustc_data_structures::base_n;
54
use rustc_data_structures::fingerprint::Fingerprint;
65
use rustc_data_structures::fx::FxHashMap;
@@ -9,7 +8,6 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
98
use rustc_hir::ItemId;
109
use rustc_index::Idx;
1110
use rustc_query_system::ich::StableHashingContext;
12-
use rustc_session::config::OptLevel;
1311
use rustc_span::source_map::Span;
1412
use rustc_span::symbol::Symbol;
1513
use std::fmt;
@@ -96,13 +94,9 @@ impl<'tcx> MonoItem<'tcx> {
9694
}
9795

9896
pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
99-
let generate_cgu_internal_copies = tcx
100-
.sess
101-
.opts
102-
.unstable_opts
103-
.inline_in_all_cgus
104-
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
105-
&& !tcx.sess.link_dead_code();
97+
let generate_cgu_internal_copies =
98+
tcx.sess.opts.unstable_opts.inline_in_all_cgus.unwrap_or(false)
99+
&& !tcx.sess.link_dead_code();
106100

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

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

0 commit comments

Comments
 (0)