Skip to content

Commit

Permalink
rustc: remove proc -> once || coercions.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 11, 2014
1 parent 402d946 commit f0c0c2a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 101 deletions.
11 changes: 1 addition & 10 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Expand Up @@ -451,17 +451,8 @@ impl<'a> GatherLoanCtxt<'a> {
r,
AutoRef)
}
ty::AutoBorrowFn(r) => {
let cmt_deref = mc.cat_deref_fn_or_obj(expr, cmt, 0);
self.guarantee_valid(expr.id,
expr.span,
cmt_deref,
ast::MutImmutable,
r,
AutoRef)
}
ty::AutoBorrowObj(r, m) => {
let cmt_deref = mc.cat_deref_fn_or_obj(expr, cmt, 0);
let cmt_deref = mc.cat_deref_obj(expr, cmt);
self.guarantee_valid(expr.id,
expr.span,
cmt_deref,
Expand Down
15 changes: 2 additions & 13 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -686,19 +686,8 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
}
}

pub fn cat_deref_fn_or_obj<N:ast_node>(&mut self,
node: &N,
base_cmt: cmt,
deref_cnt: uint)
-> cmt {
// Bit of a hack: the "dereference" of a function pointer like
// `@fn()` is a mere logical concept. We interpret it as
// dereferencing the environment pointer; of course, we don't
// know what type lies at the other end, so we just call it
// `()` (the empty tuple).

let opaque_ty = ty::mk_tup(self.tcx(), Vec::new());
self.cat_deref_common(node, base_cmt, deref_cnt, opaque_ty)
pub fn cat_deref_obj<N:ast_node>(&mut self, node: &N, base_cmt: cmt) -> cmt {
self.cat_deref_common(node, base_cmt, 0, ty::mk_nil())
}

fn cat_deref<N:ast_node>(&mut self,
Expand Down
24 changes: 1 addition & 23 deletions src/librustc/middle/trans/expr.rs
Expand Up @@ -62,7 +62,7 @@ use middle::trans::type_of;
use middle::trans::write_guard;
use middle::ty::struct_fields;
use middle::ty::{AutoBorrowObj, AutoDerefRef, AutoAddEnv, AutoObject, AutoUnsafe};
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn};
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef};
use middle::ty;
use middle::typeck::MethodCall;
use util::common::indenter;
Expand Down Expand Up @@ -200,14 +200,6 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
Some(AutoBorrowVecRef(..)) => {
unpack_datum!(bcx, auto_slice_and_ref(bcx, expr, datum))
}
Some(AutoBorrowFn(..)) => {
let adjusted_ty = ty::adjust_ty(bcx.tcx(), expr.span, expr.id, datum.ty,
Some(adjustment), |method_call| {
bcx.ccx().maps.method_map.borrow()
.find(&method_call).map(|method| method.ty)
});
unpack_datum!(bcx, auto_borrow_fn(bcx, adjusted_ty, datum))
}
Some(AutoBorrowObj(..)) => {
unpack_datum!(bcx, auto_borrow_obj(bcx, expr, datum))
}
Expand All @@ -225,20 +217,6 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>,
debug!("after adjustments, datum={}", datum.to_str(bcx.ccx()));
return DatumBlock {bcx: bcx, datum: datum};

fn auto_borrow_fn<'a>(
bcx: &'a Block<'a>,
adjusted_ty: ty::t,
datum: Datum<Expr>)
-> DatumBlock<'a, Expr> {
// Currently, all closure types are represented precisely the
// same, so no runtime adjustment is required, but we still
// must patchup the type.
DatumBlock {bcx: bcx,
datum: Datum {val: datum.val,
ty: adjusted_ty,
kind: datum.kind}}
}

fn auto_slice<'a>(
bcx: &'a Block<'a>,
expr: &ast::Expr,
Expand Down
26 changes: 0 additions & 26 deletions src/librustc/middle/ty.rs
Expand Up @@ -239,9 +239,6 @@ pub enum AutoRef {
/// Convert from ~[]/&[] to &&[] (or str)
AutoBorrowVecRef(Region, ast::Mutability),

/// Convert from @fn()/~fn()/|| to ||
AutoBorrowFn(Region),

/// Convert from T to *T
AutoUnsafe(ast::Mutability),

Expand Down Expand Up @@ -2906,10 +2903,6 @@ pub fn adjust_ty(cx: &ctxt,
})
}

AutoBorrowFn(r) => {
borrow_fn(cx, span, r, adjusted_ty)
}

AutoUnsafe(m) => {
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
}
Expand Down Expand Up @@ -2951,24 +2944,6 @@ pub fn adjust_ty(cx: &ctxt,
}
}

fn borrow_fn(cx: &ctxt, span: Span, r: Region, ty: ty::t) -> ty::t {
match get(ty).sty {
ty_closure(ref fty) => {
ty::mk_closure(cx, ClosureTy {
store: RegionTraitStore(r, ast::MutMutable),
..(**fty).clone()
})
}

ref s => {
cx.sess.span_bug(
span,
format!("borrow-fn associated with bad sty: {:?}",
s));
}
}
}

fn borrow_obj(cx: &ctxt, span: Span, r: Region,
m: ast::Mutability, ty: ty::t) -> ty::t {
match get(ty).sty {
Expand All @@ -2992,7 +2967,6 @@ impl AutoRef {
ty::AutoPtr(r, m) => ty::AutoPtr(f(r), m),
ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(f(r), m),
ty::AutoBorrowVecRef(r, m) => ty::AutoBorrowVecRef(f(r), m),
ty::AutoBorrowFn(r) => ty::AutoBorrowFn(f(r)),
ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
ty::AutoBorrowObj(r, m) => ty::AutoBorrowObj(f(r), m),
}
Expand Down
7 changes: 1 addition & 6 deletions src/librustc/middle/typeck/check/regionck.rs
Expand Up @@ -1123,13 +1123,8 @@ fn link_autoref(rcx: &mut Rcx,
link_region(mc.typer, expr.span, r, m, cmt_index);
}

ty::AutoBorrowFn(r) => {
let cmt_deref = mc.cat_deref_fn_or_obj(expr, expr_cmt, 0);
link_region(mc.typer, expr.span, r, ast::MutImmutable, cmt_deref);
}

ty::AutoBorrowObj(r, m) => {
let cmt_deref = mc.cat_deref_fn_or_obj(expr, expr_cmt, 0);
let cmt_deref = mc.cat_deref_obj(expr, expr_cmt);
link_region(mc.typer, expr.span, r, m, cmt_deref);
}

Expand Down
28 changes: 5 additions & 23 deletions src/librustc/middle/typeck/infer/coercion.rs
Expand Up @@ -65,8 +65,7 @@ we may want to adjust precisely when coercions occur.
*/


use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowFn, AutoBorrowObj};
use middle::ty::{AutoDerefRef};
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowObj, AutoDerefRef};
use middle::ty::{VstoreSlice, VstoreUniq};
use middle::ty::{mt};
use middle::ty;
Expand Down Expand Up @@ -342,31 +341,14 @@ impl<'f> Coerce<'f> {
a.inf_str(self.get_ref().infcx), sty_a,
b.inf_str(self.get_ref().infcx));

let fn_ty = match *sty_a {
ty::ty_closure(ref f) if f.store == ty::UniqTraitStore => {
(*f).clone()
}
match *sty_a {
ty::ty_bare_fn(ref f) => {
return self.coerce_from_bare_fn(a, f, b);
self.coerce_from_bare_fn(a, f, b)
}
_ => {
return self.subtype(a, b);
self.subtype(a, b)
}
};

let r_borrow = self.get_ref().infcx.next_region_var(Coercion(self.get_ref().trace));
let a_borrowed = ty::mk_closure(
self.get_ref().infcx.tcx,
ty::ClosureTy {
store: ty::RegionTraitStore(r_borrow, ast::MutMutable),
.. *fn_ty
});

if_ok!(self.subtype(a_borrowed, b));
Ok(Some(@AutoDerefRef(AutoDerefRef {
autoderefs: 0,
autoref: Some(AutoBorrowFn(r_borrow))
})))
}
}

fn coerce_from_bare_fn(&self, a: ty::t, fn_ty_a: &ty::BareFnTy, b: ty::t)
Expand Down

0 comments on commit f0c0c2a

Please sign in to comment.