Skip to content

Enable MIR inlining in incremental mode too. #99640

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 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ impl<'tcx> MirPass<'tcx> for Inline {
match sess.mir_opt_level() {
0 | 1 => false,
2 => {
(sess.opts.optimize == OptLevel::Default
|| sess.opts.optimize == OptLevel::Aggressive)
&& sess.opts.incremental == None
sess.opts.optimize == OptLevel::Default
|| sess.opts.optimize == OptLevel::Aggressive
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this match on optimize? The names are kind of confusing, and seeing them ordered by strength could make me more comfortable.

Alternatively, >= Default (assuming Default is -O aka -C opt-level=2?) would be another way to indicate that it "starts" somewhere and increases with opt-level.

}
_ => true,
}
Expand Down
100 changes: 78 additions & 22 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use rustc_data_structures::unhash::UnhashMap;
use rustc_index::vec::IndexVec;
use rustc_macros::HashStable_Generic;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::collections::hash_map::Entry;
use std::fmt;
use std::hash::Hash;
use tracing::*;
Expand Down Expand Up @@ -179,6 +180,9 @@ impl LocalExpnId {
ExpnIndex::from_u32(self.as_u32())
}

/// Creates an empty expansion to be filled later.
/// This method should only be used outside of the incremental compilation engine.
/// Prefer using `fresh` when the expansion data is available.
pub fn fresh_empty() -> LocalExpnId {
HygieneData::with(|data| {
let expn_id = data.local_expn_data.push(None);
Expand All @@ -188,17 +192,51 @@ impl LocalExpnId {
})
}

/// Creates an expansion.
pub fn fresh(mut expn_data: ExpnData, ctx: impl HashStableContext) -> LocalExpnId {
debug_assert_eq!(expn_data.parent.krate, LOCAL_CRATE);
#[cfg(debug_assertions)]
let hashing_controls = ctx.hashing_controls();
let expn_hash = update_disambiguator(&mut expn_data, ctx);
HygieneData::with(|data| match data.expn_hash_to_expn_id.entry(expn_hash) {
Entry::Vacant(v) => {
let expn_id = data.local_expn_data.push(Some(expn_data));
let _eid = data.local_expn_hashes.push(expn_hash);
debug_assert_eq!(expn_id, _eid);
debug!(?expn_hash, ?expn_id);
v.insert(expn_id.to_expn_id());
expn_id
}
Entry::Occupied(o) => {
let old_id = *o.get();
// The hash starts with the local crate's hash, so this must be a local id.
let old_id = old_id.expect_local();
#[cfg(debug_assertions)]
{
let old_data = data.local_expn_data[old_id].as_ref().unwrap();
debug!(?old_id, ?old_data, ?expn_data);
expn_data.assert_identical(&old_data, hashing_controls);
}
old_id
}
})
}

/// Fill an empty expansion.
/// This method should only be used outside of the incremental compilation engine.
pub fn set_expn_data(self, mut expn_data: ExpnData, ctx: impl HashStableContext) {
debug_assert_eq!(expn_data.parent.krate, LOCAL_CRATE);
let expn_hash = update_disambiguator(&mut expn_data, ctx);
HygieneData::with(|data| {
let expn_id = data.local_expn_data.push(Some(expn_data));
let _eid = data.local_expn_hashes.push(expn_hash);
debug_assert_eq!(expn_id, _eid);
let _old_id = data.expn_hash_to_expn_id.insert(expn_hash, expn_id.to_expn_id());
let old_expn_data = &mut data.local_expn_data[self];
assert!(old_expn_data.is_none(), "expansion data is reset for an expansion ID");
*old_expn_data = Some(expn_data);
debug_assert_eq!(data.local_expn_hashes[self].0, Fingerprint::ZERO);
data.local_expn_hashes[self] = expn_hash;
debug!(?expn_hash, ?self);
let _old_id = data.expn_hash_to_expn_id.insert(expn_hash, self.to_expn_id());
debug_assert!(_old_id.is_none());
expn_id
})
});
}

#[inline]
Expand All @@ -216,21 +254,6 @@ impl LocalExpnId {
ExpnId { krate: LOCAL_CRATE, local_id: self.as_raw() }
}

#[inline]
pub fn set_expn_data(self, mut expn_data: ExpnData, ctx: impl HashStableContext) {
debug_assert_eq!(expn_data.parent.krate, LOCAL_CRATE);
let expn_hash = update_disambiguator(&mut expn_data, ctx);
HygieneData::with(|data| {
let old_expn_data = &mut data.local_expn_data[self];
assert!(old_expn_data.is_none(), "expansion data is reset for an expansion ID");
*old_expn_data = Some(expn_data);
debug_assert_eq!(data.local_expn_hashes[self].0, Fingerprint::ZERO);
data.local_expn_hashes[self] = expn_hash;
let _old_id = data.expn_hash_to_expn_id.insert(expn_hash, self.to_expn_id());
debug_assert!(_old_id.is_none());
});
}

#[inline]
pub fn is_descendant_of(self, ancestor: LocalExpnId) -> bool {
self.to_expn_id().is_descendant_of(ancestor.to_expn_id())
Expand Down Expand Up @@ -1039,6 +1062,36 @@ impl ExpnData {
self.hash_stable(ctx, &mut hasher);
hasher.finish()
}

#[inline]
#[cfg(debug_assertions)]
fn assert_identical(&self, other: &ExpnData, ctx: HashingControls) {
let ExpnData {
kind,
parent,
call_site,
def_site,
allow_internal_unstable,
allow_internal_unsafe,
local_inner_macros,
edition,
macro_def_id,
parent_module,
disambiguator: _,
} = self;
debug_assert_eq!(*kind, other.kind);
debug_assert_eq!(*parent, other.parent);
if ctx.hash_spans {
debug_assert_eq!(*call_site, other.call_site);
debug_assert_eq!(*def_site, other.def_site);
}
debug_assert_eq!(*allow_internal_unstable, other.allow_internal_unstable);
debug_assert_eq!(*allow_internal_unsafe, other.allow_internal_unsafe);
debug_assert_eq!(*local_inner_macros, other.local_inner_macros);
debug_assert_eq!(*edition, other.edition);
debug_assert_eq!(*macro_def_id, other.macro_def_id);
debug_assert_eq!(*parent_module, other.parent_module);
}
}

/// Expansion kind.
Expand Down Expand Up @@ -1253,8 +1306,10 @@ pub fn register_local_expn_id(data: ExpnData, hash: ExpnHash) -> ExpnId {

let expn_id = expn_id.to_expn_id();

debug!(?hash, ?expn_id);
let _old_id = hygiene_data.expn_hash_to_expn_id.insert(hash, expn_id);
debug_assert!(_old_id.is_none());
debug_assert_eq!(_old_id, None);

expn_id
})
}
Expand All @@ -1273,6 +1328,7 @@ pub fn register_expn_id(
debug_assert!(_old_data.is_none());
let _old_hash = hygiene_data.foreign_expn_hashes.insert(expn_id, hash);
debug_assert!(_old_hash.is_none());
debug!(?hash, ?expn_id);
let _old_id = hygiene_data.expn_hash_to_expn_id.insert(hash, expn_id);
debug_assert!(_old_id.is_none());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// incremental
// compile-flags:-Zprint-mono-items=lazy
// compile-flags:-Zinline-in-all-cgus
// compile-flags:-Zinline-mir=no

#![crate_type="lib"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// incremental
// compile-flags:-Zprint-mono-items=lazy
// compile-flags:-Zinline-in-all-cgus=no
// compile-flags:-Zinline-mir=no

#![allow(dead_code)]
#![crate_type="lib"]
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen-units/partitioning/local-inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// incremental
// compile-flags:-Zprint-mono-items=lazy
// compile-flags:-Zinline-in-all-cgus
// compile-flags:-Zinline-mir=no

#![allow(dead_code)]
#![crate_type="lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// incremental
// compile-flags:-Zprint-mono-items=lazy
// compile-flags:-Zinline-in-all-cgus
// compile-flags:-Zinline-mir=no

#![allow(dead_code)]
#![crate_type="rlib"]
Expand Down
2 changes: 1 addition & 1 deletion src/test/incremental/hashes/function_interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pub fn return_impl_trait() -> i32 {
}

#[cfg(not(any(cfail1,cfail4)))]
#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, fn_sig, optimized_mir")]
#[rustc_clean(cfg = "cfail2", except = "hir_owner, hir_owner_nodes, typeck, fn_sig")]
#[rustc_clean(cfg = "cfail3")]
#[rustc_clean(cfg = "cfail5", except = "hir_owner, hir_owner_nodes, typeck, fn_sig, optimized_mir")]
#[rustc_clean(cfg = "cfail6")]
Expand Down