Skip to content

Commit 05c57e0

Browse files
committed
Remove Typer + ClosureTyper impls for BlockS
1 parent e2d7e90 commit 05c57e0

File tree

9 files changed

+32
-123
lines changed

9 files changed

+32
-123
lines changed

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ 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-
infer::InferCtxt<'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),

src/librustc/middle/check_rvalues.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
4141
{
4242
// FIXME (@jroesch) change this to be an inference context
4343
let param_env = ParameterEnvironment::for_item(self.tcx, fn_id);
44-
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), false);
45-
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &infcx.parameter_environment };
44+
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env.clone()), false);
45+
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &param_env };
4646
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx);
4747
euv.walk_fn(fd, b);
4848
}

src/librustc/middle/expr_use_visitor.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ 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;
2526
use middle::mem_categorization::Typer;
26-
use middle::ty::{self};
27+
use middle::ty::{self, ClosureTyper};
2728
use middle::ty::{MethodCall, MethodObject, MethodTraitObject};
2829
use middle::ty::{MethodOrigin, MethodParam, MethodTypeParam};
2930
use middle::ty::{MethodStatic, MethodStaticClosure};
@@ -291,9 +292,9 @@ impl OverloadedCallType {
291292
// supplies types from the tree. After type checking is complete, you
292293
// can just use the tcx as the typer.
293294

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

@@ -319,10 +320,10 @@ enum PassArgs {
319320
ByRef,
320321
}
321322

322-
impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
323+
impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
323324
pub fn new(delegate: &'d mut Delegate<'tcx>,
324-
typer: &'t TYPER)
325-
-> ExprUseVisitor<'d,'t,'tcx,TYPER> {
325+
typer: &'t infer::InferCtxt<'a, 'tcx>)
326+
-> ExprUseVisitor<'d,'t,'a, 'tcx> {
326327
ExprUseVisitor {
327328
typer: typer,
328329
mc: mc::MemCategorizationContext::new(typer),

src/librustc/middle/infer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use middle::region::CodeExtent;
3030
use middle::subst;
3131
use middle::subst::Substs;
3232
use middle::subst::Subst;
33-
use middle::traits::{self, FulfillmentContext, Normalized, MiscObligation,
33+
use middle::traits::{self, FulfillmentContext, Normalized,
3434
SelectionContext, ObligationCause};
3535
use middle::ty::{TyVid, IntVid, FloatVid, RegionVid, UnconstrainedNumeric};
3636
use middle::ty::{self, Ty, HasTypeFlags};
@@ -477,7 +477,7 @@ pub struct CombinedSnapshot {
477477

478478
impl<'a, 'tcx> mc::Typer<'tcx> for InferCtxt<'a, 'tcx> {
479479
fn node_ty(&self, id: ast::NodeId) -> McResult<Ty<'tcx>> {
480-
let ty = self.node_ty(id);
480+
let ty = self.node_type(id);
481481
self.resolve_type_vars_or_error(&ty)
482482
}
483483

@@ -1183,7 +1183,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11831183
.map(|method| resolve_ty(method.ty)))
11841184
}
11851185

1186-
pub fn node_ty(&self, id: ast::NodeId) -> Ty<'tcx> {
1186+
pub fn node_type(&self, id: ast::NodeId) -> Ty<'tcx> {
11871187
match self.tables.borrow().node_types.get(&id) {
11881188
Some(&t) => t,
11891189
// FIXME

src/librustc/middle/mem_categorization.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ pub use self::categorization::*;
7373
use self::Aliasability::*;
7474

7575
use ast_map;
76+
use middle::infer;
7677
use middle::check_const;
7778
use middle::def;
7879
use middle::region;
79-
use middle::ty::{self, Ty};
80+
use middle::ty::{self, Ty, ClosureTyper};
8081
use util::nodemap::NodeMap;
8182

8283
use syntax::ast::{MutImmutable, MutMutable};
@@ -255,13 +256,10 @@ impl ast_node for ast::Pat {
255256
fn span(&self) -> Span { self.span }
256257
}
257258

258-
pub struct MemCategorizationContext<'t,TYPER:'t> {
259-
typer: &'t TYPER
260-
}
261-
262-
impl<'t,TYPER:'t> Copy for MemCategorizationContext<'t,TYPER> {}
263-
impl<'t,TYPER:'t> Clone for MemCategorizationContext<'t,TYPER> {
264-
fn clone(&self) -> MemCategorizationContext<'t,TYPER> { *self }
259+
#[derive(Copy, Clone)]
260+
pub struct MemCategorizationContext<'t, 'a: 't, 'tcx : 'a> {
261+
pub typer: &'t infer::InferCtxt<'a, 'tcx>,
262+
// pub monomorphize: bool,
265263
}
266264

267265
pub type McResult<T> = Result<T, ()>;
@@ -391,13 +389,13 @@ impl MutabilityCategory {
391389
}
392390
}
393391

394-
impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
395-
pub fn new(typer: &'t TYPER) -> MemCategorizationContext<'t,TYPER> {
392+
impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
393+
pub fn new(typer: &'t infer::InferCtxt<'a, 'tcx>) -> MemCategorizationContext<'t, 'a, 'tcx> {
396394
MemCategorizationContext { typer: typer }
397395
}
398396

399-
fn tcx(&self) -> &'t ty::ctxt<'tcx> {
400-
self.typer.tcx()
397+
fn tcx(&self) -> &'a ty::ctxt<'tcx> {
398+
self.typer.tcx
401399
}
402400

403401
fn expr_ty(&self, expr: &ast::Expr) -> McResult<Ty<'tcx>> {
@@ -1175,15 +1173,15 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
11751173
}
11761174

11771175
pub fn cat_pattern<F>(&self, cmt: cmt<'tcx>, pat: &ast::Pat, mut op: F) -> McResult<()>
1178-
where F: FnMut(&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat),
1176+
where F: FnMut(&MemCategorizationContext<'t, 'a, 'tcx>, cmt<'tcx>, &ast::Pat),
11791177
{
11801178
self.cat_pattern_(cmt, pat, &mut op)
11811179
}
11821180

11831181
// FIXME(#19596) This is a workaround, but there should be a better way to do this
11841182
fn cat_pattern_<F>(&self, cmt: cmt<'tcx>, pat: &ast::Pat, op: &mut F)
11851183
-> McResult<()>
1186-
where F : FnMut(&MemCategorizationContext<'t, TYPER>, cmt<'tcx>, &ast::Pat),
1184+
where F : FnMut(&MemCategorizationContext<'t, 'a, 'tcx>, cmt<'tcx>, &ast::Pat),
11871185
{
11881186
// Here, `cmt` is the categorization for the value being
11891187
// matched and pat is the pattern it is being matched against.

src/librustc_trans/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#![feature(unicode)]
4444
#![feature(unicode)]
4545
#![feature(vec_push_all)]
46-
#![feature(cell_extras)]
4746

4847
#![allow(trivial_casts)]
4948

src/librustc_trans/trans/_match.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ use middle::check_match;
195195
use middle::const_eval;
196196
use middle::def::{self, DefMap};
197197
use middle::expr_use_visitor as euv;
198+
use middle::infer;
198199
use middle::lang_items::StrEqFnLangItem;
199200
use middle::mem_categorization as mc;
200201
use middle::pat_util::*;
@@ -1350,7 +1351,8 @@ fn is_discr_reassigned(bcx: Block, discr: &ast::Expr, body: &ast::Expr) -> bool
13501351
reassigned: false
13511352
};
13521353
{
1353-
let mut visitor = euv::ExprUseVisitor::new(&mut rc, bcx);
1354+
let infcx = infer::new_infer_ctxt(bcx.tcx(), &bcx.tcx().tables, None, false);
1355+
let mut visitor = euv::ExprUseVisitor::new(&mut rc, &infcx);
13541356
visitor.walk_expr(body);
13551357
}
13561358
rc.reassigned

src/librustc_trans/trans/common.rs

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use middle::cfg;
2222
use middle::def;
2323
use middle::infer;
2424
use middle::lang_items::LangItem;
25-
use middle::mem_categorization as mc;
2625
use middle::mem_categorization::Typer;
2726
use middle::ty::ClosureTyper;
2827
use middle::region;
@@ -48,7 +47,7 @@ use util::nodemap::{FnvHashMap, NodeMap};
4847
use arena::TypedArena;
4948
use libc::{c_uint, c_char};
5049
use std::ffi::CString;
51-
use std::cell::{Cell, RefCell, Ref};
50+
use std::cell::{Cell, RefCell};
5251
use std::result::Result as StdResult;
5352
use std::vec::Vec;
5453
use syntax::ast;
@@ -577,95 +576,6 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> {
577576
}
578577
}
579578

580-
impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> {
581-
fn node_ty(&self, id: ast::NodeId) -> mc::McResult<Ty<'tcx>> {
582-
Ok(node_id_type(self, id))
583-
}
584-
585-
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> mc::McResult<Ty<'tcx>> {
586-
Ok(expr_ty_adjusted(self, expr))
587-
}
588-
589-
fn node_method_ty(&self, method_call: ty::MethodCall) -> Option<Ty<'tcx>> {
590-
self.tcx()
591-
.tables
592-
.borrow()
593-
.method_map
594-
.get(&method_call)
595-
.map(|method| monomorphize_type(self, method.ty))
596-
}
597-
598-
fn node_method_origin(&self, method_call: ty::MethodCall)
599-
-> Option<ty::MethodOrigin<'tcx>>
600-
{
601-
self.tcx()
602-
.tables
603-
.borrow()
604-
.method_map
605-
.get(&method_call)
606-
.map(|method| method.origin.clone())
607-
}
608-
609-
fn adjustments<'a>(&'a self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
610-
// FIXME (@jroesch): this is becuase we currently have a HR inference problem
611-
// in the snapshot that causes this code not to work.
612-
fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) ->
613-
&'a NodeMap<ty::AutoAdjustment<'tcx>> {
614-
&tables.adjustments
615-
}
616-
617-
Ref::map(self.tcx().tables.borrow(), project_adjustments)
618-
}
619-
620-
fn is_method_call(&self, id: ast::NodeId) -> bool {
621-
self.tcx().tables.borrow().method_map.contains_key(&ty::MethodCall::expr(id))
622-
}
623-
624-
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<region::CodeExtent> {
625-
self.tcx().region_maps.temporary_scope(rvalue_id)
626-
}
627-
628-
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
629-
Some(self.tcx().tables.borrow().upvar_capture_map.get(&upvar_id).unwrap().clone())
630-
}
631-
632-
fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
633-
ty.moves_by_default(&self.fcx.param_env, span)
634-
}
635-
}
636-
637-
impl<'blk, 'tcx> ty::ClosureTyper<'tcx> for BlockS<'blk, 'tcx> {
638-
fn param_env<'a>(&'a self) -> &'a ty::ParameterEnvironment<'a, 'tcx> {
639-
&self.fcx.param_env
640-
}
641-
642-
fn closure_kind(&self,
643-
def_id: ast::DefId)
644-
-> Option<ty::ClosureKind>
645-
{
646-
let infcx = infer::normalizing_infer_ctxt(self.tcx(), &self.tcx().tables);
647-
infcx.closure_kind(def_id)
648-
}
649-
650-
fn closure_type(&self,
651-
def_id: ast::DefId,
652-
substs: &subst::Substs<'tcx>)
653-
-> ty::ClosureTy<'tcx>
654-
{
655-
let infcx = infer::normalizing_infer_ctxt(self.tcx(), &self.tcx().tables);
656-
infcx.closure_type(def_id, substs)
657-
}
658-
659-
fn closure_upvars(&self,
660-
def_id: ast::DefId,
661-
substs: &Substs<'tcx>)
662-
-> Option<Vec<ty::ClosureUpvar<'tcx>>>
663-
{
664-
let infcx = infer::new_infer_ctxt(self.tcx(), &self.tcx().tables, None, true);
665-
infcx.closure_upvars(def_id, substs)
666-
}
667-
}
668-
669579
pub struct Result<'blk, 'tcx: 'blk> {
670580
pub bcx: Block<'blk, 'tcx>,
671581
pub val: ValueRef

src/librustc_typeck/check/regionck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,8 @@ fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
11011101

11021102
/// Link lifetimes of any ref bindings in `root_pat` to the pointers found in the discriminant, if
11031103
/// needed.
1104-
fn link_pattern<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
1105-
mc: mc::MemCategorizationContext<InferCtxt<'a, 'tcx>>,
1104+
fn link_pattern<'t, 'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
1105+
mc: mc::MemCategorizationContext<'t, 'a, 'tcx>,
11061106
discr_cmt: mc::cmt<'tcx>,
11071107
root_pat: &ast::Pat) {
11081108
debug!("link_pattern(discr_cmt={:?}, root_pat={:?})",

0 commit comments

Comments
 (0)