Skip to content

Commit 3186267

Browse files
spastorinowesleywiser
authored andcommitted
Do not make local copies of inline fns in debug mode
1 parent 0f6f2d6 commit 3186267

File tree

2 files changed

+13
-13
lines changed
  • compiler/rustc_middle/src/mir
  • src/test/run-make-fulldeps/inline-always-many-cgu

2 files changed

+13
-13
lines changed

compiler/rustc_middle/src/mir/mono.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::dep_graph::{DepConstructor, DepNode, WorkProduct, WorkProductId};
22
use crate::ich::{NodeIdHashingMode, StableHashingContext};
33
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
4-
use rustc_attr::InlineAttr;
54
use rustc_data_structures::base_n;
65
use rustc_data_structures::fingerprint::Fingerprint;
76
use rustc_data_structures::fx::FxHashMap;
@@ -103,17 +102,13 @@ impl<'tcx> MonoItem<'tcx> {
103102
// inlined function. If we're inlining into all CGUs then we'll
104103
// be creating a local copy per CGU.
105104
if generate_cgu_internal_copies {
106-
return InstantiationMode::LocalCopy;
107-
}
108-
109-
// Finally, if this is `#[inline(always)]` we're sure to respect
110-
// that with an inline copy per CGU, but otherwise we'll be
111-
// creating one copy of this `#[inline]` function which may
112-
// conflict with upstream crates as it could be an exported
113-
// symbol.
114-
match tcx.codegen_fn_attrs(instance.def_id()).inline {
115-
InlineAttr::Always => InstantiationMode::LocalCopy,
116-
_ => InstantiationMode::GloballyShared { may_conflict: true },
105+
InstantiationMode::LocalCopy
106+
} else {
107+
// Finally, if we've reached this point, then we should optimize for
108+
// compilation speed. In that regard, we will ignore any `#[inline]`
109+
// annotations on the function and simply codegen it as usual. This could
110+
// conflict with upstream crates as it could be an exported symbol.
111+
InstantiationMode::GloballyShared { may_conflict: true }
117112
}
118113
}
119114
MonoItem::Static(..) | MonoItem::GlobalAsm(..) => {

src/test/run-make-fulldeps/inline-always-many-cgu/Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
-include ../tools.mk
22

33
all:
4-
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2
4+
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 -C opt-level=0
5+
if ![cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b']; then \
6+
echo "not found call instruction when one was expected"; \
7+
exit 1; \
8+
fi
9+
$(RUSTC) foo.rs --emit llvm-ir -C codegen-units=2 -C opt-level=1
510
if cat $(TMPDIR)/*.ll | $(CGREP) -e '\bcall\b'; then \
611
echo "found call instruction when one wasn't expected"; \
712
exit 1; \

0 commit comments

Comments
 (0)