Skip to content
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

inliner: Avoid query cycles when optimizing generators #76245

Merged
merged 1 commit into from
Sep 3, 2020
Merged
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
10 changes: 8 additions & 2 deletions compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ impl Inliner<'tcx> {
// Avoid a cycle here by only using `optimized_mir` only if we have
// a lower `HirId` than the callee. This ensures that the callee will
// not inline us. This trick only works without incremental compilation.
// So don't do it if that is enabled.
if !self.tcx.dep_graph.is_fully_enabled() && self_hir_id < callee_hir_id {
// So don't do it if that is enabled. Also avoid inlining into generators,
// since their `optimized_mir` is used for layout computation, which can
// create a cycle, even when no attempt is made to inline the function
// in the other direction.
if !self.tcx.dep_graph.is_fully_enabled()
&& self_hir_id < callee_hir_id
&& caller_body.generator_kind.is_none()
{
self.tcx.optimized_mir(callsite.callee)
} else {
continue;
Expand Down
18 changes: 18 additions & 0 deletions src/test/mir-opt/inline/inline-async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Checks that inliner doesn't introduce cycles when optimizing generators.
// The outcome of optimization is not verfied, just the absence of the cycle.
// Regression test for #76181.
//
// edition:2018

#![crate_type = "lib"]

pub struct S;

impl S {
pub async fn g(&mut self) {
self.h();
}
pub fn h(&mut self) {
let _ = self.g();
}
}