Skip to content

Commit

Permalink
rustc: fix fallout from removing ast::Sigil and use ty::TraitStore in…
Browse files Browse the repository at this point in the history
… ty::ClosureTy.
  • Loading branch information
eddyb committed Apr 11, 2014
1 parent 9351c01 commit 402d946
Show file tree
Hide file tree
Showing 28 changed files with 249 additions and 350 deletions.
3 changes: 1 addition & 2 deletions src/librustc/front/feature_gate.rs
Expand Up @@ -260,8 +260,7 @@ impl<'a> Visitor<()> for Context<'a> {

fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
match t.node {
ast::TyClosure(closure) if closure.onceness == ast::Once &&
closure.sigil != ast::OwnedSigil => {
ast::TyClosure(closure, _) if closure.onceness == ast::Once => {
self.gate_feature("once_fns", t.span,
"once functions are \
experimental and likely to be removed");
Expand Down
15 changes: 2 additions & 13 deletions src/librustc/metadata/tydecode.rs
Expand Up @@ -137,15 +137,6 @@ pub fn parse_substs_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx:
parse_substs(&mut st, conv)
}

fn parse_sigil(st: &mut PState) -> ast::Sigil {
match next(st) {
'@' => ast::ManagedSigil,
'~' => ast::OwnedSigil,
'&' => ast::BorrowedSigil,
c => st.tcx.sess.bug(format!("parse_sigil(): bad input '{}'", c))
}
}

fn parse_vstore<M>(st: &mut PState, conv: conv_did,
parse_mut: |&mut PState| -> M) -> ty::Vstore<M> {
assert_eq!(next(st), '/');
Expand Down Expand Up @@ -476,17 +467,15 @@ fn parse_onceness(c: char) -> ast::Onceness {
}

fn parse_closure_ty(st: &mut PState, conv: conv_did) -> ty::ClosureTy {
let sigil = parse_sigil(st);
let fn_style = parse_fn_style(next(st));
let onceness = parse_onceness(next(st));
let region = parse_region(st, |x,y| conv(x,y));
let store = parse_trait_store(st, |x,y| conv(x,y));
let bounds = parse_bounds(st, |x,y| conv(x,y));
let sig = parse_sig(st, |x,y| conv(x,y));
ty::ClosureTy {
fn_style: fn_style,
sigil: sigil,
onceness: onceness,
region: region,
store: store,
bounds: bounds.builtin_bounds,
sig: sig
}
Expand Down
11 changes: 1 addition & 10 deletions src/librustc/metadata/tyencode.rs
Expand Up @@ -327,14 +327,6 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
}
}

fn enc_sigil(w: &mut MemWriter, sigil: Sigil) {
match sigil {
ManagedSigil => mywrite!(w, "@"),
OwnedSigil => mywrite!(w, "~"),
BorrowedSigil => mywrite!(w, "&"),
}
}

fn enc_fn_style(w: &mut MemWriter, p: FnStyle) {
match p {
NormalFn => mywrite!(w, "n"),
Expand Down Expand Up @@ -363,10 +355,9 @@ pub fn enc_bare_fn_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::BareFnTy) {
}

fn enc_closure_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::ClosureTy) {
enc_sigil(w, ft.sigil);
enc_fn_style(w, ft.fn_style);
enc_onceness(w, ft.onceness);
enc_region(w, cx, ft.region);
enc_trait_store(w, cx, ft.store);
let bounds = ty::ParamBounds {builtin_bounds: ft.bounds,
trait_bounds: Vec::new()};
enc_bounds(w, cx, &bounds);
Expand Down
13 changes: 5 additions & 8 deletions src/librustc/middle/astencode.rs
Expand Up @@ -897,10 +897,9 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment) {
self.emit_enum("AutoAdjustment", |this| {
match *adj {
ty::AutoAddEnv(region, sigil) => {
this.emit_enum_variant("AutoAddEnv", 0, 2, |this| {
this.emit_enum_variant_arg(0, |this| region.encode(this));
this.emit_enum_variant_arg(1, |this| sigil.encode(this))
ty::AutoAddEnv(store) => {
this.emit_enum_variant("AutoAddEnv", 0, 1, |this| {
this.emit_enum_variant_arg(0, |this| store.encode(this))
})
}

Expand Down Expand Up @@ -1270,12 +1269,10 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
this.read_enum_variant(variants, |this, i| {
Ok(match i {
0 => {
let region: ty::Region =
let store: ty::TraitStore =
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
let sigil: ast::Sigil =
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();

ty:: AutoAddEnv(region.tr(xcx), sigil)
ty:: AutoAddEnv(store.tr(xcx))
}
1 => {
let auto_deref_ref: ty::AutoDerefRef =
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/borrowck/mod.rs
Expand Up @@ -620,7 +620,7 @@ impl<'a> BorrowckCtxt<'a> {
fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msg: &'static str)
-> &'static str {
match ty::get(ty).sty {
ty::ty_closure(ref cty) if cty.sigil == ast::BorrowedSigil =>
ty::ty_closure(~ty::ClosureTy { store: ty::RegionTraitStore(..), .. }) =>
"a non-copyable stack closure (capture it in a new closure, \
e.g. `|x| f(x)`, to override)",
_ if ty::type_moves_by_default(tcx, ty) =>
Expand Down
26 changes: 6 additions & 20 deletions src/librustc/middle/kind.rs
Expand Up @@ -197,27 +197,13 @@ fn with_appropriate_checker(cx: &Context,
let fty = ty::node_id_to_type(cx.tcx, id);
match ty::get(fty).sty {
ty::ty_closure(~ty::ClosureTy {
sigil: OwnedSigil,
bounds: bounds,
..
}) => {
b(|cx, fv| check_for_uniq(cx, fv, bounds))
}
ty::ty_closure(~ty::ClosureTy {
sigil: ManagedSigil,
..
}) => {
// can't happen
fail!("internal error: saw closure with managed sigil (@fn)");
}
store: ty::UniqTraitStore, bounds, ..
}) => b(|cx, fv| check_for_uniq(cx, fv, bounds)),

ty::ty_closure(~ty::ClosureTy {
sigil: BorrowedSigil,
bounds: bounds,
region: region,
..
}) => {
b(|cx, fv| check_for_block(cx, fv, bounds, region))
}
store: ty::RegionTraitStore(region, _), bounds, ..
}) => b(|cx, fv| check_for_block(cx, fv, bounds, region)),

ty::ty_bare_fn(_) => {
b(check_for_bare)
}
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/middle/lint.rs
Expand Up @@ -919,10 +919,8 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
}
ty::ty_uniq(_) | ty::ty_str(ty::VstoreUniq) |
ty::ty_vec(_, ty::VstoreUniq) |
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) => {
n_uniq += 1;
}
ty::ty_closure(ref c) if c.sigil == ast::OwnedSigil => {
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
ty::ty_closure(~ty::ClosureTy { store: ty::UniqTraitStore, .. }) => {
n_uniq += 1;
}

Expand Down
14 changes: 6 additions & 8 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -172,7 +172,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
ty::ty_vec(_, ty::VstoreUniq) |
ty::ty_str(ty::VstoreUniq) |
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
Some(deref_ptr(OwnedPtr))
}

Expand All @@ -187,8 +187,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
}

ty::ty_str(ty::VstoreSlice(r, ())) |
ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil,
region: r, ..}) => {
ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(r, _), ..}) => {
Some(deref_ptr(BorrowedPtr(ty::ImmBorrow, r)))
}

Expand Down Expand Up @@ -540,15 +539,14 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
// Decide whether to use implicit reference or by copy/move
// capture for the upvar. This, combined with the onceness,
// determines whether the closure can move out of it.
let var_is_refd = match (closure_ty.sigil, closure_ty.onceness) {
let var_is_refd = match (closure_ty.store, closure_ty.onceness) {
// Many-shot stack closures can never move out.
(ast::BorrowedSigil, ast::Many) => true,
(ty::RegionTraitStore(..), ast::Many) => true,
// 1-shot stack closures can move out.
(ast::BorrowedSigil, ast::Once) => false,
(ty::RegionTraitStore(..), ast::Once) => false,
// Heap closures always capture by copy/move, and can
// move out if they are once.
(ast::OwnedSigil, _) |
(ast::ManagedSigil, _) => false,
(ty::UniqTraitStore, _) => false,

};
if var_is_refd {
Expand Down
46 changes: 23 additions & 23 deletions src/librustc/middle/moves.rs
Expand Up @@ -650,30 +650,30 @@ impl<'a> VisitContext<'a> {
let _indenter = indenter();

let fn_ty = ty::node_id_to_type(self.tcx, fn_expr_id);
let sigil = ty::ty_closure_sigil(fn_ty);
let freevars = freevars::get_freevars(self.tcx, fn_expr_id);
let v = if sigil == BorrowedSigil {
// || captures everything by ref
freevars.iter()
.map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef})
.collect()
} else {
// @fn() and ~fn() capture by copy or by move depending on type
freevars.iter()
.map(|fvar| {
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id);
debug!("fvar_def_id={:?} fvar_ty={}",
fvar_def_id, ppaux::ty_to_str(self.tcx, fvar_ty));
let mode = if ty::type_moves_by_default(self.tcx, fvar_ty) {
CapMove
} else {
CapCopy
};
CaptureVar {def: fvar.def, span: fvar.span, mode:mode}

Rc::new(match ty::ty_closure_store(fn_ty) {
ty::RegionTraitStore(..) => {
// || captures everything by ref
freevars.iter()
.map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef})
.collect()
}
ty::UniqTraitStore => {
// proc captures by copy or by move depending on type
freevars.iter()
.map(|fvar| {
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id);
debug!("fvar_def_id={:?} fvar_ty={}",
fvar_def_id, ppaux::ty_to_str(self.tcx, fvar_ty));
let mode = if ty::type_moves_by_default(self.tcx, fvar_ty) {
CapMove
} else {
CapCopy
};
CaptureVar {def: fvar.def, span: fvar.span, mode:mode}
}).collect()
};
Rc::new(v)
}
})
}
}
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve.rs
Expand Up @@ -4274,7 +4274,7 @@ impl<'a> Resolver<'a> {
});
}

TyClosure(c) => {
TyClosure(c, _) | TyProc(c) => {
c.bounds.as_ref().map(|bounds| {
for bound in bounds.iter() {
self.resolve_type_parameter_bound(ty.id, bound);
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -112,7 +112,9 @@ impl<'a, 'b> Visitor<Scope<'a>> for LifetimeContext<'b> {

fn visit_ty(&mut self, ty: &ast::Ty, scope: Scope<'a>) {
match ty.node {
ast::TyClosure(c) => push_fn_scope(self, ty, scope, &c.lifetimes),
ast::TyClosure(c, _) | ast::TyProc(c) => {
push_fn_scope(self, ty, scope, &c.lifetimes);
}
ast::TyBareFn(c) => push_fn_scope(self, ty, scope, &c.lifetimes),
_ => visit::walk_ty(self, ty, scope),
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Expand Up @@ -260,7 +260,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
// noalias because the actual object pointer is nested.
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
ty::ty_vec(_, ty::VstoreUniq) | ty::ty_str(ty::VstoreUniq) |
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
unsafe {
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
}
Expand Down

0 comments on commit 402d946

Please sign in to comment.