Skip to content

Commit

Permalink
Rollup merge of rust-lang#39351 - nikomatsakis:incr-comp-skip-typeck-…
Browse files Browse the repository at this point in the history
…1, r=eddyb

move `cast_kinds` into `TypeckTables` where it belongs

r? @eddyb
  • Loading branch information
alexcrichton committed Jan 28, 2017
2 parents 9eb0068 + f4010d7 commit 1767d97
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ pub struct TypeckTables<'tcx> {
/// of the struct - this is needed because it is non-trivial to
/// normalize while preserving regions. This table is used only in
/// MIR construction and hence is not serialized to metadata.
pub fru_field_types: NodeMap<Vec<Ty<'tcx>>>
pub fru_field_types: NodeMap<Vec<Ty<'tcx>>>,

/// Maps a cast expression to its kind. This is keyed on the
/// *from* expression of the cast, not the cast itself.
pub cast_kinds: NodeMap<ty::cast::CastKind>,
}

impl<'tcx> TypeckTables<'tcx> {
Expand All @@ -246,7 +250,8 @@ impl<'tcx> TypeckTables<'tcx> {
closure_tys: NodeMap(),
closure_kinds: NodeMap(),
liberated_fn_sigs: NodeMap(),
fru_field_types: NodeMap()
fru_field_types: NodeMap(),
cast_kinds: NodeMap(),
}
}

Expand Down Expand Up @@ -533,10 +538,6 @@ pub struct GlobalCtxt<'tcx> {
/// expression defining the closure.
pub closure_kinds: RefCell<DepTrackingMap<maps::ClosureKinds<'tcx>>>,

/// Maps a cast expression to its kind. This is keyed on the
/// *from* expression of the cast, not the cast itself.
pub cast_kinds: RefCell<NodeMap<ty::cast::CastKind>>,

/// Maps Fn items to a collection of fragment infos.
///
/// The main goal is to identify data (each of which may be moved
Expand Down Expand Up @@ -792,7 +793,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
custom_coerce_unsized_kinds: RefCell::new(DefIdMap()),
closure_tys: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
closure_kinds: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
cast_kinds: RefCell::new(NodeMap()),
fragment_infos: RefCell::new(DefIdMap()),
crate_name: Symbol::intern(crate_name),
data_layout: data_layout,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
hir::ExprCast(ref source, _) => {
// Check to see if this cast is a "coercion cast", where the cast is actually done
// using a coercion (or is a no-op).
if let Some(&TyCastKind::CoercionCast) = cx.tcx.cast_kinds.borrow().get(&source.id) {
if let Some(&TyCastKind::CoercionCast) = cx.tables().cast_kinds.get(&source.id) {
// Convert the lexpr to a vexpr.
ExprKind::Use { source: source.to_ref() }
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node
}
hir::ExprCast(ref from, _) => {
debug!("Checking const cast(id={})", from.id);
match v.tcx.cast_kinds.borrow().get(&from.id) {
match v.tables.cast_kinds.get(&from.id) {
None => span_bug!(e.span, "no kind for cast"),
Some(&CastKind::PtrAddrCast) | Some(&CastKind::FnPtrAddrCast) => {
v.promotable = false;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
} else if self.try_coercion_cast(fcx) {
self.trivial_cast_lint(fcx);
debug!(" -> CoercionCast");
fcx.tcx.cast_kinds.borrow_mut().insert(self.expr.id, CastKind::CoercionCast);
fcx.tables.borrow_mut().cast_kinds.insert(self.expr.id, CastKind::CoercionCast);
} else {
match self.do_check(fcx) {
Ok(k) => {
debug!(" -> {:?}", k);
fcx.tcx.cast_kinds.borrow_mut().insert(self.expr.id, k);
fcx.tables.borrow_mut().cast_kinds.insert(self.expr.id, k);
}
Err(e) => self.report_cast_error(fcx, e),
};
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
wbcx.visit_anon_types();
wbcx.visit_deferred_obligations(item_id);
wbcx.visit_type_nodes();
wbcx.visit_cast_types();

let tables = self.tcx.alloc_tables(wbcx.tables);
self.tcx.tables.borrow_mut().insert(item_def_id, tables);
Expand Down Expand Up @@ -291,6 +292,15 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
}
}

fn visit_cast_types(&mut self) {
if self.fcx.writeback_errors.get() {
return
}

self.tables.cast_kinds.extend(
self.fcx.tables.borrow().cast_kinds.iter().map(|(&key, &value)| (key, value)));
}

fn visit_anon_types(&self) {
if self.fcx.writeback_errors.get() {
return
Expand Down

0 comments on commit 1767d97

Please sign in to comment.