Skip to content

Commit 487cbf8

Browse files
committed
Remove resources
Also fixed shapes for classes with dtors, as well as handling offsets for classes with dtors correctly in take glue. Closes #2485
1 parent 60a748a commit 487cbf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+145
-728
lines changed

src/libsyntax/ast.rs

-3
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,6 @@ enum item_ {
670670
item_native_mod(native_mod),
671671
item_ty(@ty, [ty_param], region_param),
672672
item_enum([variant], [ty_param], region_param),
673-
item_res(fn_decl /* dtor */, [ty_param], blk /* dtor body */,
674-
node_id /* dtor id */, node_id /* ctor id */,
675-
region_param),
676673
item_class([ty_param], /* ty params for class */
677674
[@iface_ref], /* ifaces this class implements */
678675
[@class_member], /* methods, etc. */

src/libsyntax/ast_map.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,14 @@ enum ast_node {
4343
// order they are introduced.
4444
node_arg(arg, uint),
4545
node_local(uint),
46-
// Constructor for either a resource or a class
47-
node_ctor(ident, [ty_param], a_ctor, @path),
46+
// Constructor for a class
47+
// def_id is parent id
48+
node_ctor(ident, [ty_param], @class_ctor, def_id, @path),
4849
// Destructor for a class
4950
node_dtor([ty_param], @class_dtor, def_id, @path),
5051
node_block(blk),
5152
}
5253

53-
enum a_ctor {
54-
res_ctor(fn_decl, node_id, codemap::span),
55-
class_ctor(@class_ctor, def_id /* ID for parent class */),
56-
}
57-
5854
type map = std::map::hashmap<node_id, ast_node>;
5955
type ctx = {map: map, mut path: path,
6056
mut local_id: uint, diag: span_handler};
@@ -138,7 +134,7 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
138134
span: sp};
139135
cx.map.insert(id, node_ctor(/* FIXME (#2543) */ copy nm,
140136
/* FIXME (#2543) */ copy tps,
141-
class_ctor(ct, parent_id),
137+
ct, parent_id,
142138
@/* FIXME (#2543) */ copy cx.path));
143139
}
144140
visit::fk_dtor(tps, self_id, parent_id) {
@@ -199,15 +195,6 @@ fn map_item(i: @item, cx: ctx, v: vt) {
199195
cx);
200196
}
201197
}
202-
item_res(decl, tps, _, dtor_id, ctor_id, _) {
203-
cx.map.insert(ctor_id, node_ctor(/* FIXME (#2543) */ copy i.ident,
204-
/* FIXME (#2543) */ copy tps,
205-
res_ctor(/* FIXME (#2543) */
206-
copy decl,
207-
ctor_id, i.span),
208-
item_path));
209-
cx.map.insert(dtor_id, node_item(i, item_path));
210-
}
211198
item_enum(vs, _, _) {
212199
for vs.each {|v|
213200
cx.map.insert(v.node.id, node_variant(

src/libsyntax/ast_util.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
425425
visit_item: fn@(i: @item) {
426426
vfn(i.id);
427427
alt i.node {
428-
item_res(_, _, _, d_id, c_id, _) { vfn(d_id); vfn(c_id); }
429428
item_enum(vs, _, _) { for vs.each {|v| vfn(v.node.id); } }
430429
_ {}
431430
}
@@ -497,8 +496,7 @@ fn id_visitor(vfn: fn@(node_id)) -> visit::vt<()> {
497496
vfn(self_id);
498497
vfn(parent_id.node);
499498
}
500-
visit::fk_item_fn(_, tps) |
501-
visit::fk_res(_, tps, _) {
499+
visit::fk_item_fn(_, tps) {
502500
vec::iter(tps) {|tp| vfn(tp.id)}
503501
}
504502
visit::fk_method(_, tps, m) {

src/libsyntax/fold.rs

-8
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,6 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
281281
rp,
282282
/* FIXME (#2543) */ copy methods)
283283
}
284-
item_res(decl, typms, body, did, cid, rp) {
285-
item_res(fold_fn_decl(decl, fld),
286-
fold_ty_params(typms, fld),
287-
fld.fold_block(body),
288-
fld.new_id(did),
289-
fld.new_id(cid),
290-
rp)
291-
}
292284
};
293285
}
294286

src/libsyntax/parse/parser.rs

-25
Original file line numberDiff line numberDiff line change
@@ -1917,29 +1917,6 @@ class parser {
19171917
(ident, item_impl(tps, rp, ifce, ty, meths), none)
19181918
}
19191919

1920-
fn parse_item_res() -> item_info {
1921-
let ident = self.parse_value_ident();
1922-
let rp = self.parse_region_param();
1923-
let ty_params = self.parse_ty_params();
1924-
self.expect(token::LPAREN);
1925-
let arg_ident = self.parse_value_ident();
1926-
self.expect(token::COLON);
1927-
let t = self.parse_ty(false);
1928-
self.expect(token::RPAREN);
1929-
let dtor = self.parse_block_no_value();
1930-
let decl = {
1931-
inputs: [{mode: expl(by_ref), ty: t,
1932-
ident: arg_ident, id: self.get_id()}],
1933-
output: @{id: self.get_id(), node: ty_nil,
1934-
span: ast_util::dummy_sp()},
1935-
purity: impure_fn,
1936-
cf: return_val,
1937-
constraints: []
1938-
};
1939-
(ident, item_res(decl, ty_params, dtor,
1940-
self.get_id(), self.get_id(), rp), none)
1941-
}
1942-
19431920
// Instantiates ident <i> with references to <typarams> as arguments.
19441921
// Used to create a path that refers to a class which will be defined as
19451922
// the return type of the ctor function.
@@ -2341,8 +2318,6 @@ class parser {
23412318
self.parse_item_iface()
23422319
} else if self.eat_keyword("impl") {
23432320
self.parse_item_impl()
2344-
} else if self.eat_keyword("resource") {
2345-
self.parse_item_res()
23462321
} else if self.eat_keyword("class") {
23472322
self.parse_item_class()
23482323
} else { ret none; };

src/libsyntax/parse/token.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ fn restricted_keyword_table() -> hashmap<str, ()> {
293293
"let", "log", "loop",
294294
"mod", "mut",
295295
"native", "new",
296-
"pure",
297-
"resource", "ret",
296+
"pure", "ret",
298297
"true", "trait", "type",
299298
"unchecked", "unsafe",
300299
"while"

src/libsyntax/print/pprust.rs

-49
Original file line numberDiff line numberDiff line change
@@ -130,38 +130,6 @@ fn test_fun_to_str() {
130130
assert fun_to_str(decl, "a", []) == "fn a()";
131131
}
132132

133-
fn res_to_str(decl: ast::fn_decl, name: ast::ident,
134-
params: [ast::ty_param], rp: ast::region_param) -> str {
135-
let buffer = io::mem_buffer();
136-
let s = rust_printer(io::mem_buffer_writer(buffer));
137-
print_res(s, decl, name, params, rp);
138-
end(s); // Close the head box
139-
end(s); // Close the outer box
140-
eof(s.s);
141-
io::mem_buffer_str(buffer)
142-
}
143-
144-
#[test]
145-
fn test_res_to_str() {
146-
let decl: ast::fn_decl = {
147-
inputs: [{
148-
mode: ast::expl(ast::by_val),
149-
ty: @{id: 0,
150-
node: ast::ty_nil,
151-
span: ast_util::dummy_sp()},
152-
ident: "b",
153-
id: 0
154-
}],
155-
output: @{id: 0,
156-
node: ast::ty_nil,
157-
span: ast_util::dummy_sp()},
158-
purity: ast::impure_fn,
159-
cf: ast::return_val,
160-
constraints: []
161-
};
162-
assert res_to_str(decl, "a", []) == "resource a(b: ())";
163-
}
164-
165133
fn block_to_str(blk: ast::blk) -> str {
166134
let buffer = io::mem_buffer();
167135
let s = rust_printer(io::mem_buffer_writer(buffer));
@@ -615,27 +583,10 @@ fn print_item(s: ps, &&item: @ast::item) {
615583
for methods.each {|meth| print_ty_method(s, meth); }
616584
bclose(s, item.span);
617585
}
618-
ast::item_res(decl, tps, body, dt_id, ct_id, rp) {
619-
print_res(s, decl, item.ident, tps, rp);
620-
print_block(s, body);
621-
}
622586
}
623587
s.ann.post(ann_node);
624588
}
625589

626-
fn print_res(s: ps, decl: ast::fn_decl, name: ast::ident,
627-
typarams: [ast::ty_param], rp: ast::region_param) {
628-
head(s, "resource");
629-
word(s.s, *name);
630-
print_region_param(s, rp);
631-
print_type_params(s, typarams);
632-
popen(s);
633-
word_space(s, *decl.inputs[0].ident + ":");
634-
print_type(s, decl.inputs[0].ty);
635-
pclose(s);
636-
space(s.s);
637-
}
638-
639590
fn print_variant(s: ps, v: ast::variant) {
640591
word(s.s, *v.node.name);
641592
if vec::len(v.node.args) > 0u {

src/libsyntax/visit.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ enum vt<E> { mk_vt(visitor<E>), }
1515
enum fn_kind {
1616
fk_item_fn(ident, [ty_param]), //< an item declared with fn()
1717
fk_method(ident, [ty_param], @method),
18-
fk_res(ident, [ty_param], region_param),
1918
fk_anon(proto, capture_clause), //< an anonymous function like fn@(...)
2019
fk_fn_block(capture_clause), //< a block {||...}
2120
fk_ctor(ident, [ty_param], node_id /* self id */,
@@ -27,7 +26,7 @@ enum fn_kind {
2726

2827
fn name_of_fn(fk: fn_kind) -> ident {
2928
alt fk {
30-
fk_item_fn(name, _) | fk_method(name, _, _) | fk_res(name, _, _)
29+
fk_item_fn(name, _) | fk_method(name, _, _)
3130
| fk_ctor(name, _, _, _) { /* FIXME (#2543) */ copy name }
3231
fk_anon(*) | fk_fn_block(*) { @"anon" }
3332
fk_dtor(*) { @"drop" }
@@ -36,7 +35,7 @@ fn name_of_fn(fk: fn_kind) -> ident {
3635

3736
fn tps_of_fn(fk: fn_kind) -> [ty_param] {
3837
alt fk {
39-
fk_item_fn(_, tps) | fk_method(_, tps, _) | fk_res(_, tps, _)
38+
fk_item_fn(_, tps) | fk_method(_, tps, _)
4039
| fk_ctor(_, tps, _, _) | fk_dtor(tps, _, _) {
4140
/* FIXME (#2543) */ copy tps
4241
}
@@ -130,12 +129,6 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
130129
v.visit_ty(t, e, v);
131130
v.visit_ty_params(tps, e, v);
132131
}
133-
item_res(decl, tps, body, dtor_id, _, rp) {
134-
v.visit_fn(fk_res(/* FIXME (#2543) */ copy i.ident,
135-
/* FIXME (#2543) */ copy tps,
136-
rp),
137-
decl, body, i.span, dtor_id, e, v);
138-
}
139132
item_enum(variants, tps, _) {
140133
v.visit_ty_params(tps, e, v);
141134
for variants.each {|vr|

src/rt/rust_box_annihilator.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,14 @@ class annihilator : public shape::data<annihilator,shape::ptr> {
138138
void *data;
139139
};
140140

141-
typedef void (*dtor)(void **retptr, void *env, void *dptr);
141+
typedef void (*dtor)(void **retptr, void *dptr);
142142

143143
static void run_dtor(run_dtor_args *args) {
144144
dtor f = (dtor)args->dtor;
145-
f(NULL, args->dtor->env, args->data);
145+
f(NULL, args->data);
146146
}
147147

148-
void walk_res2(const shape::rust_fn *dtor, const uint8_t *end_sp,
149-
bool live) {
148+
void walk_res2(const shape::rust_fn *dtor, const uint8_t *end_sp) {
150149
void *data = (void*)(uintptr_t)dp;
151150
// Switch back to the Rust stack to run the destructor
152151
run_dtor_args args = {dtor, data};

src/rt/rust_cc.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ class irc : public shape::data<irc,shape::ptr> {
147147
void walk_tydesc2(char) {
148148
}
149149

150-
void walk_res2(const shape::rust_fn *dtor, const uint8_t *end_sp,
151-
bool live) {
150+
void walk_res2(const shape::rust_fn *dtor, const uint8_t *end_sp) {
152151
while (this->sp != end_sp) {
153152
this->walk();
154153
align = true;
@@ -394,8 +393,7 @@ class mark : public shape::data<mark,shape::ptr> {
394393
}
395394
}
396395

397-
void walk_res2(const shape::rust_fn *dtor, const uint8_t *end_sp,
398-
bool live) {
396+
void walk_res2(const shape::rust_fn *dtor, const uint8_t *end_sp) {
399397
while (this->sp != end_sp) {
400398
this->walk();
401399
align = true;

src/rt/rust_shape.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ class cmp : public data<cmp,ptr_pair> {
304304
void walk_tag2(tag_info &tinfo,
305305
const data_pair<tag_variant_t> &tag_variants);
306306
void walk_struct2(const uint8_t *end_sp);
307-
void walk_res2(const rust_fn *dtor, const uint8_t *end_sp,
308-
const data_pair<uintptr_t> &live);
307+
void walk_res2(const rust_fn *dtor, const uint8_t *end_sp);
309308
void walk_variant2(tag_info &tinfo,
310309
tag_variant_t variant_id,
311310
const std::pair<const uint8_t *,const uint8_t *>
@@ -356,8 +355,7 @@ cmp::walk_struct2(const uint8_t *end_sp) {
356355
}
357356

358357
void
359-
cmp::walk_res2(const rust_fn *dtor, const uint8_t *end_sp,
360-
const data_pair<uintptr_t> &live) {
358+
cmp::walk_res2(const rust_fn *dtor, const uint8_t *end_sp) {
361359
abort(); // TODO
362360
}
363361

@@ -463,7 +461,7 @@ log::walk_variant2(tag_info &tinfo,
463461
}
464462

465463
void
466-
log::walk_res2(const rust_fn *dtor, const uint8_t *end_sp, bool live) {
464+
log::walk_res2(const rust_fn *dtor, const uint8_t *end_sp) {
467465
out << prefix << "res";
468466

469467
if (this->sp == end_sp)

src/rt/rust_shape.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,8 @@ class data : public ctxt< data<T,U> > {
950950
}
951951

952952
void walk_res1(const rust_fn *dtor, const uint8_t *end_sp) {
953-
typename U::template data<uintptr_t>::t live = bump_dp<uintptr_t>(dp);
954953
// Delegate to the implementation.
955-
static_cast<T *>(this)->walk_res2(dtor, end_sp, live);
954+
static_cast<T *>(this)->walk_res2(dtor, end_sp);
956955
}
957956

958957
template<typename WN>
@@ -1287,7 +1286,7 @@ class log : public data<log,ptr> {
12871286
const std::pair<const uint8_t *,const uint8_t *>
12881287
variant_ptr_and_end);
12891288
void walk_string2(const std::pair<ptr,ptr> &data);
1290-
void walk_res2(const rust_fn *dtor, const uint8_t *end_sp, bool live);
1289+
void walk_res2(const rust_fn *dtor, const uint8_t *end_sp);
12911290

12921291
template<typename T>
12931292
inline void walk_number2() {

src/rustc/metadata/encoder.rs

-39
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,6 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
186186
encode_name_and_def_id(ebml_w, it.ident, it.id);
187187
}
188188
}
189-
item_res(_, tps, _, _, ctor_id, _) {
190-
ebml_w.wr_tag(tag_paths_data_item) {||
191-
encode_name_and_def_id(ebml_w, it.ident, ctor_id);
192-
}
193-
// The same ident has to be added twice (with different positions)
194-
// because it's for both the ctor and the dtor.
195-
add_to_index(ebml_w, path, index, it.ident);
196-
ebml_w.wr_tag(tag_paths_data_item) {||
197-
encode_name_and_def_id(ebml_w, it.ident, it.id);
198-
}
199-
}
200189
item_class(_, _, items, ctor, m_dtor, _) {
201190
ebml_w.wr_tag(tag_paths_data_item) {||
202191
encode_name_and_def_id(ebml_w, it.ident, it.id);
@@ -698,34 +687,6 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
698687
encode_index(ebml_w, bkts, write_int);
699688
ebml_w.end_tag();
700689
}
701-
item_res(_, tps, _, _, ctor_id, rp) {
702-
add_to_index();
703-
let fn_ty = node_id_to_type(tcx, ctor_id);
704-
705-
ebml_w.start_tag(tag_items_data_item);
706-
encode_def_id(ebml_w, local_def(ctor_id));
707-
encode_family(ebml_w, 'y');
708-
encode_type_param_bounds(ebml_w, ecx, tps);
709-
encode_type(ecx, ebml_w, ty::ty_fn_ret(fn_ty));
710-
encode_name(ebml_w, item.ident);
711-
ecx.encode_inlined_item(ecx, ebml_w, path, ii_item(item));
712-
if (tps.len() == 0u) {
713-
encode_symbol(ecx, ebml_w, item.id);
714-
}
715-
encode_path(ebml_w, path, ast_map::path_name(item.ident));
716-
encode_region_param(ebml_w, rp);
717-
ebml_w.end_tag();
718-
719-
*index += [{val: ctor_id, pos: ebml_w.writer.tell()}];
720-
ebml_w.start_tag(tag_items_data_item);
721-
encode_def_id(ebml_w, local_def(ctor_id));
722-
encode_family(ebml_w, 'f');
723-
encode_type_param_bounds(ebml_w, ecx, tps);
724-
encode_type(ecx, ebml_w, fn_ty);
725-
encode_parent_item(ebml_w, local_def(item.id));
726-
encode_path(ebml_w, path, ast_map::path_name(item.ident));
727-
ebml_w.end_tag();
728-
}
729690
item_impl(tps, rp, ifce, _, methods) {
730691
add_to_index();
731692
ebml_w.start_tag(tag_items_data_item);

0 commit comments

Comments
 (0)