Skip to content

always try inlining functions which do not call other functions #77307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
metadata: store is_trivial_mir using a ()
  • Loading branch information
lcnr committed Oct 20, 2020
commit 6b17a76be58c4a9ba71363218b5e45e47d313a60
9 changes: 2 additions & 7 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,13 +1195,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}

fn get_is_trivial_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> bool {
self.root
.tables
.is_trivial_mir
.get(self, id)
.filter(|_| !self.is_proc_macro(id))
.map_or(false, |v| v.decode((self, tcx)))
fn get_is_trivial_mir(&self, id: DefIndex) -> bool {
self.root.tables.is_trivial_mir.get(self, id).filter(|_| !self.is_proc_macro(id)).is_some()
}

fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
})
}
is_trivial_mir => { cdata.get_is_trivial_mir(tcx, def_id.index) }
is_trivial_mir => { cdata.get_is_trivial_mir(def_id.index) }
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
mir_abstract_const => { cdata.get_mir_abstract_const(tcx, def_id.index) }
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,9 @@ impl EncodeContext<'a, 'tcx> {
debug!("EntryBuilder::encode_mir({:?})", def_id);
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
if self.tcx.is_trivial_mir(def_id) {
record!(self.tables.is_trivial_mir[def_id.to_def_id()] <- true);
// We don't store anything if `is_trivial_mir` is `false`
// so we can use a unit type here.
self.tables.is_trivial_mir.set(def_id.local_def_index, ());
}

record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ define_tables! {
super_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
// As an optimization, a missing entry indicates an empty `&[]`.
explicit_item_bounds: Table<DefIndex, Lazy!([(ty::Predicate<'tcx>, Span)])>,
is_trivial_mir: Table<DefIndex, Lazy<bool>>,
is_trivial_mir: Table<DefIndex, ()>,
mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
mir_abstract_consts: Table<DefIndex, Lazy!(&'tcx [mir::abstract_const::Node<'tcx>])>,
Expand Down
26 changes: 25 additions & 1 deletion compiler/rustc_metadata/src/rmeta/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_index::vec::Idx;
use rustc_serialize::opaque::Encoder;
use std::convert::TryInto;
use std::marker::PhantomData;
use std::num::NonZeroUsize;
use std::num::{NonZeroU8, NonZeroUsize};
use tracing::debug;

/// Helper trait, for encoding to, and decoding from, a fixed number of bytes.
Expand Down Expand Up @@ -75,6 +75,30 @@ impl FixedSizeEncoding for u32 {
}
}

impl FixedSizeEncoding for Option<NonZeroU8> {
fixed_size_encoding_byte_len_and_defaults!(1);

fn from_bytes(b: &[u8]) -> Self {
NonZeroU8::new(b[0])
}

fn write_to_bytes(self, b: &mut [u8]) {
b[0] = self.map_or(0, |x| x.get());
}
}

impl FixedSizeEncoding for Option<()> {
fixed_size_encoding_byte_len_and_defaults!(Option::<NonZeroU8>::BYTE_LEN);

fn from_bytes(b: &[u8]) -> Self {
Option::<NonZeroU8>::from_bytes(b).map(|_| ())
}

fn write_to_bytes(self, b: &mut [u8]) {
self.map(|()| NonZeroU8::new(1).unwrap()).write_to_bytes(b)
}
}

// NOTE(eddyb) there could be an impl for `usize`, which would enable a more
// generic `Lazy<T>` impl, but in the general case we might not need / want to
// fit every `usize` in `u32`.
Expand Down