mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-30 09:24:35 +00:00
Create NormalizeTy query
This commit is contained in:
parent
ff8773d7be
commit
113ebe4f1d
@ -635,6 +635,7 @@ define_dep_nodes!( <'tcx>
|
||||
|
||||
// We use this for most things when incr. comp. is turned off.
|
||||
[] Null,
|
||||
[] NormalizeTy,
|
||||
);
|
||||
|
||||
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
|
||||
|
@ -480,16 +480,16 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
{
|
||||
assert!(!value.needs_subst());
|
||||
let value = self.erase_late_bound_regions(value);
|
||||
self.normalize_associated_type(&value)
|
||||
self.normalize_associated_type_in(&value)
|
||||
}
|
||||
|
||||
/// Fully normalizes any associated types in `value`, using an
|
||||
/// empty environment and `Reveal::All` mode (therefore, suitable
|
||||
/// only for monomorphized code during trans, basically).
|
||||
pub fn normalize_associated_type<T>(self, value: &T) -> T
|
||||
pub fn normalize_associated_type_in<T>(self, value: &T) -> T
|
||||
where T: TransNormalize<'tcx>
|
||||
{
|
||||
debug!("normalize_associated_type(t={:?})", value);
|
||||
debug!("normalize_associated_type_in(t={:?})", value);
|
||||
|
||||
let param_env = ty::ParamEnv::empty(Reveal::All);
|
||||
let value = self.erase_regions(value);
|
||||
|
@ -130,10 +130,8 @@ impl<'a, 'gcx> TypeFolder<'gcx, 'gcx> for AssociatedTypeNormalizer<'a, 'gcx> {
|
||||
if !ty.has_projections() {
|
||||
ty
|
||||
} else {
|
||||
self.tcx.trans_trait_caches.project_cache.memoize(ty, || {
|
||||
debug!("AssociatedTypeNormalizer: ty={:?}", ty);
|
||||
self.tcx.normalize_associated_type(&ty)
|
||||
})
|
||||
debug!("AssociatedTypeNormalizer: ty={:?}", ty);
|
||||
self.tcx.normalize_ty(ty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2322,4 +2322,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
tcx.sess.features.borrow().clone_closures
|
||||
};
|
||||
providers.normalize_ty = |tcx, ty| {
|
||||
tcx.normalize_associated_type_in(&ty)
|
||||
};
|
||||
}
|
||||
|
@ -532,3 +532,9 @@ impl<'tcx> QueryDescription for queries::has_copy_closures<'tcx> {
|
||||
format!("seeing if the crate has enabled `Copy` closures")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> QueryDescription for queries::normalize_ty<'tcx> {
|
||||
fn describe(_tcx: TyCtxt, _: Ty) -> String {
|
||||
format!("normalising types")
|
||||
}
|
||||
}
|
@ -349,6 +349,7 @@ define_maps! { <'tcx>
|
||||
// Normally you would just use `tcx.erase_regions(&value)`,
|
||||
// however, which uses this query as a kind of cache.
|
||||
[] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
|
||||
[] fn normalize_ty: normalize_ty_node(Ty<'tcx>) -> Ty<'tcx>,
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -490,3 +491,6 @@ fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
|
||||
fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
|
||||
DepConstructor::VtableMethods{ trait_ref }
|
||||
}
|
||||
fn normalize_ty_node<'tcx>(_: Ty<'tcx>) -> DepConstructor<'tcx> {
|
||||
DepConstructor::NormalizeTy
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
// fields are actually safe.
|
||||
let mut all_phantom = true;
|
||||
for field in &def.struct_variant().fields {
|
||||
let field_ty = cx.normalize_associated_type(&field.ty(cx, substs));
|
||||
let field_ty = cx.normalize_associated_type_in(&field.ty(cx, substs));
|
||||
let r = self.check_type_for_ffi(cache, field_ty);
|
||||
match r {
|
||||
FfiSafe => {
|
||||
@ -463,7 +463,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
|
||||
let mut all_phantom = true;
|
||||
for field in &def.struct_variant().fields {
|
||||
let field_ty = cx.normalize_associated_type(&field.ty(cx, substs));
|
||||
let field_ty = cx.normalize_associated_type_in(&field.ty(cx, substs));
|
||||
let r = self.check_type_for_ffi(cache, field_ty);
|
||||
match r {
|
||||
FfiSafe => {
|
||||
@ -516,7 +516,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
// Check the contained variants.
|
||||
for variant in &def.variants {
|
||||
for field in &variant.fields {
|
||||
let arg = cx.normalize_associated_type(&field.ty(cx, substs));
|
||||
let arg = cx.normalize_associated_type_in(&field.ty(cx, substs));
|
||||
let r = self.check_type_for_ffi(cache, arg);
|
||||
match r {
|
||||
FfiSafe => {}
|
||||
@ -629,7 +629,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
fn check_type_for_ffi_and_report_errors(&mut self, sp: Span, ty: Ty<'tcx>) {
|
||||
// it is only OK to use this function because extern fns cannot have
|
||||
// any generic types right now:
|
||||
let ty = self.cx.tcx.normalize_associated_type(&ty);
|
||||
let ty = self.cx.tcx.normalize_associated_type_in(&ty);
|
||||
|
||||
match self.check_type_for_ffi(&mut FxHashSet(), ty) {
|
||||
FfiResult::FfiSafe => {}
|
||||
|
@ -80,7 +80,7 @@ pub fn compute_fields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>,
|
||||
ty::TyGenerator(def_id, substs, _) => {
|
||||
if variant_index > 0 { bug!("{} is a generator, which only has one variant", t);}
|
||||
substs.field_tys(def_id, cx.tcx()).map(|t| {
|
||||
cx.tcx().normalize_associated_type(&t)
|
||||
cx.tcx().normalize_associated_type_in(&t)
|
||||
}).collect()
|
||||
},
|
||||
_ => bug!("{} is not a type that can have fields.", t)
|
||||
|
@ -642,7 +642,7 @@ impl<'a, 'tcx> LayoutTyper<'tcx> for &'a SharedCrateContext<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn normalize_projections(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
self.tcx().normalize_associated_type(&ty)
|
||||
self.tcx().normalize_associated_type_in(&ty)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -582,7 +582,7 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
}
|
||||
ty::TyGenerator(def_id, substs, _) => {
|
||||
let upvar_tys : Vec<_> = substs.field_tys(def_id, cx.tcx()).map(|t| {
|
||||
cx.tcx().normalize_associated_type(&t)
|
||||
cx.tcx().normalize_associated_type_in(&t)
|
||||
}).collect();
|
||||
prepare_tuple_metadata(cx,
|
||||
t,
|
||||
|
@ -376,7 +376,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
name_to_append_suffix_to.push_str(",");
|
||||
}
|
||||
|
||||
let actual_type = cx.tcx().normalize_associated_type(&actual_type);
|
||||
let actual_type = cx.tcx().normalize_associated_type_in(&actual_type);
|
||||
// Add actual type name to <...> clause of function name
|
||||
let actual_type_name = compute_debuginfo_type_name(cx,
|
||||
actual_type,
|
||||
@ -389,7 +389,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
let template_params: Vec<_> = if cx.sess().opts.debuginfo == FullDebugInfo {
|
||||
let names = get_type_parameter_names(cx, generics);
|
||||
substs.types().zip(names).map(|(ty, name)| {
|
||||
let actual_type = cx.tcx().normalize_associated_type(&ty);
|
||||
let actual_type = cx.tcx().normalize_associated_type_in(&ty);
|
||||
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
|
||||
let name = CString::new(name.as_str().as_bytes()).unwrap();
|
||||
unsafe {
|
||||
|
@ -131,6 +131,6 @@ pub fn field_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
f: &'tcx ty::FieldDef)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
tcx.normalize_associated_type(&f.ty(tcx, param_substs))
|
||||
tcx.normalize_associated_type_in(&f.ty(tcx, param_substs))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user