Replace tuple of infer vars for upvar_tys with single infer var
This commit allows us to decide the number of captures required after completing capture ananysis, which is required as part of implementing RFC-2229. Co-authored-by: Aman Arora <me@aman-arora.com> Co-authored-by: Jenny Wills <wills.jenniferg@gmail.com>
This commit is contained in:
parent
25d2d09da7
commit
dc183702da
23 changed files with 178 additions and 95 deletions
|
@ -96,15 +96,25 @@ fn compute_components(
|
|||
}
|
||||
|
||||
ty::Closure(_, ref substs) => {
|
||||
for upvar_ty in substs.as_closure().upvar_tys() {
|
||||
compute_components(tcx, upvar_ty, out, visited);
|
||||
if substs.as_closure().is_valid() {
|
||||
for upvar_ty in substs.as_closure().upvar_tys() {
|
||||
compute_components(tcx, upvar_ty, out, visited);
|
||||
}
|
||||
} else {
|
||||
let tupled_ty = substs.as_closure().tupled_upvars_ty();
|
||||
compute_components(tcx, tupled_ty, out, visited);
|
||||
}
|
||||
}
|
||||
|
||||
ty::Generator(_, ref substs, _) => {
|
||||
// Same as the closure case
|
||||
for upvar_ty in substs.as_generator().upvar_tys() {
|
||||
compute_components(tcx, upvar_ty, out, visited);
|
||||
if substs.as_generator().is_valid() {
|
||||
for upvar_ty in substs.as_generator().upvar_tys() {
|
||||
compute_components(tcx, upvar_ty, out, visited);
|
||||
}
|
||||
} else {
|
||||
let tupled_ty = substs.as_generator().tupled_upvars_ty();
|
||||
compute_components(tcx, tupled_ty, out, visited);
|
||||
}
|
||||
|
||||
// We ignore regions in the generator interior as we don't
|
||||
|
|
|
@ -663,18 +663,13 @@ pub trait PrettyPrinter<'tcx>:
|
|||
}
|
||||
} else {
|
||||
p!(print_def_path(did, substs));
|
||||
if substs.as_generator().is_valid() {
|
||||
// Search for the first inference variable
|
||||
p!(" upvar_tys=(");
|
||||
let mut uninferred_ty =
|
||||
substs.as_generator().upvar_tys().filter(|ty| ty.is_ty_infer());
|
||||
if uninferred_ty.next().is_some() {
|
||||
p!(write("unavailable"));
|
||||
} else {
|
||||
self = self.comma_sep(substs.as_generator().upvar_tys())?;
|
||||
}
|
||||
p!(")");
|
||||
p!(" upvar_tys=(");
|
||||
if !substs.as_generator().is_valid() {
|
||||
p!("unavailable");
|
||||
} else {
|
||||
self = self.comma_sep(substs.as_generator().upvar_tys())?;
|
||||
}
|
||||
p!(")");
|
||||
}
|
||||
|
||||
if substs.as_generator().is_valid() {
|
||||
|
@ -704,24 +699,17 @@ pub trait PrettyPrinter<'tcx>:
|
|||
}
|
||||
} else {
|
||||
p!(print_def_path(did, substs));
|
||||
if substs.as_closure().is_valid() {
|
||||
// Search for the first inference variable
|
||||
let mut uninferred_ty =
|
||||
substs.as_closure().upvar_tys().filter(|ty| ty.is_ty_infer());
|
||||
if uninferred_ty.next().is_some() {
|
||||
// If the upvar substs contain an inference variable we haven't
|
||||
// finished capture analysis.
|
||||
p!(" closure_substs=(unavailable)");
|
||||
} else {
|
||||
p!(" closure_kind_ty=", print(substs.as_closure().kind_ty()));
|
||||
p!(
|
||||
" closure_sig_as_fn_ptr_ty=",
|
||||
print(substs.as_closure().sig_as_fn_ptr_ty())
|
||||
);
|
||||
p!(" upvar_tys=(");
|
||||
self = self.comma_sep(substs.as_closure().upvar_tys())?;
|
||||
p!(")");
|
||||
}
|
||||
if !substs.as_closure().is_valid() {
|
||||
p!(" closure_substs=(unavailable)");
|
||||
} else {
|
||||
p!(" closure_kind_ty=", print(substs.as_closure().kind_ty()));
|
||||
p!(
|
||||
" closure_sig_as_fn_ptr_ty=",
|
||||
print(substs.as_closure().sig_as_fn_ptr_ty())
|
||||
);
|
||||
p!(" upvar_tys=(");
|
||||
self = self.comma_sep(substs.as_closure().upvar_tys())?;
|
||||
p!(")");
|
||||
}
|
||||
}
|
||||
p!("]");
|
||||
|
|
|
@ -656,6 +656,14 @@ impl<'tcx> UpvarSubsts<'tcx> {
|
|||
};
|
||||
tupled_upvars_ty.expect_ty().tuple_fields()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn tupled_upvars_ty(self) -> Ty<'tcx> {
|
||||
match self {
|
||||
UpvarSubsts::Closure(substs) => substs.as_closure().tupled_upvars_ty(),
|
||||
UpvarSubsts::Generator(substs) => substs.as_generator().tupled_upvars_ty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, TyEncodable, TyDecodable)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue