Refactored ty::ctxt so node_types mutations must go through ty methods.
This commit is contained in:
parent
60289ac7e7
commit
2f7658a528
@ -1197,7 +1197,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
|
||||
})
|
||||
}
|
||||
|
||||
if let Some(ty) = tcx.node_types.borrow().get(&id) {
|
||||
if let Some(ty) = tcx.node_types().get(&id) {
|
||||
rbml_w.tag(c::tag_table_node_type, |rbml_w| {
|
||||
rbml_w.id(id);
|
||||
rbml_w.emit_ty(ecx, *ty);
|
||||
@ -1884,7 +1884,7 @@ fn decode_side_tables(dcx: &DecodeContext,
|
||||
let ty = val_dsr.read_ty(dcx);
|
||||
debug!("inserting ty for node {}: {}",
|
||||
id, ty_to_string(dcx.tcx, ty));
|
||||
dcx.tcx.node_types.borrow_mut().insert(id, ty);
|
||||
dcx.tcx.node_type_insert(id, ty);
|
||||
}
|
||||
c::tag_table_item_subst => {
|
||||
let item_substs = ty::ItemSubsts {
|
||||
|
@ -68,7 +68,7 @@
|
||||
|
||||
use arena::TypedArena;
|
||||
use std::borrow::{Borrow, Cow};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cell::{Cell, RefCell, Ref};
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, SipHasher, Hasher};
|
||||
@ -689,7 +689,7 @@ pub struct ctxt<'tcx> {
|
||||
/// Stores the types for various nodes in the AST. Note that this table
|
||||
/// is not guaranteed to be populated until after typeck. See
|
||||
/// typeck::check::fn_ctxt for details.
|
||||
pub node_types: RefCell<NodeMap<Ty<'tcx>>>,
|
||||
node_types: RefCell<NodeMap<Ty<'tcx>>>,
|
||||
|
||||
/// Stores the type parameters which were substituted to obtain the type
|
||||
/// of this node. This only applies to nodes that refer to entities
|
||||
@ -854,6 +854,13 @@ pub struct ctxt<'tcx> {
|
||||
pub const_qualif_map: RefCell<NodeMap<check_const::ConstQualif>>,
|
||||
}
|
||||
|
||||
impl<'tcx> ctxt<'tcx> {
|
||||
pub fn node_types(&self) -> Ref<NodeMap<Ty<'tcx>>> { self.node_types.borrow() }
|
||||
pub fn node_type_insert(&self, id: NodeId, ty: Ty<'tcx>) {
|
||||
self.node_types.borrow_mut().insert(id, ty);
|
||||
}
|
||||
}
|
||||
|
||||
// Flags that we track on types. These flags are propagated upwards
|
||||
// through the type during type construction, so that we can quickly
|
||||
// check whether the type has various kinds of types in it without
|
||||
|
@ -272,7 +272,7 @@ fn process_formals(&mut self, formals: &Vec<ast::Arg>, qualname: &str) {
|
||||
let typ =
|
||||
ppaux::ty_to_string(
|
||||
&self.analysis.ty_cx,
|
||||
*self.analysis.ty_cx.node_types.borrow().get(&id).unwrap());
|
||||
*self.analysis.ty_cx.node_types().get(&id).unwrap());
|
||||
// get the span only for the name of the variable (I hope the path is only ever a
|
||||
// variable name, but who knows?)
|
||||
self.fmt.formal_str(p.span,
|
||||
@ -436,7 +436,7 @@ fn process_struct_field_def(&mut self,
|
||||
let typ =
|
||||
ppaux::ty_to_string(
|
||||
&self.analysis.ty_cx,
|
||||
*self.analysis.ty_cx.node_types.borrow().get(&field.node.id).unwrap());
|
||||
*self.analysis.ty_cx.node_types().get(&field.node.id).unwrap());
|
||||
match self.span.sub_span_before_token(field.span, token::Colon) {
|
||||
Some(sub_span) => self.fmt.field_str(field.span,
|
||||
Some(sub_span),
|
||||
@ -1471,7 +1471,7 @@ fn visit_local(&mut self, l: &ast::Local) {
|
||||
|
||||
for &(id, ref p, ref immut, _) in &self.collected_paths {
|
||||
let value = if *immut { value.to_string() } else { "<mutable>".to_string() };
|
||||
let types = self.analysis.ty_cx.node_types.borrow();
|
||||
let types = self.analysis.ty_cx.node_types();
|
||||
let typ = ppaux::ty_to_string(&self.analysis.ty_cx, *types.get(&id).unwrap());
|
||||
// Get the span only for the name of the variable (I hope the path
|
||||
// is only ever a variable name, but who knows?).
|
||||
|
@ -3207,7 +3207,7 @@ fn fn_should_be_ignored(fcx: &FunctionContext) -> bool {
|
||||
fn assert_type_for_node_id(cx: &CrateContext,
|
||||
node_id: ast::NodeId,
|
||||
error_reporting_span: Span) {
|
||||
if !cx.tcx().node_types.borrow().contains_key(&node_id) {
|
||||
if !cx.tcx().node_types().contains_key(&node_id) {
|
||||
cx.sess().span_bug(error_reporting_span,
|
||||
"debuginfo: Could not find type for node id!");
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ pub struct CrateCtxt<'a, 'tcx: 'a> {
|
||||
fn write_ty_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>, node_id: ast::NodeId, ty: Ty<'tcx>) {
|
||||
debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_string(tcx, ty));
|
||||
assert!(!ty::type_needs_infer(ty));
|
||||
tcx.node_types.borrow_mut().insert(node_id, ty);
|
||||
tcx.node_type_insert(node_id, ty);
|
||||
}
|
||||
|
||||
fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
|
Loading…
Reference in New Issue
Block a user