Skip to content

Commit c6ed442

Browse files
committed
ty: STILL_FURTHER_SPECIALIZABLE w/out prnt subst
This commit modifies the `STILL_FURTHER_SPECIALIZABLE` flag so that the flag isn't set by the parent substs of closures or generators. Signed-off-by: David Wood <david@davidtw.co>
1 parent 576deef commit c6ed442

File tree

2 files changed

+66
-8
lines changed

2 files changed

+66
-8
lines changed

src/librustc_middle/ty/flags.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,19 @@ impl FlagComputation {
8585
}
8686

8787
&ty::Generator(_, ref substs, _) => {
88-
self.add_substs(substs);
88+
let substs = substs.as_generator();
89+
let should_remove_further_specializable =
90+
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
91+
self.add_substs(substs.parent_substs());
92+
if should_remove_further_specializable {
93+
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
94+
}
95+
96+
self.add_ty(substs.resume_ty());
97+
self.add_ty(substs.return_ty());
98+
self.add_ty(substs.witness());
99+
self.add_ty(substs.yield_ty());
100+
self.add_ty(substs.tupled_upvars_ty());
89101
}
90102

91103
&ty::GeneratorWitness(ts) => {
@@ -95,7 +107,17 @@ impl FlagComputation {
95107
}
96108

97109
&ty::Closure(_, substs) => {
98-
self.add_substs(substs);
110+
let substs = substs.as_closure();
111+
let should_remove_further_specializable =
112+
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
113+
self.add_substs(substs.parent_substs());
114+
if should_remove_further_specializable {
115+
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
116+
}
117+
118+
self.add_ty(substs.sig_as_fn_ptr_ty());
119+
self.add_ty(substs.kind_ty());
120+
self.add_ty(substs.tupled_upvars_ty());
99121
}
100122

101123
&ty::Bound(debruijn, _) => {

src/librustc_middle/ty/sty.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ pub struct ClosureSubsts<'tcx> {
318318
/// Struct returned by `split()`. Note that these are subslices of the
319319
/// parent slice and not canonical substs themselves.
320320
struct SplitClosureSubsts<'tcx> {
321+
parent: &'tcx [GenericArg<'tcx>],
321322
closure_kind_ty: GenericArg<'tcx>,
322323
closure_sig_as_fn_ptr_ty: GenericArg<'tcx>,
323324
tupled_upvars_ty: GenericArg<'tcx>,
@@ -329,8 +330,13 @@ impl<'tcx> ClosureSubsts<'tcx> {
329330
/// ordering.
330331
fn split(self) -> SplitClosureSubsts<'tcx> {
331332
match self.substs[..] {
332-
[.., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
333-
SplitClosureSubsts { closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty }
333+
[ref parent @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
334+
SplitClosureSubsts {
335+
parent,
336+
closure_kind_ty,
337+
closure_sig_as_fn_ptr_ty,
338+
tupled_upvars_ty,
339+
}
334340
}
335341
_ => bug!("closure substs missing synthetics"),
336342
}
@@ -345,9 +351,20 @@ impl<'tcx> ClosureSubsts<'tcx> {
345351
self.substs.len() >= 3 && matches!(self.split().tupled_upvars_ty.expect_ty().kind, Tuple(_))
346352
}
347353

354+
/// Returns the substitutions of the closure's parent.
355+
pub fn parent_substs(self) -> &'tcx [GenericArg<'tcx>] {
356+
self.split().parent
357+
}
358+
348359
#[inline]
349360
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
350-
self.split().tupled_upvars_ty.expect_ty().tuple_fields()
361+
self.tupled_upvars_ty().tuple_fields()
362+
}
363+
364+
/// Returns the tuple type representing the upvars for this closure.
365+
#[inline]
366+
pub fn tupled_upvars_ty(self) -> Ty<'tcx> {
367+
self.split().tupled_upvars_ty.expect_ty()
351368
}
352369

353370
/// Returns the closure kind for this closure; may return a type
@@ -392,6 +409,7 @@ pub struct GeneratorSubsts<'tcx> {
392409
}
393410

394411
struct SplitGeneratorSubsts<'tcx> {
412+
parent: &'tcx [GenericArg<'tcx>],
395413
resume_ty: GenericArg<'tcx>,
396414
yield_ty: GenericArg<'tcx>,
397415
return_ty: GenericArg<'tcx>,
@@ -402,8 +420,15 @@ struct SplitGeneratorSubsts<'tcx> {
402420
impl<'tcx> GeneratorSubsts<'tcx> {
403421
fn split(self) -> SplitGeneratorSubsts<'tcx> {
404422
match self.substs[..] {
405-
[.., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
406-
SplitGeneratorSubsts { resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty }
423+
[ref parent @ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
424+
SplitGeneratorSubsts {
425+
parent,
426+
resume_ty,
427+
yield_ty,
428+
return_ty,
429+
witness,
430+
tupled_upvars_ty,
431+
}
407432
}
408433
_ => bug!("generator substs missing synthetics"),
409434
}
@@ -418,6 +443,11 @@ impl<'tcx> GeneratorSubsts<'tcx> {
418443
self.substs.len() >= 5 && matches!(self.split().tupled_upvars_ty.expect_ty().kind, Tuple(_))
419444
}
420445

446+
/// Returns the substitutions of the generator's parent.
447+
pub fn parent_substs(self) -> &'tcx [GenericArg<'tcx>] {
448+
self.split().parent
449+
}
450+
421451
/// This describes the types that can be contained in a generator.
422452
/// It will be a type variable initially and unified in the last stages of typeck of a body.
423453
/// It contains a tuple of all the types that could end up on a generator frame.
@@ -429,7 +459,13 @@ impl<'tcx> GeneratorSubsts<'tcx> {
429459

430460
#[inline]
431461
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
432-
self.split().tupled_upvars_ty.expect_ty().tuple_fields()
462+
self.tupled_upvars_ty().tuple_fields()
463+
}
464+
465+
/// Returns the tuple type representing the upvars for this generator.
466+
#[inline]
467+
pub fn tupled_upvars_ty(self) -> Ty<'tcx> {
468+
self.split().tupled_upvars_ty.expect_ty()
433469
}
434470

435471
/// Returns the type representing the resume type of the generator.

0 commit comments

Comments
 (0)