1
Fork 0

comments for defining_ty and compute_indices

Plus an extra assertion.
This commit is contained in:
Niko Matsakis 2017-12-12 19:46:36 -05:00
parent 75ac071cd6
commit abd6d0d76e

View file

@ -456,6 +456,21 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
} }
} }
/// Returns the "defining type" of the current MIR:
///
/// - for functions, this is the `TyFnDef`;
/// - for closures, this is the `TyClosure`;
/// - for generators, this is the `TyGenerator`;
/// - for constants, this is the type of value that gets produced.
/// - FIXME. Constants are handled somewhat inelegantly; this gets
/// patched in a later PR that has already landed on nll-master.
///
/// The key feature of the "defining type" is that it contains the
/// information needed to derive all the universal regions that
/// are in scope as well as the types of the inputs/output from
/// the MIR. In general, early-bound universal regions appear free
/// in the defining type and late-bound regions appear bound in
/// the signature.
fn defining_ty(&self) -> ty::Ty<'tcx> { fn defining_ty(&self) -> ty::Ty<'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id);
@ -471,6 +486,10 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
.replace_free_regions_with_nll_infer_vars(FR, &defining_ty) .replace_free_regions_with_nll_infer_vars(FR, &defining_ty)
} }
/// Builds a hashmap that maps from the universal regions that are
/// in scope (as a `ty::Region<'tcx>`) to their indices (as a
/// `RegionVid`). The map returned by this function contains only
/// the early-bound regions.
fn compute_indices( fn compute_indices(
&self, &self,
fr_static: RegionVid, fr_static: RegionVid,
@ -490,6 +509,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
// that correspond to early-bound regions declared on // that correspond to early-bound regions declared on
// the `closure_base_def_id`. // the `closure_base_def_id`.
assert!(substs.substs.len() >= identity_substs.len()); assert!(substs.substs.len() >= identity_substs.len());
assert_eq!(substs.substs.regions().count(), identity_substs.regions().count());
substs.substs substs.substs
} }
ty::TyFnDef(_, substs) => substs, ty::TyFnDef(_, substs) => substs,