Skip to content

Commit bbdba21

Browse files
committed
rustc: Revert the conversion to interior vectors due to heap corruption
1 parent ec890ff commit bbdba21

27 files changed

+633
-778
lines changed

src/comp/front/attr.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Functions dealing with attributes and meta_items
22

3-
import std::ivec;
43
import std::vec;
54
import std::str;
65
import std::map;
@@ -29,11 +28,13 @@ export mk_attr;
2928

3029
// From a list of crate attributes get only the meta_items that impact crate
3130
// linkage
32-
fn find_linkage_metas(&ast::attribute[] attrs) -> (@ast::meta_item)[] {
33-
let (@ast::meta_item)[] metas = ~[];
31+
fn find_linkage_metas(vec[ast::attribute] attrs) -> vec[@ast::meta_item] {
32+
let vec[@ast::meta_item] metas = [];
3433
for (ast::attribute attr in find_attrs_by_name(attrs, "link")) {
3534
alt (attr.node.value.node) {
36-
case (ast::meta_list(_, ?items)) { metas += items; }
35+
case (ast::meta_list(_, ?items)) {
36+
metas += items;
37+
}
3738
case (_) {
3839
log "ignoring link attribute that has incorrect type";
3940
}
@@ -43,8 +44,8 @@ fn find_linkage_metas(&ast::attribute[] attrs) -> (@ast::meta_item)[] {
4344
}
4445

4546
// Search a list of attributes and return only those with a specific name
46-
fn find_attrs_by_name(&ast::attribute[] attrs,
47-
ast::ident name) -> ast::attribute[] {
47+
fn find_attrs_by_name(vec[ast::attribute] attrs,
48+
ast::ident name) -> vec[ast::attribute] {
4849
auto filter = bind fn(&ast::attribute a,
4950
ast::ident name) -> option::t[ast::attribute] {
5051
if (get_attr_name(a) == name) {
@@ -53,7 +54,7 @@ fn find_attrs_by_name(&ast::attribute[] attrs,
5354
option::none
5455
}
5556
} (_, name);
56-
ret ivec::filter_map(filter, attrs);
57+
ret vec::filter_map(filter, attrs);
5758
}
5859

5960
fn get_attr_name(&ast::attribute attr) -> ast::ident {
@@ -100,10 +101,8 @@ fn get_meta_item_value_str(&@ast::meta_item meta) -> option::t[str] {
100101
fn attr_meta(&ast::attribute attr) -> @ast::meta_item { @attr.node.value }
101102

102103
// Get the meta_items from inside a vector of attributes
103-
fn attr_metas(&ast::attribute[] attrs) -> vec[@ast::meta_item] {
104-
auto mitems = [];
105-
for (ast::attribute a in attrs) { mitems += [attr_meta(a)]; }
106-
ret mitems;
104+
fn attr_metas(&vec[ast::attribute] attrs) -> vec[@ast::meta_item] {
105+
ret vec::map(attr_meta, attrs);
107106
}
108107

109108
fn eq(@ast::meta_item a, @ast::meta_item b) -> bool {
@@ -131,7 +130,7 @@ fn eq(@ast::meta_item a, @ast::meta_item b) -> bool {
131130
}
132131
}
133132

134-
fn contains(&(@ast::meta_item)[] haystack, @ast::meta_item needle) -> bool {
133+
fn contains(&vec[@ast::meta_item] haystack, @ast::meta_item needle) -> bool {
135134
log #fmt("looking for %s",
136135
syntax::print::pprust::meta_item_to_str(*needle));
137136
for (@ast::meta_item item in haystack) {
@@ -220,8 +219,8 @@ fn mk_name_value_item(ast::ident name, ast::lit value) -> @ast::meta_item {
220219
ret @span(ast::meta_name_value(name, value));
221220
}
222221

223-
fn mk_list_item(ast::ident name, &(@ast::meta_item)[] items)
224-
-> @ast::meta_item {
222+
fn mk_list_item(ast::ident name,
223+
&vec[@ast::meta_item] items) -> @ast::meta_item {
225224
ret @span(ast::meta_list(name, items));
226225
}
227226

src/comp/front/config.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import std::ivec;
21
import std::option;
32
import std::vec;
43
import syntax::ast;
@@ -98,20 +97,20 @@ fn native_item_in_cfg(&ast::crate_cfg cfg, &@ast::native_item item) -> bool {
9897

9998
// Determine if an item should be translated in the current crate
10099
// configuration based on the item's attributes
101-
fn in_cfg(&ast::crate_cfg cfg, &ast::attribute[] attrs) -> bool {
100+
fn in_cfg(&ast::crate_cfg cfg, &vec[ast::attribute] attrs) -> bool {
102101

103102
// The "cfg" attributes on the item
104103
auto item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg");
105-
auto item_has_cfg_attrs = ivec::len(item_cfg_attrs) > 0u;
104+
auto item_has_cfg_attrs = vec::len(item_cfg_attrs) > 0u;
106105
if (!item_has_cfg_attrs) { ret true; }
107106

108107
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
109108
// so we can match against them. This is the list of configurations for
110109
// which the item is valid
111110
auto item_cfg_metas = {
112-
fn extract_metas(&(@ast::meta_item)[] inner_items,
111+
fn extract_metas(&vec[@ast::meta_item] inner_items,
113112
&@ast::meta_item cfg_item)
114-
-> (@ast::meta_item)[] {
113+
-> vec[@ast::meta_item] {
115114

116115
alt (cfg_item.node) {
117116
case (ast::meta_list(?name, ?items)) {
@@ -122,11 +121,13 @@ fn in_cfg(&ast::crate_cfg cfg, &ast::attribute[] attrs) -> bool {
122121
}
123122
}
124123
auto cfg_metas = attr::attr_metas(item_cfg_attrs);
125-
ivec::foldl(extract_metas, ~[], cfg_metas)
124+
vec::foldl(extract_metas, [], cfg_metas)
126125
};
127126

128127
for (@ast::meta_item cfg_mi in item_cfg_metas) {
129-
if (attr::contains(cfg, cfg_mi)) { ret true; }
128+
if (attr::contains(cfg, cfg_mi)) {
129+
ret true;
130+
}
130131
}
131132

132133
ret false;

src/comp/metadata/decoder.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,27 +194,27 @@ fn get_symbol(session::session sess, ast::def_id def) -> str {
194194
ret item_symbol(lookup_item(def._1, data));
195195
}
196196

197-
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> ty::variant_info[] {
197+
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> vec[ty::variant_info] {
198198
auto external_crate_id = def._0;
199199
auto data = tcx.sess.get_external_crate(external_crate_id).data;
200200
auto items = ebml::get_doc(ebml::new_doc(data), tag_items);
201201
auto item = find_item(def._1, items);
202-
let ty::variant_info[] infos = ~[];
202+
let vec[ty::variant_info] infos = [];
203203
auto variant_ids = tag_variant_ids(item, external_crate_id);
204204
for (ast::def_id did in variant_ids) {
205205
auto item = find_item(did._1, items);
206206
auto ctor_ty = item_type(item, external_crate_id, tcx);
207-
let ty::t[] arg_tys = ~[];
207+
let vec[ty::t] arg_tys = [];
208208
alt (ty::struct(tcx, ctor_ty)) {
209209
case (ty::ty_fn(_, ?args, _, _, _)) {
210-
for (ty::arg a in args) { arg_tys += ~[a.ty]; }
210+
for (ty::arg a in args) { arg_tys += [a.ty]; }
211211
}
212212
case (_) {
213213
// Nullary tag variant.
214214

215215
}
216216
}
217-
infos += ~[rec(args=arg_tys, ctor_ty=ctor_ty, id=did)];
217+
infos += [rec(args=arg_tys, ctor_ty=ctor_ty, id=did)];
218218
}
219219
ret infos;
220220
}
@@ -290,8 +290,8 @@ fn get_meta_items(&ebml::doc md) -> vec[@ast::meta_item] {
290290
ret items;
291291
}
292292

293-
fn get_attributes(&ebml::doc md) -> ast::attribute[] {
294-
let ast::attribute[] attrs = ~[];
293+
fn get_attributes(&ebml::doc md) -> vec[ast::attribute] {
294+
let vec[ast::attribute] attrs = [];
295295
alt (ebml::maybe_get_doc(md, tag_attributes)) {
296296
case (option::some(?attrs_d)) {
297297
for each (ebml::doc attr_doc in
@@ -301,9 +301,9 @@ fn get_attributes(&ebml::doc md) -> ast::attribute[] {
301301
// an attribute
302302
assert (vec::len(meta_items) == 1u);
303303
auto meta_item = meta_items.(0);
304-
attrs += ~[rec(node=rec(style=ast::attr_outer,
305-
value=*meta_item),
306-
span=rec(lo=0u, hi=0u))];
304+
attrs += [rec(node=rec(style=ast::attr_outer,
305+
value=*meta_item),
306+
span=rec(lo=0u, hi=0u))];
307307
}
308308
}
309309
case (option::none) { }
@@ -327,7 +327,7 @@ fn list_crate_attributes(&ebml::doc md, io::writer out) {
327327
out.write_str("\n\n");
328328
}
329329

330-
fn get_crate_attributes(&vec[u8] data) -> ast::attribute[] {
330+
fn get_crate_attributes(&vec[u8] data) -> vec[ast::attribute] {
331331
ret get_attributes(ebml::new_doc(data));
332332
}
333333

src/comp/metadata/tydecode.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ fn parse_ty_or_bang(@pstate st, str_def sd) -> ty_or_bang {
6565
}
6666
}
6767

68-
fn parse_constrs(@pstate st, str_def sd) -> (@ty::constr_def)[] {
69-
let (@ty::constr_def)[] rslt = ~[];
68+
fn parse_constrs(@pstate st, str_def sd) -> vec[@ty::constr_def] {
69+
let vec[@ty::constr_def] rslt = [];
7070
alt (peek(st) as char) {
7171
case (':') {
7272
do {
7373
next(st);
74-
rslt += ~[parse_constr(st, sd)];
74+
vec::push(rslt, parse_constr(st, sd));
7575
} while (peek(st) as char == ';')
7676
}
7777
case (_) { }
@@ -80,21 +80,21 @@ fn parse_constrs(@pstate st, str_def sd) -> (@ty::constr_def)[] {
8080
}
8181

8282
fn parse_path(@pstate st, str_def sd) -> ast::path {
83-
let ast::ident[] idents = ~[];
83+
let vec[ast::ident] idents = [];
8484
fn is_last(char c) -> bool {
8585
ret (c == '(' || c == ':');
8686
}
87-
idents += ~[parse_ident_(st, sd, is_last)];
87+
idents += [parse_ident_(st, sd, is_last)];
8888
while (true) {
8989
alt (peek(st) as char) {
9090
case (':') { next(st); next(st); }
9191
case (?c) {
9292
if (c == '(') {
9393
ret respan(rec(lo=0u, hi=0u),
94-
rec(idents=idents, types=~[]));
94+
rec(idents=idents, types=[]));
9595
}
9696
else {
97-
idents += ~[parse_ident_(st, sd, is_last)];
97+
idents += [parse_ident_(st, sd, is_last)];
9898
}
9999
}
100100
}
@@ -103,7 +103,7 @@ fn parse_path(@pstate st, str_def sd) -> ast::path {
103103
}
104104

105105
fn parse_constr(@pstate st, str_def sd) -> @ty::constr_def {
106-
let (@ast::constr_arg)[] args = ~[];
106+
let vec[@ast::constr_arg] args = [];
107107
auto sp = rec(lo=0u,hi=0u); // FIXME: use a real span
108108
let ast::path pth = parse_path(st, sd);
109109
let char ignore = next(st) as char;
@@ -113,15 +113,14 @@ fn parse_constr(@pstate st, str_def sd) -> @ty::constr_def {
113113
alt (peek(st) as char) {
114114
case ('*') {
115115
st.pos += 1u;
116-
args += ~[@respan(sp, ast::carg_base)];
116+
args += [@respan(sp, ast::carg_base)];
117117
}
118118
case (?c) {
119119
/* how will we disambiguate between
120120
an arg index and a lit argument? */
121121
if (c >= '0' && c <= '9') {
122122
// FIXME
123-
args += ~[@respan(sp,
124-
ast::carg_ident((c as uint) - 48u))];
123+
args += [@respan(sp, ast::carg_ident((c as uint) - 48u))];
125124
ignore = next(st) as char;
126125
}
127126
else {
@@ -170,8 +169,8 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
170169
case ('t') {
171170
assert (next(st) as char == '[');
172171
auto def = parse_def(st, sd);
173-
let ty::t[] params = ~[];
174-
while (peek(st) as char != ']') { params += ~[parse_ty(st, sd)]; }
172+
let vec[ty::t] params = [];
173+
while (peek(st) as char != ']') { params += [parse_ty(st, sd)]; }
175174
st.pos = st.pos + 1u;
176175
ret ty::mk_tag(st.tcx, def, params);
177176
}
@@ -227,7 +226,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
227226
}
228227
case ('O') {
229228
assert (next(st) as char == '[');
230-
let ty::method[] methods = ~[];
229+
let vec[ty::method] methods = [];
231230
while (peek(st) as char != ']') {
232231
auto proto;
233232
alt (next(st) as char) {
@@ -240,12 +239,12 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
240239
}
241240
auto func = parse_ty_fn(st, sd);
242241
methods +=
243-
~[rec(proto=proto,
244-
ident=name,
245-
inputs=func._0,
246-
output=func._1,
247-
cf=func._2,
248-
constrs=func._3)];
242+
[rec(proto=proto,
243+
ident=name,
244+
inputs=func._0,
245+
output=func._1,
246+
cf=func._2,
247+
constrs=func._3)];
249248
}
250249
st.pos += 1u;
251250
ret ty::mk_obj(st.tcx, methods);
@@ -254,8 +253,8 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
254253
assert (next(st) as char == '[');
255254
auto def = parse_def(st, sd);
256255
auto inner = parse_ty(st, sd);
257-
let ty::t[] params = ~[];
258-
while (peek(st) as char != ']') { params += ~[parse_ty(st, sd)]; }
256+
let vec[ty::t] params = [];
257+
while (peek(st) as char != ']') { params += [parse_ty(st, sd)]; }
259258
st.pos = st.pos + 1u;
260259
ret ty::mk_res(st.tcx, def, inner, params);
261260
}
@@ -334,7 +333,7 @@ fn parse_hex(@pstate st) -> uint {
334333
}
335334

336335
fn parse_ty_fn(@pstate st, str_def sd) ->
337-
tup(ty::arg[], ty::t, ast::controlflow, (@ty::constr_def)[]) {
336+
tup(ty::arg[], ty::t, ast::controlflow, vec[@ty::constr_def]) {
338337
assert (next(st) as char == '[');
339338
let ty::arg[] inputs = ~[];
340339
while (peek(st) as char != ']') {

src/comp/metadata/tyencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
162162
case (native_abi_cdecl) { w.write_char('c'); }
163163
case (native_abi_llvm) { w.write_char('l'); }
164164
}
165-
enc_ty_fn(w, cx, args, out, return, ~[]);
165+
enc_ty_fn(w, cx, args, out, return, []);
166166
}
167167
case (ty::ty_obj(?methods)) {
168168
w.write_str("O[");
@@ -205,7 +205,7 @@ fn enc_proto(&io::writer w, proto proto) {
205205
}
206206
}
207207
fn enc_ty_fn(&io::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
208-
&controlflow cf, &(@ty::constr_def)[] constrs) {
208+
&controlflow cf, &vec[@ty::constr_def] constrs) {
209209
w.write_char('[');
210210
for (ty::arg arg in args) {
211211
alt (arg.mode) {

src/comp/middle/resolve.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import syntax::ast::respan;
1818
import middle::ty::constr_table;
1919
import syntax::visit;
2020
import visit::vt;
21-
import std::ivec;
2221
import std::map::hashmap;
2322
import std::list;
2423
import std::list::list;
@@ -139,7 +138,7 @@ fn resolve_crate(session sess, &ast_map::map amap, @ast::crate crate) ->
139138
auto e =
140139
@rec(crate_map=new_int_hash[ast::crate_num](),
141140
def_map=new_int_hash[def](),
142-
fn_constrs = new_int_hash[ty::constr_def[]](),
141+
fn_constrs = new_int_hash[vec[ty::constr_def]](),
143142
ast_map=amap,
144143
imports=new_int_hash[import_state](),
145144
mod_map=new_int_hash[@indexed_mod](),
@@ -417,14 +416,8 @@ fn resolve_constr(@env e, node_id id, &@ast::constr c, &scopes sc,
417416
if (option::is_some(new_def)) {
418417
alt (option::get(new_def)) {
419418
case (ast::def_fn(?pred_id, ast::pure_fn)) {
420-
// FIXME: Remove this vec->ivec conversion.
421-
let (@ast::constr_arg_general[uint])[] cag_ivec = ~[];
422-
for (@ast::constr_arg_general[uint] cag in c.node.args) {
423-
cag_ivec += ~[cag];
424-
}
425-
426419
let ty::constr_general[uint] c_ =
427-
rec(path=c.node.path, args=cag_ivec, id=pred_id);
420+
rec(path=c.node.path, args=c.node.args, id=pred_id);
428421
let ty::constr_def new_constr = respan(c.span, c_);
429422
add_constr(e, id, new_constr);
430423
}
@@ -440,8 +433,8 @@ fn resolve_constr(@env e, node_id id, &@ast::constr c, &scopes sc,
440433
fn add_constr(&@env e, node_id id, &ty::constr_def c) {
441434
e.fn_constrs.insert(id,
442435
alt (e.fn_constrs.find(id)) {
443-
case (none) { ~[c] }
444-
case (some(?cs)) { cs + ~[c] }
436+
case (none) { [c] }
437+
case (some(?cs)) { cs + [c] }
445438
});
446439
}
447440

@@ -555,9 +548,9 @@ fn mk_unresolved_msg(&ident id, &str kind) -> str {
555548
}
556549

557550
// Lookup helpers
558-
fn lookup_path_strict(&env e, &scopes sc, &span sp, &ident[] idents,
551+
fn lookup_path_strict(&env e, &scopes sc, &span sp, vec[ident] idents,
559552
namespace ns) -> option::t[def] {
560-
auto n_idents = ivec::len(idents);
553+
auto n_idents = vec::len(idents);
561554
auto headns = if (n_idents == 1u) { ns } else { ns_module };
562555
auto dcur = lookup_in_scope_strict(e, sc, sp, idents.(0), headns);
563556
auto i = 1u;

0 commit comments

Comments
 (0)