Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 169955f

Browse files
Properly drain pending obligations for coroutines
1 parent 67df5b9 commit 169955f

File tree

19 files changed

+241
-63
lines changed

19 files changed

+241
-63
lines changed

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
163163
// Resume type defaults to `()` if the coroutine has no argument.
164164
let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
165165

166+
// TODO: In the new solver, we can just instantiate this eagerly
167+
// with the witness. This will ensure that goals that don't need
168+
// to stall on interior types will get processed eagerly.
166169
let interior = self.next_ty_var(expr_span);
167170
self.deferred_coroutine_interiors.borrow_mut().push((expr_def_id, interior));
168171

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
659659
obligations.extend(ok.obligations);
660660
}
661661

662-
// FIXME: Use a real visitor for unstalled obligations in the new solver.
663662
if !coroutines.is_empty() {
664-
obligations
665-
.extend(self.fulfillment_cx.borrow_mut().drain_unstalled_obligations(&self.infcx));
663+
obligations.extend(
664+
self.fulfillment_cx
665+
.borrow_mut()
666+
.drain_stalled_obligations_for_coroutines(&self.infcx),
667+
);
666668
}
667669

668670
self.typeck_results

compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'tcx> TypeckRootCtxt<'tcx> {
8484
let hir_owner = tcx.local_def_id_to_hir_id(def_id).owner;
8585

8686
let infcx =
87-
tcx.infer_ctxt().ignoring_regions().build(TypingMode::analysis_in_body(tcx, def_id));
87+
tcx.infer_ctxt().ignoring_regions().build(TypingMode::typeck_for_body(tcx, def_id));
8888
let typeck_results = RefCell::new(ty::TypeckResults::new(hir_owner));
8989

9090
TypeckRootCtxt {

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ impl<'tcx> InferCtxt<'tcx> {
967967
pub fn can_define_opaque_ty(&self, id: impl Into<DefId>) -> bool {
968968
debug_assert!(!self.next_trait_solver());
969969
match self.typing_mode() {
970-
TypingMode::Analysis { defining_opaque_types }
970+
TypingMode::Analysis { defining_opaque_types, stalled_generators: _ }
971971
| TypingMode::Borrowck { defining_opaque_types } => {
972972
id.into().as_local().is_some_and(|def_id| defining_opaque_types.contains(&def_id))
973973
}
@@ -1262,7 +1262,7 @@ impl<'tcx> InferCtxt<'tcx> {
12621262
// to handle them without proper canonicalization. This means we may cause cycle
12631263
// errors and fail to reveal opaques while inside of bodies. We should rename this
12641264
// function and require explicit comments on all use-sites in the future.
1265-
ty::TypingMode::Analysis { defining_opaque_types: _ }
1265+
ty::TypingMode::Analysis { defining_opaque_types: _, stalled_generators: _ }
12661266
| ty::TypingMode::Borrowck { defining_opaque_types: _ } => {
12671267
TypingMode::non_body_analysis()
12681268
}

compiler/rustc_infer/src/traits/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx {
9494
/// Among all pending obligations, collect those are stalled on a inference variable which has
9595
/// changed since the last call to `select_where_possible`. Those obligations are marked as
9696
/// successful and returned.
97-
fn drain_unstalled_obligations(
97+
fn drain_stalled_obligations_for_coroutines(
9898
&mut self,
9999
infcx: &InferCtxt<'tcx>,
100100
) -> PredicateObligations<'tcx>;

compiler/rustc_middle/src/query/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ rustc_queries! {
387387
}
388388
}
389389

390+
query stalled_generators_within(
391+
key: LocalDefId
392+
) -> &'tcx ty::List<LocalDefId> {
393+
desc {
394+
|tcx| "computing the opaque types defined by `{}`",
395+
tcx.def_path_str(key.to_def_id())
396+
}
397+
}
398+
390399
/// Returns the explicitly user-written *bounds* on the associated or opaque type given by `DefId`
391400
/// that must be proven true at definition site (and which can be assumed at usage sites).
392401
///

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ macro_rules! define_callbacks {
366366

367367
pub type Storage<'tcx> = <$($K)* as keys::Key>::Cache<Erase<$V>>;
368368

369-
// Ensure that keys grow no larger than 80 bytes by accident.
369+
// Ensure that keys grow no larger than 96 bytes by accident.
370370
// Increase this limit if necessary, but do try to keep the size low if possible
371371
#[cfg(target_pointer_width = "64")]
372372
const _: () = {
373-
if size_of::<Key<'static>>() > 88 {
373+
if size_of::<Key<'static>>() > 96 {
374374
panic!("{}", concat!(
375375
"the query `",
376376
stringify!($name),

compiler/rustc_middle/src/ty/context.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
106106
) -> Self::PredefinedOpaques {
107107
self.mk_predefined_opaques_in_body(data)
108108
}
109-
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
109+
type LocalDefIds = &'tcx ty::List<LocalDefId>;
110110
type CanonicalVars = CanonicalVarInfos<'tcx>;
111111
fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars {
112112
self.mk_canonical_var_infos(infos)
@@ -674,9 +674,13 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
674674
self.anonymize_bound_vars(binder)
675675
}
676676

677-
fn opaque_types_defined_by(self, defining_anchor: LocalDefId) -> Self::DefiningOpaqueTypes {
677+
fn opaque_types_defined_by(self, defining_anchor: LocalDefId) -> Self::LocalDefIds {
678678
self.opaque_types_defined_by(defining_anchor)
679679
}
680+
681+
fn stalled_generators_within(self, defining_anchor: Self::LocalDefId) -> Self::LocalDefIds {
682+
self.stalled_generators_within(defining_anchor)
683+
}
680684
}
681685

682686
macro_rules! bidirectional_lang_item_map {

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,10 @@ where
329329
TypingMode::Coherence | TypingMode::PostAnalysis => false,
330330
// During analysis, opaques are rigid unless they may be defined by
331331
// the current body.
332-
TypingMode::Analysis { defining_opaque_types: non_rigid_opaques }
332+
TypingMode::Analysis {
333+
defining_opaque_types: non_rigid_opaques,
334+
stalled_generators: _,
335+
}
333336
| TypingMode::Borrowck { defining_opaque_types: non_rigid_opaques }
334337
| TypingMode::PostBorrowckAnalysis { defined_opaque_types: non_rigid_opaques } => {
335338
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id))

compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
);
3434
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
3535
}
36-
TypingMode::Analysis { defining_opaque_types } => {
36+
TypingMode::Analysis { defining_opaque_types, stalled_generators: _ } => {
3737
let Some(def_id) = opaque_ty
3838
.def_id
3939
.as_local()

0 commit comments

Comments
 (0)