Skip to content
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
5 changes: 4 additions & 1 deletion compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::mem;

use rustc_data_structures::sso::SsoHashMap;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::def_id::DefId;
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
use rustc_middle::ty::error::TypeError;
Expand Down Expand Up @@ -226,7 +227,9 @@ where
let old_ambient_variance = self.ambient_variance;
self.ambient_variance = self.ambient_variance.xform(variance);
debug!(?self.ambient_variance, "new ambient variance");
let r = self.relate(a, b)?;
// Recursive calls to `relate` can overflow the stack. For example a deeper version of
Copy link
Member

Choose a reason for hiding this comment

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

Could you put this onto the top generalizer relate call, in generalize? Or is the stack overflow due to a really deep type being generated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a really deep type.

I'm a bit guessing what the stack trace from CI points to. The failing test uses a deep type, and by making it even deeper I got a backtrace pointing involving this recursion.

Copy link
Member

Choose a reason for hiding this comment

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

Discussed this offline. I guess this ensure_sufficient_stack invocation is fine.

// `ui/associated-consts/issue-93775.rs`.
let r = ensure_sufficient_stack(|| self.relate(a, b))?;
self.ambient_variance = old_ambient_variance;
Ok(r)
}
Expand Down
Loading