Skip to content

Commit b6f1961

Browse files
Eagerly instantiate coroutine witness in new solver
1 parent eaf2d15 commit b6f1961

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

compiler/rustc_hir_typeck/src/closure.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,15 @@ 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
166+
// In the new solver, we can just instantiate this eagerly
167167
// with the witness. This will ensure that goals that don't need
168168
// to stall on interior types will get processed eagerly.
169-
let interior = self.next_ty_var(expr_span);
169+
let interior = if self.next_trait_solver() {
170+
Ty::new_coroutine_witness(tcx, expr_def_id.to_def_id(), parent_args)
171+
} else {
172+
self.next_ty_var(expr_span)
173+
};
174+
170175
self.deferred_coroutine_interiors.borrow_mut().push((expr_def_id, interior));
171176

172177
// Coroutines that come from coroutine closures have not yet determined

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+24-21
Original file line numberDiff line numberDiff line change
@@ -635,28 +635,31 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
635635

636636
let mut obligations = vec![];
637637

638-
for &(coroutine_def_id, interior) in coroutines.iter() {
639-
debug!(?coroutine_def_id);
638+
if !self.next_trait_solver() {
639+
for &(coroutine_def_id, interior) in coroutines.iter() {
640+
debug!(?coroutine_def_id);
641+
642+
// Create the `CoroutineWitness` type that we will unify with `interior`.
643+
let args = ty::GenericArgs::identity_for_item(
644+
self.tcx,
645+
self.tcx.typeck_root_def_id(coroutine_def_id.to_def_id()),
646+
);
647+
let witness =
648+
Ty::new_coroutine_witness(self.tcx, coroutine_def_id.to_def_id(), args);
640649

641-
// Create the `CoroutineWitness` type that we will unify with `interior`.
642-
let args = ty::GenericArgs::identity_for_item(
643-
self.tcx,
644-
self.tcx.typeck_root_def_id(coroutine_def_id.to_def_id()),
645-
);
646-
let witness = Ty::new_coroutine_witness(self.tcx, coroutine_def_id.to_def_id(), args);
647-
648-
// Unify `interior` with `witness` and collect all the resulting obligations.
649-
let span = self.tcx.hir_body_owned_by(coroutine_def_id).value.span;
650-
let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else {
651-
span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind())
652-
};
653-
let ok = self
654-
.at(&self.misc(span), self.param_env)
655-
// Will never define opaque types, as all we do is instantiate a type variable.
656-
.eq(DefineOpaqueTypes::Yes, interior, witness)
657-
.expect("Failed to unify coroutine interior type");
658-
659-
obligations.extend(ok.obligations);
650+
// Unify `interior` with `witness` and collect all the resulting obligations.
651+
let span = self.tcx.hir_body_owned_by(coroutine_def_id).value.span;
652+
let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else {
653+
span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind())
654+
};
655+
let ok = self
656+
.at(&self.misc(span), self.param_env)
657+
// Will never define opaque types, as all we do is instantiate a type variable.
658+
.eq(DefineOpaqueTypes::Yes, interior, witness)
659+
.expect("Failed to unify coroutine interior type");
660+
661+
obligations.extend(ok.obligations);
662+
}
660663
}
661664

662665
if !coroutines.is_empty() {

0 commit comments

Comments
 (0)