Skip to content

Commit

Permalink
Auto merge of #72983 - Lezzz:rename-typeck, r=nikomatsakis
Browse files Browse the repository at this point in the history
Rename TypeckTables to TypeckResults.

Originally suggested by @eddyb.
  • Loading branch information
bors committed Jul 17, 2020
2 parents 3014f23 + 1e6adad commit 39d5a61
Show file tree
Hide file tree
Showing 222 changed files with 1,439 additions and 1,313 deletions.
20 changes: 11 additions & 9 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ where
PpmTyped => {
abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);

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

struct TypedAnnotation<'tcx> {
tcx: TyCtxt<'tcx>,
maybe_typeck_tables: Cell<Option<&'tcx ty::TypeckTables<'tcx>>>,
maybe_typeck_results: Cell<Option<&'tcx ty::TypeckResults<'tcx>>>,
}

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

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

impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
let old_maybe_typeck_tables = self.maybe_typeck_tables.get();
let old_maybe_typeck_results = self.maybe_typeck_results.get();
if let pprust_hir::Nested::Body(id) = nested {
self.maybe_typeck_tables.set(Some(self.tcx.body_tables(id)));
self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id)));
}
let pp_ann = &(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>);
pprust_hir::PpAnn::nested(pp_ann, state, nested);
self.maybe_typeck_tables.set(old_maybe_typeck_tables);
self.maybe_typeck_results.set(old_maybe_typeck_results);
}
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
if let pprust_hir::AnnNode::Expr(_) = node {
Expand All @@ -356,7 +358,7 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
s.s.space();
s.s.word("as");
s.s.space();
s.s.word(self.tables().expr_ty(expr).to_string());
s.s.word(self.typeck_results().expr_ty(expr).to_string());
s.pclose();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ pub enum ExprKind<'hir> {
/// To resolve the called method to a `DefId`, call [`type_dependent_def_id`] with
/// the `hir_id` of the `MethodCall` node itself.
///
/// [`type_dependent_def_id`]: ../ty/struct.TypeckTables.html#method.type_dependent_def_id
/// [`type_dependent_def_id`]: ../ty/struct.TypeckResults.html#method.type_dependent_def_id
MethodCall(&'hir PathSegment<'hir>, Span, &'hir [Expr<'hir>], Span),
/// A tuple (e.g., `(a, b, c, d)`).
Tup(&'hir [Expr<'hir>]),
Expand Down Expand Up @@ -1659,7 +1659,7 @@ pub enum ExprKind<'hir> {
///
/// To resolve the path to a `DefId`, call [`qpath_res`].
///
/// [`qpath_res`]: ../rustc_middle/ty/struct.TypeckTables.html#method.qpath_res
/// [`qpath_res`]: ../rustc_middle/ty/struct.TypeckResults.html#method.qpath_res
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
pub enum QPath<'hir> {
/// Path to a definition, optionally "fully-qualified" with a `Self`
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//! we will compare the fingerprint from the current and from the previous
//! compilation session as appropriate:
//!
//! - `#[rustc_clean(cfg="rev2", except="typeck_tables_of")]` if we are
//! - `#[rustc_clean(cfg="rev2", except="typeck")]` if we are
//! in `#[cfg(rev2)]`, then the fingerprints associated with
//! `DepNode::typeck_tables_of(X)` must be DIFFERENT (`X` is the `DefId` of the
//! `DepNode::typeck(X)` must be DIFFERENT (`X` is the `DefId` of the
//! current node).
//! - `#[rustc_clean(cfg="rev2")]` same as above, except that the
//! fingerprints must be the SAME (along with all other fingerprints).
Expand Down Expand Up @@ -48,7 +48,7 @@ const BASE_FN: &[&str] = &[
label_strs::type_of,
// And a big part of compilation (that we eventually want to cache) is type inference
// information:
label_strs::typeck_tables_of,
label_strs::typeck,
];

/// DepNodes for Hir, which is pretty much everything
Expand Down
15 changes: 9 additions & 6 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
let scrut_ty = if let hir::ExprKind::Call(_, args) = &scrut_expr.kind {
let arg_expr = args.first().expect("try desugaring call w/out arg");
self.in_progress_tables
.and_then(|tables| tables.borrow().expr_ty_opt(arg_expr))
self.in_progress_typeck_results.and_then(|typeck_results| {
typeck_results.borrow().expr_ty_opt(arg_expr)
})
} else {
bug!("try desugaring w/out call expr as scrutinee");
};
Expand Down Expand Up @@ -1683,9 +1684,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let hir = &self.tcx.hir();
// Attempt to obtain the span of the parameter so we can
// suggest adding an explicit lifetime bound to it.
let generics =
self.in_progress_tables.map(|table| table.borrow().hir_owner).map(|table_owner| {
let hir_id = hir.as_local_hir_id(table_owner);
let generics = self
.in_progress_typeck_results
.map(|typeck_results| typeck_results.borrow().hir_owner)
.map(|owner| {
let hir_id = hir.as_local_hir_id(owner);
let parent_id = hir.get_parent_item(hir_id);
(
// Parent item could be a `mod`, so we check the HIR before calling:
Expand All @@ -1698,7 +1701,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} else {
None
},
self.tcx.generics_of(table_owner.to_def_id()),
self.tcx.generics_of(owner.to_def_id()),
)
});
let type_param_span = match (generics, bound_kind) {
Expand Down
17 changes: 11 additions & 6 deletions src/librustc_infer/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
}

fn node_ty_contains_target(&mut self, hir_id: HirId) -> Option<Ty<'tcx>> {
let ty_opt =
self.infcx.in_progress_tables.and_then(|tables| tables.borrow().node_type_opt(hir_id));
let ty_opt = self
.infcx
.in_progress_typeck_results
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
match ty_opt {
Some(ty) => {
let ty = self.infcx.resolve_vars_if_possible(&ty);
Expand Down Expand Up @@ -123,8 +125,11 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
if let ExprKind::MethodCall(_, call_span, exprs, _) = expr.kind {
if call_span == self.target_span
&& Some(self.target)
== self.infcx.in_progress_tables.and_then(|tables| {
tables.borrow().node_type_opt(exprs.first().unwrap().hir_id).map(Into::into)
== self.infcx.in_progress_typeck_results.and_then(|typeck_results| {
typeck_results
.borrow()
.node_type_opt(exprs.first().unwrap().hir_id)
.map(Into::into)
})
{
self.found_exact_method_call = Some(&expr);
Expand Down Expand Up @@ -580,8 +585,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
e: &Expr<'_>,
err: &mut DiagnosticBuilder<'_>,
) {
if let (Some(tables), None) = (self.in_progress_tables, &segment.args) {
let borrow = tables.borrow();
if let (Some(typeck_results), None) = (self.in_progress_typeck_results, &segment.args) {
let borrow = typeck_results.borrow();
if let Some((DefKind::AssocFn, did)) = borrow.type_dependent_def(e.hir_id) {
let generics = self.tcx.generics_of(did);
if !generics.params.is_empty() {
Expand Down
34 changes: 18 additions & 16 deletions src/librustc_infer/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
pub struct InferCtxt<'a, 'tcx> {
pub tcx: TyCtxt<'tcx>,

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

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

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

pub trait TyCtxtInferExt<'tcx> {
Expand All @@ -580,15 +580,15 @@ pub trait TyCtxtInferExt<'tcx> {

impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
InferCtxtBuilder { tcx: self, fresh_tables: None }
InferCtxtBuilder { tcx: self, fresh_typeck_results: None }
}
}

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

Expand Down Expand Up @@ -616,11 +616,11 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
}

pub fn enter<R>(&mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'tcx>) -> R) -> R {
let InferCtxtBuilder { tcx, ref fresh_tables } = *self;
let in_progress_tables = fresh_tables.as_ref();
let InferCtxtBuilder { tcx, ref fresh_typeck_results } = *self;
let in_progress_typeck_results = fresh_typeck_results.as_ref();
f(InferCtxt {
tcx,
in_progress_tables,
in_progress_typeck_results,
inner: RefCell::new(InferCtxtInner::new()),
lexical_region_resolutions: RefCell::new(None),
selection_cache: Default::default(),
Expand Down Expand Up @@ -667,7 +667,7 @@ pub struct CombinedSnapshot<'a, 'tcx> {
region_constraints_snapshot: RegionSnapshot,
universe: ty::UniverseIndex,
was_in_snapshot: bool,
_in_progress_tables: Option<Ref<'a, ty::TypeckTables<'tcx>>>,
_in_progress_typeck_results: Option<Ref<'a, ty::TypeckResults<'tcx>>>,
}

impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
Expand Down Expand Up @@ -789,9 +789,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(),
universe: self.universe(),
was_in_snapshot: in_snapshot,
// Borrow tables "in progress" (i.e., during typeck)
// Borrow typeck results "in progress" (i.e., during typeck)
// to ban writes from within a snapshot to them.
_in_progress_tables: self.in_progress_tables.map(|tables| tables.borrow()),
_in_progress_typeck_results: self
.in_progress_typeck_results
.map(|typeck_results| typeck_results.borrow()),
}
}

Expand All @@ -802,7 +804,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
region_constraints_snapshot,
universe,
was_in_snapshot,
_in_progress_tables,
_in_progress_typeck_results,
} = snapshot;

self.in_snapshot.set(was_in_snapshot);
Expand All @@ -820,7 +822,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
region_constraints_snapshot: _,
universe: _,
was_in_snapshot,
_in_progress_tables,
_in_progress_typeck_results,
} = snapshot;

self.in_snapshot.set(was_in_snapshot);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_lint/array_into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {

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

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

Expand Down
12 changes: 6 additions & 6 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
}

fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
let ty = cx.tables().node_type(e.hir_id);
let ty = cx.typeck_results().node_type(e.hir_id);
self.check_heap_type(cx, e.span, ty);
}
}
Expand All @@ -161,7 +161,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &hir::Pat<'_>) {
if let PatKind::Struct(ref qpath, field_pats, _) = pat.kind {
let variant = cx
.tables()
.typeck_results()
.pat_ty(pat)
.ty_adt_def()
.expect("struct pattern type is not an ADT")
Expand All @@ -178,7 +178,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
}
if let PatKind::Binding(binding_annot, _, ident, None) = fieldpat.pat.kind {
if cx.tcx.find_field_index(ident, &variant)
== Some(cx.tcx.field_index(fieldpat.hir_id, cx.tables()))
== Some(cx.tcx.field_index(fieldpat.hir_id, cx.typeck_results()))
{
cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, |lint| {
let mut err = lint
Expand Down Expand Up @@ -909,7 +909,7 @@ impl<'tcx> LateLintPass<'tcx> for MutableTransmutes {
if !def_id_is_transmute(cx, did) {
return None;
}
let sig = cx.tables().node_type(expr.hir_id).fn_sig(cx.tcx);
let sig = cx.typeck_results().node_type(expr.hir_id).fn_sig(cx.tcx);
let from = sig.inputs().skip_binder()[0];
let to = sig.output().skip_binder();
return Some((from, to));
Expand Down Expand Up @@ -1901,7 +1901,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
}
} else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
// Find problematic calls to `MaybeUninit::assume_init`.
let def_id = cx.tables().type_dependent_def_id(expr.hir_id)?;
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) {
// This is a call to *some* method named `assume_init`.
// See if the `self` parameter is one of the dangerous constructors.
Expand Down Expand Up @@ -2020,7 +2020,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
// This conjures an instance of a type out of nothing,
// using zeroed or uninitialized memory.
// We are extremely conservative with what we warn about.
let conjured_ty = cx.tables().expr_ty(expr);
let conjured_ty = cx.typeck_results().expr_ty(expr);
if let Some((msg, span)) = ty_find_init_error(cx.tcx, conjured_ty, init) {
cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| {
let mut err = lint.build(&format!(
Expand Down
Loading

0 comments on commit 39d5a61

Please sign in to comment.