Skip to content

Commit 0101125

Browse files
committed
rustc: Make function types have vstores in them
1 parent 99942ae commit 0101125

22 files changed

+237
-114
lines changed

src/rustc/metadata/tydecode.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,11 @@ fn parse_ty_rust_fn(st: @pstate, conv: conv_did) -> ty::t {
8585
return ty::mk_fn(st.tcx, parse_ty_fn(st, conv));
8686
}
8787

88-
fn parse_proto(c: char) -> ast::proto {
89-
match c {
90-
'~' => ast::proto_uniq,
91-
'@' => ast::proto_box,
92-
'&' => ast::proto_block,
93-
'n' => ast::proto_bare,
94-
_ => fail ~"illegal fn type kind " + str::from_char(c)
88+
fn parse_proto(st: @pstate) -> ty::fn_proto {
89+
match next(st) {
90+
'n' => ty::proto_bare,
91+
'v' => ty::proto_vstore(parse_vstore(st)),
92+
c => fail ~"illegal proto type kind " + str::from_char(c)
9593
}
9694
}
9795
@@ -360,7 +358,7 @@ fn parse_purity(c: char) -> purity {
360358
}
361359

362360
fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
363-
let proto = parse_proto(next(st));
361+
let proto = parse_proto(st);
364362
let purity = parse_purity(next(st));
365363
let bounds = parse_bounds(st, conv);
366364
assert (next(st) == '[');

src/rustc/metadata/tyencode.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,15 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
306306
}
307307
}
308308
}
309-
fn enc_proto(w: io::writer, proto: proto) {
309+
310+
fn enc_proto(w: io::writer, cx: @ctxt, proto: ty::fn_proto) {
311+
w.write_str(&"f");
310312
match proto {
311-
proto_uniq => w.write_str(&"f~"),
312-
proto_box => w.write_str(&"f@"),
313-
proto_block => w.write_str(~"f&"),
314-
proto_bare => w.write_str(&"fn")
313+
ty::proto_bare => w.write_str(&"n"),
314+
ty::proto_vstore(vstore) => {
315+
w.write_str(&"v");
316+
enc_vstore(w, cx, vstore);
317+
}
315318
}
316319
}
317320

@@ -335,7 +338,7 @@ fn enc_purity(w: io::writer, p: purity) {
335338
}
336339

337340
fn enc_ty_fn(w: io::writer, cx: @ctxt, ft: ty::fn_ty) {
338-
enc_proto(w, ft.proto);
341+
enc_proto(w, cx, ft.proto);
339342
enc_purity(w, ft.purity);
340343
enc_bounds(w, cx, ft.bounds);
341344
w.write_char('[');

src/rustc/middle/block_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) {
1414
fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
1515
if !cx.allow_block {
1616
match ty::get(ty::expr_ty(cx.tcx, ex)).struct {
17-
ty::ty_fn({proto: p, _}) if is_blockish(p) => {
17+
ty::ty_fn({proto: p, _}) if ty::is_blockish(p) => {
1818
cx.tcx.sess.span_err(ex.span,
1919
~"expressions with stack closure type \
2020
can only appear in callee or (by-ref) argument position");

src/rustc/middle/borrowck/check_loans.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,7 @@ impl check_loan_ctxt {
218218
fn is_stack_closure(id: ast::node_id) -> bool {
219219
let fn_ty = ty::node_id_to_type(self.tcx(), id);
220220
let proto = ty::ty_fn_proto(fn_ty);
221-
match proto {
222-
ast::proto_block => true,
223-
ast::proto_bare | ast::proto_uniq | ast::proto_box => false
224-
}
221+
return ty::is_blockish(proto);
225222
}
226223

227224
fn is_allowed_pure_arg(expr: @ast::expr) -> bool {

src/rustc/middle/capture.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn check_capture_clause(tcx: ty::ctxt,
5959

6060
fn compute_capture_vars(tcx: ty::ctxt,
6161
fn_expr_id: ast::node_id,
62-
fn_proto: ast::proto,
62+
fn_proto: ty::fn_proto,
6363
cap_clause: ast::capture_clause) -> ~[capture_var] {
6464
let freevars = freevars::get_freevars(tcx, fn_expr_id);
6565
let cap_map = map::int_hash();
@@ -101,10 +101,12 @@ fn compute_capture_vars(tcx: ty::ctxt,
101101
// now go through anything that is referenced but was not explicitly
102102
// named and add that
103103

104-
let implicit_mode = match fn_proto {
105-
ast::proto_block => cap_ref,
106-
ast::proto_bare | ast::proto_box | ast::proto_uniq => cap_copy
107-
};
104+
let implicit_mode;
105+
if ty::is_blockish(fn_proto) {
106+
implicit_mode = cap_ref;
107+
} else {
108+
implicit_mode = cap_copy;
109+
}
108110

109111
do vec::iter(*freevars) |fvar| {
110112
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;

src/rustc/middle/check_loop.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) {
2525
v.visit_block(b, {in_loop: false, can_ret: false}, v);
2626
}
2727
expr_loop_body(@{node: expr_fn_block(_, b, _), _}) => {
28-
let blk = is_blockish(ty::ty_fn_proto(ty::expr_ty(tcx, e)));
28+
let blk = ty::is_blockish(ty::ty_fn_proto(ty::expr_ty(tcx,
29+
e)));
2930
v.visit_block(b, {in_loop: true, can_ret: blk}, v);
3031
}
3132
expr_break => {

src/rustc/middle/kind.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
144144

145145
let fty = ty::node_id_to_type(cx.tcx, id);
146146
match ty::ty_fn_proto(fty) {
147-
proto_uniq => b(check_for_uniq),
148-
proto_box => b(check_for_box),
149-
proto_bare => b(check_for_bare),
150-
proto_block => b(check_for_block)
147+
ty::proto_vstore(ty::vstore_uniq) => b(check_for_uniq),
148+
ty::proto_vstore(ty::vstore_box) => b(check_for_box),
149+
ty::proto_bare => b(check_for_bare),
150+
ty::proto_vstore(ty::vstore_slice(_)) => b(check_for_block),
151+
ty::proto_vstore(ty::vstore_fixed(_)) =>
152+
fail ~"fixed vstore not allowed here"
151153
}
152154
}
153155

src/rustc/middle/mem_categorization.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,22 @@ impl &mem_categorization_ctxt {
383383
let ty = ty::node_id_to_type(self.tcx, fn_node_id);
384384
let proto = ty::ty_fn_proto(ty);
385385
match proto {
386-
ast::proto_block => {
386+
ty::proto_vstore(ty::vstore_slice(_)) => {
387387
let upcmt = self.cat_def(id, span, expr_ty, *inner);
388388
@{id:id, span:span,
389389
cat:cat_stack_upvar(upcmt), lp:upcmt.lp,
390390
mutbl:upcmt.mutbl, ty:upcmt.ty}
391391
}
392-
ast::proto_bare | ast::proto_uniq | ast::proto_box => {
392+
ty::proto_bare |
393+
ty::proto_vstore(ty::vstore_uniq) |
394+
ty::proto_vstore(ty::vstore_box) => {
393395
// FIXME #2152 allow mutation of moved upvars
394396
@{id:id, span:span,
395397
cat:cat_special(sk_heap_upvar), lp:none,
396398
mutbl:m_imm, ty:expr_ty}
397399
}
400+
ty::proto_vstore(ty::vstore_fixed(_)) =>
401+
fail ~"fixed vstore not allowed here"
398402
}
399403
}
400404

src/rustc/middle/trans/base.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,8 @@ fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> option<ty::t> {
20432043
}
20442044
ty::ty_trait(_, _) => {
20452045
some(ty::mk_fn(tcx, {purity: ast::impure_fn,
2046-
proto: ast::proto_box,
2046+
proto: ty::proto_vstore(ty::vstore_slice
2047+
(ty::re_static)),
20472048
bounds: @~[],
20482049
inputs: ~[],
20492050
output: ty::mk_nil(tcx),
@@ -3774,8 +3775,11 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
37743775
}
37753776
ast::expr_addr_of(_, x) => { return trans_addr_of(bcx, x, dest); }
37763777
ast::expr_fn(proto, decl, body, cap_clause) => {
3777-
return closure::trans_expr_fn(bcx, proto, decl, body, e.id,
3778-
cap_clause, none, dest);
3778+
// XXX: This syntax should be reworked a bit (in the parser I
3779+
// guess?); @fn() { ... } won't work.
3780+
return closure::trans_expr_fn(bcx, ty::ast_proto_to_proto(proto),
3781+
decl, body, e.id, cap_clause, none,
3782+
dest);
37793783
}
37803784
ast::expr_fn_block(decl, body, cap_clause) => {
37813785
match check ty::get(expr_ty(bcx, e)).struct {

src/rustc/middle/trans/closure.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ fn load_environment(fcx: fn_ctxt,
347347
}
348348

349349
fn trans_expr_fn(bcx: block,
350-
proto: ast::proto,
350+
proto: ty::fn_proto,
351351
decl: ast::fn_decl,
352352
body: ast::blk,
353353
id: ast::node_id,
@@ -364,8 +364,8 @@ fn trans_expr_fn(bcx: block,
364364
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
365365

366366
let trans_closure_env = fn@(ck: ty::closure_kind) -> result {
367-
let cap_vars = capture::compute_capture_vars(
368-
ccx.tcx, id, proto, cap_clause);
367+
let cap_vars = capture::compute_capture_vars(ccx.tcx, id, proto,
368+
cap_clause);
369369
let ret_handle = match is_loop_body { some(x) => x, none => none };
370370
let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, ck, id,
371371
ret_handle);
@@ -382,14 +382,19 @@ fn trans_expr_fn(bcx: block,
382382
};
383383

384384
let {bcx: bcx, val: closure} = match proto {
385-
ast::proto_block => trans_closure_env(ty::ck_block),
386-
ast::proto_box => trans_closure_env(ty::ck_box),
387-
ast::proto_uniq => trans_closure_env(ty::ck_uniq),
388-
ast::proto_bare => {
385+
ty::proto_vstore(ty::vstore_slice(_)) =>
386+
trans_closure_env(ty::ck_block),
387+
ty::proto_vstore(ty::vstore_box) =>
388+
trans_closure_env(ty::ck_box),
389+
ty::proto_vstore(ty::vstore_uniq) =>
390+
trans_closure_env(ty::ck_uniq),
391+
ty::proto_bare => {
389392
trans_closure(ccx, sub_path, decl, body, llfn, no_self, none,
390393
id, |_fcx| { }, |_bcx| { });
391394
{bcx: bcx, val: C_null(T_opaque_box_ptr(ccx))}
392395
}
396+
ty::proto_vstore(ty::vstore_fixed(_)) =>
397+
fail ~"vstore_fixed unexpected"
393398
};
394399
fill_fn_pair(bcx, get_dest_addr(dest), llfn, closure);
395400

@@ -416,11 +421,15 @@ fn make_fn_glue(
416421
};
417422

418423
return match ty::get(t).struct {
419-
ty::ty_fn({proto: ast::proto_bare, _}) |
420-
ty::ty_fn({proto: ast::proto_block, _}) => bcx,
421-
ty::ty_fn({proto: ast::proto_uniq, _}) => fn_env(ty::ck_uniq),
422-
ty::ty_fn({proto: ast::proto_box, _}) => fn_env(ty::ck_box),
423-
_ => fail ~"make_fn_glue invoked on non-function type"
424+
ty::ty_fn({proto: ty::proto_bare, _}) |
425+
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_slice(_)), _}) =>
426+
bcx,
427+
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_uniq), _}) =>
428+
fn_env(ty::ck_uniq),
429+
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_box), _}) =>
430+
fn_env(ty::ck_box),
431+
_ =>
432+
fail ~"make_fn_glue invoked on non-function type"
424433
};
425434
}
426435

src/rustc/middle/trans/foreign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
960960
let frameaddress_val = Call(bcx, frameaddress, ~[C_i32(0i32)]);
961961
let fty = ty::mk_fn(bcx.tcx(), {
962962
purity: ast::impure_fn,
963-
proto: ast::proto_block,
963+
proto: ty::proto_vstore(ty::vstore_slice(ty::re_static)),
964964
bounds: @~[],
965965
inputs: ~[{
966966
mode: ast::expl(ast::by_val),

src/rustc/middle/trans/reflect.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,12 @@ impl reflector {
185185
ast::extern_fn => 3u
186186
};
187187
let protoval = match fty.proto {
188-
ast::proto_bare => 0u,
189-
ast::proto_uniq => 2u,
190-
ast::proto_box => 3u,
191-
ast::proto_block => 4u
188+
ty::proto_bare => 0u,
189+
ty::proto_vstore(ty::vstore_uniq) => 2u,
190+
ty::proto_vstore(ty::vstore_box) => 3u,
191+
ty::proto_vstore(ty::vstore_slice(_)) => 4u,
192+
ty::proto_vstore(ty::vstore_fixed(_)) =>
193+
fail ~"fixed unexpected"
192194
};
193195
let retval = match fty.ret_style {
194196
ast::noreturn => 0u,

src/rustc/middle/trans/shape.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,20 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
351351
ty::ty_param(*) => {
352352
ccx.tcx.sess.bug(~"non-monomorphized type parameter");
353353
}
354-
ty::ty_fn({proto: ast::proto_box, _}) => ~[shape_box_fn],
355-
ty::ty_fn({proto: ast::proto_uniq, _}) => ~[shape_uniq_fn],
356-
ty::ty_fn({proto: ast::proto_block, _}) => ~[shape_stack_fn],
357-
ty::ty_fn({proto: ast::proto_bare, _}) => ~[shape_bare_fn],
358-
ty::ty_opaque_closure_ptr(_) => ~[shape_opaque_closure_ptr],
359-
ty::ty_var(_) | ty::ty_var_integral(_) | ty::ty_self => {
360-
ccx.sess.bug(~"shape_of: unexpected type struct found");
361-
}
354+
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_box), _}) =>
355+
~[shape_box_fn],
356+
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_uniq), _}) =>
357+
~[shape_uniq_fn],
358+
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_slice(_)), _}) =>
359+
~[shape_stack_fn],
360+
ty::ty_fn({proto: ty::proto_vstore(ty::vstore_fixed(_)), _}) =>
361+
fail ~"fixed vstore is impossible",
362+
ty::ty_fn({proto: ty::proto_bare, _}) =>
363+
~[shape_bare_fn],
364+
ty::ty_opaque_closure_ptr(_) =>
365+
~[shape_opaque_closure_ptr],
366+
ty::ty_var(_) | ty::ty_var_integral(_) | ty::ty_self =>
367+
ccx.sess.bug(~"shape_of: unexpected type struct found")
362368
}
363369
}
364370

src/rustc/middle/trans/type_use.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,16 @@ fn mark_for_expr(cx: ctx, e: @expr) {
202202
}
203203
expr_fn(*) | expr_fn_block(*) => {
204204
match ty::ty_fn_proto(ty::expr_ty(cx.ccx.tcx, e)) {
205-
proto_bare | proto_uniq => {}
206-
proto_box | proto_block => {
205+
ty::proto_bare | ty::proto_vstore(ty::vstore_uniq) => {}
206+
ty::proto_vstore(ty::vstore_box) |
207+
ty::proto_vstore(ty::vstore_slice(_)) => {
207208
for vec::each(*freevars::get_freevars(cx.ccx.tcx, e.id)) |fv| {
208209
let node_id = ast_util::def_id_of_def(fv.def).node;
209210
node_type_needs(cx, use_repr, node_id);
210211
}
211212
}
213+
ty::proto_vstore(ty::vstore_fixed(_)) =>
214+
fail ~"vstore_fixed not allowed here"
212215
}
213216
}
214217
expr_assign(val, _) | expr_swap(val, _) | expr_assign_op(_, val, _) |

0 commit comments

Comments
 (0)