Skip to content

Commit 2fed66f

Browse files
committed
Allow inlining into coroutines.
1 parent 5dd3644 commit 2fed66f

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
@@ -124,8 +124,6 @@ trait Inliner<'tcx> {
124124
callee_attrs: &CodegenFnAttrs,
125125
) -> Result<(), &'static str>;
126126

127-
fn check_caller_mir_body(&self, body: &Body<'tcx>) -> bool;
128-
129127
/// Returns inlining decision that is based on the examination of callee MIR body.
130128
/// Assumes that codegen attributes have been checked for compatibility already.
131129
fn check_callee_mir_body(
@@ -199,10 +197,6 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
199197
Ok(())
200198
}
201199

202-
fn check_caller_mir_body(&self, _: &Body<'tcx>) -> bool {
203-
true
204-
}
205-
206200
#[instrument(level = "debug", skip(self, callee_body))]
207201
fn check_callee_mir_body(
208202
&self,
@@ -349,17 +343,6 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
349343
}
350344
}
351345

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

504487
let mut inliner = T::new(tcx, def_id, body);
505-
if !inliner.check_caller_mir_body(body) {
506-
return false;
507-
}
508-
509488
let blocks = START_BLOCK..body.basic_blocks.next_index();
510489
process_blocks(&mut inliner, body, blocks);
511490
inliner.changed()
@@ -774,11 +753,12 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>(
774753
&& !inliner
775754
.tcx()
776755
.is_lang_item(inliner.tcx().parent(caller_def_id), rustc_hir::LangItem::FnOnce)
756+
// The caller may be a shim.
757+
&& let Some(caller_def_id) = caller_def_id.as_local()
777758
{
778759
// If we know for sure that the function we're calling will itself try to
779760
// call us, then we avoid inlining that function.
780-
if inliner.tcx().mir_callgraph_cyclic(caller_def_id.expect_local()).contains(&callee_def_id)
781-
{
761+
if inliner.tcx().mir_callgraph_cyclic(caller_def_id).contains(&callee_def_id) {
782762
debug!("query cycle avoidance");
783763
return Err("caller might be reachable from callee");
784764
}

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)