Skip to content

Commit 9d6086f

Browse files
committed
wip
1 parent 4911572 commit 9d6086f

File tree

16 files changed

+242
-32
lines changed

16 files changed

+242
-32
lines changed

src/bootstrap/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,9 @@ impl<'a> Builder<'a> {
10981098
}
10991099

11001100
if let Mode::Rustc | Mode::Codegen = mode {
1101+
if stage > 0 {
1102+
rustflags.arg("-Zcross-crate-inline-threshold=50");
1103+
}
11011104
rustflags.arg("-Zunstable-options");
11021105
rustflags.arg("-Wrustc::internal");
11031106
}

src/librustc/middle/codegen_fn_attrs.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@ impl CodegenFnAttrs {
9595
}
9696
}
9797

98-
/// Returns `true` if `#[inline]` or `#[inline(always)]` is present.
99-
pub fn requests_inline(&self) -> bool {
100-
match self.inline {
101-
InlineAttr::Hint | InlineAttr::Always => true,
102-
InlineAttr::None | InlineAttr::Never => false,
103-
}
104-
}
105-
10698
/// Returns `true` if it looks like this symbol needs to be exported, for example:
10799
///
108100
/// * `#[no_mangle]` is present

src/librustc/mir/mono.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ impl<'tcx> MonoItem<'tcx> {
9090

9191
match *self {
9292
MonoItem::Fn(ref instance) => {
93+
/*use rustc_hir::ItemKind;
94+
use rustc_hir::Node;
95+
tcx.hir().as_local_hir_id(instance.def_id()).map(|id| match tcx.hir().get(id) {
96+
Node::Item(item) => match item.kind {
97+
ItemKind::Static(..) | ItemKind::Const(..) => {
98+
panic!("STATIC!! {:?}", self);
99+
}
100+
_ => (),
101+
},
102+
_ => (),
103+
});*/
104+
93105
let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id);
94106
// If this function isn't inlined or otherwise has explicit
95107
// linkage, then we'll be creating a globally shared version.

src/librustc/query/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ rustc_queries! {
649649
query codegen_fn_attrs(_: DefId) -> CodegenFnAttrs {
650650
cache_on_disk_if { true }
651651
}
652+
653+
query cross_crate_inlinable(_: DefId) -> bool {}
652654
}
653655

654656
Other {

src/librustc/ty/instance.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,13 @@ impl<'tcx> InstanceDef<'tcx> {
204204
// drops of `Option::None` before LTO. We also respect the intent of
205205
// `#[inline]` on `Drop::drop` implementations.
206206
return ty.ty_adt_def().map_or(true, |adt_def| {
207-
adt_def.destructor(tcx).map_or(adt_def.is_enum(), |dtor| {
208-
tcx.codegen_fn_attrs(dtor.did).requests_inline()
209-
})
207+
adt_def
208+
.destructor(tcx)
209+
.map_or(adt_def.is_enum(), |dtor| tcx.cross_crate_inlinable(dtor.did))
210210
});
211211
}
212-
tcx.codegen_fn_attrs(self.def_id()).requests_inline()
212+
213+
tcx.cross_crate_inlinable(self.def_id())
213214
}
214215

215216
pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ fn reachable_non_generics_provider(
8585
}
8686

8787
// Only consider nodes that actually have exported symbols.
88-
Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })
89-
| Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
88+
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
9089
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
9190
let def_id = tcx.hir().local_def_id(hir_id);
9291
let generics = tcx.generics_of(def_id);
@@ -101,6 +100,15 @@ fn reachable_non_generics_provider(
101100
}
102101
}
103102

103+
Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. }) => {
104+
let def_id = tcx.hir().local_def_id(hir_id);
105+
let generics = tcx.generics_of(def_id);
106+
let r =
107+
if !generics.requires_monomorphization(tcx) { Some(def_id) } else { None };
108+
//assert!(r.is_some());
109+
r
110+
}
111+
104112
_ => None,
105113
}
106114
})

src/librustc_metadata/rmeta/decoder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10991099
!self.is_proc_macro(id) && self.root.per_def.mir.get(self, id).is_some()
11001100
}
11011101

1102+
fn is_item_cross_crate_inlinable(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> bool {
1103+
self.root
1104+
.per_def
1105+
.cross_crate_inlinable
1106+
.get(self, id)
1107+
.map(|v| v.decode((self, tcx)))
1108+
.unwrap_or(false)
1109+
}
1110+
11021111
fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyAndCache<'tcx> {
11031112
let mut cache = self
11041113
.root

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
149149
impl_parent => { cdata.get_parent_impl(def_id.index) }
150150
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
151151
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
152+
cross_crate_inlinable => { cdata.is_item_cross_crate_inlinable(tcx, def_id.index) }
152153

153154
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
154155
is_panic_runtime => { cdata.root.panic_runtime }

src/librustc_metadata/rmeta/encoder.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,9 @@ impl EncodeContext<'tcx> {
882882
ty::AssocKind::OpaqueTy => unreachable!(),
883883
}
884884
if trait_item.kind == ty::AssocKind::Method {
885+
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
886+
record!(self.per_def.cross_crate_inlinable[def_id] <- self.tcx.cross_crate_inlinable(def_id));
887+
}
885888
record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id));
886889
self.encode_variances_of(def_id);
887890
}
@@ -968,9 +971,11 @@ impl EncodeContext<'tcx> {
968971
let mir = match ast_item.kind {
969972
hir::ImplItemKind::Const(..) => true,
970973
hir::ImplItemKind::Fn(ref sig, _) => {
974+
record!(self.per_def.cross_crate_inlinable[def_id] <- self.tcx.cross_crate_inlinable(def_id));
975+
971976
let generics = self.tcx.generics_of(def_id);
972977
let needs_inline = (generics.requires_monomorphization(self.tcx)
973-
|| tcx.codegen_fn_attrs(def_id).requests_inline())
978+
|| tcx.cross_crate_inlinable(def_id))
974979
&& !self.metadata_output_only();
975980
let is_const_fn = sig.header.constness == hir::Constness::Const;
976981
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
@@ -1266,9 +1271,11 @@ impl EncodeContext<'tcx> {
12661271
let mir = match item.kind {
12671272
hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => true,
12681273
hir::ItemKind::Fn(ref sig, ..) => {
1274+
record!(self.per_def.cross_crate_inlinable[def_id] <- self.tcx.cross_crate_inlinable(def_id));
1275+
12691276
let generics = tcx.generics_of(def_id);
12701277
let needs_inline = (generics.requires_monomorphization(tcx)
1271-
|| tcx.codegen_fn_attrs(def_id).requests_inline())
1278+
|| tcx.cross_crate_inlinable(def_id))
12721279
&& !self.metadata_output_only();
12731280
let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir;
12741281
needs_inline || sig.header.constness == hir::Constness::Const || always_encode_mir
@@ -1743,8 +1750,8 @@ impl<'tcx, 'v> ParItemLikeVisitor<'v> for PrefetchVisitor<'tcx> {
17431750
hir::ItemKind::Fn(ref sig, ..) => {
17441751
let def_id = tcx.hir().local_def_id(item.hir_id);
17451752
let generics = tcx.generics_of(def_id);
1746-
let needs_inline = generics.requires_monomorphization(tcx)
1747-
|| tcx.codegen_fn_attrs(def_id).requests_inline();
1753+
let needs_inline =
1754+
generics.requires_monomorphization(tcx) || tcx.cross_crate_inlinable(def_id);
17481755
if needs_inline || sig.header.constness == hir::Constness::Const {
17491756
self.prefetch_mir(def_id)
17501757
}
@@ -1768,8 +1775,8 @@ impl<'tcx, 'v> ParItemLikeVisitor<'v> for PrefetchVisitor<'tcx> {
17681775
hir::ImplItemKind::Fn(ref sig, _) => {
17691776
let def_id = tcx.hir().local_def_id(impl_item.hir_id);
17701777
let generics = tcx.generics_of(def_id);
1771-
let needs_inline = generics.requires_monomorphization(tcx)
1772-
|| tcx.codegen_fn_attrs(def_id).requests_inline();
1778+
let needs_inline =
1779+
generics.requires_monomorphization(tcx) || tcx.cross_crate_inlinable(def_id);
17731780
let is_const_fn = sig.header.constness == hir::Constness::Const;
17741781
if needs_inline || is_const_fn {
17751782
self.prefetch_mir(def_id)

src/librustc_metadata/rmeta/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ define_per_def_tables! {
276276
inferred_outlives: Table<DefIndex, Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>,
277277
super_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
278278
mir: Table<DefIndex, Lazy!(mir::BodyAndCache<'tcx>)>,
279+
cross_crate_inlinable: Table<DefIndex, Lazy<bool>>,
279280
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::BodyAndCache<'tcx>>)>,
280281
}
281282

0 commit comments

Comments
 (0)