Skip to content

Commit

Permalink
Refactor writeback code. cc #5527
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed May 6, 2014
1 parent 061db52 commit 5f48cb6
Show file tree
Hide file tree
Showing 4 changed files with 416 additions and 297 deletions.
17 changes: 17 additions & 0 deletions src/librustc/middle/ty_fold.rs
Expand Up @@ -71,6 +71,10 @@ pub trait TypeFolder {
fn fold_trait_store(&mut self, s: ty::TraitStore) -> ty::TraitStore {
super_fold_trait_store(self, s)
}

fn fold_autoref(&mut self, ar: &ty::AutoRef) -> ty::AutoRef {
super_fold_autoref(self, ar)
}
}

pub fn fold_opt_ty<T:TypeFolder>(this: &mut T,
Expand Down Expand Up @@ -195,6 +199,19 @@ pub fn super_fold_trait_store<T:TypeFolder>(this: &mut T,
}
}

pub fn super_fold_autoref<T:TypeFolder>(this: &mut T,
autoref: &ty::AutoRef)
-> ty::AutoRef
{
match *autoref {
ty::AutoPtr(r, m) => ty::AutoPtr(this.fold_region(r), m),
ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(this.fold_region(r), m),
ty::AutoBorrowVecRef(r, m) => ty::AutoBorrowVecRef(this.fold_region(r), m),
ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
ty::AutoBorrowObj(r, m) => ty::AutoBorrowObj(this.fold_region(r), m),
}
}

///////////////////////////////////////////////////////////////////////////
// Some sample folders

Expand Down
13 changes: 9 additions & 4 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -221,6 +221,10 @@ enum IsBinopAssignment{

#[deriving(Clone)]
pub struct FnCtxt<'a> {
// This flag is set to true if, during the writeback phase, we encounter
// a type error in this function.
writeback_errors: Cell<bool>,

// Number of errors that had been reported when we started
// checking this function. On exit, if we find that *more* errors
// have been reported, we will skip regionck and other work that
Expand Down Expand Up @@ -280,6 +284,7 @@ fn blank_fn_ctxt<'a>(ccx: &'a CrateCtxt<'a>,
region_bnd: ast::NodeId)
-> FnCtxt<'a> {
FnCtxt {
writeback_errors: Cell::new(false),
err_count_on_creation: ccx.tcx.sess.err_count(),
ret_ty: rty,
ps: RefCell::new(FnStyleState::function(ast::NormalFn, 0)),
Expand Down Expand Up @@ -469,6 +474,7 @@ fn check_fn<'a>(ccx: &'a CrateCtxt<'a>,
// Create the function context. This is either derived from scratch or,
// in the case of function expressions, based on the outer context.
let fcx = FnCtxt {
writeback_errors: Cell::new(false),
err_count_on_creation: err_count_on_creation,
ret_ty: ret_ty,
ps: RefCell::new(FnStyleState::function(fn_style, id)),
Expand Down Expand Up @@ -1198,11 +1204,10 @@ impl<'a> FnCtxt<'a> {

pub fn opt_node_ty_substs(&self,
id: ast::NodeId,
f: |&ty::substs| -> bool)
-> bool {
f: |&ty::substs|) {
match self.inh.node_type_substs.borrow().find(&id) {
Some(s) => f(s),
None => true
Some(s) => { f(s) }
None => { }
}
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/typeck/check/vtable.rs
Expand Up @@ -644,7 +644,6 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
insert_vtables(fcx, MethodCall::expr(ex.id), vtbls);
}
}
true
});
}

Expand Down

0 comments on commit 5f48cb6

Please sign in to comment.