Skip to content

Commit

Permalink
Remove GeneratorWitness and rename GeneratorWitnessMIR.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Sep 23, 2023
1 parent 855a75b commit 44ac8dc
Show file tree
Hide file tree
Showing 60 changed files with 91 additions and 333 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ fn push_debuginfo_type_name<'tcx>(
| ty::Placeholder(..)
| ty::Alias(..)
| ty::Bound(..)
| ty::GeneratorWitnessMIR(..)
| ty::GeneratorWitness(..) => {
bug!(
"debuginfo: Trying to create type name for \
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/const_eval/valtrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
// FIXME(oli-obk): we can probably encode closures just like structs
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..) |ty::GeneratorWitnessMIR(..)=> Err(ValTreeCreationError::NonSupportedType),
| ty::GeneratorWitness(..) => Err(ValTreeCreationError::NonSupportedType),
}
}

Expand Down Expand Up @@ -280,7 +280,6 @@ pub fn valtree_to_const_value<'tcx>(
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::FnPtr(_)
| ty::RawPtr(_)
| ty::Str
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
| ty::Ref(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Array(..)
| ty::Closure(..)
| ty::Never
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
| ty::Dynamic(_, _, _)
| ty::Closure(_, _)
| ty::Generator(_, _, _)
| ty::GeneratorWitness(_)
| ty::GeneratorWitnessMIR(_, _)
| ty::GeneratorWitness(..)
| ty::Never
| ty::Tuple(_)
| ty::Error(_) => ConstValue::from_target_usize(0u64, &tcx),
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
| ty::Bound(..)
| ty::Param(..)
| ty::Alias(..)
| ty::GeneratorWitnessMIR(..)
| ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty),
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {

ty::Alias(ty::Weak, _) => bug!("type_name: unexpected weak projection"),
ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"),
ty::GeneratorWitness(_) => bug!("type_name: unexpected `GeneratorWitness`"),
ty::GeneratorWitnessMIR(..) => bug!("type_name: unexpected `GeneratorWitnessMIR`"),
ty::GeneratorWitness(..) => bug!("type_name: unexpected `GeneratorWitness`"),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ impl<'tcx> InherentCollect<'tcx> {
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Bound(..)
| ty::Placeholder(_)
| ty::Infer(_) => {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ fn do_orphan_check_impl<'tcx>(
ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Infer(..) => {
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
// types, where we use Error as the Self type
}

ty::Placeholder(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Bound(..)
| ty::Infer(..) => {
ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Bound(..) | ty::Infer(..) => {
bug!("unexpected type encountered in variance inference: {}", ty);
}
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| ty::Float(_)
| ty::Array(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::RawPtr(_)
| ty::Ref(..)
| ty::FnDef(..)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx,
self.tcx.typeck_root_def_id(expr_def_id.to_def_id()),
);
let witness = Ty::new_generator_witness_mir(self.tcx, expr_def_id.to_def_id(), args);
let witness = Ty::new_generator_witness(self.tcx, expr_def_id.to_def_id(), args);

// Unify `interior` with `witness` and collect all the resulting obligations.
let span = self.tcx.hir().body(body_id).value.span;
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Bool
| ty::Char
| ty::Int(..)
Expand Down
20 changes: 0 additions & 20 deletions compiler/rustc_infer/src/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,6 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
.obligations,
);
}
// Optimization of GeneratorWitness relation since we know that all
// free regions are replaced with bound regions during construction.
// This greatly speeds up equating of GeneratorWitness.
(&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => {
let a_types = infcx.tcx.anonymize_bound_vars(a_types);
let b_types = infcx.tcx.anonymize_bound_vars(b_types);
if a_types.bound_vars() == b_types.bound_vars() {
let (a_types, b_types) = infcx.instantiate_binder_with_placeholders(
a_types.map_bound(|a_types| (a_types, b_types.skip_binder())),
);
for (a, b) in std::iter::zip(a_types, b_types) {
self.relate(a, b)?;
}
} else {
return Err(ty::error::TypeError::Sorts(ty::relate::expected_found(
self, a, b,
)));
}
}

_ => {
self.fields.infcx.super_combine_tys(self, a, b)?;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/outlives/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn compute_components<'tcx>(
}

// All regions are bound inside a witness
ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) => (),
ty::GeneratorWitness(..) => (),

// OutlivesTypeParameterEnv -- the actual checking that `X:'a`
// is implied by the environment is done in regionck.
Expand Down
19 changes: 0 additions & 19 deletions compiler/rustc_infer/src/infer/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,6 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
);
Ok(a)
}
// Optimization of GeneratorWitness relation since we know that all
// free regions are replaced with bound regions during construction.
// This greatly speeds up subtyping of GeneratorWitness.
(&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => {
let a_types = infcx.tcx.anonymize_bound_vars(a_types);
let b_types = infcx.tcx.anonymize_bound_vars(b_types);
if a_types.bound_vars() == b_types.bound_vars() {
let (a_types, b_types) = infcx.instantiate_binder_with_placeholders(
a_types.map_bound(|a_types| (a_types, b_types.skip_binder())),
);
for (a, b) in std::iter::zip(a_types, b_types) {
self.relate(a, b)?;
}
Ok(a)
} else {
Err(ty::error::TypeError::Sorts(ty::relate::expected_found(self, a, b)))
}
}

_ => {
self.fields.infcx.super_combine_tys(self, a, b)?;
Ok(a)
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Placeholder(..)
| ty::FnDef(..) => bug!("unexpected type in foreign function: {:?}", ty),
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,6 @@ impl<'tcx> TyCtxt<'tcx> {
Placeholder,
Generator,
GeneratorWitness,
GeneratorWitnessMIR,
Dynamic,
Closure,
Tuple,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ impl<'tcx> Ty<'tcx> {
ty::Dynamic(..) => "trait object".into(),
ty::Closure(..) => "closure".into(),
ty::Generator(def_id, ..) => tcx.generator_kind(def_id).unwrap().descr().into(),
ty::GeneratorWitness(..) |
ty::GeneratorWitnessMIR(..) => "generator witness".into(),
ty::GeneratorWitness(..) => "generator witness".into(),
ty::Infer(ty::TyVar(_)) => "inferred type".into(),
ty::Infer(ty::IntVar(_)) => "integer".into(),
ty::Infer(ty::FloatVar(_)) => "floating-point number".into(),
Expand Down Expand Up @@ -295,7 +294,7 @@ impl<'tcx> Ty<'tcx> {
ty::Dynamic(..) => "trait object".into(),
ty::Closure(..) => "closure".into(),
ty::Generator(def_id, ..) => tcx.generator_kind(def_id).unwrap().descr().into(),
ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) => "generator witness".into(),
ty::GeneratorWitness(..) => "generator witness".into(),
ty::Tuple(..) => "tuple".into(),
ty::Placeholder(..) => "higher-ranked type".into(),
ty::Bound(..) => "bound type variable".into(),
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_middle/src/ty/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ pub enum SimplifiedType {
Trait(DefId),
Closure(DefId),
Generator(DefId),
GeneratorWitness(usize),
GeneratorWitnessMIR(DefId),
GeneratorWitness(DefId),
Function(usize),
Placeholder,
}
Expand Down Expand Up @@ -130,10 +129,7 @@ pub fn simplify_type<'tcx>(
ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)),
ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(SimplifiedType::Closure(def_id)),
ty::Generator(def_id, _, _) => Some(SimplifiedType::Generator(def_id)),
ty::GeneratorWitness(tys) => {
Some(SimplifiedType::GeneratorWitness(tys.skip_binder().len()))
}
ty::GeneratorWitnessMIR(def_id, _) => Some(SimplifiedType::GeneratorWitnessMIR(def_id)),
ty::GeneratorWitness(def_id, _) => Some(SimplifiedType::GeneratorWitness(def_id)),
ty::Never => Some(SimplifiedType::Never),
ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())),
ty::FnPtr(f) => Some(SimplifiedType::Function(f.skip_binder().inputs().len())),
Expand Down Expand Up @@ -169,7 +165,7 @@ impl SimplifiedType {
| SimplifiedType::Trait(d)
| SimplifiedType::Closure(d)
| SimplifiedType::Generator(d)
| SimplifiedType::GeneratorWitnessMIR(d) => Some(d),
| SimplifiedType::GeneratorWitness(d) => Some(d),
_ => None,
}
}
Expand Down Expand Up @@ -240,7 +236,6 @@ impl DeepRejectCtxt {
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Placeholder(..)
| ty::Bound(..)
| ty::Infer(_) => bug!("unexpected impl_ty: {impl_ty}"),
Expand Down Expand Up @@ -342,7 +337,7 @@ impl DeepRejectCtxt {

ty::Error(_) => true,

ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) => {
ty::GeneratorWitness(..) => {
bug!("unexpected obligation type: {:?}", obligation_ty)
}
}
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_middle/src/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ impl FlagComputation {
self.add_ty(args.tupled_upvars_ty());
}

&ty::GeneratorWitness(ts) => {
self.bound_computation(ts, |flags, ts| flags.add_tys(ts));
}

ty::GeneratorWitnessMIR(_, args) => {
ty::GeneratorWitness(_, args) => {
let should_remove_further_specializable =
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
self.add_args(args);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,6 @@ where
| ty::Never
| ty::FnDef(..)
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Foreign(..)
| ty::Dynamic(_, _, ty::Dyn) => {
bug!("TyAndLayout::field({:?}): not applicable", this)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
Ty::new_generator(self.tcx, def_id, args, movability)
}

ty::GeneratorWitnessMIR(def_id, args) => {
ty::GeneratorWitness(def_id, args) => {
let args = self.fold_closure_args(def_id, args);
Ty::new_generator_witness_mir(self.tcx, def_id, args)
Ty::new_generator_witness(self.tcx, def_id, args)
}

ty::Param(param) => {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn characteristic_def_id_of_type_cached<'a>(
ty::FnDef(def_id, _)
| ty::Closure(def_id, _)
| ty::Generator(def_id, _, _)
| ty::GeneratorWitnessMIR(def_id, _)
| ty::GeneratorWitness(def_id, _)
| ty::Foreign(def_id) => Some(def_id),

ty::Bool
Expand All @@ -286,7 +286,6 @@ fn characteristic_def_id_of_type_cached<'a>(
| ty::Infer(_)
| ty::Bound(..)
| ty::Error(_)
| ty::GeneratorWitness(..)
| ty::Never
| ty::Float(_) => None,
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,7 @@ pub trait PrettyPrinter<'tcx>:

p!("}}")
}
ty::GeneratorWitness(types) => {
p!(in_binder(&types));
}
ty::GeneratorWitnessMIR(did, args) => {
ty::GeneratorWitness(did, args) => {
p!(write("{{"));
if !self.tcx().sess.verbose() {
p!("generator witness");
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,24 +453,14 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
Ok(Ty::new_generator(tcx, a_id, args, movability))
}

(&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => {
// Wrap our types with a temporary GeneratorWitness struct
// inside the binder so we can related them
let a_types = a_types.map_bound(GeneratorWitness);
let b_types = b_types.map_bound(GeneratorWitness);
// Then remove the GeneratorWitness for the result
let types = relation.relate(a_types, b_types)?.map_bound(|witness| witness.0);
Ok(Ty::new_generator_witness(tcx, types))
}

(&ty::GeneratorWitnessMIR(a_id, a_args), &ty::GeneratorWitnessMIR(b_id, b_args))
(&ty::GeneratorWitness(a_id, a_args), &ty::GeneratorWitness(b_id, b_args))
if a_id == b_id =>
{
// All GeneratorWitness types with the same id represent
// the (anonymous) type of the same generator expression. So
// all of their regions should be equated.
let args = relation.relate(a_args, b_args)?;
Ok(Ty::new_generator_witness_mir(tcx, a_id, args))
Ok(Ty::new_generator_witness(tcx, a_id, args))
}

(&ty::Closure(a_id, a_args), &ty::Closure(b_id, b_args)) if a_id == b_id => {
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_middle/src/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,8 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
ty::Generator(did, args, movability) => {
ty::Generator(did, args.try_fold_with(folder)?, movability)
}
ty::GeneratorWitness(types) => ty::GeneratorWitness(types.try_fold_with(folder)?),
ty::GeneratorWitnessMIR(did, args) => {
ty::GeneratorWitnessMIR(did, args.try_fold_with(folder)?)
ty::GeneratorWitness(did, args) => {
ty::GeneratorWitness(did, args.try_fold_with(folder)?)
}
ty::Closure(did, args) => ty::Closure(did, args.try_fold_with(folder)?),
ty::Alias(kind, data) => ty::Alias(kind, data.try_fold_with(folder)?),
Expand Down Expand Up @@ -708,8 +707,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
ty.visit_with(visitor)
}
ty::Generator(_did, ref args, _) => args.visit_with(visitor),
ty::GeneratorWitness(ref types) => types.visit_with(visitor),
ty::GeneratorWitnessMIR(_did, ref args) => args.visit_with(visitor),
ty::GeneratorWitness(_did, ref args) => args.visit_with(visitor),
ty::Closure(_did, ref args) => args.visit_with(visitor),
ty::Alias(_, ref data) => data.visit_with(visitor),

Expand Down
Loading

0 comments on commit 44ac8dc

Please sign in to comment.