Skip to content

Commit 3f9eba1

Browse files
committed
rustc: clean up lookup_item_type and remove TypeScheme.
1 parent b46ce08 commit 3f9eba1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+400
-492
lines changed

src/librustc/dep_graph/dep_tracking_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
112112
/// switched to `Map(key)`. Therefore, if `op` makes use of any
113113
/// HIR nodes or shared state accessed through its closure
114114
/// environment, it must explicitly register a read of that
115-
/// state. As an example, see `type_scheme_of_item` in `collect`,
115+
/// state. As an example, see `type_of_item` in `collect`,
116116
/// which looks something like this:
117117
///
118118
/// ```
119-
/// fn type_scheme_of_item(..., item: &hir::Item) -> ty::TypeScheme<'tcx> {
119+
/// fn type_of_item(..., item: &hir::Item) -> Ty<'tcx> {
120120
/// let item_def_id = ccx.tcx.map.local_def_id(it.id);
121-
/// ccx.tcx.tcache.memoized(item_def_id, || {
121+
/// ccx.tcx.item_types.memoized(item_def_id, || {
122122
/// ccx.tcx.dep_graph.read(DepNode::Hir(item_def_id)); // (*)
123-
/// compute_type_scheme_of_item(ccx, item)
123+
/// compute_type_of_item(ccx, item)
124124
/// });
125125
/// }
126126
/// ```

src/librustc/infer/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ impl<'a, 'gcx, 'tcx> Rebuilder<'a, 'gcx, 'tcx> {
14361436
match self.tcx.expect_def(cur_ty.id) {
14371437
Def::Enum(did) | Def::TyAlias(did) |
14381438
Def::Struct(did) | Def::Union(did) => {
1439-
let generics = self.tcx.lookup_generics(did);
1439+
let generics = self.tcx.item_generics(did);
14401440

14411441
let expected =
14421442
generics.regions.len() as u32;

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
433433
}
434434

435435
fn should_warn_about_field(&mut self, field: &hir::StructField) -> bool {
436-
let field_type = self.tcx.tables().node_id_to_type(field.id);
436+
let field_type = self.tcx.item_type(self.tcx.map.local_def_id(field.id));
437437
let is_marker_field = match field_type.ty_to_def_id() {
438438
Some(def_id) => self.tcx.lang_items.items().iter().any(|item| *item == Some(def_id)),
439439
_ => false

src/librustc/middle/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct ExprVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
5151

5252
impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
5353
fn def_id_is_transmute(&self, def_id: DefId) -> bool {
54-
let intrinsic = match self.infcx.tcx.lookup_item_type(def_id).ty.sty {
54+
let intrinsic = match self.infcx.tcx.item_type(def_id).sty {
5555
ty::TyFnDef(.., ref bfty) => bfty.abi == RustIntrinsic,
5656
_ => return false
5757
};

src/librustc/middle/liveness.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ use self::VarKind::*;
112112
use dep_graph::DepNode;
113113
use hir::def::*;
114114
use hir::pat_util;
115-
use ty::{self, Ty, TyCtxt, ParameterEnvironment};
115+
use ty::{self, TyCtxt, ParameterEnvironment};
116116
use traits::{self, Reveal};
117117
use ty::subst::Subst;
118118
use lint;
@@ -1440,28 +1440,30 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14401440
}
14411441

14421442
impl<'a, 'tcx> Liveness<'a, 'tcx> {
1443-
fn fn_ret(&self, id: NodeId) -> ty::Binder<Ty<'tcx>> {
1444-
let fn_ty = self.ir.tcx.tables().node_id_to_type(id);
1445-
match fn_ty.sty {
1446-
ty::TyClosure(closure_def_id, substs) =>
1447-
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
1448-
_ => fn_ty.fn_ret()
1449-
}
1450-
}
1451-
14521443
fn check_ret(&self,
14531444
id: NodeId,
14541445
sp: Span,
1455-
_fk: FnKind,
1446+
fk: FnKind,
14561447
entry_ln: LiveNode,
14571448
body: &hir::Expr)
14581449
{
1450+
let fn_ty = if let FnKind::Closure(_) = fk {
1451+
self.ir.tcx.tables().node_id_to_type(id)
1452+
} else {
1453+
self.ir.tcx.item_type(self.ir.tcx.map.local_def_id(id))
1454+
};
1455+
let fn_ret = match fn_ty.sty {
1456+
ty::TyClosure(closure_def_id, substs) =>
1457+
self.ir.tcx.closure_type(closure_def_id, substs).sig.output(),
1458+
_ => fn_ty.fn_ret()
1459+
};
1460+
14591461
// within the fn body, late-bound regions are liberated
14601462
// and must outlive the *call-site* of the function.
14611463
let fn_ret =
14621464
self.ir.tcx.liberate_late_bound_regions(
14631465
self.ir.tcx.region_maps.call_site_extent(id, body.id),
1464-
&self.fn_ret(id));
1466+
&fn_ret);
14651467

14661468
if !fn_ret.is_never() && self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
14671469
let param_env = ParameterEnvironment::for_item(self.ir.tcx, id);

src/librustc/mir/tcx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'tcx> Lvalue<'tcx> {
125125
Lvalue::Local(index) =>
126126
LvalueTy::Ty { ty: mir.local_decls[index].ty },
127127
Lvalue::Static(def_id) =>
128-
LvalueTy::Ty { ty: tcx.lookup_item_type(def_id).ty },
128+
LvalueTy::Ty { ty: tcx.item_type(def_id) },
129129
Lvalue::Projection(ref proj) =>
130130
proj.base.ty(mir, tcx).projection_ty(tcx, &proj.elem),
131131
}
@@ -188,7 +188,7 @@ impl<'tcx> Rvalue<'tcx> {
188188
))
189189
}
190190
AggregateKind::Adt(def, _, substs, _) => {
191-
Some(tcx.lookup_item_type(def.did).ty.subst(tcx, substs))
191+
Some(tcx.item_type(def.did).subst(tcx, substs))
192192
}
193193
AggregateKind::Closure(did, substs) => {
194194
Some(tcx.mk_closure_from_closure_substs(did, substs))

src/librustc/traits/fulfill.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,13 @@ impl<'a, 'gcx, 'tcx> DeferredObligation<'tcx> {
154154
pub fn try_select(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
155155
-> Option<Vec<PredicateObligation<'tcx>>> {
156156
if let ty::TyAnon(def_id, substs) = self.predicate.skip_binder().self_ty().sty {
157+
let ty = if def_id.is_local() {
158+
tcx.item_types.borrow().get(&def_id).cloned()
159+
} else {
160+
Some(tcx.item_type(def_id))
161+
};
157162
// We can resolve the `impl Trait` to its concrete type.
158-
if let Some(ty_scheme) = tcx.opt_lookup_item_type(def_id) {
159-
let concrete_ty = ty_scheme.ty.subst(tcx, substs);
163+
if let Some(concrete_ty) = ty.subst(tcx, substs) {
160164
let predicate = ty::TraitRef {
161165
def_id: self.predicate.def_id(),
162166
substs: tcx.mk_substs_trait(concrete_ty, &[])

src/librustc/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ pub fn get_vtable_methods<'a, 'tcx>(
603603
// do not hold for this particular set of type parameters.
604604
// Note that this method could then never be called, so we
605605
// do not want to try and trans it, in that case (see #23435).
606-
let predicates = tcx.lookup_predicates(def_id).instantiate_own(tcx, substs);
606+
let predicates = tcx.item_predicates(def_id).instantiate_own(tcx, substs);
607607
if !normalize_and_test_predicates(tcx, predicates.predicates) {
608608
debug!("get_vtable_methods: predicates do not hold");
609609
return None;

src/librustc/traits/object_safety.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
129129
let trait_def = self.lookup_trait_def(trait_def_id);
130130
let trait_ref = trait_def.trait_ref.clone();
131131
let trait_ref = trait_ref.to_poly_trait_ref();
132-
let predicates = self.lookup_super_predicates(trait_def_id);
132+
let predicates = self.item_super_predicates(trait_def_id);
133133
predicates
134134
.predicates
135135
.into_iter()
@@ -166,7 +166,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
166166
// Search for a predicate like `Self : Sized` amongst the trait bounds.
167167
let free_substs = self.construct_free_substs(def_id,
168168
self.region_maps.node_extent(ast::DUMMY_NODE_ID));
169-
let predicates = self.lookup_predicates(def_id);
169+
let predicates = self.item_predicates(def_id);
170170
let predicates = predicates.instantiate(self, free_substs).predicates;
171171
elaborate_predicates(self, predicates)
172172
.any(|predicate| {
@@ -238,7 +238,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
238238

239239
// The `Self` type is erased, so it should not appear in list of
240240
// arguments or return type apart from the receiver.
241-
let ref sig = self.lookup_item_type(method.def_id).ty.fn_sig();
241+
let ref sig = self.item_type(method.def_id).fn_sig();
242242
for &input_ty in &sig.0.inputs[1..] {
243243
if self.contains_illegal_self_type_reference(trait_def_id, input_ty) {
244244
return Some(MethodViolationCode::ReferencesSelf);
@@ -249,7 +249,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
249249
}
250250

251251
// We can't monomorphize things like `fn foo<A>(...)`.
252-
if !self.lookup_generics(method.def_id).types.is_empty() {
252+
if !self.item_generics(method.def_id).types.is_empty() {
253253
return Some(MethodViolationCode::Generic);
254254
}
255255

src/librustc/traits/project.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
311311
ty::TyAnon(def_id, substs) if !substs.has_escaping_regions() => { // (*)
312312
// Only normalize `impl Trait` after type-checking, usually in trans.
313313
if self.selcx.projection_mode() == Reveal::All {
314-
let generic_ty = self.tcx().lookup_item_type(def_id).ty;
314+
let generic_ty = self.tcx().item_type(def_id);
315315
let concrete_ty = generic_ty.subst(self.tcx(), substs);
316316
self.fold_ty(concrete_ty)
317317
} else {
@@ -809,7 +809,7 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
809809
};
810810

811811
// If so, extract what we know from the trait and try to come up with a good answer.
812-
let trait_predicates = selcx.tcx().lookup_predicates(def_id);
812+
let trait_predicates = selcx.tcx().item_predicates(def_id);
813813
let bounds = trait_predicates.instantiate(selcx.tcx(), substs);
814814
let bounds = elaborate_predicates(selcx.tcx(), bounds.predicates);
815815
assemble_candidates_from_predicates(selcx,
@@ -1313,7 +1313,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
13131313
obligation.predicate.trait_ref);
13141314
tcx.types.err
13151315
} else {
1316-
tcx.lookup_item_type(node_item.item.def_id).ty
1316+
tcx.item_type(node_item.item.def_id)
13171317
};
13181318
let substs = translate_substs(selcx.infcx(), impl_def_id, substs, node_item.node);
13191319
Progress {

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
12001200
def_id={:?}, substs={:?}",
12011201
def_id, substs);
12021202

1203-
let item_predicates = self.tcx().lookup_predicates(def_id);
1203+
let item_predicates = self.tcx().item_predicates(def_id);
12041204
let bounds = item_predicates.instantiate(self.tcx(), substs);
12051205
debug!("match_projection_obligation_against_definition_bounds: \
12061206
bounds={:?}",
@@ -2884,7 +2884,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
28842884
// obligation will normalize to `<$0 as Iterator>::Item = $1` and
28852885
// `$1: Copy`, so we must ensure the obligations are emitted in
28862886
// that order.
2887-
let predicates = tcx.lookup_predicates(def_id);
2887+
let predicates = tcx.item_predicates(def_id);
28882888
assert_eq!(predicates.parent, None);
28892889
let predicates = predicates.predicates.iter().flat_map(|predicate| {
28902890
let predicate = normalize_with_depth(self, cause.clone(), recursion_depth,

src/librustc/traits/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
128128
match *predicate {
129129
ty::Predicate::Trait(ref data) => {
130130
// Predicates declared on the trait.
131-
let predicates = tcx.lookup_super_predicates(data.def_id());
131+
let predicates = tcx.item_super_predicates(data.def_id());
132132

133133
let mut predicates: Vec<_> =
134134
predicates.predicates
@@ -295,7 +295,7 @@ impl<'cx, 'gcx, 'tcx> Iterator for SupertraitDefIds<'cx, 'gcx, 'tcx> {
295295
None => { return None; }
296296
};
297297

298-
let predicates = self.tcx.lookup_super_predicates(def_id);
298+
let predicates = self.tcx.item_super_predicates(def_id);
299299
let visited = &mut self.visited;
300300
self.stack.extend(
301301
predicates.predicates
@@ -362,7 +362,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a,
362362
let Normalized { value: impl_trait_ref, obligations: normalization_obligations1 } =
363363
super::normalize(selcx, ObligationCause::dummy(), &impl_trait_ref);
364364

365-
let predicates = selcx.tcx().lookup_predicates(impl_def_id);
365+
let predicates = selcx.tcx().item_predicates(impl_def_id);
366366
let predicates = predicates.instantiate(selcx.tcx(), impl_substs);
367367
let Normalized { value: predicates, obligations: normalization_obligations2 } =
368368
super::normalize(selcx, ObligationCause::dummy(), &predicates);

src/librustc/ty/context.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ pub struct GlobalCtxt<'tcx> {
444444
pub maybe_unused_trait_imports: NodeSet,
445445

446446
// Records the type of every item.
447-
pub tcache: RefCell<DepTrackingMap<maps::Tcache<'tcx>>>,
447+
pub item_types: RefCell<DepTrackingMap<maps::Types<'tcx>>>,
448448

449449
// Internal cache for metadata decoding. No need to track deps on this.
450450
pub rcache: RefCell<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
@@ -665,10 +665,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
665665
self.ty_param_defs.borrow().get(&node_id).unwrap().clone()
666666
}
667667

668-
pub fn node_type_insert(self, id: NodeId, ty: Ty<'gcx>) {
669-
self.tables.borrow_mut().node_types.insert(id, ty);
670-
}
671-
672668
pub fn alloc_generics(self, generics: ty::Generics<'gcx>)
673669
-> &'gcx ty::Generics<'gcx> {
674670
self.global_interners.arenas.generics.alloc(generics)
@@ -815,7 +811,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
815811
mir_map: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
816812
freevars: RefCell::new(freevars),
817813
maybe_unused_trait_imports: maybe_unused_trait_imports,
818-
tcache: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
814+
item_types: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
819815
rcache: RefCell::new(FxHashMap()),
820816
tc_cache: RefCell::new(FxHashMap()),
821817
associated_items: RefCell::new(DepTrackingMap::new(dep_graph.clone())),

src/librustc/ty/item_path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
218218
// users may find it useful. Currently, we omit the parent if
219219
// the impl is either in the same module as the self-type or
220220
// as the trait.
221-
let self_ty = self.lookup_item_type(impl_def_id).ty;
221+
let self_ty = self.item_type(impl_def_id);
222222
let in_self_mod = match characteristic_def_id_of_type(self_ty) {
223223
None => false,
224224
Some(ty_def_id) => self.parent_def_id(ty_def_id) == Some(parent_def_id),

src/librustc/ty/maps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ macro_rules! dep_map_ty {
3333
}
3434

3535
dep_map_ty! { AssociatedItems: AssociatedItems(DefId) -> ty::AssociatedItem }
36-
dep_map_ty! { Tcache: ItemSignature(DefId) -> Ty<'tcx> }
36+
dep_map_ty! { Types: ItemSignature(DefId) -> Ty<'tcx> }
3737
dep_map_ty! { Generics: ItemSignature(DefId) -> &'tcx ty::Generics<'tcx> }
3838
dep_map_ty! { Predicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }
3939
dep_map_ty! { SuperPredicates: ItemSignature(DefId) -> ty::GenericPredicates<'tcx> }

0 commit comments

Comments
 (0)