Skip to content

Commit 8dd8077

Browse files
committed
---
yaml --- r: 3343 b: refs/heads/master c: 61fc12d h: refs/heads/master i: 3341: b67ad48 3339: f231e5f 3335: 51cac9d 3327: a69d790 v: v3
1 parent f87379e commit 8dd8077

File tree

13 files changed

+199
-18
lines changed

13 files changed

+199
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 781a265b88f7fc3c8c406b327e8a548e742d6224
2+
refs/heads/master: 61fc12d0d0d1b8acb7472bfc6223882b32acd3d2

trunk/src/comp/front/ast.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ tag ty_ {
335335
/* bot represents the value of functions that don't return a value
336336
locally to their context. in contrast, things like log that do
337337
return, but don't return a meaningful value, have result type nil. */
338-
ty_bool;
338+
ty_bool;
339339
ty_int;
340340
ty_uint;
341341
ty_float;
@@ -478,7 +478,7 @@ type attribute_ = rec(attr_style style, meta_item value);
478478

479479
type item = rec(ident ident,
480480
vec[attribute] attrs,
481-
node_id id, // For objs, this is the type's def_id
481+
node_id id, // For objs and resources, this is the type def_id
482482
item_ node,
483483
span span);
484484

@@ -490,6 +490,8 @@ tag item_ {
490490
item_ty(@ty, vec[ty_param]);
491491
item_tag(vec[variant], vec[ty_param]);
492492
item_obj(_obj, vec[ty_param], node_id /* constructor id */);
493+
item_res(_fn /* dtor */, node_id /* dtor id */,
494+
vec[ty_param], node_id /* ctor id */);
493495
}
494496

495497
type native_item = rec(ident ident,

trunk/src/comp/front/creader.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
281281
st.pos += 1u;
282282
ret ty::mk_obj(st.tcx, methods);
283283
}
284+
case ('r') {
285+
auto def = parse_def(st, sd);
286+
auto inner = parse_ty(st, sd);
287+
ret ty::mk_res(st.tcx, def, inner);
288+
}
284289
case ('X') { ret ty::mk_var(st.tcx, parse_int(st)); }
285290
case ('E') { ret ty::mk_native(st.tcx); }
286291
case ('Y') { ret ty::mk_type(st.tcx); }

trunk/src/comp/front/parser.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ fn bad_expr_word_table() -> hashmap[str, ()] {
139139
words.insert("be", ());
140140
words.insert("fail", ());
141141
words.insert("type", ());
142+
words.insert("res", ());
142143
words.insert("check", ());
143144
words.insert("assert", ());
144145
words.insert("claim", ());
@@ -1656,7 +1657,6 @@ fn parse_ty_params(&parser p) -> vec[ast::ty_param] {
16561657
}
16571658

16581659
fn parse_fn_decl(&parser p, ast::purity purity) -> ast::fn_decl {
1659-
auto pf = parse_arg;
16601660
let util::common::spanned[vec[ast::arg]] inputs =
16611661
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_arg,
16621662
p);
@@ -1765,10 +1765,9 @@ fn parse_item_obj(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
17651765
auto lo = p.get_last_lo_pos();
17661766
auto ident = parse_value_ident(p);
17671767
auto ty_params = parse_ty_params(p);
1768-
auto pf = parse_obj_field;
17691768
let util::common::spanned[vec[ast::obj_field]] fields =
17701769
parse_seq[ast::obj_field](token::LPAREN, token::RPAREN,
1771-
some(token::COMMA), pf, p);
1770+
some(token::COMMA), parse_obj_field, p);
17721771
let vec[@ast::method] meths = [];
17731772
let option::t[@ast::method] dtor = none;
17741773
expect(p, token::LBRACE);
@@ -1784,6 +1783,27 @@ fn parse_item_obj(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
17841783
p.get_id()), attrs);
17851784
}
17861785

1786+
fn parse_item_res(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
1787+
@ast::item {
1788+
auto lo = p.get_last_lo_pos();
1789+
auto ident = parse_value_ident(p);
1790+
auto ty_params = parse_ty_params(p);
1791+
expect(p, token::LPAREN);
1792+
auto t = parse_ty(p);
1793+
auto arg_ident = parse_value_ident(p);
1794+
expect(p, token::RPAREN);
1795+
auto dtor = parse_block(p);
1796+
auto decl = rec(inputs=[rec(mode=ast::alias(false), ty=t, ident=arg_ident,
1797+
id=p.get_id())],
1798+
output=@spanned(lo, lo, ast::ty_nil),
1799+
purity=ast::impure_fn,
1800+
cf=ast::return,
1801+
constraints=[]);
1802+
auto f = rec(decl=decl, proto=ast::proto_fn, body=dtor);
1803+
ret mk_item(p, lo, dtor.span.hi, ident,
1804+
ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs);
1805+
}
1806+
17871807
fn parse_mod_items(&parser p, token::token term,
17881808
vec[ast::attribute] first_item_attrs) -> ast::_mod {
17891809
auto view_items = if (vec::len(first_item_attrs) == 0u) {
@@ -2028,6 +2048,8 @@ fn parse_item(&parser p, vec[ast::attribute] attrs) -> parsed_item {
20282048
ret got_item(parse_item_tag(p, attrs));
20292049
} else if (eat_word(p, "obj")) {
20302050
ret got_item(parse_item_obj(p, lyr, attrs));
2051+
} else if (eat_word(p, "res")) {
2052+
ret got_item(parse_item_res(p, lyr, attrs));
20312053
} else { ret no_item; }
20322054
}
20332055

trunk/src/comp/middle/metadata.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ mod encode {
231231
}
232232
w.write_char(']');
233233
}
234+
case (ty::ty_res(?def, ?ty)) {
235+
w.write_char('r');
236+
w.write_str(cx.ds(def));
237+
w.write_char('|');
238+
enc_ty(w, cx, ty);
239+
}
234240
case (ty::ty_var(?id)) {
235241
w.write_char('X');
236242
w.write_str(common::istr(id));
@@ -393,6 +399,18 @@ fn encode_module_item_paths(&ebml::writer ebml_w, &_mod module,
393399
encode_def_id(ebml_w, local_def(it.id));
394400
ebml::end_tag(ebml_w);
395401
}
402+
case (item_res(_, _, ?tps, ?ctor_id)) {
403+
add_to_index(ebml_w, path, index, it.ident);
404+
ebml::start_tag(ebml_w, tag_paths_data_item);
405+
encode_name(ebml_w, it.ident);
406+
encode_def_id(ebml_w, local_def(ctor_id));
407+
ebml::end_tag(ebml_w);
408+
add_to_index(ebml_w, path, index, it.ident);
409+
ebml::start_tag(ebml_w, tag_paths_data_item);
410+
encode_name(ebml_w, it.ident);
411+
encode_def_id(ebml_w, local_def(it.id));
412+
ebml::end_tag(ebml_w);
413+
}
396414
case (item_tag(?variants, ?tps)) {
397415
add_to_index(ebml_w, path, index, it.ident);
398416
ebml::start_tag(ebml_w, tag_paths_data_item);
@@ -553,6 +571,23 @@ fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
553571
encode_tag_variant_info(cx, ebml_w, item.id, variants, index,
554572
tps);
555573
}
574+
case (item_res(_, _, ?tps, ?ctor_id)) {
575+
ebml::start_tag(ebml_w, tag_items_data_item);
576+
encode_def_id(ebml_w, local_def(ctor_id));
577+
encode_kind(ebml_w, 'f' as u8);
578+
encode_type_param_count(ebml_w, tps);
579+
auto fn_ty = trans::node_id_type(cx, item.id);
580+
encode_type(cx, ebml_w, fn_ty);
581+
encode_symbol(cx, ebml_w, ctor_id);
582+
ebml::end_tag(ebml_w);
583+
index += [tup(item.id, ebml_w.writer.tell())];
584+
ebml::start_tag(ebml_w, tag_items_data_item);
585+
encode_def_id(ebml_w, local_def(item.id));
586+
encode_kind(ebml_w, 'y' as u8);
587+
encode_type_param_count(ebml_w, tps);
588+
encode_type(cx, ebml_w, ty::ty_fn_ret(cx.tcx, fn_ty));
589+
ebml::end_tag(ebml_w);
590+
}
556591
case (item_obj(_, ?tps, ?ctor_id)) {
557592
ebml::start_tag(ebml_w, tag_items_data_item);
558593
encode_def_id(ebml_w, local_def(ctor_id));

trunk/src/comp/middle/resolve.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,14 @@ fn found_def_item(&@ast::item i, namespace ns) -> option::t[def] {
819819
ret some(ast::def_ty(local_def(i.id)));
820820
}
821821
}
822+
case (ast::item_res(_, _, _, ?ctor_id)) {
823+
alt (ns) {
824+
case (ns_value) { ret some(ast::def_fn(local_def(ctor_id),
825+
ast::impure_fn)); }
826+
case (ns_type) { ret some(ast::def_ty(local_def(i.id))); }
827+
case (_) { }
828+
}
829+
}
822830
case (ast::item_tag(_, _)) {
823831
if (ns == ns_type) {
824832
ret some(ast::def_ty(local_def(i.id)));
@@ -1085,6 +1093,9 @@ fn index_mod(&ast::_mod md) -> mod_index {
10851093
case (ast::item_ty(_, _)) {
10861094
add_to_index(index, it.ident, mie_item(it));
10871095
}
1096+
case (ast::item_res(_, _, _, _)) {
1097+
add_to_index(index, it.ident, mie_item(it));
1098+
}
10881099
case (ast::item_tag(?variants, _)) {
10891100
add_to_index(index, it.ident, mie_item(it));
10901101
let uint variant_idx = 0u;
@@ -1282,6 +1293,10 @@ fn check_block(@env e, &ast::block b, &() x, &vt[()] v) {
12821293
case (ast::item_ty(_, _)) {
12831294
add_name(types, it.span, it.ident);
12841295
}
1296+
case (ast::item_res(_, _, _, _)) {
1297+
add_name(types, it.span, it.ident);
1298+
add_name(values, it.span, it.ident);
1299+
}
12851300
case (ast::item_obj(_, _, _)) {
12861301
add_name(types, it.span, it.ident);
12871302
add_name(values, it.span, it.ident);

trunk/src/comp/middle/trans.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,9 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
881881
abs_pair = llvm::LLVMResolveTypeHandle(th.llth);
882882
llty = abs_pair;
883883
}
884+
case (ty::ty_res(_, ?sub)) {
885+
ret type_of_inner(cx, sp, sub);
886+
}
884887
case (ty::ty_var(_)) {
885888
cx.tcx.sess.span_fatal(sp, "trans::type_of called on ty_var");
886889
}
@@ -1217,6 +1220,7 @@ fn simplify_type(&@crate_ctxt ccx, &ty::t typ) -> ty::t {
12171220
ty::mk_imm_box(ccx.tcx,
12181221
ty::mk_nil(ccx.tcx))]);
12191222
}
1223+
case (ty::ty_res(_, ?sub)) { ret simplify_type(ccx, sub);}
12201224
case (_) { ret typ; }
12211225
}
12221226
}
@@ -2064,7 +2068,7 @@ fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
20642068
case (ty::ty_vec(_)) { decr_refcnt_maybe_free(cx, v0, v0, t) }
20652069
case (ty::ty_ivec(?tm)) {
20662070
auto v1;
2067-
if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, tm.ty)) {
2071+
if (ty::type_has_dynamic_size(ccx.tcx, tm.ty)) {
20682072
v1 = cx.build.PointerCast(v0, T_ptr(T_opaque_ivec()));
20692073
} else {
20702074
v1 = v0;
@@ -2082,6 +2086,18 @@ fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
20822086
cx.build.GEP(v0, [C_int(0), C_int(abi::obj_field_box)]);
20832087
decr_refcnt_maybe_free(cx, box_cell, v0, t)
20842088
}
2089+
case (ty::ty_res(?did, ?inner)) {
2090+
auto dtor = alt (ccx.ast_map.get(did._1)) {
2091+
case (ast_map::node_item(?i)) {
2092+
alt (i.node) {
2093+
case (ast::item_res(?dtor, _, _, _)) { dtor }
2094+
}
2095+
}
2096+
};
2097+
cx.fcx.llargs.insert(dtor.decl.inputs.(0).id, v0);
2098+
auto rs = trans_block(cx, dtor.body, return);
2099+
drop_ty(rs.bcx, v0, inner)
2100+
}
20852101
case (ty::ty_fn(_, _, _, _, _)) {
20862102
auto box_cell =
20872103
cx.build.GEP(v0, [C_int(0), C_int(abi::fn_field_box)]);
@@ -2549,6 +2565,10 @@ fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
25492565
i += 1;
25502566
}
25512567
}
2568+
case (ty::ty_res(_, ?inner)) {
2569+
f(r.bcx, load_if_immediate(r.bcx, av, inner),
2570+
load_if_immediate(r.bcx, bv, inner), inner);
2571+
}
25522572
case (ty::ty_tag(?tid, ?tps)) {
25532573
auto variants = ty::tag_variants(cx.fcx.lcx.ccx.tcx, tid);
25542574
auto n_variants = vec::len[ty::variant_info](variants);
@@ -4633,12 +4653,10 @@ fn lval_generic_fn(&@block_ctxt cx, &ty::ty_param_count_and_ty tpt,
46334653
auto lv;
46344654
if (cx.fcx.lcx.ccx.sess.get_targ_crate_num() == fn_id._0) {
46354655
// Internal reference.
4636-
46374656
assert (cx.fcx.lcx.ccx.fn_pairs.contains_key(fn_id._1));
46384657
lv = lval_val(cx, cx.fcx.lcx.ccx.fn_pairs.get(fn_id._1));
46394658
} else {
46404659
// External reference.
4641-
46424660
lv = trans_external_path(cx, fn_id, tpt);
46434661
}
46444662
auto tys = ty::node_id_to_type_params(cx.fcx.lcx.ccx.tcx, id);
@@ -7621,6 +7639,26 @@ fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::node_id ctor_id,
76217639
finish_fn(fcx, lltop);
76227640
}
76237641

7642+
fn trans_res(@local_ctxt cx, &span sp, &ast::_fn f, ast::node_id ctor_id,
7643+
&vec[ast::ty_param] ty_params) {
7644+
auto llctor_decl = cx.ccx.item_ids.get(ctor_id);
7645+
auto fcx = new_fn_ctxt(cx, sp, llctor_decl);
7646+
auto ret_ty = ty::ret_ty_of_fn(cx.ccx.tcx, ctor_id);
7647+
create_llargs_for_fn_args(fcx, ast::proto_fn, none[ty_self_pair],
7648+
ret_ty, f.decl.inputs, ty_params);
7649+
auto bcx = new_top_block_ctxt(fcx);
7650+
auto lltop = bcx.llbb;
7651+
auto self_ty = ty::ret_ty_of_fn(cx.ccx.tcx, ctor_id);
7652+
auto llself_ty = type_of(cx.ccx, sp, self_ty);
7653+
auto arg_ty = arg_tys_of_fn(cx.ccx, ctor_id).(0).ty;
7654+
auto arg = load_if_immediate
7655+
(bcx, fcx.llargs.get(f.decl.inputs.(0).id), arg_ty);
7656+
bcx = copy_val(bcx, INIT, fcx.llretptr, arg, arg_ty).bcx;
7657+
bcx.build.RetVoid();
7658+
finish_fn(fcx, lltop);
7659+
}
7660+
7661+
76247662
fn trans_tag_variant(@local_ctxt cx, ast::node_id tag_id,
76257663
&ast::variant variant, int index,
76267664
&vec[ast::ty_param] ty_params) {
@@ -7729,6 +7767,9 @@ fn trans_item(@local_ctxt cx, &ast::item item) {
77297767
with *extend_path(cx, item.ident));
77307768
trans_obj(sub_cx, item.span, ob, ctor_id, tps);
77317769
}
7770+
case (ast::item_res(?decl, _, ?tps, ?ctor_id)) {
7771+
trans_res(cx, item.span, decl, ctor_id, tps);
7772+
}
77327773
case (ast::item_mod(?m)) {
77337774
auto sub_cx =
77347775
@rec(path=cx.path + [item.ident],
@@ -8062,6 +8103,9 @@ fn collect_item_2(&@crate_ctxt ccx, &@ast::item i, &vec[str] pt,
80628103
ccx.obj_methods.insert(m.node.id, ());
80638104
}
80648105
}
8106+
case (ast::item_res(?decl, _, ?tps, ?ctor_id)) {
8107+
decl_fn_and_pair(ccx, i.span, new_pt, "res_ctor", tps, ctor_id);
8108+
}
80658109
case (_) { }
80668110
}
80678111
}

trunk/src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn find_pre_post_item(&crate_ctxt ccx, &item i) {
119119
ccx=ccx);
120120
find_pre_post_expr(fake_fcx, e);
121121
}
122-
case (item_fn(?f, ?ps)) {
122+
case (item_fn(?f, _)) {
123123
assert (ccx.fm.contains_key(i.id));
124124
auto fcx =
125125
rec(enclosing=ccx.fm.get(i.id),
@@ -132,6 +132,13 @@ fn find_pre_post_item(&crate_ctxt ccx, &item i) {
132132
case (item_native_mod(?nm)) { find_pre_post_native_mod(nm); }
133133
case (item_ty(_, _)) { ret; }
134134
case (item_tag(_, _)) { ret; }
135+
case (item_res(?dtor, ?dtor_id, _, _)) {
136+
auto fcx = rec(enclosing=ccx.fm.get(dtor_id),
137+
id=dtor_id,
138+
name=i.ident,
139+
ccx=ccx);
140+
find_pre_post_fn(fcx, dtor);
141+
}
135142
case (item_obj(?o, _, _)) { find_pre_post_obj(ccx, o); }
136143
}
137144
}

0 commit comments

Comments
 (0)