Skip to content

Commit 113ebe4

Browse files
committed
Create NormalizeTy query
1 parent ff8773d commit 113ebe4

File tree

12 files changed

+29
-17
lines changed

12 files changed

+29
-17
lines changed

src/librustc/dep_graph/dep_node.rs

+1
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ define_dep_nodes!( <'tcx>
635635

636636
// We use this for most things when incr. comp. is turned off.
637637
[] Null,
638+
[] NormalizeTy,
638639
);
639640

640641
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -480,16 +480,16 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
480480
{
481481
assert!(!value.needs_subst());
482482
let value = self.erase_late_bound_regions(value);
483-
self.normalize_associated_type(&value)
483+
self.normalize_associated_type_in(&value)
484484
}
485485

486486
/// Fully normalizes any associated types in `value`, using an
487487
/// empty environment and `Reveal::All` mode (therefore, suitable
488488
/// only for monomorphized code during trans, basically).
489-
pub fn normalize_associated_type<T>(self, value: &T) -> T
489+
pub fn normalize_associated_type_in<T>(self, value: &T) -> T
490490
where T: TransNormalize<'tcx>
491491
{
492-
debug!("normalize_associated_type(t={:?})", value);
492+
debug!("normalize_associated_type_in(t={:?})", value);
493493

494494
let param_env = ty::ParamEnv::empty(Reveal::All);
495495
let value = self.erase_regions(value);

src/librustc/traits/trans/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ impl<'a, 'gcx> TypeFolder<'gcx, 'gcx> for AssociatedTypeNormalizer<'a, 'gcx> {
130130
if !ty.has_projections() {
131131
ty
132132
} else {
133-
self.tcx.trans_trait_caches.project_cache.memoize(ty, || {
134-
debug!("AssociatedTypeNormalizer: ty={:?}", ty);
135-
self.tcx.normalize_associated_type(&ty)
136-
})
133+
debug!("AssociatedTypeNormalizer: ty={:?}", ty);
134+
self.tcx.normalize_ty(ty)
137135
}
138136
}
139137
}

src/librustc/ty/context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2322,4 +2322,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
23222322
assert_eq!(cnum, LOCAL_CRATE);
23232323
tcx.sess.features.borrow().clone_closures
23242324
};
2325+
providers.normalize_ty = |tcx, ty| {
2326+
tcx.normalize_associated_type_in(&ty)
2327+
};
23252328
}

src/librustc/ty/maps/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,9 @@ impl<'tcx> QueryDescription for queries::has_copy_closures<'tcx> {
532532
format!("seeing if the crate has enabled `Copy` closures")
533533
}
534534
}
535+
536+
impl<'tcx> QueryDescription for queries::normalize_ty<'tcx> {
537+
fn describe(_tcx: TyCtxt, _: Ty) -> String {
538+
format!("normalising types")
539+
}
540+
}

src/librustc/ty/maps/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ define_maps! { <'tcx>
349349
// Normally you would just use `tcx.erase_regions(&value)`,
350350
// however, which uses this query as a kind of cache.
351351
[] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
352+
[] fn normalize_ty: normalize_ty_node(Ty<'tcx>) -> Ty<'tcx>,
352353
}
353354

354355
//////////////////////////////////////////////////////////////////////
@@ -490,3 +491,6 @@ fn output_filenames_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
490491
fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructor<'tcx> {
491492
DepConstructor::VtableMethods{ trait_ref }
492493
}
494+
fn normalize_ty_node<'tcx>(_: Ty<'tcx>) -> DepConstructor<'tcx> {
495+
DepConstructor::NormalizeTy
496+
}

src/librustc_lint/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
431431
// fields are actually safe.
432432
let mut all_phantom = true;
433433
for field in &def.struct_variant().fields {
434-
let field_ty = cx.normalize_associated_type(&field.ty(cx, substs));
434+
let field_ty = cx.normalize_associated_type_in(&field.ty(cx, substs));
435435
let r = self.check_type_for_ffi(cache, field_ty);
436436
match r {
437437
FfiSafe => {
@@ -463,7 +463,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
463463

464464
let mut all_phantom = true;
465465
for field in &def.struct_variant().fields {
466-
let field_ty = cx.normalize_associated_type(&field.ty(cx, substs));
466+
let field_ty = cx.normalize_associated_type_in(&field.ty(cx, substs));
467467
let r = self.check_type_for_ffi(cache, field_ty);
468468
match r {
469469
FfiSafe => {
@@ -516,7 +516,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
516516
// Check the contained variants.
517517
for variant in &def.variants {
518518
for field in &variant.fields {
519-
let arg = cx.normalize_associated_type(&field.ty(cx, substs));
519+
let arg = cx.normalize_associated_type_in(&field.ty(cx, substs));
520520
let r = self.check_type_for_ffi(cache, arg);
521521
match r {
522522
FfiSafe => {}
@@ -629,7 +629,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
629629
fn check_type_for_ffi_and_report_errors(&mut self, sp: Span, ty: Ty<'tcx>) {
630630
// it is only OK to use this function because extern fns cannot have
631631
// any generic types right now:
632-
let ty = self.cx.tcx.normalize_associated_type(&ty);
632+
let ty = self.cx.tcx.normalize_associated_type_in(&ty);
633633

634634
match self.check_type_for_ffi(&mut FxHashSet(), ty) {
635635
FfiResult::FfiSafe => {}

src/librustc_trans/adt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn compute_fields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>,
8080
ty::TyGenerator(def_id, substs, _) => {
8181
if variant_index > 0 { bug!("{} is a generator, which only has one variant", t);}
8282
substs.field_tys(def_id, cx.tcx()).map(|t| {
83-
cx.tcx().normalize_associated_type(&t)
83+
cx.tcx().normalize_associated_type_in(&t)
8484
}).collect()
8585
},
8686
_ => bug!("{} is not a type that can have fields.", t)

src/librustc_trans/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<'a, 'tcx> LayoutTyper<'tcx> for &'a SharedCrateContext<'a, 'tcx> {
642642
}
643643

644644
fn normalize_projections(self, ty: Ty<'tcx>) -> Ty<'tcx> {
645-
self.tcx().normalize_associated_type(&ty)
645+
self.tcx().normalize_associated_type_in(&ty)
646646
}
647647
}
648648

src/librustc_trans/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
582582
}
583583
ty::TyGenerator(def_id, substs, _) => {
584584
let upvar_tys : Vec<_> = substs.field_tys(def_id, cx.tcx()).map(|t| {
585-
cx.tcx().normalize_associated_type(&t)
585+
cx.tcx().normalize_associated_type_in(&t)
586586
}).collect();
587587
prepare_tuple_metadata(cx,
588588
t,

src/librustc_trans/debuginfo/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
376376
name_to_append_suffix_to.push_str(",");
377377
}
378378

379-
let actual_type = cx.tcx().normalize_associated_type(&actual_type);
379+
let actual_type = cx.tcx().normalize_associated_type_in(&actual_type);
380380
// Add actual type name to <...> clause of function name
381381
let actual_type_name = compute_debuginfo_type_name(cx,
382382
actual_type,
@@ -389,7 +389,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
389389
let template_params: Vec<_> = if cx.sess().opts.debuginfo == FullDebugInfo {
390390
let names = get_type_parameter_names(cx, generics);
391391
substs.types().zip(names).map(|(ty, name)| {
392-
let actual_type = cx.tcx().normalize_associated_type(&ty);
392+
let actual_type = cx.tcx().normalize_associated_type_in(&ty);
393393
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
394394
let name = CString::new(name.as_str().as_bytes()).unwrap();
395395
unsafe {

src/librustc_trans_utils/monomorphize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ pub fn field_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
131131
f: &'tcx ty::FieldDef)
132132
-> Ty<'tcx>
133133
{
134-
tcx.normalize_associated_type(&f.ty(tcx, param_substs))
134+
tcx.normalize_associated_type_in(&f.ty(tcx, param_substs))
135135
}
136136

0 commit comments

Comments
 (0)