Skip to content

Commit 39d5a61

Browse files
committed
Auto merge of #72983 - Lezzz:rename-typeck, r=nikomatsakis
Rename TypeckTables to TypeckResults. Originally suggested by @eddyb.
2 parents 3014f23 + 1e6adad commit 39d5a61

File tree

222 files changed

+1439
-1313
lines changed

Some content is hidden

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

222 files changed

+1439
-1313
lines changed

src/librustc_driver/pretty.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ where
8080
PpmTyped => {
8181
abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);
8282

83-
let annotation = TypedAnnotation { tcx, maybe_typeck_tables: Cell::new(None) };
83+
let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) };
8484
tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
8585
}
8686
_ => panic!("Should use call_with_pp_support"),
@@ -305,16 +305,18 @@ impl<'a> pprust::PpAnn for HygieneAnnotation<'a> {
305305

306306
struct TypedAnnotation<'tcx> {
307307
tcx: TyCtxt<'tcx>,
308-
maybe_typeck_tables: Cell<Option<&'tcx ty::TypeckTables<'tcx>>>,
308+
maybe_typeck_results: Cell<Option<&'tcx ty::TypeckResults<'tcx>>>,
309309
}
310310

311311
impl<'tcx> TypedAnnotation<'tcx> {
312-
/// Gets the type-checking side-tables for the current body.
312+
/// Gets the type-checking results for the current body.
313313
/// As this will ICE if called outside bodies, only call when working with
314314
/// `Expr` or `Pat` nodes (they are guaranteed to be found only in bodies).
315315
#[track_caller]
316-
fn tables(&self) -> &'tcx ty::TypeckTables<'tcx> {
317-
self.maybe_typeck_tables.get().expect("`TypedAnnotation::tables` called outside of body")
316+
fn typeck_results(&self) -> &'tcx ty::TypeckResults<'tcx> {
317+
self.maybe_typeck_results
318+
.get()
319+
.expect("`TypedAnnotation::typeck_results` called outside of body")
318320
}
319321
}
320322

@@ -338,13 +340,13 @@ impl<'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'tcx> {
338340

339341
impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
340342
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
341-
let old_maybe_typeck_tables = self.maybe_typeck_tables.get();
343+
let old_maybe_typeck_results = self.maybe_typeck_results.get();
342344
if let pprust_hir::Nested::Body(id) = nested {
343-
self.maybe_typeck_tables.set(Some(self.tcx.body_tables(id)));
345+
self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id)));
344346
}
345347
let pp_ann = &(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>);
346348
pprust_hir::PpAnn::nested(pp_ann, state, nested);
347-
self.maybe_typeck_tables.set(old_maybe_typeck_tables);
349+
self.maybe_typeck_results.set(old_maybe_typeck_results);
348350
}
349351
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
350352
if let pprust_hir::AnnNode::Expr(_) = node {
@@ -356,7 +358,7 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
356358
s.s.space();
357359
s.s.word("as");
358360
s.s.space();
359-
s.s.word(self.tables().expr_ty(expr).to_string());
361+
s.s.word(self.typeck_results().expr_ty(expr).to_string());
360362
s.pclose();
361363
}
362364
}

src/librustc_hir/hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ pub enum ExprKind<'hir> {
15711571
/// To resolve the called method to a `DefId`, call [`type_dependent_def_id`] with
15721572
/// the `hir_id` of the `MethodCall` node itself.
15731573
///
1574-
/// [`type_dependent_def_id`]: ../ty/struct.TypeckTables.html#method.type_dependent_def_id
1574+
/// [`type_dependent_def_id`]: ../ty/struct.TypeckResults.html#method.type_dependent_def_id
15751575
MethodCall(&'hir PathSegment<'hir>, Span, &'hir [Expr<'hir>], Span),
15761576
/// A tuple (e.g., `(a, b, c, d)`).
15771577
Tup(&'hir [Expr<'hir>]),
@@ -1659,7 +1659,7 @@ pub enum ExprKind<'hir> {
16591659
///
16601660
/// To resolve the path to a `DefId`, call [`qpath_res`].
16611661
///
1662-
/// [`qpath_res`]: ../rustc_middle/ty/struct.TypeckTables.html#method.qpath_res
1662+
/// [`qpath_res`]: ../rustc_middle/ty/struct.TypeckResults.html#method.qpath_res
16631663
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
16641664
pub enum QPath<'hir> {
16651665
/// Path to a definition, optionally "fully-qualified" with a `Self`

src/librustc_incremental/persist/dirty_clean.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//! we will compare the fingerprint from the current and from the previous
44
//! compilation session as appropriate:
55
//!
6-
//! - `#[rustc_clean(cfg="rev2", except="typeck_tables_of")]` if we are
6+
//! - `#[rustc_clean(cfg="rev2", except="typeck")]` if we are
77
//! in `#[cfg(rev2)]`, then the fingerprints associated with
8-
//! `DepNode::typeck_tables_of(X)` must be DIFFERENT (`X` is the `DefId` of the
8+
//! `DepNode::typeck(X)` must be DIFFERENT (`X` is the `DefId` of the
99
//! current node).
1010
//! - `#[rustc_clean(cfg="rev2")]` same as above, except that the
1111
//! fingerprints must be the SAME (along with all other fingerprints).
@@ -48,7 +48,7 @@ const BASE_FN: &[&str] = &[
4848
label_strs::type_of,
4949
// And a big part of compilation (that we eventually want to cache) is type inference
5050
// information:
51-
label_strs::typeck_tables_of,
51+
label_strs::typeck,
5252
];
5353

5454
/// DepNodes for Hir, which is pretty much everything

src/librustc_infer/infer/error_reporting/mod.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
624624
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
625625
let scrut_ty = if let hir::ExprKind::Call(_, args) = &scrut_expr.kind {
626626
let arg_expr = args.first().expect("try desugaring call w/out arg");
627-
self.in_progress_tables
628-
.and_then(|tables| tables.borrow().expr_ty_opt(arg_expr))
627+
self.in_progress_typeck_results.and_then(|typeck_results| {
628+
typeck_results.borrow().expr_ty_opt(arg_expr)
629+
})
629630
} else {
630631
bug!("try desugaring w/out call expr as scrutinee");
631632
};
@@ -1683,9 +1684,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16831684
let hir = &self.tcx.hir();
16841685
// Attempt to obtain the span of the parameter so we can
16851686
// suggest adding an explicit lifetime bound to it.
1686-
let generics =
1687-
self.in_progress_tables.map(|table| table.borrow().hir_owner).map(|table_owner| {
1688-
let hir_id = hir.as_local_hir_id(table_owner);
1687+
let generics = self
1688+
.in_progress_typeck_results
1689+
.map(|typeck_results| typeck_results.borrow().hir_owner)
1690+
.map(|owner| {
1691+
let hir_id = hir.as_local_hir_id(owner);
16891692
let parent_id = hir.get_parent_item(hir_id);
16901693
(
16911694
// Parent item could be a `mod`, so we check the HIR before calling:
@@ -1698,7 +1701,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16981701
} else {
16991702
None
17001703
},
1701-
self.tcx.generics_of(table_owner.to_def_id()),
1704+
self.tcx.generics_of(owner.to_def_id()),
17021705
)
17031706
});
17041707
let type_param_span = match (generics, bound_kind) {

src/librustc_infer/infer/error_reporting/need_type_info.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
4242
}
4343

4444
fn node_ty_contains_target(&mut self, hir_id: HirId) -> Option<Ty<'tcx>> {
45-
let ty_opt =
46-
self.infcx.in_progress_tables.and_then(|tables| tables.borrow().node_type_opt(hir_id));
45+
let ty_opt = self
46+
.infcx
47+
.in_progress_typeck_results
48+
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
4749
match ty_opt {
4850
Some(ty) => {
4951
let ty = self.infcx.resolve_vars_if_possible(&ty);
@@ -123,8 +125,11 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
123125
if let ExprKind::MethodCall(_, call_span, exprs, _) = expr.kind {
124126
if call_span == self.target_span
125127
&& Some(self.target)
126-
== self.infcx.in_progress_tables.and_then(|tables| {
127-
tables.borrow().node_type_opt(exprs.first().unwrap().hir_id).map(Into::into)
128+
== self.infcx.in_progress_typeck_results.and_then(|typeck_results| {
129+
typeck_results
130+
.borrow()
131+
.node_type_opt(exprs.first().unwrap().hir_id)
132+
.map(Into::into)
128133
})
129134
{
130135
self.found_exact_method_call = Some(&expr);
@@ -580,8 +585,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
580585
e: &Expr<'_>,
581586
err: &mut DiagnosticBuilder<'_>,
582587
) {
583-
if let (Some(tables), None) = (self.in_progress_tables, &segment.args) {
584-
let borrow = tables.borrow();
588+
if let (Some(typeck_results), None) = (self.in_progress_typeck_results, &segment.args) {
589+
let borrow = typeck_results.borrow();
585590
if let Some((DefKind::AssocFn, did)) = borrow.type_dependent_def(e.hir_id) {
586591
let generics = self.tcx.generics_of(did);
587592
if !generics.params.is_empty() {

src/librustc_infer/infer/mod.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
283283
pub struct InferCtxt<'a, 'tcx> {
284284
pub tcx: TyCtxt<'tcx>,
285285

286-
/// During type-checking/inference of a body, `in_progress_tables`
287-
/// contains a reference to the tables being built up, which are
286+
/// During type-checking/inference of a body, `in_progress_typeck_results`
287+
/// contains a reference to the typeck results being built up, which are
288288
/// used for reading closure kinds/signatures as they are inferred,
289289
/// and for error reporting logic to read arbitrary node types.
290-
pub in_progress_tables: Option<&'a RefCell<ty::TypeckTables<'tcx>>>,
290+
pub in_progress_typeck_results: Option<&'a RefCell<ty::TypeckResults<'tcx>>>,
291291

292292
pub inner: RefCell<InferCtxtInner<'tcx>>,
293293

@@ -571,7 +571,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
571571
/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`.
572572
pub struct InferCtxtBuilder<'tcx> {
573573
tcx: TyCtxt<'tcx>,
574-
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
574+
fresh_typeck_results: Option<RefCell<ty::TypeckResults<'tcx>>>,
575575
}
576576

577577
pub trait TyCtxtInferExt<'tcx> {
@@ -580,15 +580,15 @@ pub trait TyCtxtInferExt<'tcx> {
580580

581581
impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
582582
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
583-
InferCtxtBuilder { tcx: self, fresh_tables: None }
583+
InferCtxtBuilder { tcx: self, fresh_typeck_results: None }
584584
}
585585
}
586586

587587
impl<'tcx> InferCtxtBuilder<'tcx> {
588588
/// Used only by `rustc_typeck` during body type-checking/inference,
589-
/// will initialize `in_progress_tables` with fresh `TypeckTables`.
590-
pub fn with_fresh_in_progress_tables(mut self, table_owner: LocalDefId) -> Self {
591-
self.fresh_tables = Some(RefCell::new(ty::TypeckTables::new(table_owner)));
589+
/// will initialize `in_progress_typeck_results` with fresh `TypeckResults`.
590+
pub fn with_fresh_in_progress_typeck_results(mut self, table_owner: LocalDefId) -> Self {
591+
self.fresh_typeck_results = Some(RefCell::new(ty::TypeckResults::new(table_owner)));
592592
self
593593
}
594594

@@ -616,11 +616,11 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
616616
}
617617

618618
pub fn enter<R>(&mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'tcx>) -> R) -> R {
619-
let InferCtxtBuilder { tcx, ref fresh_tables } = *self;
620-
let in_progress_tables = fresh_tables.as_ref();
619+
let InferCtxtBuilder { tcx, ref fresh_typeck_results } = *self;
620+
let in_progress_typeck_results = fresh_typeck_results.as_ref();
621621
f(InferCtxt {
622622
tcx,
623-
in_progress_tables,
623+
in_progress_typeck_results,
624624
inner: RefCell::new(InferCtxtInner::new()),
625625
lexical_region_resolutions: RefCell::new(None),
626626
selection_cache: Default::default(),
@@ -667,7 +667,7 @@ pub struct CombinedSnapshot<'a, 'tcx> {
667667
region_constraints_snapshot: RegionSnapshot,
668668
universe: ty::UniverseIndex,
669669
was_in_snapshot: bool,
670-
_in_progress_tables: Option<Ref<'a, ty::TypeckTables<'tcx>>>,
670+
_in_progress_typeck_results: Option<Ref<'a, ty::TypeckResults<'tcx>>>,
671671
}
672672

673673
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
@@ -789,9 +789,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
789789
region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(),
790790
universe: self.universe(),
791791
was_in_snapshot: in_snapshot,
792-
// Borrow tables "in progress" (i.e., during typeck)
792+
// Borrow typeck results "in progress" (i.e., during typeck)
793793
// to ban writes from within a snapshot to them.
794-
_in_progress_tables: self.in_progress_tables.map(|tables| tables.borrow()),
794+
_in_progress_typeck_results: self
795+
.in_progress_typeck_results
796+
.map(|typeck_results| typeck_results.borrow()),
795797
}
796798
}
797799

@@ -802,7 +804,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
802804
region_constraints_snapshot,
803805
universe,
804806
was_in_snapshot,
805-
_in_progress_tables,
807+
_in_progress_typeck_results,
806808
} = snapshot;
807809

808810
self.in_snapshot.set(was_in_snapshot);
@@ -820,7 +822,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
820822
region_constraints_snapshot: _,
821823
universe: _,
822824
was_in_snapshot,
823-
_in_progress_tables,
825+
_in_progress_typeck_results,
824826
} = snapshot;
825827

826828
self.in_snapshot.set(was_in_snapshot);

src/librustc_lint/array_into_iter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
3131

3232
// Check if the method call actually calls the libcore
3333
// `IntoIterator::into_iter`.
34-
let def_id = cx.tables().type_dependent_def_id(expr.hir_id).unwrap();
34+
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
3535
match cx.tcx.trait_of_item(def_id) {
3636
Some(trait_id) if cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_id) => {}
3737
_ => return,
@@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
4545
// `Box` is the only thing that values can be moved out of via
4646
// method call. `Box::new([1]).into_iter()` should trigger this
4747
// lint.
48-
let mut recv_ty = cx.tables().expr_ty(receiver_arg);
48+
let mut recv_ty = cx.typeck_results().expr_ty(receiver_arg);
4949
let mut num_box_derefs = 0;
5050
while recv_ty.is_box() {
5151
num_box_derefs += 1;
@@ -60,13 +60,13 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
6060
// Make sure that there is an autoref coercion at the expected
6161
// position. The first `num_box_derefs` adjustments are the derefs
6262
// of the box.
63-
match cx.tables().expr_adjustments(receiver_arg).get(num_box_derefs) {
63+
match cx.typeck_results().expr_adjustments(receiver_arg).get(num_box_derefs) {
6464
Some(Adjustment { kind: Adjust::Borrow(_), .. }) => {}
6565
_ => return,
6666
}
6767

6868
// Emit lint diagnostic.
69-
let target = match cx.tables().expr_ty_adjusted(receiver_arg).kind {
69+
let target = match cx.typeck_results().expr_ty_adjusted(receiver_arg).kind {
7070
ty::Ref(_, ty::TyS { kind: ty::Array(..), .. }, _) => "[T; N]",
7171
ty::Ref(_, ty::TyS { kind: ty::Slice(..), .. }, _) => "[T]",
7272

src/librustc_lint/builtin.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
144144
}
145145

146146
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
147-
let ty = cx.tables().node_type(e.hir_id);
147+
let ty = cx.typeck_results().node_type(e.hir_id);
148148
self.check_heap_type(cx, e.span, ty);
149149
}
150150
}
@@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
161161
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &hir::Pat<'_>) {
162162
if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind {
163163
let variant = cx
164-
.tables()
164+
.typeck_results()
165165
.pat_ty(pat)
166166
.ty_adt_def()
167167
.expect("struct pattern type is not an ADT")
@@ -178,7 +178,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
178178
}
179179
if let PatKind::Binding(binding_annot, _, ident, None) = fieldpat.pat.kind {
180180
if cx.tcx.find_field_index(ident, &variant)
181-
== Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables()))
181+
== Some(cx.tcx.field_index(fieldpat.hir_id, cx.typeck_results()))
182182
{
183183
cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, |lint| {
184184
let mut err = lint
@@ -909,7 +909,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
909909
if !def_id_is_transmute(cx, did) {
910910
return None;
911911
}
912-
let sig = cx.tables().node_type(expr.hir_id).fn_sig(cx.tcx);
912+
let sig = cx.typeck_results().node_type(expr.hir_id).fn_sig(cx.tcx);
913913
let from = sig.inputs().skip_binder()[0];
914914
let to = sig.output().skip_binder();
915915
return Some((from, to));
@@ -1901,7 +1901,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
19011901
}
19021902
} else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
19031903
// Find problematic calls to `MaybeUninit::assume_init`.
1904-
let def_id = cx.tables().type_dependent_def_id(expr.hir_id)?;
1904+
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
19051905
if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) {
19061906
// This is a call to *some* method named `assume_init`.
19071907
// See if the `self` parameter is one of the dangerous constructors.
@@ -2020,7 +2020,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
20202020
// This conjures an instance of a type out of nothing,
20212021
// using zeroed or uninitialized memory.
20222022
// We are extremely conservative with what we warn about.
2023-
let conjured_ty = cx.tables().expr_ty(expr);
2023+
let conjured_ty = cx.typeck_results().expr_ty(expr);
20242024
if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty, init) {
20252025
cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| {
20262026
let mut err = lint.build(&format!(

0 commit comments

Comments
 (0)