compiler: fold by value
This commit is contained in:
parent
3ec6720bf1
commit
2bf93bd852
140 changed files with 679 additions and 699 deletions
|
@ -876,7 +876,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
}
|
||||
|
||||
// Type-test failed. Report the error.
|
||||
let erased_generic_kind = infcx.tcx.erase_regions(&type_test.generic_kind);
|
||||
let erased_generic_kind = infcx.tcx.erase_regions(type_test.generic_kind);
|
||||
|
||||
// Skip duplicate-ish errors.
|
||||
if deduplicate_errors.insert((
|
||||
|
@ -1006,7 +1006,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
|
||||
debug!("try_promote_type_test_subject(ty = {:?})", ty);
|
||||
|
||||
let ty = tcx.fold_regions(&ty, &mut false, |r, _depth| {
|
||||
let ty = tcx.fold_regions(ty, &mut false, |r, _depth| {
|
||||
let region_vid = self.to_region_vid(r);
|
||||
|
||||
// The challenge if this. We have some region variable `r`
|
||||
|
@ -1248,7 +1248,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
tcx.fold_regions(&value, &mut false, |r, _db| {
|
||||
tcx.fold_regions(value, &mut false, |r, _db| {
|
||||
let vid = self.to_region_vid(r);
|
||||
let scc = self.constraint_sccs.scc(vid);
|
||||
let repr = self.scc_representatives[scc];
|
||||
|
|
|
@ -63,7 +63,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
|
||||
let mut subst_regions = vec![self.universal_regions.fr_static];
|
||||
let universal_substs =
|
||||
infcx.tcx.fold_regions(&substs, &mut false, |region, _| match *region {
|
||||
infcx.tcx.fold_regions(substs, &mut false, |region, _| match *region {
|
||||
ty::ReVar(vid) => {
|
||||
subst_regions.push(vid);
|
||||
self.definitions[vid].external_name.unwrap_or_else(|| {
|
||||
|
@ -94,7 +94,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
subst_regions.dedup();
|
||||
|
||||
let universal_concrete_type =
|
||||
infcx.tcx.fold_regions(&concrete_type, &mut false, |region, _| match *region {
|
||||
infcx.tcx.fold_regions(concrete_type, &mut false, |region, _| match *region {
|
||||
ty::ReVar(vid) => subst_regions
|
||||
.iter()
|
||||
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
|
||||
|
@ -139,7 +139,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
tcx.fold_regions(&ty, &mut false, |region, _| match *region {
|
||||
tcx.fold_regions(ty, &mut false, |region, _| match *region {
|
||||
ty::ReVar(vid) => {
|
||||
// Find something that we can name
|
||||
let upper_bound = self.approx_universal_upper_bound(vid);
|
||||
|
|
|
@ -26,7 +26,7 @@ pub fn renumber_mir<'tcx>(
|
|||
|
||||
/// Replaces all regions appearing in `value` with fresh inference
|
||||
/// variables.
|
||||
pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: &T) -> T
|
||||
pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ struct NLLVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> NLLVisitor<'a, 'tcx> {
|
||||
fn renumber_regions<T>(&mut self, value: &T) -> T
|
||||
fn renumber_regions<T>(&mut self, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
|
|||
_: Location,
|
||||
) -> Option<PlaceElem<'tcx>> {
|
||||
if let PlaceElem::Field(field, ty) = elem {
|
||||
let new_ty = self.renumber_regions(&ty);
|
||||
let new_ty = self.renumber_regions(ty);
|
||||
|
||||
if new_ty != ty {
|
||||
return Some(PlaceElem::Field(field, new_ty));
|
||||
|
@ -83,7 +83,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
|
|||
fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) {
|
||||
debug!("visit_substs(substs={:?}, location={:?})", substs, location);
|
||||
|
||||
*substs = self.renumber_regions(&{ *substs });
|
||||
*substs = self.renumber_regions(*substs);
|
||||
|
||||
debug!("visit_substs: substs={:?}", substs);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
.replace_bound_vars_with_fresh_vars(
|
||||
body.span,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
&poly_sig,
|
||||
poly_sig,
|
||||
)
|
||||
.0,
|
||||
)
|
||||
|
|
|
@ -784,7 +784,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
|||
};
|
||||
|
||||
if let Some(field) = variant.fields.get(field.index()) {
|
||||
Ok(self.cx.normalize(&field.ty(tcx, substs), location))
|
||||
Ok(self.cx.normalize(field.ty(tcx, substs), location))
|
||||
} else {
|
||||
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
|
||||
}
|
||||
|
@ -1245,7 +1245,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
anon_owner_def_id,
|
||||
dummy_body_id,
|
||||
param_env,
|
||||
&anon_ty,
|
||||
anon_ty,
|
||||
locations.span(body),
|
||||
));
|
||||
debug!(
|
||||
|
@ -1271,7 +1271,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
);
|
||||
|
||||
for (&opaque_def_id, opaque_decl) in &opaque_type_map {
|
||||
let resolved_ty = infcx.resolve_vars_if_possible(&opaque_decl.concrete_ty);
|
||||
let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty);
|
||||
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
|
||||
*def_id == opaque_def_id
|
||||
} else {
|
||||
|
@ -1296,7 +1296,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
let subst_opaque_defn_ty =
|
||||
opaque_defn_ty.concrete_type.subst(tcx, opaque_decl.substs);
|
||||
let renumbered_opaque_defn_ty =
|
||||
renumber::renumber_regions(infcx, &subst_opaque_defn_ty);
|
||||
renumber::renumber_regions(infcx, subst_opaque_defn_ty);
|
||||
|
||||
debug!(
|
||||
"eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}",
|
||||
|
@ -1601,7 +1601,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
let (sig, map) = self.infcx.replace_bound_vars_with_fresh_vars(
|
||||
term.source_info.span,
|
||||
LateBoundRegionConversionTime::FnCall,
|
||||
&sig,
|
||||
sig,
|
||||
);
|
||||
let sig = self.normalize(sig, term_location);
|
||||
self.check_call_dest(body, term, &sig, destination, term_location);
|
||||
|
@ -1900,7 +1900,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
// Erase the regions from `ty` to get a global type. The
|
||||
// `Sized` bound in no way depends on precise regions, so this
|
||||
// shouldn't affect `is_sized`.
|
||||
let erased_ty = tcx.erase_regions(&ty);
|
||||
let erased_ty = tcx.erase_regions(ty);
|
||||
if !erased_ty.is_sized(tcx.at(span), self.param_env) {
|
||||
// in current MIR construction, all non-control-flow rvalue
|
||||
// expressions evaluate through `as_temp` or `into` a return
|
||||
|
|
|
@ -438,7 +438,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
|
||||
FR,
|
||||
self.mir_def.did,
|
||||
&bound_inputs_and_output,
|
||||
bound_inputs_and_output,
|
||||
&mut indices,
|
||||
);
|
||||
// Converse of above, if this is a function then the late-bound regions declared on its
|
||||
|
@ -522,7 +522,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
debug!("defining_ty (pre-replacement): {:?}", defining_ty);
|
||||
|
||||
let defining_ty =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, &defining_ty);
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, defining_ty);
|
||||
|
||||
match *defining_ty.kind() {
|
||||
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id, substs),
|
||||
|
@ -543,7 +543,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
assert_eq!(self.mir_def.did.to_def_id(), closure_base_def_id);
|
||||
let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id);
|
||||
let substs =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, &identity_substs);
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs);
|
||||
DefiningTy::Const(self.mir_def.did.to_def_id(), substs)
|
||||
}
|
||||
}
|
||||
|
@ -628,7 +628,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
|
||||
DefiningTy::FnDef(def_id, _) => {
|
||||
let sig = tcx.fn_sig(def_id);
|
||||
let sig = indices.fold_to_region_vids(tcx, &sig);
|
||||
let sig = indices.fold_to_region_vids(tcx, sig);
|
||||
sig.inputs_and_output()
|
||||
}
|
||||
|
||||
|
@ -637,7 +637,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
// "output" (the type of the constant).
|
||||
assert_eq!(self.mir_def.did.to_def_id(), def_id);
|
||||
let ty = tcx.type_of(self.mir_def.def_id_for_type_of());
|
||||
let ty = indices.fold_to_region_vids(tcx, &ty);
|
||||
let ty = indices.fold_to_region_vids(tcx, ty);
|
||||
ty::Binder::dummy(tcx.intern_type_list(&[ty]))
|
||||
}
|
||||
}
|
||||
|
@ -648,7 +648,7 @@ trait InferCtxtExt<'tcx> {
|
|||
fn replace_free_regions_with_nll_infer_vars<T>(
|
||||
&self,
|
||||
origin: NLLRegionVariableOrigin,
|
||||
value: &T,
|
||||
value: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>;
|
||||
|
@ -657,7 +657,7 @@ trait InferCtxtExt<'tcx> {
|
|||
&self,
|
||||
origin: NLLRegionVariableOrigin,
|
||||
all_outlive_scope: LocalDefId,
|
||||
value: &ty::Binder<T>,
|
||||
value: ty::Binder<T>,
|
||||
indices: &mut UniversalRegionIndices<'tcx>,
|
||||
) -> T
|
||||
where
|
||||
|
@ -674,7 +674,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
|
|||
fn replace_free_regions_with_nll_infer_vars<T>(
|
||||
&self,
|
||||
origin: NLLRegionVariableOrigin,
|
||||
value: &T,
|
||||
value: T,
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
|
@ -686,7 +686,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
|
|||
&self,
|
||||
origin: NLLRegionVariableOrigin,
|
||||
all_outlive_scope: LocalDefId,
|
||||
value: &ty::Binder<T>,
|
||||
value: ty::Binder<T>,
|
||||
indices: &mut UniversalRegionIndices<'tcx>,
|
||||
) -> T
|
||||
where
|
||||
|
@ -771,7 +771,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
|
|||
|
||||
/// Replaces all free regions in `value` with region vids, as
|
||||
/// returned by `to_region_vid`.
|
||||
pub fn fold_to_region_vids<T>(&self, tcx: TyCtxt<'tcx>, value: &T) -> T
|
||||
pub fn fold_to_region_vids<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
|
|
|
@ -152,7 +152,7 @@ pub(crate) fn on_all_drop_children_bits<'tcx, F>(
|
|||
let ty = place.ty(body, tcx).ty;
|
||||
debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, place, ty);
|
||||
|
||||
let erased_ty = tcx.erase_regions(&ty);
|
||||
let erased_ty = tcx.erase_regions(ty);
|
||||
if erased_ty.needs_drop(tcx, ctxt.param_env) {
|
||||
each_child(child);
|
||||
} else {
|
||||
|
|
|
@ -505,7 +505,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
|
||||
value: T,
|
||||
) -> T {
|
||||
frame.instance.subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, &value)
|
||||
frame.instance.subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, value)
|
||||
}
|
||||
|
||||
/// The `substs` are assumed to already be in our interpreter "universe" (param_env).
|
||||
|
|
|
@ -21,7 +21,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
|
||||
trace!("get_vtable(trait_ref={:?})", poly_trait_ref);
|
||||
|
||||
let (ty, poly_trait_ref) = self.tcx.erase_regions(&(ty, poly_trait_ref));
|
||||
let (ty, poly_trait_ref) = self.tcx.erase_regions((ty, poly_trait_ref));
|
||||
|
||||
// All vtables must be monomorphic, bail out otherwise.
|
||||
ensure_monomorphic_enough(*self.tcx, ty)?;
|
||||
|
@ -37,7 +37,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
|
||||
let methods = if let Some(poly_trait_ref) = poly_trait_ref {
|
||||
let trait_ref = poly_trait_ref.with_self_ty(*self.tcx, ty);
|
||||
let trait_ref = self.tcx.erase_regions(&trait_ref);
|
||||
let trait_ref = self.tcx.erase_regions(trait_ref);
|
||||
|
||||
self.tcx.vtable_methods(trait_ref)
|
||||
} else {
|
||||
|
@ -143,7 +143,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let drop_instance = self.memory.get_fn(drop_fn)?.as_instance()?;
|
||||
trace!("Found drop fn: {:?}", drop_instance);
|
||||
let fn_sig = drop_instance.ty(*self.tcx, self.param_env).fn_sig(*self.tcx);
|
||||
let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, &fn_sig);
|
||||
let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig);
|
||||
// The drop function takes `*mut T` where `T` is the type being dropped, so get that.
|
||||
let args = fn_sig.inputs();
|
||||
if args.len() != 1 {
|
||||
|
|
|
@ -546,7 +546,7 @@ impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> {
|
|||
self.instance.subst_mir_and_normalize_erasing_regions(
|
||||
self.tcx,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&value,
|
||||
value,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1118,7 +1118,7 @@ impl RootCollector<'_, 'v> {
|
|||
// late-bound regions, since late-bound
|
||||
// regions must appear in the argument
|
||||
// listing.
|
||||
let main_ret_ty = self.tcx.erase_regions(&main_ret_ty.no_bound_vars().unwrap());
|
||||
let main_ret_ty = self.tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap());
|
||||
|
||||
let start_instance = Instance::resolve(
|
||||
self.tcx,
|
||||
|
|
|
@ -304,7 +304,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
|
|||
let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&tcx.type_of(impl_def_id),
|
||||
tcx.type_of(impl_def_id),
|
||||
);
|
||||
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
|
||||
return Some(def_id);
|
||||
|
|
|
@ -135,7 +135,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
|
|||
// Check if this is a generator, if so, return the drop glue for it
|
||||
if let Some(&ty::Generator(gen_def_id, substs, _)) = ty.map(|ty| ty.kind()) {
|
||||
let body = &**tcx.optimized_mir(gen_def_id).generator_drop.as_ref().unwrap();
|
||||
return body.subst(tcx, substs);
|
||||
return body.clone().subst(tcx, substs);
|
||||
}
|
||||
|
||||
let substs = if let Some(ty) = ty {
|
||||
|
@ -144,7 +144,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
|
|||
InternalSubsts::identity_for_item(tcx, def_id)
|
||||
};
|
||||
let sig = tcx.fn_sig(def_id).subst(tcx, substs);
|
||||
let sig = tcx.erase_late_bound_regions(&sig);
|
||||
let sig = tcx.erase_late_bound_regions(sig);
|
||||
let span = tcx.def_span(def_id);
|
||||
|
||||
let source_info = SourceInfo::outermost(span);
|
||||
|
@ -338,7 +338,7 @@ impl CloneShimBuilder<'tcx> {
|
|||
// or access fields of a Place of type TySelf.
|
||||
let substs = tcx.mk_substs_trait(self_ty, &[]);
|
||||
let sig = tcx.fn_sig(def_id).subst(tcx, substs);
|
||||
let sig = tcx.erase_late_bound_regions(&sig);
|
||||
let sig = tcx.erase_late_bound_regions(sig);
|
||||
let span = tcx.def_span(def_id);
|
||||
|
||||
CloneShimBuilder {
|
||||
|
@ -656,7 +656,7 @@ fn build_call_shim<'tcx>(
|
|||
// to substitute into the signature of the shim. It is not necessary for users of this
|
||||
// MIR body to perform further substitutions (see `InstanceDef::has_polymorphic_mir_body`).
|
||||
let (sig_substs, untuple_args) = if let ty::InstanceDef::FnPtrShim(_, ty) = instance {
|
||||
let sig = tcx.erase_late_bound_regions(&ty.fn_sig(tcx));
|
||||
let sig = tcx.erase_late_bound_regions(ty.fn_sig(tcx));
|
||||
|
||||
let untuple_args = sig.inputs();
|
||||
|
||||
|
@ -671,7 +671,7 @@ fn build_call_shim<'tcx>(
|
|||
|
||||
let def_id = instance.def_id();
|
||||
let sig = tcx.fn_sig(def_id);
|
||||
let mut sig = tcx.erase_late_bound_regions(&sig);
|
||||
let mut sig = tcx.erase_late_bound_regions(sig);
|
||||
|
||||
assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body());
|
||||
if let Some(sig_substs) = sig_substs {
|
||||
|
|
|
@ -720,13 +720,13 @@ fn sanitize_witness<'tcx>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
body: &Body<'tcx>,
|
||||
witness: Ty<'tcx>,
|
||||
upvars: &Vec<Ty<'tcx>>,
|
||||
upvars: Vec<Ty<'tcx>>,
|
||||
saved_locals: &GeneratorSavedLocals,
|
||||
) {
|
||||
let did = body.source.def_id();
|
||||
let allowed_upvars = tcx.erase_regions(upvars);
|
||||
let allowed = match witness.kind() {
|
||||
ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(&s),
|
||||
&ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(s),
|
||||
_ => {
|
||||
tcx.sess.delay_span_bug(
|
||||
body.span,
|
||||
|
@ -1303,7 +1303,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
|||
let liveness_info =
|
||||
locals_live_across_suspend_points(tcx, body, &always_live_locals, movable);
|
||||
|
||||
sanitize_witness(tcx, body, interior, &upvars, &liveness_info.saved_locals);
|
||||
sanitize_witness(tcx, body, interior, upvars, &liveness_info.saved_locals);
|
||||
|
||||
if tcx.sess.opts.debugging_opts.validate_mir {
|
||||
let mut vis = EnsureGeneratorFieldAssignmentsNeverAlias {
|
||||
|
|
|
@ -122,7 +122,7 @@ impl Inliner<'tcx> {
|
|||
let callee_body = callsite.callee.subst_mir_and_normalize_erasing_regions(
|
||||
self.tcx,
|
||||
self.param_env,
|
||||
callee_body,
|
||||
callee_body.clone(),
|
||||
);
|
||||
|
||||
let old_blocks = caller_body.basic_blocks().next_index();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue