Skip to content

Commit a789fa0

Browse files
committed
Auto merge of #44984 - Maaarcocr:master, r=nikomatsakis
Create NormalizeTy query As part of the effort to solve #44891, I've created the normalize_ty query. As outlined in the issue this meant: - renamed `normalize_associated_type()` to `normalize_associated_type_in()` - created the `normalize_ty` query - substituted the use of memoize with the query This PR is not ready. While running tests, one of the incremental ones failed. [This](https://pastebin.com/vGhH6bv6) is the error I got.
2 parents 3366247 + 5c51bf5 commit a789fa0

File tree

13 files changed

+37
-39
lines changed

13 files changed

+37
-39
lines changed

src/librustc/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ define_dep_nodes!( <'tcx>
632632
[] CodegenUnit(InternedString),
633633
[] CompileCodegenUnit(InternedString),
634634
[] OutputFilenames,
635-
635+
[anon] NormalizeTy,
636636
// We use this for most things when incr. comp. is turned off.
637637
[] Null,
638638
);

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.fully_normalize_associated_types_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 fully_normalize_associated_types_in<T>(self, value: &T) -> T
490490
where T: TransNormalize<'tcx>
491491
{
492-
debug!("normalize_associated_type(t={:?})", value);
492+
debug!("fully_normalize_associated_types_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

+3-21
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313
// seems likely that they should eventually be merged into more
1414
// general routines.
1515

16-
use dep_graph::{DepGraph, DepKind, DepTrackingMap, DepTrackingMapConfig};
16+
use dep_graph::{DepKind, DepTrackingMapConfig};
1717
use infer::TransNormalize;
18-
use std::cell::RefCell;
1918
use std::marker::PhantomData;
2019
use syntax_pos::DUMMY_SP;
2120
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable};
2221
use ty::{self, Ty, TyCtxt};
2322
use ty::subst::{Subst, Substs};
2423
use ty::fold::{TypeFoldable, TypeFolder};
25-
use util::common::MemoizationMap;
2624

2725
/// Attempts to resolve an obligation to a vtable.. The result is
2826
/// a shallow vtable resolution -- meaning that we do not
@@ -130,24 +128,8 @@ impl<'a, 'gcx> TypeFolder<'gcx, 'gcx> for AssociatedTypeNormalizer<'a, 'gcx> {
130128
if !ty.has_projections() {
131129
ty
132130
} else {
133-
self.tcx.trans_trait_caches.project_cache.memoize(ty, || {
134-
debug!("AssociatedTypeNormalizer: ty={:?}", ty);
135-
self.tcx.normalize_associated_type(&ty)
136-
})
137-
}
138-
}
139-
}
140-
141-
/// Specializes caches used in trans -- in particular, they assume all
142-
/// types are fully monomorphized and that free regions can be erased.
143-
pub struct TransTraitCaches<'tcx> {
144-
project_cache: RefCell<DepTrackingMap<ProjectionCache<'tcx>>>,
145-
}
146-
147-
impl<'tcx> TransTraitCaches<'tcx> {
148-
pub fn new(graph: DepGraph) -> Self {
149-
TransTraitCaches {
150-
project_cache: RefCell::new(DepTrackingMap::new(graph)),
131+
debug!("AssociatedTypeNormalizer: ty={:?}", ty);
132+
self.tcx.fully_normalize_monormophic_ty(ty)
151133
}
152134
}
153135
}

src/librustc/ty/context.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -851,9 +851,6 @@ pub struct GlobalCtxt<'tcx> {
851851

852852
pub sess: &'tcx Session,
853853

854-
855-
pub trans_trait_caches: traits::trans::TransTraitCaches<'tcx>,
856-
857854
pub dep_graph: DepGraph,
858855

859856
/// Common types, pre-interned for your convenience.
@@ -1137,7 +1134,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11371134
tls::enter_global(GlobalCtxt {
11381135
sess: s,
11391136
cstore,
1140-
trans_trait_caches: traits::trans::TransTraitCaches::new(dep_graph.clone()),
11411137
global_arenas: arenas,
11421138
global_interners: interners,
11431139
dep_graph: dep_graph.clone(),
@@ -2322,4 +2318,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
23222318
assert_eq!(cnum, LOCAL_CRATE);
23232319
tcx.sess.features.borrow().clone_closures
23242320
};
2321+
providers.fully_normalize_monormophic_ty = |tcx, ty| {
2322+
tcx.fully_normalize_associated_types_in(&ty)
2323+
};
23252324
}

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::fully_normalize_monormophic_ty<'tcx> {
537+
fn describe(_tcx: TyCtxt, _: Ty) -> String {
538+
format!("normalizing 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 fully_normalize_monormophic_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/ty/maps/plumbing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
697697
DepKind::FulfillObligation |
698698
DepKind::VtableMethods |
699699
DepKind::EraseRegionsTy |
700+
DepKind::NormalizeTy |
700701

701702
// These are just odd
702703
DepKind::Null |

src/librustc_lint/types.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ 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.fully_normalize_associated_types_in(
435+
&field.ty(cx, substs)
436+
);
435437
let r = self.check_type_for_ffi(cache, field_ty);
436438
match r {
437439
FfiSafe => {
@@ -463,7 +465,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
463465

464466
let mut all_phantom = true;
465467
for field in &def.struct_variant().fields {
466-
let field_ty = cx.normalize_associated_type(&field.ty(cx, substs));
468+
let field_ty = cx.fully_normalize_associated_types_in(
469+
&field.ty(cx, substs)
470+
);
467471
let r = self.check_type_for_ffi(cache, field_ty);
468472
match r {
469473
FfiSafe => {
@@ -516,7 +520,9 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
516520
// Check the contained variants.
517521
for variant in &def.variants {
518522
for field in &variant.fields {
519-
let arg = cx.normalize_associated_type(&field.ty(cx, substs));
523+
let arg = cx.fully_normalize_associated_types_in(
524+
&field.ty(cx, substs)
525+
);
520526
let r = self.check_type_for_ffi(cache, arg);
521527
match r {
522528
FfiSafe => {}
@@ -629,7 +635,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
629635
fn check_type_for_ffi_and_report_errors(&mut self, sp: Span, ty: Ty<'tcx>) {
630636
// it is only OK to use this function because extern fns cannot have
631637
// any generic types right now:
632-
let ty = self.cx.tcx.normalize_associated_type(&ty);
638+
let ty = self.cx.tcx.fully_normalize_associated_types_in(&ty);
633639

634640
match self.check_type_for_ffi(&mut FxHashSet(), ty) {
635641
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().fully_normalize_associated_types_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().fully_normalize_associated_types_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().fully_normalize_associated_types_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().fully_normalize_associated_types_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().fully_normalize_associated_types_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.fully_normalize_associated_types_in(&f.ty(tcx, param_substs))
135135
}
136136

0 commit comments

Comments
 (0)