Skip to content

Commit 10f08ab

Browse files
committed
rustc: keep upvars tupled in {Closure,Generator}Substs.
1 parent 98803c1 commit 10f08ab

File tree

65 files changed

+353
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+353
-332
lines changed

src/librustc/traits/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
229229
// (T1..Tn) and closures have same properties as T1..Tn --
230230
// check if *any* of those are trivial.
231231
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
232-
ty::Closure(def_id, ref substs) => {
233-
substs.as_closure().upvar_tys(def_id, tcx).all(|t| trivial_dropck_outlives(tcx, t))
232+
ty::Closure(_, ref substs) => {
233+
substs.as_closure().upvar_tys().all(|t| trivial_dropck_outlives(tcx, t))
234234
}
235235

236236
ty::Adt(def, _) => {

src/librustc/ty/instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'tcx> Instance<'tcx> {
341341
substs: ty::SubstsRef<'tcx>,
342342
requested_kind: ty::ClosureKind,
343343
) -> Instance<'tcx> {
344-
let actual_kind = substs.as_closure().kind(def_id, tcx);
344+
let actual_kind = substs.as_closure().kind();
345345

346346
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
347347
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs),
@@ -372,7 +372,7 @@ impl<'tcx> Instance<'tcx> {
372372

373373
let self_ty = tcx.mk_closure(closure_did, substs);
374374

375-
let sig = substs.as_closure().sig(closure_did, tcx);
375+
let sig = substs.as_closure().sig();
376376
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
377377
assert_eq!(sig.inputs().len(), 1);
378378
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);

src/librustc/ty/layout.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
632632

633633
ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, substs)?,
634634

635-
ty::Closure(def_id, ref substs) => {
636-
let tys = substs.as_closure().upvar_tys(def_id, tcx);
635+
ty::Closure(_, ref substs) => {
636+
let tys = substs.as_closure().upvar_tys();
637637
univariant(
638638
&tys.map(|ty| self.layout_of(ty)).collect::<Result<Vec<_>, _>>()?,
639639
&ReprOptions::default(),
@@ -1406,7 +1406,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14061406
// Build a prefix layout, including "promoting" all ineligible
14071407
// locals as part of the prefix. We compute the layout of all of
14081408
// these fields at once to get optimal packing.
1409-
let discr_index = substs.as_generator().prefix_tys(def_id, tcx).count();
1409+
let discr_index = substs.as_generator().prefix_tys().count();
14101410

14111411
// `info.variant_fields` already accounts for the reserved variants, so no need to add them.
14121412
let max_discr = (info.variant_fields.len() - 1) as u128;
@@ -1423,7 +1423,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14231423
.map(|ty| self.layout_of(ty));
14241424
let prefix_layouts = substs
14251425
.as_generator()
1426-
.prefix_tys(def_id, tcx)
1426+
.prefix_tys()
14271427
.map(|ty| self.layout_of(ty))
14281428
.chain(iter::once(Ok(discr_layout)))
14291429
.chain(promoted_layouts)
@@ -2099,9 +2099,7 @@ where
20992099
ty::Str => tcx.types.u8,
21002100

21012101
// Tuples, generators and closures.
2102-
ty::Closure(def_id, ref substs) => {
2103-
substs.as_closure().upvar_tys(def_id, tcx).nth(i).unwrap()
2104-
}
2102+
ty::Closure(_, ref substs) => substs.as_closure().upvar_tys().nth(i).unwrap(),
21052103

21062104
ty::Generator(def_id, ref substs, _) => match this.variants {
21072105
Variants::Single { index } => substs
@@ -2115,7 +2113,7 @@ where
21152113
if i == discr_index {
21162114
return discr_layout(discr);
21172115
}
2118-
substs.as_generator().prefix_tys(def_id, tcx).nth(i).unwrap()
2116+
substs.as_generator().prefix_tys().nth(i).unwrap()
21192117
}
21202118
},
21212119

@@ -2302,7 +2300,7 @@ impl<'tcx> ty::Instance<'tcx> {
23022300
sig
23032301
}
23042302
ty::Closure(def_id, substs) => {
2305-
let sig = substs.as_closure().sig(def_id, tcx);
2303+
let sig = substs.as_closure().sig();
23062304

23072305
let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
23082306
sig.map_bound(|sig| tcx.mk_fn_sig(
@@ -2313,8 +2311,8 @@ impl<'tcx> ty::Instance<'tcx> {
23132311
sig.abi
23142312
))
23152313
}
2316-
ty::Generator(def_id, substs, _) => {
2317-
let sig = substs.as_generator().poly_sig(def_id, tcx);
2314+
ty::Generator(_, substs, _) => {
2315+
let sig = substs.as_generator().poly_sig();
23182316

23192317
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
23202318
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);

src/librustc/ty/outlives.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo
6161
// in the `subtys` iterator (e.g., when encountering a
6262
// projection).
6363
match ty.kind {
64-
ty::Closure(def_id, ref substs) => {
65-
for upvar_ty in substs.as_closure().upvar_tys(def_id, tcx) {
64+
ty::Closure(_, ref substs) => {
65+
for upvar_ty in substs.as_closure().upvar_tys() {
6666
compute_components(tcx, upvar_ty, out);
6767
}
6868
}
6969

70-
ty::Generator(def_id, ref substs, _) => {
70+
ty::Generator(_, ref substs, _) => {
7171
// Same as the closure case
72-
for upvar_ty in substs.as_generator().upvar_tys(def_id, tcx) {
72+
for upvar_ty in substs.as_generator().upvar_tys() {
7373
compute_components(tcx, upvar_ty, out);
7474
}
7575

src/librustc/ty/print/pretty.rs

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,6 @@ pub trait PrettyPrinter<'tcx>:
617617
}
618618
ty::Str => p!(write("str")),
619619
ty::Generator(did, substs, movability) => {
620-
let upvar_tys = substs.as_generator().upvar_tys(did, self.tcx());
621-
let witness = substs.as_generator().witness(did, self.tcx());
622620
match movability {
623621
hir::Movability::Movable => p!(write("[generator")),
624622
hir::Movability::Static => p!(write("[static generator")),
@@ -627,31 +625,47 @@ pub trait PrettyPrinter<'tcx>:
627625
// FIXME(eddyb) should use `def_span`.
628626
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) {
629627
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
630-
let mut sep = " ";
631-
for (&var_id, upvar_ty) in
632-
self.tcx().upvars(did).as_ref().iter().flat_map(|v| v.keys()).zip(upvar_tys)
633-
{
634-
p!(write("{}{}:", sep, self.tcx().hir().name(var_id)), print(upvar_ty));
635-
sep = ", ";
628+
629+
if substs.as_generator().is_valid() {
630+
let upvar_tys = substs.as_generator().upvar_tys();
631+
let mut sep = " ";
632+
for (&var_id, upvar_ty) in self
633+
.tcx()
634+
.upvars(did)
635+
.as_ref()
636+
.iter()
637+
.flat_map(|v| v.keys())
638+
.zip(upvar_tys)
639+
{
640+
p!(write("{}{}:", sep, self.tcx().hir().name(var_id)), print(upvar_ty));
641+
sep = ", ";
642+
}
636643
}
637644
} else {
638645
// Cross-crate closure types should only be
639646
// visible in codegen bug reports, I imagine.
640647
p!(write("@{:?}", did));
641-
let mut sep = " ";
642-
for (index, upvar_ty) in upvar_tys.enumerate() {
643-
p!(write("{}{}:", sep, index), print(upvar_ty));
644-
sep = ", ";
648+
649+
if substs.as_generator().is_valid() {
650+
let upvar_tys = substs.as_generator().upvar_tys();
651+
let mut sep = " ";
652+
for (index, upvar_ty) in upvar_tys.enumerate() {
653+
p!(write("{}{}:", sep, index), print(upvar_ty));
654+
sep = ", ";
655+
}
645656
}
646657
}
647658

648-
p!(write(" "), print(witness), write("]"))
659+
if substs.as_generator().is_valid() {
660+
p!(write(" "), print(substs.as_generator().witness()));
661+
}
662+
663+
p!(write("]"))
649664
}
650665
ty::GeneratorWitness(types) => {
651666
p!(in_binder(&types));
652667
}
653668
ty::Closure(did, substs) => {
654-
let upvar_tys = substs.as_closure().upvar_tys(did, self.tcx());
655669
p!(write("[closure"));
656670

657671
// FIXME(eddyb) should use `def_span`.
@@ -661,30 +675,43 @@ pub trait PrettyPrinter<'tcx>:
661675
} else {
662676
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
663677
}
664-
let mut sep = " ";
665-
for (&var_id, upvar_ty) in
666-
self.tcx().upvars(did).as_ref().iter().flat_map(|v| v.keys()).zip(upvar_tys)
667-
{
668-
p!(write("{}{}:", sep, self.tcx().hir().name(var_id)), print(upvar_ty));
669-
sep = ", ";
678+
679+
if substs.as_closure().is_valid() {
680+
let upvar_tys = substs.as_closure().upvar_tys();
681+
let mut sep = " ";
682+
for (&var_id, upvar_ty) in self
683+
.tcx()
684+
.upvars(did)
685+
.as_ref()
686+
.iter()
687+
.flat_map(|v| v.keys())
688+
.zip(upvar_tys)
689+
{
690+
p!(write("{}{}:", sep, self.tcx().hir().name(var_id)), print(upvar_ty));
691+
sep = ", ";
692+
}
670693
}
671694
} else {
672695
// Cross-crate closure types should only be
673696
// visible in codegen bug reports, I imagine.
674697
p!(write("@{:?}", did));
675-
let mut sep = " ";
676-
for (index, upvar_ty) in upvar_tys.enumerate() {
677-
p!(write("{}{}:", sep, index), print(upvar_ty));
678-
sep = ", ";
698+
699+
if substs.as_closure().is_valid() {
700+
let upvar_tys = substs.as_closure().upvar_tys();
701+
let mut sep = " ";
702+
for (index, upvar_ty) in upvar_tys.enumerate() {
703+
p!(write("{}{}:", sep, index), print(upvar_ty));
704+
sep = ", ";
705+
}
679706
}
680707
}
681708

682-
if self.tcx().sess.verbose() {
683-
p!(write(
684-
" closure_kind_ty={:?} closure_sig_as_fn_ptr_ty={:?}",
685-
substs.as_closure().kind_ty(did, self.tcx()),
686-
substs.as_closure().sig_as_fn_ptr_ty(did, self.tcx())
687-
));
709+
if self.tcx().sess.verbose() && substs.as_closure().is_valid() {
710+
p!(write(" closure_kind_ty="), print(substs.as_closure().kind_ty()));
711+
p!(
712+
write(" closure_sig_as_fn_ptr_ty="),
713+
print(substs.as_closure().sig_as_fn_ptr_ty())
714+
);
688715
}
689716

690717
p!(write("]"))

0 commit comments

Comments
 (0)