Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aac4020

Browse files
committedOct 7, 2023
Attempt
1 parent cdca82c commit aac4020

23 files changed

+381
-157
lines changed
 

‎compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ fn test_unstable_options_tracking_hash() {
769769
);
770770
tracked!(codegen_backend, Some("abc".to_string()));
771771
tracked!(crate_attr, vec!["abc".to_string()]);
772+
tracked!(cross_crate_inline_threshold, Some(200));
772773
tracked!(debug_info_for_profiling, true);
773774
tracked!(debug_macros, true);
774775
tracked!(dep_info_omit_d_target, true);

‎compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12731273
self.root.tables.optimized_mir.get(self, id).is_some()
12741274
}
12751275

1276+
fn cross_crate_inlinable(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> bool {
1277+
self.root
1278+
.tables
1279+
.cross_crate_inlinable
1280+
.get(self, id)
1281+
.map(|v| v.decode((self, tcx.sess)))
1282+
.unwrap_or(false)
1283+
}
1284+
12761285
fn get_fn_has_self_parameter(self, id: DefIndex, sess: &'a Session) -> bool {
12771286
self.root
12781287
.tables

‎compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ provide! { tcx, def_id, other, cdata,
287287
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
288288
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
289289
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
290+
cross_crate_inlinable => { cdata.cross_crate_inlinable(tcx, def_id.index) }
290291

291292
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
292293
is_private_dep => {

‎compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ fn should_encode_mir(
10461046
|| (tcx.sess.opts.output_types.should_codegen()
10471047
&& reachable_set.contains(&def_id)
10481048
&& (generics.requires_monomorphization(tcx)
1049-
|| tcx.codegen_fn_attrs(def_id).requests_inline()));
1049+
|| tcx.cross_crate_inlinable(def_id)));
10501050
// The function has a `const` modifier or is in a `#[const_trait]`.
10511051
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
10521052
|| tcx.is_const_default_method(def_id.to_def_id());
@@ -1612,6 +1612,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16121612
debug!("EntryBuilder::encode_mir({:?})", def_id);
16131613
if encode_opt {
16141614
record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
1615+
record!(self.tables.cross_crate_inlinable[def_id.to_def_id()] <- self.tcx.cross_crate_inlinable(def_id));
16151616
record!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()]
16161617
<- tcx.closure_saved_names_of_captured_variables(def_id));
16171618

‎compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ define_tables! {
427427
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
428428
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
429429
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
430+
cross_crate_inlinable: Table<DefIndex, LazyValue<bool>>,
430431
closure_saved_names_of_captured_variables: Table<DefIndex, LazyValue<IndexVec<FieldIdx, Symbol>>>,
431432
mir_generator_witnesses: Table<DefIndex, LazyValue<mir::GeneratorLayout<'static>>>,
432433
promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>,

‎compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,29 @@ impl FixedSizeEncoding for bool {
299299
}
300300
}
301301

302+
impl FixedSizeEncoding for Option<bool> {
303+
type ByteArray = [u8; 1];
304+
305+
#[inline]
306+
fn from_bytes(b: &[u8; 1]) -> Self {
307+
match b[0] {
308+
0 => Some(false),
309+
1 => Some(true),
310+
_ => None,
311+
}
312+
}
313+
314+
#[inline]
315+
fn write_to_bytes(self, b: &mut [u8; 1]) {
316+
debug_assert!(!self.is_default());
317+
b[0] = match self {
318+
Some(false) => 0,
319+
Some(true) => 1,
320+
None => 2,
321+
};
322+
}
323+
}
324+
302325
impl FixedSizeEncoding for UnusedGenericParams {
303326
type ByteArray = [u8; 4];
304327

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,11 @@ rustc_queries! {
22022202
query generics_require_sized_self(def_id: DefId) -> bool {
22032203
desc { "check whether the item has a `where Self: Sized` bound" }
22042204
}
2205+
2206+
query cross_crate_inlinable(def_id: DefId) -> bool {
2207+
desc { "whether the item should be made inlinable across crates" }
2208+
separate_provide_extern
2209+
}
22052210
}
22062211

22072212
rustc_query_append! { define_callbacks! }

‎compiler/rustc_middle/src/ty/instance.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,15 @@ impl<'tcx> InstanceDef<'tcx> {
245245
// drops of `Option::None` before LTO. We also respect the intent of
246246
// `#[inline]` on `Drop::drop` implementations.
247247
return ty.ty_adt_def().map_or(true, |adt_def| {
248-
adt_def.destructor(tcx).map_or_else(
249-
|| adt_def.is_enum(),
250-
|dtor| tcx.codegen_fn_attrs(dtor.did).requests_inline(),
251-
)
248+
adt_def
249+
.destructor(tcx)
250+
.map_or_else(|| adt_def.is_enum(), |dtor| tcx.cross_crate_inlinable(dtor.did))
252251
});
253252
}
254253
if let ty::InstanceDef::ThreadLocalShim(..) = *self {
255254
return false;
256255
}
257-
tcx.codegen_fn_attrs(self.def_id()).requests_inline()
256+
tcx.cross_crate_inlinable(self.def_id())
258257
}
259258

260259
pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
use rustc_attr::InlineAttr;
2+
use rustc_hir::def_id::LocalDefId;
3+
use rustc_middle::query::Providers;
4+
use rustc_middle::ty::TyCtxt;
5+
use rustc_session::config::OptLevel;
6+
7+
pub fn provide(providers: &mut Providers) {
8+
providers.cross_crate_inlinable = cross_crate_inlinable;
9+
}
10+
11+
fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
12+
if tcx.sess.opts.incremental.is_some() {
13+
return false;
14+
}
15+
16+
match tcx.codegen_fn_attrs(def_id).inline {
17+
InlineAttr::Never => return false,
18+
InlineAttr::Hint | InlineAttr::Always => return true,
19+
_ => {}
20+
}
21+
22+
if matches!(tcx.sess.opts.optimize, OptLevel::No | OptLevel::Default) {
23+
return false;
24+
}
25+
26+
match tcx.hir().body_const_context(def_id) {
27+
Some(rustc_hir::ConstContext::ConstFn) | None => {}
28+
_ => return false,
29+
}
30+
31+
if tcx.lang_items().iter().any(|(_, lang_def_id)| lang_def_id == def_id.into()) {
32+
return false;
33+
}
34+
35+
let mir = tcx.optimized_mir(def_id);
36+
let mut checker = CostChecker { tcx, cost: 0, callee_body: mir };
37+
checker.visit_body(mir);
38+
checker.cost <= tcx.sess.opts.unstable_opts.cross_crate_inline_threshold.unwrap_or(100)
39+
}
40+
41+
use rustc_middle::mir::visit::Visitor;
42+
use rustc_middle::mir::*;
43+
44+
const INSTR_COST: usize = 5;
45+
const CALL_PENALTY: usize = 25;
46+
const LANDINGPAD_PENALTY: usize = 50;
47+
const RESUME_PENALTY: usize = 45;
48+
49+
struct CostChecker<'b, 'tcx> {
50+
tcx: TyCtxt<'tcx>,
51+
cost: usize,
52+
callee_body: &'b Body<'tcx>,
53+
}
54+
55+
impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
56+
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
57+
// Don't count StorageLive/StorageDead in the inlining cost.
58+
match statement.kind {
59+
StatementKind::StorageLive(_)
60+
| StatementKind::StorageDead(_)
61+
| StatementKind::Deinit(_)
62+
| StatementKind::Nop => {}
63+
_ => self.cost += INSTR_COST,
64+
}
65+
}
66+
67+
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, _: Location) {
68+
let tcx = self.tcx;
69+
match terminator.kind {
70+
TerminatorKind::Drop { ref place, unwind, .. } => {
71+
let ty = place.ty(self.callee_body, tcx).ty;
72+
if !ty.is_trivially_pure_clone_copy() {
73+
self.cost += CALL_PENALTY;
74+
if let UnwindAction::Cleanup(_) = unwind {
75+
self.cost += LANDINGPAD_PENALTY;
76+
}
77+
}
78+
}
79+
TerminatorKind::Call { unwind, .. } => {
80+
self.cost += CALL_PENALTY;
81+
if let UnwindAction::Cleanup(_) = unwind {
82+
self.cost += LANDINGPAD_PENALTY;
83+
}
84+
}
85+
TerminatorKind::Assert { unwind, .. } => {
86+
self.cost += CALL_PENALTY;
87+
if let UnwindAction::Cleanup(_) = unwind {
88+
self.cost += LANDINGPAD_PENALTY;
89+
}
90+
}
91+
TerminatorKind::UnwindResume => self.cost += RESUME_PENALTY,
92+
TerminatorKind::InlineAsm { unwind, .. } => {
93+
self.cost += INSTR_COST;
94+
if let UnwindAction::Cleanup(_) = unwind {
95+
self.cost += LANDINGPAD_PENALTY;
96+
}
97+
}
98+
_ => self.cost += INSTR_COST,
99+
}
100+
}
101+
}

‎compiler/rustc_mir_transform/src/inline.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ impl<'tcx> Inliner<'tcx> {
170170
callsite: &CallSite<'tcx>,
171171
) -> Result<std::ops::Range<BasicBlock>, &'static str> {
172172
let callee_attrs = self.tcx.codegen_fn_attrs(callsite.callee.def_id());
173-
self.check_codegen_attributes(callsite, callee_attrs)?;
173+
let cross_crate_inlinable = if callsite.callee.def_id().is_local() {
174+
// Avoid a query cycle, cross_crate_inlinable is based on optimized_mir
175+
callee_attrs.requests_inline()
176+
} else {
177+
self.tcx.cross_crate_inlinable(callsite.callee.def_id())
178+
};
179+
self.check_codegen_attributes(callsite, callee_attrs, cross_crate_inlinable)?;
174180

175181
let terminator = caller_body[callsite.block].terminator.as_ref().unwrap();
176182
let TerminatorKind::Call { args, destination, .. } = &terminator.kind else { bug!() };
@@ -185,7 +191,7 @@ impl<'tcx> Inliner<'tcx> {
185191

186192
self.check_mir_is_available(caller_body, &callsite.callee)?;
187193
let callee_body = try_instance_mir(self.tcx, callsite.callee.def)?;
188-
self.check_mir_body(callsite, callee_body, callee_attrs)?;
194+
self.check_mir_body(callsite, callee_body, callee_attrs, cross_crate_inlinable)?;
189195

190196
if !self.tcx.consider_optimizing(|| {
191197
format!("Inline {:?} into {:?}", callsite.callee, caller_body.source)
@@ -401,6 +407,7 @@ impl<'tcx> Inliner<'tcx> {
401407
&self,
402408
callsite: &CallSite<'tcx>,
403409
callee_attrs: &CodegenFnAttrs,
410+
cross_crate_inlinable: bool,
404411
) -> Result<(), &'static str> {
405412
if let InlineAttr::Never = callee_attrs.inline {
406413
return Err("never inline hint");
@@ -414,7 +421,7 @@ impl<'tcx> Inliner<'tcx> {
414421
.non_erasable_generics(self.tcx, callsite.callee.def_id())
415422
.next()
416423
.is_some();
417-
if !is_generic && !callee_attrs.requests_inline() {
424+
if !is_generic && !cross_crate_inlinable {
418425
return Err("not exported");
419426
}
420427

@@ -456,10 +463,11 @@ impl<'tcx> Inliner<'tcx> {
456463
callsite: &CallSite<'tcx>,
457464
callee_body: &Body<'tcx>,
458465
callee_attrs: &CodegenFnAttrs,
466+
cross_crate_inlinable: bool,
459467
) -> Result<(), &'static str> {
460468
let tcx = self.tcx;
461469

462-
let mut threshold = if callee_attrs.requests_inline() {
470+
let mut threshold = if cross_crate_inlinable {
463471
self.tcx.sess.opts.unstable_opts.inline_mir_hint_threshold.unwrap_or(100)
464472
} else {
465473
self.tcx.sess.opts.unstable_opts.inline_mir_threshold.unwrap_or(50)

‎compiler/rustc_mir_transform/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod const_prop;
6262
mod const_prop_lint;
6363
mod copy_prop;
6464
mod coverage;
65+
mod cross_crate_inline;
6566
mod ctfe_limit;
6667
mod dataflow_const_prop;
6768
mod dead_store_elimination;
@@ -123,6 +124,7 @@ pub fn provide(providers: &mut Providers) {
123124
coverage::query::provide(providers);
124125
ffi_unwind_calls::provide(providers);
125126
shim::provide(providers);
127+
cross_crate_inline::provide(providers);
126128
*providers = Providers {
127129
mir_keys,
128130
mir_const,

‎compiler/rustc_passes/src/reachable.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use rustc_target::spec::abi::Abi;
2121
// Returns true if the given item must be inlined because it may be
2222
// monomorphized or it was marked with `#[inline]`. This will only return
2323
// true for functions.
24-
fn item_might_be_inlined(tcx: TyCtxt<'_>, item: &hir::Item<'_>, attrs: &CodegenFnAttrs) -> bool {
25-
if attrs.requests_inline() {
24+
fn item_might_be_inlined(tcx: TyCtxt<'_>, item: &hir::Item<'_>, inlinable: bool) -> bool {
25+
if inlinable {
2626
return true;
2727
}
2828

@@ -41,9 +41,9 @@ fn method_might_be_inlined(
4141
impl_item: &hir::ImplItem<'_>,
4242
impl_src: LocalDefId,
4343
) -> bool {
44-
let codegen_fn_attrs = tcx.codegen_fn_attrs(impl_item.hir_id().owner.to_def_id());
44+
let inlinable = tcx.cross_crate_inlinable(impl_item.hir_id().owner.to_def_id());
4545
let generics = tcx.generics_of(impl_item.owner_id);
46-
if codegen_fn_attrs.requests_inline() || generics.requires_monomorphization(tcx) {
46+
if inlinable || generics.requires_monomorphization(tcx) {
4747
return true;
4848
}
4949
if let hir::ImplItemKind::Fn(method_sig, _) = &impl_item.kind {
@@ -52,7 +52,7 @@ fn method_might_be_inlined(
5252
}
5353
}
5454
match tcx.hir().find_by_def_id(impl_src) {
55-
Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, codegen_fn_attrs),
55+
Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, inlinable),
5656
Some(..) | None => span_bug!(impl_item.span, "impl did is not an item"),
5757
}
5858
}
@@ -149,7 +149,7 @@ impl<'tcx> ReachableContext<'tcx> {
149149
match self.tcx.hir().find_by_def_id(def_id) {
150150
Some(Node::Item(item)) => match item.kind {
151151
hir::ItemKind::Fn(..) => {
152-
item_might_be_inlined(self.tcx, &item, self.tcx.codegen_fn_attrs(def_id))
152+
item_might_be_inlined(self.tcx, &item, self.tcx.cross_crate_inlinable(def_id))
153153
}
154154
_ => false,
155155
},
@@ -227,7 +227,7 @@ impl<'tcx> ReachableContext<'tcx> {
227227
if item_might_be_inlined(
228228
self.tcx,
229229
&item,
230-
self.tcx.codegen_fn_attrs(item.owner_id),
230+
self.tcx.cross_crate_inlinable(item.owner_id),
231231
) {
232232
self.visit_nested_body(body);
233233
}

‎compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,8 @@ options! {
14411441
"combine CGUs into a single one"),
14421442
crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
14431443
"inject the given attribute in the crate"),
1444+
cross_crate_inline_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
1445+
"threshold to allow cross crate inlining of functions"),
14441446
debug_info_for_profiling: bool = (false, parse_bool, [TRACKED],
14451447
"emit discriminators and other data necessary for AutoFDO"),
14461448
debug_macros: bool = (false, parse_bool, [TRACKED],

‎library/alloc/src/raw_vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> {
530530
// ensure that the code generation related to these panics is minimal as there's
531531
// only one location which panics rather than a bunch throughout the module.
532532
#[cfg(not(no_global_oom_handling))]
533+
#[inline(never)]
533534
fn capacity_overflow() -> ! {
534535
panic!("capacity overflow");
535536
}

‎tests/mir-opt/enum_opt.cand.EnumSizeOpt.32bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
}
6767
+ }
6868
+
69-
+ alloc15 (size: 8, align: 4) {
69+
+ alloc14 (size: 8, align: 4) {
7070
+ 02 00 00 00 05 20 00 00 │ ..... ..
7171
}
7272

‎tests/mir-opt/enum_opt.cand.EnumSizeOpt.64bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
}
6767
+ }
6868
+
69-
+ alloc15 (size: 16, align: 8) {
69+
+ alloc14 (size: 16, align: 8) {
7070
+ 02 00 00 00 00 00 00 00 05 20 00 00 00 00 00 00 │ ......... ......
7171
}
7272

‎tests/mir-opt/enum_opt.unin.EnumSizeOpt.32bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
}
6767
+ }
6868
+
69-
+ alloc14 (size: 8, align: 4) {
69+
+ alloc15 (size: 8, align: 4) {
7070
+ 05 20 00 00 01 00 00 00 │ . ......
7171
}
7272

‎tests/mir-opt/enum_opt.unin.EnumSizeOpt.64bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
}
6767
+ }
6868
+
69-
+ alloc14 (size: 16, align: 8) {
69+
+ alloc15 (size: 16, align: 8) {
7070
+ 05 20 00 00 00 00 00 00 01 00 00 00 00 00 00 00 │ . ..............
7171
}
7272

‎tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,104 +7,104 @@
77
debug upper => _3;
88
let mut _0: std::result::Result<(), std::fmt::Error>;
99
let _4: bool;
10-
let mut _5: &std::fmt::Formatter<'_>;
11-
let mut _7: std::option::Option<usize>;
12-
let mut _8: &std::fmt::Formatter<'_>;
13-
let mut _9: isize;
14-
let mut _11: &mut std::fmt::Formatter<'_>;
15-
let mut _12: &T;
16-
let mut _13: core::num::flt2dec::Sign;
17-
let mut _14: u32;
18-
let mut _15: u32;
19-
let mut _16: usize;
20-
let mut _17: bool;
21-
let mut _18: &mut std::fmt::Formatter<'_>;
22-
let mut _19: &T;
23-
let mut _20: core::num::flt2dec::Sign;
24-
let mut _21: bool;
10+
let mut _6: std::option::Option<usize>;
11+
let mut _7: isize;
12+
let mut _9: &mut std::fmt::Formatter<'_>;
13+
let mut _10: &T;
14+
let mut _11: core::num::flt2dec::Sign;
15+
let mut _12: u32;
16+
let mut _13: u32;
17+
let mut _14: usize;
18+
let mut _15: bool;
19+
let mut _16: &mut std::fmt::Formatter<'_>;
20+
let mut _17: &T;
21+
let mut _18: core::num::flt2dec::Sign;
22+
let mut _19: bool;
2523
scope 1 {
2624
debug force_sign => _4;
27-
let _6: core::num::flt2dec::Sign;
25+
let _5: core::num::flt2dec::Sign;
2826
scope 2 {
29-
debug sign => _6;
27+
debug sign => _5;
3028
scope 3 {
31-
debug precision => _10;
32-
let _10: usize;
29+
debug precision => _8;
30+
let _8: usize;
31+
scope 5 (inlined Formatter::<'_>::precision) {
32+
debug self => _1;
33+
}
3334
}
3435
}
3536
}
37+
scope 4 (inlined Formatter::<'_>::sign_plus) {
38+
debug self => _1;
39+
let mut _20: u32;
40+
let mut _21: u32;
41+
}
3642

3743
bb0: {
3844
StorageLive(_4);
45+
StorageLive(_20);
46+
StorageLive(_21);
47+
_21 = ((*_1).0: u32);
48+
_20 = BitAnd(move _21, const 1_u32);
49+
StorageDead(_21);
50+
_4 = Ne(move _20, const 0_u32);
51+
StorageDead(_20);
3952
StorageLive(_5);
40-
_5 = &(*_1);
41-
_4 = Formatter::<'_>::sign_plus(move _5) -> [return: bb1, unwind unreachable];
53+
switchInt(_4) -> [0: bb2, otherwise: bb1];
4254
}
4355

4456
bb1: {
45-
StorageDead(_5);
46-
StorageLive(_6);
47-
switchInt(_4) -> [0: bb3, otherwise: bb2];
57+
- _5 = MinusPlus;
58+
+ _5 = const MinusPlus;
59+
goto -> bb3;
4860
}
4961

5062
bb2: {
51-
- _6 = MinusPlus;
52-
+ _6 = const MinusPlus;
53-
goto -> bb4;
63+
- _5 = Minus;
64+
+ _5 = const Minus;
65+
goto -> bb3;
5466
}
5567

5668
bb3: {
57-
- _6 = Minus;
58-
+ _6 = const Minus;
59-
goto -> bb4;
69+
StorageLive(_6);
70+
_6 = ((*_1).4: std::option::Option<usize>);
71+
_7 = discriminant(_6);
72+
switchInt(move _7) -> [1: bb4, otherwise: bb6];
6073
}
6174

6275
bb4: {
63-
StorageLive(_7);
64-
StorageLive(_8);
65-
_8 = &(*_1);
66-
_7 = Formatter::<'_>::precision(move _8) -> [return: bb5, unwind unreachable];
76+
_8 = ((_6 as Some).0: usize);
77+
StorageLive(_11);
78+
_11 = _5;
79+
StorageLive(_12);
80+
StorageLive(_13);
81+
_13 = _8 as u32 (IntToInt);
82+
_12 = Add(move _13, const 1_u32);
83+
StorageDead(_13);
84+
_0 = float_to_exponential_common_exact::<T>(_1, _2, move _11, move _12, _3) -> [return: bb5, unwind unreachable];
6785
}
6886

6987
bb5: {
70-
StorageDead(_8);
71-
_9 = discriminant(_7);
72-
switchInt(move _9) -> [1: bb6, otherwise: bb8];
88+
StorageDead(_12);
89+
StorageDead(_11);
90+
goto -> bb8;
7391
}
7492

7593
bb6: {
76-
_10 = ((_7 as Some).0: usize);
77-
StorageLive(_13);
78-
_13 = _6;
79-
StorageLive(_14);
80-
StorageLive(_15);
81-
_15 = _10 as u32 (IntToInt);
82-
_14 = Add(move _15, const 1_u32);
83-
StorageDead(_15);
84-
_0 = float_to_exponential_common_exact::<T>(_1, _2, move _13, move _14, _3) -> [return: bb7, unwind unreachable];
94+
StorageLive(_18);
95+
_18 = _5;
96+
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _18, _3) -> [return: bb7, unwind unreachable];
8597
}
8698

8799
bb7: {
88-
StorageDead(_14);
89-
StorageDead(_13);
90-
goto -> bb10;
100+
StorageDead(_18);
101+
goto -> bb8;
91102
}
92103

93104
bb8: {
94-
StorageLive(_20);
95-
_20 = _6;
96-
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _20, _3) -> [return: bb9, unwind unreachable];
97-
}
98-
99-
bb9: {
100-
StorageDead(_20);
101-
goto -> bb10;
102-
}
103-
104-
bb10: {
105-
StorageDead(_6);
105+
StorageDead(_5);
106106
StorageDead(_4);
107-
StorageDead(_7);
107+
StorageDead(_6);
108108
return;
109109
}
110110
}

‎tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-unwind.diff

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,104 +7,104 @@
77
debug upper => _3;
88
let mut _0: std::result::Result<(), std::fmt::Error>;
99
let _4: bool;
10-
let mut _5: &std::fmt::Formatter<'_>;
11-
let mut _7: std::option::Option<usize>;
12-
let mut _8: &std::fmt::Formatter<'_>;
13-
let mut _9: isize;
14-
let mut _11: &mut std::fmt::Formatter<'_>;
15-
let mut _12: &T;
16-
let mut _13: core::num::flt2dec::Sign;
17-
let mut _14: u32;
18-
let mut _15: u32;
19-
let mut _16: usize;
20-
let mut _17: bool;
21-
let mut _18: &mut std::fmt::Formatter<'_>;
22-
let mut _19: &T;
23-
let mut _20: core::num::flt2dec::Sign;
24-
let mut _21: bool;
10+
let mut _6: std::option::Option<usize>;
11+
let mut _7: isize;
12+
let mut _9: &mut std::fmt::Formatter<'_>;
13+
let mut _10: &T;
14+
let mut _11: core::num::flt2dec::Sign;
15+
let mut _12: u32;
16+
let mut _13: u32;
17+
let mut _14: usize;
18+
let mut _15: bool;
19+
let mut _16: &mut std::fmt::Formatter<'_>;
20+
let mut _17: &T;
21+
let mut _18: core::num::flt2dec::Sign;
22+
let mut _19: bool;
2523
scope 1 {
2624
debug force_sign => _4;
27-
let _6: core::num::flt2dec::Sign;
25+
let _5: core::num::flt2dec::Sign;
2826
scope 2 {
29-
debug sign => _6;
27+
debug sign => _5;
3028
scope 3 {
31-
debug precision => _10;
32-
let _10: usize;
29+
debug precision => _8;
30+
let _8: usize;
31+
scope 5 (inlined Formatter::<'_>::precision) {
32+
debug self => _1;
33+
}
3334
}
3435
}
3536
}
37+
scope 4 (inlined Formatter::<'_>::sign_plus) {
38+
debug self => _1;
39+
let mut _20: u32;
40+
let mut _21: u32;
41+
}
3642

3743
bb0: {
3844
StorageLive(_4);
45+
StorageLive(_20);
46+
StorageLive(_21);
47+
_21 = ((*_1).0: u32);
48+
_20 = BitAnd(move _21, const 1_u32);
49+
StorageDead(_21);
50+
_4 = Ne(move _20, const 0_u32);
51+
StorageDead(_20);
3952
StorageLive(_5);
40-
_5 = &(*_1);
41-
_4 = Formatter::<'_>::sign_plus(move _5) -> [return: bb1, unwind continue];
53+
switchInt(_4) -> [0: bb2, otherwise: bb1];
4254
}
4355

4456
bb1: {
45-
StorageDead(_5);
46-
StorageLive(_6);
47-
switchInt(_4) -> [0: bb3, otherwise: bb2];
57+
- _5 = MinusPlus;
58+
+ _5 = const MinusPlus;
59+
goto -> bb3;
4860
}
4961

5062
bb2: {
51-
- _6 = MinusPlus;
52-
+ _6 = const MinusPlus;
53-
goto -> bb4;
63+
- _5 = Minus;
64+
+ _5 = const Minus;
65+
goto -> bb3;
5466
}
5567

5668
bb3: {
57-
- _6 = Minus;
58-
+ _6 = const Minus;
59-
goto -> bb4;
69+
StorageLive(_6);
70+
_6 = ((*_1).4: std::option::Option<usize>);
71+
_7 = discriminant(_6);
72+
switchInt(move _7) -> [1: bb4, otherwise: bb6];
6073
}
6174

6275
bb4: {
63-
StorageLive(_7);
64-
StorageLive(_8);
65-
_8 = &(*_1);
66-
_7 = Formatter::<'_>::precision(move _8) -> [return: bb5, unwind continue];
76+
_8 = ((_6 as Some).0: usize);
77+
StorageLive(_11);
78+
_11 = _5;
79+
StorageLive(_12);
80+
StorageLive(_13);
81+
_13 = _8 as u32 (IntToInt);
82+
_12 = Add(move _13, const 1_u32);
83+
StorageDead(_13);
84+
_0 = float_to_exponential_common_exact::<T>(_1, _2, move _11, move _12, _3) -> [return: bb5, unwind continue];
6785
}
6886

6987
bb5: {
70-
StorageDead(_8);
71-
_9 = discriminant(_7);
72-
switchInt(move _9) -> [1: bb6, otherwise: bb8];
88+
StorageDead(_12);
89+
StorageDead(_11);
90+
goto -> bb8;
7391
}
7492

7593
bb6: {
76-
_10 = ((_7 as Some).0: usize);
77-
StorageLive(_13);
78-
_13 = _6;
79-
StorageLive(_14);
80-
StorageLive(_15);
81-
_15 = _10 as u32 (IntToInt);
82-
_14 = Add(move _15, const 1_u32);
83-
StorageDead(_15);
84-
_0 = float_to_exponential_common_exact::<T>(_1, _2, move _13, move _14, _3) -> [return: bb7, unwind continue];
94+
StorageLive(_18);
95+
_18 = _5;
96+
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _18, _3) -> [return: bb7, unwind continue];
8597
}
8698

8799
bb7: {
88-
StorageDead(_14);
89-
StorageDead(_13);
90-
goto -> bb10;
100+
StorageDead(_18);
101+
goto -> bb8;
91102
}
92103

93104
bb8: {
94-
StorageLive(_20);
95-
_20 = _6;
96-
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _20, _3) -> [return: bb9, unwind continue];
97-
}
98-
99-
bb9: {
100-
StorageDead(_20);
101-
goto -> bb10;
102-
}
103-
104-
bb10: {
105-
StorageDead(_6);
105+
StorageDead(_5);
106106
StorageDead(_4);
107-
StorageDead(_7);
107+
StorageDead(_6);
108108
return;
109109
}
110110
}

‎tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,53 @@
1212
+ scope 3 (inlined std::ptr::drop_in_place::<Vec<A>> - shim(Some(Vec<A>))) {
1313
+ let mut _6: &mut std::vec::Vec<A>;
1414
+ let mut _7: ();
15+
+ scope 4 (inlined <Vec<A> as Drop>::drop) {
16+
+ debug self => _6;
17+
+ let mut _8: *mut [A];
18+
+ let mut _9: *mut A;
19+
+ let mut _10: usize;
20+
+ scope 5 {
21+
+ scope 6 (inlined Vec::<A>::as_mut_ptr) {
22+
+ debug self => _6;
23+
+ let mut _11: &alloc::raw_vec::RawVec<A>;
24+
+ scope 7 (inlined alloc::raw_vec::RawVec::<A>::ptr) {
25+
+ debug self => _11;
26+
+ let mut _13: std::ptr::NonNull<A>;
27+
+ scope 8 (inlined Unique::<A>::as_ptr) {
28+
+ debug ((self: Unique<A>).0: std::ptr::NonNull<A>) => _13;
29+
+ debug ((self: Unique<A>).1: std::marker::PhantomData<A>) => const ZeroSized: PhantomData<A>;
30+
+ scope 9 (inlined NonNull::<A>::as_ptr) {
31+
+ debug self => _13;
32+
+ let mut _12: *const A;
33+
+ }
34+
+ }
35+
+ }
36+
+ }
37+
+ scope 10 (inlined slice_from_raw_parts_mut::<A>) {
38+
+ debug data => _9;
39+
+ debug len => _10;
40+
+ let mut _14: *mut ();
41+
+ scope 11 (inlined ptr::mut_ptr::<impl *mut A>::cast::<()>) {
42+
+ debug self => _9;
43+
+ }
44+
+ scope 12 (inlined std::ptr::from_raw_parts_mut::<[A]>) {
45+
+ debug data_address => _14;
46+
+ debug metadata => _10;
47+
+ let mut _15: std::ptr::metadata::PtrRepr<[A]>;
48+
+ let mut _16: std::ptr::metadata::PtrComponents<[A]>;
49+
+ let mut _17: *const ();
50+
+ scope 13 {
51+
+ }
52+
+ }
53+
+ }
54+
+ }
55+
+ }
1556
+ }
1657
}
1758
scope 2 {
18-
+ scope 4 (inlined std::ptr::drop_in_place::<Option<B>> - shim(Some(Option<B>))) {
19-
+ let mut _8: isize;
20-
+ let mut _9: isize;
59+
+ scope 14 (inlined std::ptr::drop_in_place::<Option<B>> - shim(Some(Option<B>))) {
60+
+ let mut _18: isize;
61+
+ let mut _19: isize;
2162
+ }
2263
}
2364

@@ -29,7 +70,35 @@
2970
+ StorageLive(_6);
3071
+ StorageLive(_7);
3172
+ _6 = &mut (*_4);
32-
+ _7 = <Vec<A> as Drop>::drop(move _6) -> [return: bb2, unwind unreachable];
73+
+ StorageLive(_8);
74+
+ StorageLive(_9);
75+
+ StorageLive(_11);
76+
+ StorageLive(_13);
77+
+ _13 = ((((*_6).0: alloc::raw_vec::RawVec<A>).0: std::ptr::Unique<A>).0: std::ptr::NonNull<A>);
78+
+ StorageLive(_12);
79+
+ _12 = (_13.0: *const A);
80+
+ _9 = move _12 as *mut A (PtrToPtr);
81+
+ StorageDead(_12);
82+
+ StorageDead(_13);
83+
+ StorageDead(_11);
84+
+ StorageLive(_10);
85+
+ _10 = ((*_6).1: usize);
86+
+ StorageLive(_14);
87+
+ _14 = _9 as *mut () (PtrToPtr);
88+
+ StorageLive(_15);
89+
+ StorageLive(_16);
90+
+ StorageLive(_17);
91+
+ _17 = _14 as *const () (PointerCoercion(MutToConstPointer));
92+
+ _16 = ptr::metadata::PtrComponents::<[A]> { data_address: move _17, metadata: _10 };
93+
+ StorageDead(_17);
94+
+ _15 = ptr::metadata::PtrRepr::<[A]> { const_ptr: move _16 };
95+
+ StorageDead(_16);
96+
+ _8 = (_15.1: *mut [A]);
97+
+ StorageDead(_15);
98+
+ StorageDead(_14);
99+
+ StorageDead(_10);
100+
+ StorageDead(_9);
101+
+ _7 = std::ptr::drop_in_place::<[A]>(move _8) -> [return: bb2, unwind unreachable];
33102
}
34103

35104
bb1: {
@@ -40,19 +109,20 @@
40109
StorageLive(_5);
41110
_5 = _2;
42111
- _0 = std::ptr::drop_in_place::<Option<B>>(move _5) -> [return: bb2, unwind unreachable];
43-
+ StorageLive(_8);
44-
+ StorageLive(_9);
45-
+ _8 = discriminant((*_5));
46-
+ switchInt(move _8) -> [0: bb3, otherwise: bb4];
112+
+ StorageLive(_18);
113+
+ StorageLive(_19);
114+
+ _18 = discriminant((*_5));
115+
+ switchInt(move _18) -> [0: bb3, otherwise: bb4];
47116
}
48117

49118
bb2: {
119+
+ StorageDead(_8);
50120
+ drop(((*_4).0: alloc::raw_vec::RawVec<A>)) -> [return: bb1, unwind unreachable];
51121
+ }
52122
+
53123
+ bb3: {
54-
+ StorageDead(_9);
55-
+ StorageDead(_8);
124+
+ StorageDead(_19);
125+
+ StorageDead(_18);
56126
StorageDead(_5);
57127
return;
58128
+ }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
thread 'main' panicked at library/alloc/src/raw_vec.rs:534:5:
1+
thread 'main' panicked at library/alloc/src/raw_vec.rs:535:5:
22
capacity overflow
33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
thread 'main' panicked at library/std/src/io/stdio.rs:LL:CC:
1+
thread 'main' panicked at $SRC_DIR/std/src/io/stdio.rs:LL:COL:
22
failed printing to stdout: Broken pipe (os error 32)
33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 commit comments

Comments
 (0)
Please sign in to comment.