Skip to content

Commit fc19876

Browse files
committed
Allow inlining into coroutines.
1 parent 1681b06 commit fc19876

File tree

2 files changed

+7
-29
lines changed

2 files changed

+7
-29
lines changed

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ trait Inliner<'tcx> {
121121
callee_attrs: &CodegenFnAttrs,
122122
) -> Result<(), &'static str>;
123123

124-
fn check_caller_mir_body(&self, body: &Body<'tcx>) -> bool;
125-
126124
/// Returns inlining decision that is based on the examination of callee MIR body.
127125
/// Assumes that codegen attributes have been checked for compatibility already.
128126
fn check_callee_mir_body(
@@ -196,10 +194,6 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
196194
Ok(())
197195
}
198196

199-
fn check_caller_mir_body(&self, _: &Body<'tcx>) -> bool {
200-
true
201-
}
202-
203197
#[instrument(level = "debug", skip(self, callee_body))]
204198
fn check_callee_mir_body(
205199
&self,
@@ -346,17 +340,6 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
346340
}
347341
}
348342

349-
fn check_caller_mir_body(&self, body: &Body<'tcx>) -> bool {
350-
// Avoid inlining into coroutines, since their `optimized_mir` is used for layout computation,
351-
// which can create a cycle, even when no attempt is made to inline the function in the other
352-
// direction.
353-
if body.coroutine.is_some() {
354-
return false;
355-
}
356-
357-
true
358-
}
359-
360343
#[instrument(level = "debug", skip(self, callee_body))]
361344
fn check_callee_mir_body(
362345
&self,
@@ -499,10 +482,6 @@ fn inline<'tcx, T: Inliner<'tcx>>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> b
499482
}
500483

501484
let mut inliner = T::new(tcx, def_id, body);
502-
if !inliner.check_caller_mir_body(body) {
503-
return false;
504-
}
505-
506485
let blocks = START_BLOCK..body.basic_blocks.next_index();
507486
process_blocks(&mut inliner, body, blocks);
508487
inliner.changed()
@@ -771,11 +750,12 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>(
771750
&& !inliner
772751
.tcx()
773752
.is_lang_item(inliner.tcx().parent(caller_def_id), rustc_hir::LangItem::FnOnce)
753+
// The caller may be a shim.
754+
&& let Some(caller_def_id) = caller_def_id.as_local()
774755
{
775756
// If we know for sure that the function we're calling will itself try to
776757
// call us, then we avoid inlining that function.
777-
if inliner.tcx().mir_callgraph_cyclic(caller_def_id.expect_local()).contains(&callee_def_id)
778-
{
758+
if inliner.tcx().mir_callgraph_cyclic(caller_def_id).contains(&callee_def_id) {
779759
debug!("query cycle avoidance");
780760
return Err("caller might be reachable from callee");
781761
}

tests/coverage/await_ready.cov-map

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ Number of file 0 mappings: 1
88
Highest counter ID seen: c0
99

1010
Function name: await_ready::await_ready::{closure#0}
11-
Raw bytes (21): 0x[01, 01, 01, 05, 09, 03, 01, 0e, 1e, 00, 1f, 01, 02, 05, 01, 0f, 02, 02, 01, 00, 02]
11+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 0e, 1e, 00, 1f, 01, 02, 05, 01, 0f, 05, 02, 01, 00, 02]
1212
Number of files: 1
1313
- file 0 => $DIR/await_ready.rs
14-
Number of expressions: 1
15-
- expression 0 operands: lhs = Counter(1), rhs = Counter(2)
14+
Number of expressions: 0
1615
Number of file 0 mappings: 3
1716
- Code(Counter(0)) at (prev + 14, 30) to (start + 0, 31)
1817
- Code(Counter(0)) at (prev + 2, 5) to (start + 1, 15)
19-
- Code(Expression(0, Sub)) at (prev + 2, 1) to (start + 0, 2)
20-
= (c1 - c2)
21-
Highest counter ID seen: c0
18+
- Code(Counter(1)) at (prev + 2, 1) to (start + 0, 2)
19+
Highest counter ID seen: c1
2220

0 commit comments

Comments
 (0)