Rollup merge of #138729 - compiler-errors:gen, r=lcnr
Clean up `FnCtxt::resolve_coroutine_interiors` Random cleanups before I make a PR that stalls generator obligations. r? lcnr
This commit is contained in:
commit
84a2bb953e
3 changed files with 19 additions and 16 deletions
|
@ -164,11 +164,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
|
let resume_ty = liberated_sig.inputs().get(0).copied().unwrap_or(tcx.types.unit);
|
||||||
|
|
||||||
let interior = self.next_ty_var(expr_span);
|
let interior = self.next_ty_var(expr_span);
|
||||||
self.deferred_coroutine_interiors.borrow_mut().push((
|
self.deferred_coroutine_interiors.borrow_mut().push((expr_def_id, interior));
|
||||||
expr_def_id,
|
|
||||||
body.id(),
|
|
||||||
interior,
|
|
||||||
));
|
|
||||||
|
|
||||||
// Coroutines that come from coroutine closures have not yet determined
|
// Coroutines that come from coroutine closures have not yet determined
|
||||||
// their kind ty, so make a fresh infer var which will be constrained
|
// their kind ty, so make a fresh infer var which will be constrained
|
||||||
|
|
|
@ -633,18 +633,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let coroutines = std::mem::take(&mut *self.deferred_coroutine_interiors.borrow_mut());
|
let coroutines = std::mem::take(&mut *self.deferred_coroutine_interiors.borrow_mut());
|
||||||
debug!(?coroutines);
|
debug!(?coroutines);
|
||||||
|
|
||||||
for &(expr_def_id, body_id, interior) in coroutines.iter() {
|
let mut obligations = vec![];
|
||||||
debug!(?expr_def_id);
|
|
||||||
|
for &(coroutine_def_id, interior) in coroutines.iter() {
|
||||||
|
debug!(?coroutine_def_id);
|
||||||
|
|
||||||
// Create the `CoroutineWitness` type that we will unify with `interior`.
|
// Create the `CoroutineWitness` type that we will unify with `interior`.
|
||||||
let args = ty::GenericArgs::identity_for_item(
|
let args = ty::GenericArgs::identity_for_item(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
|
self.tcx.typeck_root_def_id(coroutine_def_id.to_def_id()),
|
||||||
);
|
);
|
||||||
let witness = Ty::new_coroutine_witness(self.tcx, expr_def_id.to_def_id(), args);
|
let witness = Ty::new_coroutine_witness(self.tcx, coroutine_def_id.to_def_id(), args);
|
||||||
|
|
||||||
// Unify `interior` with `witness` and collect all the resulting obligations.
|
// Unify `interior` with `witness` and collect all the resulting obligations.
|
||||||
let span = self.tcx.hir_body(body_id).value.span;
|
let span = self.tcx.hir_body_owned_by(coroutine_def_id).value.span;
|
||||||
let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else {
|
let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else {
|
||||||
span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind())
|
span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind())
|
||||||
};
|
};
|
||||||
|
@ -653,15 +655,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// Will never define opaque types, as all we do is instantiate a type variable.
|
// Will never define opaque types, as all we do is instantiate a type variable.
|
||||||
.eq(DefineOpaqueTypes::Yes, interior, witness)
|
.eq(DefineOpaqueTypes::Yes, interior, witness)
|
||||||
.expect("Failed to unify coroutine interior type");
|
.expect("Failed to unify coroutine interior type");
|
||||||
let mut obligations = ok.obligations;
|
|
||||||
|
|
||||||
// Also collect the obligations that were unstalled by this unification.
|
obligations.extend(ok.obligations);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Use a real visitor for unstalled obligations in the new solver.
|
||||||
|
if !coroutines.is_empty() {
|
||||||
obligations
|
obligations
|
||||||
.extend(self.fulfillment_cx.borrow_mut().drain_unstalled_obligations(&self.infcx));
|
.extend(self.fulfillment_cx.borrow_mut().drain_unstalled_obligations(&self.infcx));
|
||||||
|
|
||||||
let obligations = obligations.into_iter().map(|o| (o.predicate, o.cause));
|
|
||||||
self.typeck_results.borrow_mut().coroutine_stalled_predicates.extend(obligations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.typeck_results
|
||||||
|
.borrow_mut()
|
||||||
|
.coroutine_stalled_predicates
|
||||||
|
.extend(obligations.into_iter().map(|o| (o.predicate, o.cause)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub(crate) struct TypeckRootCtxt<'tcx> {
|
||||||
|
|
||||||
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, HirId)>>,
|
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, HirId)>>,
|
||||||
|
|
||||||
pub(super) deferred_coroutine_interiors: RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>)>>,
|
pub(super) deferred_coroutine_interiors: RefCell<Vec<(LocalDefId, Ty<'tcx>)>>,
|
||||||
|
|
||||||
pub(super) deferred_repeat_expr_checks:
|
pub(super) deferred_repeat_expr_checks:
|
||||||
RefCell<Vec<(&'tcx hir::Expr<'tcx>, Ty<'tcx>, ty::Const<'tcx>)>>,
|
RefCell<Vec<(&'tcx hir::Expr<'tcx>, Ty<'tcx>, ty::Const<'tcx>)>>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue