-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Properly stall coroutine witnesses in new solver #138845
base: master
Are you sure you want to change the base?
Properly stall coroutine witnesses in new solver #138845
Conversation
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor changes to |
@@ -65,13 +65,13 @@ pub enum TypingMode<I: Interner> { | |||
/// let x: <() as Assoc>::Output = true; | |||
/// } | |||
/// ``` | |||
Analysis { defining_opaque_types: I::DefiningOpaqueTypes }, | |||
Analysis { defining_opaque_types: I::LocalDefIds, stalled_generators: I::LocalDefIds }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably could squash this into one list.
@@ -162,7 +162,7 @@ where | |||
self.select(selcx) | |||
} | |||
|
|||
fn drain_unstalled_obligations( | |||
fn drain_stall_obligations_for_coroutines( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn drain_stall_obligations_for_coroutines( | |
fn drain_stalled_obligations_for_coroutines( |
ScrubbedTraitError<'tcx>, | ||
>(self.at, ct, vec![None; ct.outer_exclusive_binder().as_usize()]) | ||
{ | ||
Ok((value, _)) => value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We throw away ambiguous preds here b/c we may be using this folder on types that really are just not fully normalizable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preds list should just contain stalled coroutine obligations, after all.
/// entered before passing `value` to the function. This is currently needed for | ||
/// `normalize_erasing_regions`, which skips binders as it walks through a type. | ||
/// | ||
/// TODO: doc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to explain that this doesn't return all ambiguous preds, just the ones that are stalled on coroutines.
struct StalledOnCoroutines<'tcx> { | ||
stalled_generators: &'tcx ty::List<LocalDefId>, | ||
span: Span, | ||
// TODO: Cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cache would be nice since visiting everything 128318913 times to look for coroutines is probably expensive.
@@ -189,6 +189,20 @@ where | |||
debug_assert!(ecx.opaque_type_is_rigid(opaque_ty.def_id)); | |||
} | |||
|
|||
if let ty::CoroutineWitness(def_id, _) = goal.predicate.self_ty().kind() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should pull this out into a helper, b/c I think I need to also apply this hack to copy/clone. I think those are it tho.
// Increase this limit if necessary, but do try to keep the size low if possible | ||
#[cfg(target_pointer_width = "64")] | ||
const _: () = { | ||
if size_of::<Key<'static>>() > 88 { | ||
if size_of::<Key<'static>>() > 96 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:((
predicate | ||
assert!( | ||
!self.should_normalize, | ||
"normalizing predicats in writeback is not generally sound" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"normalizing predicats in writeback is not generally sound" | |
"normalizing predicates in writeback is not generally sound" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could be a bug!()
so that we don't need to fold here.
The job Click to see the possible cause of the failure (guessed by this bot)
|
Tweaks to writeback and `Obligation -> Goal` conversion Each of these commits are self-contained, but are prerequisites that I'd like to land before rust-lang#138845, which still needs some cleaning. The ""most controversial"" one is probably [Explicitly don't fold coroutine obligations in writeback](rust-lang@e7d27ba), which I prefer because I think using `fold_predicate` to control against not normalizing predicates seems... easy to mess up 🤔, and we could have *other things* that we don't want to normalize. Explicitly noting whether we want `resolve` to normalize is a lot clearer (and currently in writeback is limited to resolving stalled coroutine obligations), since we can attach it to a comment that explains *why*.
Rollup merge of rust-lang#138846 - compiler-errors:stall-prereqs, r=lcnr Tweaks to writeback and `Obligation -> Goal` conversion Each of these commits are self-contained, but are prerequisites that I'd like to land before rust-lang#138845, which still needs some cleaning. The ""most controversial"" one is probably [Explicitly don't fold coroutine obligations in writeback](rust-lang@e7d27ba), which I prefer because I think using `fold_predicate` to control against not normalizing predicates seems... easy to mess up 🤔, and we could have *other things* that we don't want to normalize. Explicitly noting whether we want `resolve` to normalize is a lot clearer (and currently in writeback is limited to resolving stalled coroutine obligations), since we can attach it to a comment that explains *why*.
☔ The latest upstream changes (presumably #138873) made this pull request unmergeable. Please resolve the merge conflicts. |
} | ||
|
||
fn pending_obligations(&self) -> PredicateObligations<'tcx> { | ||
self.obligations.clone_pending() | ||
} | ||
|
||
fn drain_unstalled_obligations(&mut self, _: &InferCtxt<'tcx>) -> PredicateObligations<'tcx> { | ||
self.obligations.take_pending() | ||
fn drain_stall_obligations_for_coroutines( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn drain_stall_obligations_for_coroutines( | |
fn drain_stalled_obligations_for_coroutines( |
fn visit_goal(&mut self, inspect_goal: &super::inspect::InspectGoal<'_, 'tcx>) -> Self::Result { | ||
inspect_goal.goal().predicate.visit_with(self)?; | ||
|
||
if let Some(candidate) = inspect_goal.unique_applicable_candidate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type visitor feels somewhat fragile and I expect unique_applicable_candidate
and the limited recursion depth to cause us to fail to stall obligations in very rare cases. otoh I don't think this is a problem though
so my understanding here is:
- for correctness it doesn't matter how many obligations we stall
- for diagnostics (and perf) we want to stall as few obligations as possible
- failing to stall causes unexpected ambiguity errors
Please add this as a comment somewhere, prolly the stalled_coroutine_obligations field of the typeck results
TODO: write description
r? lcnr