Skip to content

Commit 84855fe

Browse files
committed
Auto merge of #26582 - jroesch:infer-ctxt-refactor, r=nikomatsakis
This branch begins the work of unifying our type checking contexts into a single piece of state. The goal is to eventually have a single context that we can pass around instead of the fractured situation we currently have. There are still several things that must be done before beginning to make tables item local: - [ ] move FulfillmentContext into InferCtxt - [ ] modify SelectionContext to only take a single context argument - [ ] remove remaining typer impls - [ ] remove the ClosureTyper + Typer trait - [ ] do some renaming to make these things more applicable to their new roles r? @nikomatsakis As a side note there are a couple oddities that are temporary refactors that will be quickly cleaned up in a follow-up PR. cc @eddyb @Aatch @arielb1 @nrc
2 parents c1b8bd2 + 15bc4a3 commit 84855fe

Some content is hidden

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

50 files changed

+585
-350
lines changed

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#![feature(str_match_indices)]
6262
#![feature(vec_push_all)]
6363
#![feature(wrapping)]
64+
#![feature(cell_extras)]
6465
#![cfg_attr(test, feature(test))]
6566

6667
#![allow(trivial_casts)]

src/librustc/middle/astencode.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10271027
})
10281028
}
10291029

1030-
if let Some(item_substs) = tcx.item_substs.borrow().get(&id) {
1030+
if let Some(item_substs) = tcx.tables.borrow().item_substs.get(&id) {
10311031
rbml_w.tag(c::tag_table_item_subst, |rbml_w| {
10321032
rbml_w.id(id);
10331033
rbml_w.emit_substs(ecx, &item_substs.substs);
@@ -1051,7 +1051,12 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10511051
var_id: var_id,
10521052
closure_expr_id: id
10531053
};
1054-
let upvar_capture = tcx.upvar_capture_map.borrow().get(&upvar_id).unwrap().clone();
1054+
let upvar_capture = tcx.tables
1055+
.borrow()
1056+
.upvar_capture_map
1057+
.get(&upvar_id)
1058+
.unwrap()
1059+
.clone();
10551060
var_id.encode(rbml_w);
10561061
upvar_capture.encode(rbml_w);
10571062
})
@@ -1074,19 +1079,19 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
10741079
}
10751080

10761081
let method_call = MethodCall::expr(id);
1077-
if let Some(method) = tcx.method_map.borrow().get(&method_call) {
1082+
if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) {
10781083
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
10791084
rbml_w.id(id);
10801085
encode_method_callee(ecx, rbml_w, method_call.autoderef, method)
10811086
})
10821087
}
10831088

1084-
if let Some(adjustment) = tcx.adjustments.borrow().get(&id) {
1089+
if let Some(adjustment) = tcx.tables.borrow().adjustments.get(&id) {
10851090
match *adjustment {
10861091
ty::AdjustDerefRef(ref adj) => {
10871092
for autoderef in 0..adj.autoderefs {
10881093
let method_call = MethodCall::autoderef(id, autoderef as u32);
1089-
if let Some(method) = tcx.method_map.borrow().get(&method_call) {
1094+
if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) {
10901095
rbml_w.tag(c::tag_table_method_map, |rbml_w| {
10911096
rbml_w.id(id);
10921097
encode_method_callee(ecx, rbml_w,
@@ -1104,14 +1109,14 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
11041109
})
11051110
}
11061111

1107-
if let Some(closure_type) = tcx.closure_tys.borrow().get(&ast_util::local_def(id)) {
1112+
if let Some(closure_type) = tcx.tables.borrow().closure_tys.get(&ast_util::local_def(id)) {
11081113
rbml_w.tag(c::tag_table_closure_tys, |rbml_w| {
11091114
rbml_w.id(id);
11101115
rbml_w.emit_closure_type(ecx, closure_type);
11111116
})
11121117
}
11131118

1114-
if let Some(closure_kind) = tcx.closure_kinds.borrow().get(&ast_util::local_def(id)) {
1119+
if let Some(closure_kind) = tcx.tables.borrow().closure_kinds.get(&ast_util::local_def(id)) {
11151120
rbml_w.tag(c::tag_table_closure_kinds, |rbml_w| {
11161121
rbml_w.id(id);
11171122
encode_closure_kind(rbml_w, *closure_kind)
@@ -1630,7 +1635,7 @@ fn decode_side_tables(dcx: &DecodeContext,
16301635
let item_substs = ty::ItemSubsts {
16311636
substs: val_dsr.read_substs(dcx)
16321637
};
1633-
dcx.tcx.item_substs.borrow_mut().insert(
1638+
dcx.tcx.tables.borrow_mut().item_substs.insert(
16341639
id, item_substs);
16351640
}
16361641
c::tag_table_freevars => {
@@ -1646,7 +1651,7 @@ fn decode_side_tables(dcx: &DecodeContext,
16461651
closure_expr_id: id
16471652
};
16481653
let ub: ty::UpvarCapture = Decodable::decode(val_dsr).unwrap();
1649-
dcx.tcx.upvar_capture_map.borrow_mut().insert(upvar_id, ub.tr(dcx));
1654+
dcx.tcx.tables.borrow_mut().upvar_capture_map.insert(upvar_id, ub.tr(dcx));
16501655
}
16511656
c::tag_table_tcache => {
16521657
let type_scheme = val_dsr.read_type_scheme(dcx);
@@ -1663,22 +1668,22 @@ fn decode_side_tables(dcx: &DecodeContext,
16631668
expr_id: id,
16641669
autoderef: autoderef
16651670
};
1666-
dcx.tcx.method_map.borrow_mut().insert(method_call, method);
1671+
dcx.tcx.tables.borrow_mut().method_map.insert(method_call, method);
16671672
}
16681673
c::tag_table_adjustments => {
16691674
let adj: ty::AutoAdjustment = val_dsr.read_auto_adjustment(dcx);
1670-
dcx.tcx.adjustments.borrow_mut().insert(id, adj);
1675+
dcx.tcx.tables.borrow_mut().adjustments.insert(id, adj);
16711676
}
16721677
c::tag_table_closure_tys => {
16731678
let closure_ty =
16741679
val_dsr.read_closure_ty(dcx);
1675-
dcx.tcx.closure_tys.borrow_mut().insert(ast_util::local_def(id),
1680+
dcx.tcx.tables.borrow_mut().closure_tys.insert(ast_util::local_def(id),
16761681
closure_ty);
16771682
}
16781683
c::tag_table_closure_kinds => {
16791684
let closure_kind =
16801685
val_dsr.read_closure_kind(dcx);
1681-
dcx.tcx.closure_kinds.borrow_mut().insert(ast_util::local_def(id),
1686+
dcx.tcx.tables.borrow_mut().closure_kinds.insert(ast_util::local_def(id),
16821687
closure_kind);
16831688
}
16841689
c::tag_table_cast_kinds => {

src/librustc/middle/cfg/construct.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
411411
func_or_rcvr: &ast::Expr,
412412
args: I) -> CFGIndex {
413413
let method_call = ty::MethodCall::expr(call_expr.id);
414-
let fn_ty = match self.tcx.method_map.borrow().get(&method_call) {
414+
let fn_ty = match self.tcx.tables.borrow().method_map.get(&method_call) {
415415
Some(method) => method.ty,
416416
None => self.tcx.expr_ty_adjusted(func_or_rcvr)
417417
};
@@ -634,6 +634,6 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
634634

635635
fn is_method_call(&self, expr: &ast::Expr) -> bool {
636636
let method_call = ty::MethodCall::expr(expr.id);
637-
self.tcx.method_map.borrow().contains_key(&method_call)
637+
self.tcx.tables.borrow().method_map.contains_key(&method_call)
638638
}
639639
}

src/librustc/middle/check_const.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,11 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
283283

284284
fn check_static_type(&self, e: &ast::Expr) {
285285
let ty = self.tcx.node_id_to_type(e.id);
286-
let infcx = infer::new_infer_ctxt(self.tcx);
286+
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None);
287287
let mut fulfill_cx = traits::FulfillmentContext::new(false);
288288
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
289289
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
290-
let env = self.tcx.empty_parameter_environment();
291-
match fulfill_cx.select_all_or_error(&infcx, &env) {
290+
match fulfill_cx.select_all_or_error(&infcx, &infcx.parameter_environment) {
292291
Ok(()) => { },
293292
Err(ref errors) => {
294293
traits::report_fulfillment_errors(&infcx, errors);
@@ -544,7 +543,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
544543
match e.node {
545544
ast::ExprUnary(..) |
546545
ast::ExprBinary(..) |
547-
ast::ExprIndex(..) if v.tcx.method_map.borrow().contains_key(&method_call) => {
546+
ast::ExprIndex(..) if v.tcx.tables.borrow().method_map.contains_key(&method_call) => {
548547
v.add_qualif(ConstQualif::NOT_CONST);
549548
if v.mode != Mode::Var {
550549
span_err!(v.tcx.sess, e.span, E0011,
@@ -695,7 +694,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
695694
}
696695
}
697696
ast::ExprMethodCall(..) => {
698-
let method_did = match v.tcx.method_map.borrow()[&method_call].origin {
697+
let method_did = match v.tcx.tables.borrow().method_map[&method_call].origin {
699698
ty::MethodStatic(did) => Some(did),
700699
_ => None
701700
};

src/librustc/middle/check_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl<'a> FromIterator<Vec<&'a Pat>> for Matrix<'a> {
9898
}
9999
}
100100

101+
//NOTE: appears to be the only place other then InferCtxt to contain a ParamEnv
101102
pub struct MatchCheckCtxt<'a, 'tcx: 'a> {
102103
pub tcx: &'a ty::ctxt<'tcx>,
103104
pub param_env: ParameterEnvironment<'a, 'tcx>,

src/librustc/middle/const_eval.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1031,10 +1031,9 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
10311031
substs: trait_substs });
10321032

10331033
tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id());
1034-
let infcx = infer::new_infer_ctxt(tcx);
1034+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
10351035

1036-
let param_env = tcx.empty_parameter_environment();
1037-
let mut selcx = traits::SelectionContext::new(&infcx, &param_env);
1036+
let mut selcx = traits::SelectionContext::new(&infcx, &infcx.parameter_environment);
10381037
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(),
10391038
trait_ref.to_poly_trait_predicate());
10401039
let selection = match selcx.select(&obligation) {

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9696
fn lookup_and_handle_method(&mut self, id: ast::NodeId,
9797
span: codemap::Span) {
9898
let method_call = ty::MethodCall::expr(id);
99-
match self.tcx.method_map.borrow().get(&method_call) {
99+
match self.tcx.tables.borrow().method_map.get(&method_call) {
100100
Some(method) => {
101101
match method.origin {
102102
ty::MethodStatic(def_id) => {

src/librustc/middle/effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
140140
match expr.node {
141141
ast::ExprMethodCall(_, _, _) => {
142142
let method_call = MethodCall::expr(expr.id);
143-
let base_type = self.tcx.method_map.borrow().get(&method_call).unwrap().ty;
143+
let base_type = self.tcx.tables.borrow().method_map.get(&method_call).unwrap().ty;
144144
debug!("effect: method call case, base type is {:?}",
145145
base_type);
146146
if type_is_unsafe_function(base_type) {

src/librustc/middle/expr_use_visitor.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ impl OverloadedCallType {
257257
fn from_closure(tcx: &ty::ctxt, closure_did: ast::DefId)
258258
-> OverloadedCallType {
259259
let trait_did =
260-
tcx.closure_kinds
260+
tcx.tables
261261
.borrow()
262+
.closure_kinds
262263
.get(&closure_did)
263264
.expect("OverloadedCallType::from_closure: didn't find closure id")
264265
.trait_did(tcx);
@@ -787,8 +788,10 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
787788
// process.
788789
fn walk_adjustment(&mut self, expr: &ast::Expr) {
789790
let typer = self.typer;
790-
if let Some(adjustment) = typer.adjustments().borrow().get(&expr.id) {
791-
match *adjustment {
791+
//NOTE(@jroesch): mixed RefCell borrow causes crash
792+
let adj = typer.adjustments().get(&expr.id).map(|x| x.clone());
793+
if let Some(adjustment) = adj {
794+
match adjustment {
792795
ty::AdjustReifyFnPointer |
793796
ty::AdjustUnsafeFnPointer => {
794797
// Creating a closure/fn-pointer or unsizing consumes

0 commit comments

Comments
 (0)