Skip to content

Commit 560b1da

Browse files
committed
Auto merge of #26677 - jroesch:fulfillment-context-refactor, r=nrc
This patch implements the next chunk of flattening out the type checking context. In a series of patches I moved around the necessary state and logic in order to delete the `Typer` and `ClosureTyper` traits. My next goal is to clean the interfaces and start to move the normalization code behind them. r? @nrc I hope my PR is coherent, doing this too late at night ;)
2 parents 1768b10 + c64bda3 commit 560b1da

Some content is hidden

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

54 files changed

+477
-604
lines changed

src/librustc/middle/astencode.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use metadata::tydecode::{RegionParameter, ClosureSource};
2626
use metadata::tyencode;
2727
use middle::cast;
2828
use middle::check_const::ConstQualif;
29-
use middle::mem_categorization::Typer;
3029
use middle::privacy::{AllPublic, LastMod};
3130
use middle::subst;
3231
use middle::subst::VecPerParamSpace;

src/librustc/middle/check_const.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,16 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
110110
}
111111

112112
fn with_euv<'b, F, R>(&'b mut self, item_id: Option<ast::NodeId>, f: F) -> R where
113-
F: for<'t> FnOnce(&mut euv::ExprUseVisitor<'b, 't, 'tcx,
114-
ty::ParameterEnvironment<'a, 'tcx>>) -> R,
113+
F: for<'t> FnOnce(&mut euv::ExprUseVisitor<'b, 't, 'b, 'tcx>) -> R,
115114
{
116115
let param_env = match item_id {
117116
Some(item_id) => ty::ParameterEnvironment::for_item(self.tcx, item_id),
118117
None => self.tcx.empty_parameter_environment()
119118
};
120-
f(&mut euv::ExprUseVisitor::new(self, &param_env))
119+
120+
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), false);
121+
122+
f(&mut euv::ExprUseVisitor::new(self, &infcx))
121123
}
122124

123125
fn global_expr(&mut self, mode: Mode, expr: &ast::Expr) -> ConstQualif {
@@ -283,11 +285,11 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
283285

284286
fn check_static_type(&self, e: &ast::Expr) {
285287
let ty = self.tcx.node_id_to_type(e.id);
286-
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None);
287-
let mut fulfill_cx = traits::FulfillmentContext::new(false);
288+
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None, false);
288289
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
290+
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
289291
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
290-
match fulfill_cx.select_all_or_error(&infcx, &infcx.parameter_environment) {
292+
match fulfill_cx.select_all_or_error(&infcx) {
291293
Ok(()) => { },
292294
Err(ref errors) => {
293295
traits::report_fulfillment_errors(&infcx, errors);

src/librustc/middle/check_match.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
2020
use middle::expr_use_visitor::{JustWrite, LoanCause, MutateMode};
2121
use middle::expr_use_visitor::WriteAndRead;
2222
use middle::expr_use_visitor as euv;
23-
use middle::mem_categorization::{cmt, Typer};
23+
use middle::infer;
24+
use middle::mem_categorization::{cmt};
2425
use middle::pat_util::*;
2526
use middle::ty::*;
2627
use middle::ty;
@@ -1111,7 +1112,12 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
11111112
match p.node {
11121113
ast::PatIdent(ast::BindByValue(_), _, ref sub) => {
11131114
let pat_ty = tcx.node_id_to_type(p.id);
1114-
if cx.param_env.type_moves_by_default(pat_ty, pat.span) {
1115+
//FIXME: (@jroesch) this code should be floated up as well
1116+
let infcx = infer::new_infer_ctxt(cx.tcx,
1117+
&cx.tcx.tables,
1118+
Some(cx.param_env.clone()),
1119+
false);
1120+
if infcx.type_moves_by_default(pat_ty, pat.span) {
11151121
check_move(p, sub.as_ref().map(|p| &**p));
11161122
}
11171123
}
@@ -1139,8 +1145,13 @@ fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>,
11391145
let mut checker = MutationChecker {
11401146
cx: cx,
11411147
};
1142-
let mut visitor = ExprUseVisitor::new(&mut checker,
1143-
&checker.cx.param_env);
1148+
1149+
let infcx = infer::new_infer_ctxt(cx.tcx,
1150+
&cx.tcx.tables,
1151+
Some(checker.cx.param_env.clone()),
1152+
false);
1153+
1154+
let mut visitor = ExprUseVisitor::new(&mut checker, &infcx);
11441155
visitor.walk_expr(guard);
11451156
}
11461157

src/librustc/middle/check_rvalues.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// is the public starting point.
1313

1414
use middle::expr_use_visitor as euv;
15+
use middle::infer;
1516
use middle::mem_categorization as mc;
1617
use middle::ty::ParameterEnvironment;
1718
use middle::ty;
@@ -38,9 +39,14 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
3839
s: Span,
3940
fn_id: ast::NodeId) {
4041
{
42+
// FIXME (@jroesch) change this to be an inference context
4143
let param_env = ParameterEnvironment::for_item(self.tcx, fn_id);
44+
let infcx = infer::new_infer_ctxt(self.tcx,
45+
&self.tcx.tables,
46+
Some(param_env.clone()),
47+
false);
4248
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &param_env };
43-
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &param_env);
49+
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx);
4450
euv.walk_fn(fd, b);
4551
}
4652
visit::walk_fn(self, fk, fd, b, s)

src/librustc/middle/const_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,9 +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, &tcx.tables, None);
1034+
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false);
10351035

1036-
let mut selcx = traits::SelectionContext::new(&infcx, &infcx.parameter_environment);
1036+
let mut selcx = traits::SelectionContext::new(&infcx);
10371037
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(),
10381038
trait_ref.to_poly_trait_predicate());
10391039
let selection = match selcx.select(&obligation) {

src/librustc/middle/expr_use_visitor.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use self::TrackMatchMode::*;
2121
use self::OverloadedCallType::*;
2222

2323
use middle::{def, region, pat_util};
24+
use middle::infer;
2425
use middle::mem_categorization as mc;
25-
use middle::mem_categorization::Typer;
2626
use middle::ty::{self};
2727
use middle::ty::{MethodCall, MethodObject, MethodTraitObject};
2828
use middle::ty::{MethodOrigin, MethodParam, MethodTypeParam};
@@ -291,9 +291,9 @@ impl OverloadedCallType {
291291
// supplies types from the tree. After type checking is complete, you
292292
// can just use the tcx as the typer.
293293

294-
pub struct ExprUseVisitor<'d,'t,'tcx:'t,TYPER:'t> {
295-
typer: &'t TYPER,
296-
mc: mc::MemCategorizationContext<'t,TYPER>,
294+
pub struct ExprUseVisitor<'d,'t,'a: 't, 'tcx:'a> {
295+
typer: &'t infer::InferCtxt<'a, 'tcx>,
296+
mc: mc::MemCategorizationContext<'t, 'a, 'tcx>,
297297
delegate: &'d mut (Delegate<'tcx>+'d),
298298
}
299299

@@ -319,10 +319,10 @@ enum PassArgs {
319319
ByRef,
320320
}
321321

322-
impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
322+
impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
323323
pub fn new(delegate: &'d mut Delegate<'tcx>,
324-
typer: &'t TYPER)
325-
-> ExprUseVisitor<'d,'t,'tcx,TYPER> {
324+
typer: &'t infer::InferCtxt<'a, 'tcx>)
325+
-> ExprUseVisitor<'d,'t,'a, 'tcx> {
326326
ExprUseVisitor {
327327
typer: typer,
328328
mc: mc::MemCategorizationContext::new(typer),
@@ -355,7 +355,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
355355
}
356356

357357
fn tcx(&self) -> &'t ty::ctxt<'tcx> {
358-
self.typer.tcx()
358+
self.typer.tcx
359359
}
360360

361361
fn delegate_consume(&mut self,
@@ -690,7 +690,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
690690
match local.init {
691691
None => {
692692
let delegate = &mut self.delegate;
693-
pat_util::pat_bindings(&self.typer.tcx().def_map, &*local.pat,
693+
pat_util::pat_bindings(&self.typer.tcx.def_map, &*local.pat,
694694
|_, id, span, _| {
695695
delegate.decl_without_init(id, span);
696696
})
@@ -1052,7 +1052,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10521052
let delegate = &mut self.delegate;
10531053
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |mc, cmt_pat, pat| {
10541054
if pat_util::pat_is_binding(def_map, pat) {
1055-
let tcx = typer.tcx();
1055+
let tcx = typer.tcx;
10561056

10571057
debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}",
10581058
cmt_pat,
@@ -1139,7 +1139,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
11391139
// the leaves of the pattern tree structure.
11401140
return_if_err!(mc.cat_pattern(cmt_discr, pat, |mc, cmt_pat, pat| {
11411141
let def_map = def_map.borrow();
1142-
let tcx = typer.tcx();
1142+
let tcx = typer.tcx;
11431143

11441144
match pat.node {
11451145
ast::PatEnum(_, _) | ast::PatQPath(..) |
@@ -1278,7 +1278,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
12781278
}
12791279
}
12801280

1281-
fn copy_or_move<'tcx>(typer: &mc::Typer<'tcx>,
1281+
fn copy_or_move<'a, 'tcx>(typer: &infer::InferCtxt<'a, 'tcx>,
12821282
cmt: &mc::cmt<'tcx>,
12831283
move_reason: MoveReason)
12841284
-> ConsumeMode

src/librustc/middle/implicator.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub enum Implication<'tcx> {
3434

3535
struct Implicator<'a, 'tcx: 'a> {
3636
infcx: &'a InferCtxt<'a,'tcx>,
37-
closure_typer: &'a (ty::ClosureTyper<'tcx>+'a),
3837
body_id: ast::NodeId,
3938
stack: Vec<(ty::Region, Option<Ty<'tcx>>)>,
4039
span: Span,
@@ -46,7 +45,6 @@ struct Implicator<'a, 'tcx: 'a> {
4645
/// appear in a context with lifetime `outer_region`
4746
pub fn implications<'a,'tcx>(
4847
infcx: &'a InferCtxt<'a,'tcx>,
49-
closure_typer: &ty::ClosureTyper<'tcx>,
5048
body_id: ast::NodeId,
5149
ty: Ty<'tcx>,
5250
outer_region: ty::Region,
@@ -60,8 +58,7 @@ pub fn implications<'a,'tcx>(
6058

6159
let mut stack = Vec::new();
6260
stack.push((outer_region, None));
63-
let mut wf = Implicator { closure_typer: closure_typer,
64-
infcx: infcx,
61+
let mut wf = Implicator { infcx: infcx,
6562
body_id: body_id,
6663
span: span,
6764
stack: stack,
@@ -404,7 +401,6 @@ impl<'a, 'tcx> Implicator<'a, 'tcx> {
404401
{
405402
let value =
406403
traits::fully_normalize(self.infcx,
407-
self.closure_typer,
408404
traits::ObligationCause::misc(self.span, self.body_id),
409405
value);
410406
match value {

0 commit comments

Comments
 (0)