Skip to content

Commit 7209b8e

Browse files
Remove the witness type from coroutine args
1 parent a86564d commit 7209b8e

File tree

17 files changed

+54
-128
lines changed

17 files changed

+54
-128
lines changed

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8686
// them with fresh ty vars.
8787
resume_ty: next_ty_var(),
8888
yield_ty: next_ty_var(),
89-
witness: next_ty_var(),
9089
},
9190
)
9291
.args,

compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,20 +379,14 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
379379
// for info on the usage of each of these fields.
380380
let dummy_args = match kind {
381381
ClosureKind::Closure => &["<closure_kind>", "<closure_signature>", "<upvars>"][..],
382-
ClosureKind::Coroutine(_) => &[
383-
"<coroutine_kind>",
384-
"<resume_ty>",
385-
"<yield_ty>",
386-
"<return_ty>",
387-
"<witness>",
388-
"<upvars>",
389-
][..],
382+
ClosureKind::Coroutine(_) => {
383+
&["<coroutine_kind>", "<resume_ty>", "<yield_ty>", "<return_ty>", "<upvars>"][..]
384+
}
390385
ClosureKind::CoroutineClosure(_) => &[
391386
"<closure_kind>",
392387
"<closure_signature_parts>",
393388
"<upvars>",
394389
"<bound_captures_by_ref>",
395-
"<witness>",
396390
][..],
397391
};
398392

compiler/rustc_hir_typeck/src/closure.rs

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

164-
let interior = Ty::new_coroutine_witness(tcx, expr_def_id.to_def_id(), parent_args);
165-
166164
// Coroutines that come from coroutine closures have not yet determined
167165
// their kind ty, so make a fresh infer var which will be constrained
168166
// later during upvar analysis. Regular coroutines always have the kind
@@ -182,7 +180,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
182180
resume_ty,
183181
yield_ty,
184182
return_ty: liberated_sig.output(),
185-
witness: interior,
186183
tupled_upvars_ty,
187184
},
188185
);
@@ -210,7 +207,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
210207
};
211208
// Compute all of the variables that will be used to populate the coroutine.
212209
let resume_ty = self.next_ty_var(expr_span);
213-
let interior = self.next_ty_var(expr_span);
214210

215211
let closure_kind_ty = match expected_kind {
216212
Some(kind) => Ty::from_closure_kind(tcx, kind),
@@ -243,7 +239,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
243239
),
244240
tupled_upvars_ty,
245241
coroutine_captures_by_ref_ty,
246-
coroutine_witness_ty: interior,
247242
},
248243
);
249244

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,38 +96,29 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
9696
signature_parts_ty,
9797
tupled_upvars_ty,
9898
coroutine_captures_by_ref_ty,
99-
coroutine_witness_ty,
10099
] => ty::CoroutineClosureArgsParts {
101100
parent_args,
102101
closure_kind_ty: closure_kind_ty.expect_ty(),
103102
signature_parts_ty: signature_parts_ty.expect_ty(),
104103
tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
105104
coroutine_captures_by_ref_ty: coroutine_captures_by_ref_ty.expect_ty(),
106-
coroutine_witness_ty: coroutine_witness_ty.expect_ty(),
107105
},
108106
_ => bug!("closure args missing synthetics"),
109107
}
110108
}
111109

112110
fn split_coroutine_args(self) -> ty::CoroutineArgsParts<TyCtxt<'tcx>> {
113111
match self[..] {
114-
[
115-
ref parent_args @ ..,
116-
kind_ty,
117-
resume_ty,
118-
yield_ty,
119-
return_ty,
120-
witness,
121-
tupled_upvars_ty,
122-
] => ty::CoroutineArgsParts {
123-
parent_args,
124-
kind_ty: kind_ty.expect_ty(),
125-
resume_ty: resume_ty.expect_ty(),
126-
yield_ty: yield_ty.expect_ty(),
127-
return_ty: return_ty.expect_ty(),
128-
witness: witness.expect_ty(),
129-
tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
130-
},
112+
[ref parent_args @ .., kind_ty, resume_ty, yield_ty, return_ty, tupled_upvars_ty] => {
113+
ty::CoroutineArgsParts {
114+
parent_args,
115+
kind_ty: kind_ty.expect_ty(),
116+
resume_ty: resume_ty.expect_ty(),
117+
yield_ty: yield_ty.expect_ty(),
118+
return_ty: return_ty.expect_ty(),
119+
tupled_upvars_ty: tupled_upvars_ty.expect_ty(),
120+
}
121+
}
131122
_ => bug!("coroutine args missing synthetics"),
132123
}
133124
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
913913
" yield_ty=",
914914
print(args.as_coroutine().yield_ty()),
915915
" return_ty=",
916-
print(args.as_coroutine().return_ty()),
917-
" witness=",
918-
print(args.as_coroutine().witness())
916+
print(args.as_coroutine().return_ty())
919917
);
920918
}
921919

@@ -1035,9 +1033,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
10351033
" upvar_tys=",
10361034
print(args.as_coroutine_closure().tupled_upvars_ty()),
10371035
" coroutine_captures_by_ref_ty=",
1038-
print(args.as_coroutine_closure().coroutine_captures_by_ref_ty()),
1039-
" coroutine_witness_ty=",
1040-
print(args.as_coroutine_closure().coroutine_witness_ty())
1036+
print(args.as_coroutine_closure().coroutine_captures_by_ref_ty())
10411037
);
10421038
}
10431039
p!("}}");

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,16 @@ where
7575
Ok(ty::Binder::dummy(vec![args.as_coroutine_closure().tupled_upvars_ty()]))
7676
}
7777

78-
ty::Coroutine(_, args) => {
78+
ty::Coroutine(def_id, args) => {
7979
let coroutine_args = args.as_coroutine();
80-
Ok(ty::Binder::dummy(vec![coroutine_args.tupled_upvars_ty(), coroutine_args.witness()]))
80+
Ok(ty::Binder::dummy(vec![
81+
coroutine_args.tupled_upvars_ty(),
82+
Ty::new_coroutine_witness(
83+
ecx.cx(),
84+
def_id,
85+
ecx.cx().mk_args(coroutine_args.parent_args().as_slice()),
86+
),
87+
]))
8188
}
8289

8390
ty::CoroutineWitness(def_id, args) => Ok(ecx
@@ -245,7 +252,14 @@ where
245252
Movability::Movable => {
246253
if ecx.cx().features().coroutine_clone() {
247254
let coroutine = args.as_coroutine();
248-
Ok(ty::Binder::dummy(vec![coroutine.tupled_upvars_ty(), coroutine.witness()]))
255+
Ok(ty::Binder::dummy(vec![
256+
coroutine.tupled_upvars_ty(),
257+
Ty::new_coroutine_witness(
258+
ecx.cx(),
259+
def_id,
260+
ecx.cx().mk_args(coroutine.parent_args().as_slice()),
261+
),
262+
]))
249263
} else {
250264
Err(NoSolution)
251265
}

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,9 +1166,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11661166
if self.tcx().features().coroutine_clone() {
11671167
let resolved_upvars =
11681168
self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
1169-
let resolved_witness =
1170-
self.infcx.shallow_resolve(args.as_coroutine().witness());
1171-
if resolved_upvars.is_ty_var() || resolved_witness.is_ty_var() {
1169+
if resolved_upvars.is_ty_var() {
11721170
// Not yet resolved.
11731171
candidates.ambiguous = true;
11741172
} else {

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
21992199
args.as_coroutine()
22002200
.upvar_tys()
22012201
.iter()
2202-
.chain([args.as_coroutine().witness()])
2202+
.chain([Ty::new_coroutine_witness(
2203+
self.tcx(),
2204+
coroutine_def_id,
2205+
self.tcx().mk_args(args.as_coroutine().parent_args()),
2206+
)])
22032207
.collect::<Vec<_>>(),
22042208
)
22052209
} else {
@@ -2330,9 +2334,13 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
23302334
ty::Binder::dummy(AutoImplConstituents { types: vec![ty], assumptions: vec![] })
23312335
}
23322336

2333-
ty::Coroutine(_, args) => {
2337+
ty::Coroutine(def_id, args) => {
23342338
let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
2335-
let witness = args.as_coroutine().witness();
2339+
let witness = Ty::new_coroutine_witness(
2340+
self.tcx(),
2341+
def_id,
2342+
self.tcx().mk_args(args.as_coroutine().parent_args()),
2343+
);
23362344
ty::Binder::dummy(AutoImplConstituents {
23372345
types: [ty].into_iter().chain(iter::once(witness)).collect(),
23382346
assumptions: vec![],

compiler/rustc_type_ir/src/ty_kind/closure.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ use crate::{self as ty, Interner};
101101
/// `yield` inside the coroutine.
102102
/// * `GR`: The "return type", which is the type of value returned upon
103103
/// completion of the coroutine.
104-
/// * `GW`: The "coroutine witness".
105104
#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)]
106105
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
107106
pub struct ClosureArgs<I: Interner> {
@@ -239,8 +238,6 @@ pub struct CoroutineClosureArgsParts<I: Interner> {
239238
/// while the `tupled_upvars_ty`, representing the by-move version of the same
240239
/// captures, will be `(String,)`.
241240
pub coroutine_captures_by_ref_ty: I::Ty,
242-
/// Witness type returned by the generator produced by this coroutine-closure.
243-
pub coroutine_witness_ty: I::Ty,
244241
}
245242

246243
impl<I: Interner> CoroutineClosureArgs<I> {
@@ -251,7 +248,6 @@ impl<I: Interner> CoroutineClosureArgs<I> {
251248
parts.signature_parts_ty.into(),
252249
parts.tupled_upvars_ty.into(),
253250
parts.coroutine_captures_by_ref_ty.into(),
254-
parts.coroutine_witness_ty.into(),
255251
])),
256252
}
257253
}
@@ -292,7 +288,6 @@ impl<I: Interner> CoroutineClosureArgs<I> {
292288
}
293289

294290
pub fn coroutine_closure_sig(self) -> ty::Binder<I, CoroutineClosureSignature<I>> {
295-
let interior = self.coroutine_witness_ty();
296291
let ty::FnPtr(sig_tys, hdr) = self.signature_parts_ty().kind() else { panic!() };
297292
sig_tys.map_bound(|sig_tys| {
298293
let [resume_ty, tupled_inputs_ty] = *sig_tys.inputs().as_slice() else {
@@ -302,7 +297,6 @@ impl<I: Interner> CoroutineClosureArgs<I> {
302297
panic!()
303298
};
304299
CoroutineClosureSignature {
305-
interior,
306300
tupled_inputs_ty,
307301
resume_ty,
308302
yield_ty,
@@ -318,10 +312,6 @@ impl<I: Interner> CoroutineClosureArgs<I> {
318312
self.split().coroutine_captures_by_ref_ty
319313
}
320314

321-
pub fn coroutine_witness_ty(self) -> I::Ty {
322-
self.split().coroutine_witness_ty
323-
}
324-
325315
pub fn has_self_borrows(&self) -> bool {
326316
match self.coroutine_captures_by_ref_ty().kind() {
327317
ty::FnPtr(sig_tys, _) => sig_tys
@@ -361,7 +351,6 @@ impl<I: Interner> TypeVisitor<I> for HasRegionsBoundAt {
361351
#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)]
362352
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
363353
pub struct CoroutineClosureSignature<I: Interner> {
364-
pub interior: I::Ty,
365354
pub tupled_inputs_ty: I::Ty,
366355
pub resume_ty: I::Ty,
367356
pub yield_ty: I::Ty,
@@ -407,7 +396,6 @@ impl<I: Interner> CoroutineClosureSignature<I> {
407396
resume_ty: self.resume_ty,
408397
yield_ty: self.yield_ty,
409398
return_ty: self.return_ty,
410-
witness: self.interior,
411399
tupled_upvars_ty,
412400
},
413401
);
@@ -587,11 +575,6 @@ pub struct CoroutineArgsParts<I: Interner> {
587575
pub yield_ty: I::Ty,
588576
pub return_ty: I::Ty,
589577

590-
/// The interior type of the coroutine.
591-
/// Represents all types that are stored in locals
592-
/// in the coroutine's body.
593-
pub witness: I::Ty,
594-
595578
/// The upvars captured by the closure. Remains an inference variable
596579
/// until the upvar analysis, which happens late in HIR typeck.
597580
pub tupled_upvars_ty: I::Ty,
@@ -607,7 +590,6 @@ impl<I: Interner> CoroutineArgs<I> {
607590
parts.resume_ty.into(),
608591
parts.yield_ty.into(),
609592
parts.return_ty.into(),
610-
parts.witness.into(),
611593
parts.tupled_upvars_ty.into(),
612594
])),
613595
}
@@ -629,15 +611,6 @@ impl<I: Interner> CoroutineArgs<I> {
629611
self.split().kind_ty
630612
}
631613

632-
/// This describes the types that can be contained in a coroutine.
633-
/// It will be a type variable initially and unified in the last stages of typeck of a body.
634-
/// It contains a tuple of all the types that could end up on a coroutine frame.
635-
/// The state transformation MIR pass may only produce layouts which mention types
636-
/// in this tuple. Upvars are not counted here.
637-
pub fn witness(self) -> I::Ty {
638-
self.split().witness
639-
}
640-
641614
/// Returns an iterator over the list of types of captured paths by the coroutine.
642615
/// In case there was a type error in figuring out the types of the captured path, an
643616
/// empty iterator is returned.

tests/ui/async-await/async-closures/def-path.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ LL | let x = async || {};
55
| -- the expected `async` closure body
66
LL |
77
LL | let () = x();
8-
| ^^ --- this expression has type `{static main::{closure#0}::{closure#0}<?16t> upvar_tys=?15t resume_ty=ResumeTy yield_ty=() return_ty=() witness={main::{closure#0}::{closure#0}}}`
8+
| ^^ --- this expression has type `{static main::{closure#0}::{closure#0}<?15t> upvar_tys=?14t resume_ty=ResumeTy yield_ty=() return_ty=()}`
99
| |
1010
| expected `async` closure body, found `()`
1111
|
12-
= note: expected `async` closure body `{static main::{closure#0}::{closure#0}<?16t> upvar_tys=?15t resume_ty=ResumeTy yield_ty=() return_ty=() witness={main::{closure#0}::{closure#0}}}`
12+
= note: expected `async` closure body `{static main::{closure#0}::{closure#0}<?15t> upvar_tys=?14t resume_ty=ResumeTy yield_ty=() return_ty=()}`
1313
found unit type `()`
1414

1515
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)