Skip to content

Commit 96aeb7e

Browse files
committed
auto merge of #13461 : eddyb/rust/cleanup-at-fn, r=luqmana
2 parents e4178db + 9d570ad commit 96aeb7e

36 files changed

+334
-552
lines changed

src/librustc/front/feature_gate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ impl<'a> Visitor<()> for Context<'a> {
260260

261261
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
262262
match t.node {
263-
ast::TyClosure(closure) if closure.onceness == ast::Once &&
264-
closure.sigil != ast::OwnedSigil => {
263+
ast::TyClosure(closure, _) if closure.onceness == ast::Once => {
265264
self.gate_feature("once_fns", t.span,
266265
"once functions are \
267266
experimental and likely to be removed");

src/librustc/metadata/tydecode.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,6 @@ pub fn parse_substs_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx:
137137
parse_substs(&mut st, conv)
138138
}
139139

140-
fn parse_sigil(st: &mut PState) -> ast::Sigil {
141-
match next(st) {
142-
'@' => ast::ManagedSigil,
143-
'~' => ast::OwnedSigil,
144-
'&' => ast::BorrowedSigil,
145-
c => st.tcx.sess.bug(format!("parse_sigil(): bad input '{}'", c))
146-
}
147-
}
148-
149140
fn parse_vstore<M>(st: &mut PState, conv: conv_did,
150141
parse_mut: |&mut PState| -> M) -> ty::Vstore<M> {
151142
assert_eq!(next(st), '/');
@@ -476,17 +467,15 @@ fn parse_onceness(c: char) -> ast::Onceness {
476467
}
477468

478469
fn parse_closure_ty(st: &mut PState, conv: conv_did) -> ty::ClosureTy {
479-
let sigil = parse_sigil(st);
480470
let fn_style = parse_fn_style(next(st));
481471
let onceness = parse_onceness(next(st));
482-
let region = parse_region(st, |x,y| conv(x,y));
472+
let store = parse_trait_store(st, |x,y| conv(x,y));
483473
let bounds = parse_bounds(st, |x,y| conv(x,y));
484474
let sig = parse_sig(st, |x,y| conv(x,y));
485475
ty::ClosureTy {
486476
fn_style: fn_style,
487-
sigil: sigil,
488477
onceness: onceness,
489-
region: region,
478+
store: store,
490479
bounds: bounds.builtin_bounds,
491480
sig: sig
492481
}

src/librustc/metadata/tyencode.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,6 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
327327
}
328328
}
329329

330-
fn enc_sigil(w: &mut MemWriter, sigil: Sigil) {
331-
match sigil {
332-
ManagedSigil => mywrite!(w, "@"),
333-
OwnedSigil => mywrite!(w, "~"),
334-
BorrowedSigil => mywrite!(w, "&"),
335-
}
336-
}
337-
338330
fn enc_fn_style(w: &mut MemWriter, p: FnStyle) {
339331
match p {
340332
NormalFn => mywrite!(w, "n"),
@@ -363,10 +355,9 @@ pub fn enc_bare_fn_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::BareFnTy) {
363355
}
364356

365357
fn enc_closure_ty(w: &mut MemWriter, cx: &ctxt, ft: &ty::ClosureTy) {
366-
enc_sigil(w, ft.sigil);
367358
enc_fn_style(w, ft.fn_style);
368359
enc_onceness(w, ft.onceness);
369-
enc_region(w, cx, ft.region);
360+
enc_trait_store(w, cx, ft.store);
370361
let bounds = ty::ParamBounds {builtin_bounds: ft.bounds,
371362
trait_bounds: Vec::new()};
372363
enc_bounds(w, cx, &bounds);

src/librustc/middle/astencode.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -897,10 +897,9 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
897897
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment) {
898898
self.emit_enum("AutoAdjustment", |this| {
899899
match *adj {
900-
ty::AutoAddEnv(region, sigil) => {
901-
this.emit_enum_variant("AutoAddEnv", 0, 2, |this| {
902-
this.emit_enum_variant_arg(0, |this| region.encode(this));
903-
this.emit_enum_variant_arg(1, |this| sigil.encode(this))
900+
ty::AutoAddEnv(store) => {
901+
this.emit_enum_variant("AutoAddEnv", 0, 1, |this| {
902+
this.emit_enum_variant_arg(0, |this| store.encode(this))
904903
})
905904
}
906905

@@ -1270,12 +1269,10 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
12701269
this.read_enum_variant(variants, |this, i| {
12711270
Ok(match i {
12721271
0 => {
1273-
let region: ty::Region =
1272+
let store: ty::TraitStore =
12741273
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();
1275-
let sigil: ast::Sigil =
1276-
this.read_enum_variant_arg(1, |this| Decodable::decode(this)).unwrap();
12771274

1278-
ty:: AutoAddEnv(region.tr(xcx), sigil)
1275+
ty:: AutoAddEnv(store.tr(xcx))
12791276
}
12801277
1 => {
12811278
let auto_deref_ref: ty::AutoDerefRef =

src/librustc/middle/borrowck/gather_loans/mod.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -451,17 +451,8 @@ impl<'a> GatherLoanCtxt<'a> {
451451
r,
452452
AutoRef)
453453
}
454-
ty::AutoBorrowFn(r) => {
455-
let cmt_deref = mc.cat_deref_fn_or_obj(expr, cmt, 0);
456-
self.guarantee_valid(expr.id,
457-
expr.span,
458-
cmt_deref,
459-
ast::MutImmutable,
460-
r,
461-
AutoRef)
462-
}
463454
ty::AutoBorrowObj(r, m) => {
464-
let cmt_deref = mc.cat_deref_fn_or_obj(expr, cmt, 0);
455+
let cmt_deref = mc.cat_deref_obj(expr, cmt);
465456
self.guarantee_valid(expr.id,
466457
expr.span,
467458
cmt_deref,

src/librustc/middle/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ impl<'a> BorrowckCtxt<'a> {
620620
fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msg: &'static str)
621621
-> &'static str {
622622
match ty::get(ty).sty {
623-
ty::ty_closure(ref cty) if cty.sigil == ast::BorrowedSigil =>
623+
ty::ty_closure(~ty::ClosureTy { store: ty::RegionTraitStore(..), .. }) =>
624624
"a non-copyable stack closure (capture it in a new closure, \
625625
e.g. `|x| f(x)`, to override)",
626626
_ if ty::type_moves_by_default(tcx, ty) =>

src/librustc/middle/kind.rs

+6-20
Original file line numberDiff line numberDiff line change
@@ -197,27 +197,13 @@ fn with_appropriate_checker(cx: &Context,
197197
let fty = ty::node_id_to_type(cx.tcx, id);
198198
match ty::get(fty).sty {
199199
ty::ty_closure(~ty::ClosureTy {
200-
sigil: OwnedSigil,
201-
bounds: bounds,
202-
..
203-
}) => {
204-
b(|cx, fv| check_for_uniq(cx, fv, bounds))
205-
}
206-
ty::ty_closure(~ty::ClosureTy {
207-
sigil: ManagedSigil,
208-
..
209-
}) => {
210-
// can't happen
211-
fail!("internal error: saw closure with managed sigil (@fn)");
212-
}
200+
store: ty::UniqTraitStore, bounds, ..
201+
}) => b(|cx, fv| check_for_uniq(cx, fv, bounds)),
202+
213203
ty::ty_closure(~ty::ClosureTy {
214-
sigil: BorrowedSigil,
215-
bounds: bounds,
216-
region: region,
217-
..
218-
}) => {
219-
b(|cx, fv| check_for_block(cx, fv, bounds, region))
220-
}
204+
store: ty::RegionTraitStore(region, _), bounds, ..
205+
}) => b(|cx, fv| check_for_block(cx, fv, bounds, region)),
206+
221207
ty::ty_bare_fn(_) => {
222208
b(check_for_bare)
223209
}

src/librustc/middle/lint.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -919,10 +919,8 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
919919
}
920920
ty::ty_uniq(_) | ty::ty_str(ty::VstoreUniq) |
921921
ty::ty_vec(_, ty::VstoreUniq) |
922-
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) => {
923-
n_uniq += 1;
924-
}
925-
ty::ty_closure(ref c) if c.sigil == ast::OwnedSigil => {
922+
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
923+
ty::ty_closure(~ty::ClosureTy { store: ty::UniqTraitStore, .. }) => {
926924
n_uniq += 1;
927925
}
928926

src/librustc/middle/mem_categorization.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use syntax::parse::token;
7676
pub enum categorization {
7777
cat_rvalue(ty::Region), // temporary val, argument is its scope
7878
cat_static_item,
79-
cat_copied_upvar(CopiedUpvar), // upvar copied into @fn or ~fn env
79+
cat_copied_upvar(CopiedUpvar), // upvar copied into proc env
8080
cat_upvar(ty::UpvarId, ty::UpvarBorrow), // by ref upvar from stack closure
8181
cat_local(ast::NodeId), // local variable
8282
cat_arg(ast::NodeId), // formal argument
@@ -172,7 +172,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
172172
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
173173
ty::ty_vec(_, ty::VstoreUniq) |
174174
ty::ty_str(ty::VstoreUniq) |
175-
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
175+
ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
176176
Some(deref_ptr(OwnedPtr))
177177
}
178178

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

189189
ty::ty_str(ty::VstoreSlice(r, ())) |
190-
ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil,
191-
region: r, ..}) => {
190+
ty::ty_closure(~ty::ClosureTy {store: ty::RegionTraitStore(r, _), ..}) => {
192191
Some(deref_ptr(BorrowedPtr(ty::ImmBorrow, r)))
193192
}
194193

@@ -540,15 +539,14 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
540539
// Decide whether to use implicit reference or by copy/move
541540
// capture for the upvar. This, combined with the onceness,
542541
// determines whether the closure can move out of it.
543-
let var_is_refd = match (closure_ty.sigil, closure_ty.onceness) {
542+
let var_is_refd = match (closure_ty.store, closure_ty.onceness) {
544543
// Many-shot stack closures can never move out.
545-
(ast::BorrowedSigil, ast::Many) => true,
544+
(ty::RegionTraitStore(..), ast::Many) => true,
546545
// 1-shot stack closures can move out.
547-
(ast::BorrowedSigil, ast::Once) => false,
546+
(ty::RegionTraitStore(..), ast::Once) => false,
548547
// Heap closures always capture by copy/move, and can
549548
// move out if they are once.
550-
(ast::OwnedSigil, _) |
551-
(ast::ManagedSigil, _) => false,
549+
(ty::UniqTraitStore, _) => false,
552550

553551
};
554552
if var_is_refd {
@@ -688,19 +686,8 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
688686
}
689687
}
690688

691-
pub fn cat_deref_fn_or_obj<N:ast_node>(&mut self,
692-
node: &N,
693-
base_cmt: cmt,
694-
deref_cnt: uint)
695-
-> cmt {
696-
// Bit of a hack: the "dereference" of a function pointer like
697-
// `@fn()` is a mere logical concept. We interpret it as
698-
// dereferencing the environment pointer; of course, we don't
699-
// know what type lies at the other end, so we just call it
700-
// `()` (the empty tuple).
701-
702-
let opaque_ty = ty::mk_tup(self.tcx(), Vec::new());
703-
self.cat_deref_common(node, base_cmt, deref_cnt, opaque_ty)
689+
pub fn cat_deref_obj<N:ast_node>(&mut self, node: &N, base_cmt: cmt) -> cmt {
690+
self.cat_deref_common(node, base_cmt, 0, ty::mk_nil())
704691
}
705692

706693
fn cat_deref<N:ast_node>(&mut self,
@@ -1105,7 +1092,7 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
11051092
~"static item"
11061093
}
11071094
cat_copied_upvar(_) => {
1108-
~"captured outer variable in a heap closure"
1095+
~"captured outer variable in a proc"
11091096
}
11101097
cat_rvalue(..) => {
11111098
~"non-lvalue"

src/librustc/middle/moves.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -650,30 +650,30 @@ impl<'a> VisitContext<'a> {
650650
let _indenter = indenter();
651651

652652
let fn_ty = ty::node_id_to_type(self.tcx, fn_expr_id);
653-
let sigil = ty::ty_closure_sigil(fn_ty);
654653
let freevars = freevars::get_freevars(self.tcx, fn_expr_id);
655-
let v = if sigil == BorrowedSigil {
656-
// || captures everything by ref
657-
freevars.iter()
658-
.map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef})
659-
.collect()
660-
} else {
661-
// @fn() and ~fn() capture by copy or by move depending on type
662-
freevars.iter()
663-
.map(|fvar| {
664-
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
665-
let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id);
666-
debug!("fvar_def_id={:?} fvar_ty={}",
667-
fvar_def_id, ppaux::ty_to_str(self.tcx, fvar_ty));
668-
let mode = if ty::type_moves_by_default(self.tcx, fvar_ty) {
669-
CapMove
670-
} else {
671-
CapCopy
672-
};
673-
CaptureVar {def: fvar.def, span: fvar.span, mode:mode}
674-
654+
Rc::new(match ty::ty_closure_store(fn_ty) {
655+
ty::RegionTraitStore(..) => {
656+
// || captures everything by ref
657+
freevars.iter()
658+
.map(|fvar| CaptureVar {def: fvar.def, span: fvar.span, mode: CapRef})
659+
.collect()
660+
}
661+
ty::UniqTraitStore => {
662+
// proc captures by copy or by move depending on type
663+
freevars.iter()
664+
.map(|fvar| {
665+
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
666+
let fvar_ty = ty::node_id_to_type(self.tcx, fvar_def_id);
667+
debug!("fvar_def_id={:?} fvar_ty={}",
668+
fvar_def_id, ppaux::ty_to_str(self.tcx, fvar_ty));
669+
let mode = if ty::type_moves_by_default(self.tcx, fvar_ty) {
670+
CapMove
671+
} else {
672+
CapCopy
673+
};
674+
CaptureVar {def: fvar.def, span: fvar.span, mode:mode}
675675
}).collect()
676-
};
677-
Rc::new(v)
676+
}
677+
})
678678
}
679679
}

src/librustc/middle/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4274,7 +4274,7 @@ impl<'a> Resolver<'a> {
42744274
});
42754275
}
42764276

4277-
TyClosure(c) => {
4277+
TyClosure(c, _) | TyProc(c) => {
42784278
c.bounds.as_ref().map(|bounds| {
42794279
for bound in bounds.iter() {
42804280
self.resolve_type_parameter_bound(ty.id, bound);

src/librustc/middle/resolve_lifetime.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ impl<'a, 'b> Visitor<Scope<'a>> for LifetimeContext<'b> {
112112

113113
fn visit_ty(&mut self, ty: &ast::Ty, scope: Scope<'a>) {
114114
match ty.node {
115-
ast::TyClosure(c) => push_fn_scope(self, ty, scope, &c.lifetimes),
115+
ast::TyClosure(c, _) | ast::TyProc(c) => {
116+
push_fn_scope(self, ty, scope, &c.lifetimes);
117+
}
116118
ast::TyBareFn(c) => push_fn_scope(self, ty, scope, &c.lifetimes),
117119
_ => visit::walk_ty(self, ty, scope),
118120
}

src/librustc/middle/trans/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
260260
// noalias because the actual object pointer is nested.
261261
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
262262
ty::ty_vec(_, ty::VstoreUniq) | ty::ty_str(ty::VstoreUniq) |
263-
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
263+
ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
264264
unsafe {
265265
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
266266
}

0 commit comments

Comments
 (0)