Skip to content

Commit 26db74c

Browse files
committed
rustc: Box the vectors returned from ty::tag_variants
1 parent a1b3e3e commit 26db74c

File tree

8 files changed

+39
-37
lines changed

8 files changed

+39
-37
lines changed

src/comp/middle/check_alt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
149149
}
150150
pat_tag(_, args) {
151151
let vdef = variant_def_ids(tcx.def_map.get(pat.id));
152-
if vec::len(ty::tag_variants(tcx, vdef.tg)) != 1u { ret true; }
152+
if vec::len(*ty::tag_variants(tcx, vdef.tg)) != 1u { ret true; }
153153
for p: @pat in args { if is_refutable(tcx, p) { ret true; } }
154154
false
155155
}

src/comp/middle/gc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
128128

129129
ty::ty_tag(did, tps) {
130130
let variants = ty::tag_variants(cx, did);
131-
for variant in variants {
131+
for variant in *variants {
132132
for aty in variant.args {
133133
let arg_ty = ty::substitute_type_params(cx, tps, aty);
134134
if type_is_gc_relevant(cx, arg_ty) { ret true; }

src/comp/middle/mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
3232
}
3333
ty::ty_tag(did, tps) {
3434
let variants = ty::tag_variants(tcx, did);
35-
if vec::len(variants) != 1u ||
35+
if vec::len(*variants) != 1u ||
3636
vec::len(variants[0].args) != 1u {
3737
break;
3838
}

src/comp/middle/shape.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
106106
// just T.
107107
let ranges = [];
108108
let variants = ty::tag_variants(ccx.tcx, tag_id);
109-
for variant: ty::variant_info in variants {
109+
for variant: ty::variant_info in *variants {
110110
let bounded = true;
111111
let {a: min_size, b: min_align} = {a: 0u, b: 0u};
112112
for elem_t: ty::t in variant.args {
@@ -134,7 +134,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
134134

135135
// Initialize the candidate set to contain all variants.
136136
let candidates = [mutable];
137-
for variant in variants { candidates += [mutable true]; }
137+
for variant in *variants { candidates += [mutable true]; }
138138

139139
// Do a pairwise comparison among all variants still in the candidate set.
140140
// Throw out any variant that we know has size and alignment at least as
@@ -214,7 +214,7 @@ fn compute_static_tag_size(ccx: @crate_ctxt, largest_variants: [uint],
214214
// Add space for the tag if applicable.
215215
// FIXME (issue #792): This is wrong. If the tag starts with an 8 byte
216216
// aligned quantity, we don't align it.
217-
if vec::len(variants) > 1u {
217+
if vec::len(*variants) > 1u {
218218
let variant_t = T_tag_variant(ccx);
219219
max_size += trans::llsize_of_real(ccx, variant_t) as u16;
220220
let align = trans::llalign_of_real(ccx, variant_t) as u8;
@@ -228,11 +228,11 @@ tag tag_kind { tk_unit; tk_enum; tk_complex; }
228228

229229
fn tag_kind(ccx: @crate_ctxt, did: ast::def_id) -> tag_kind {
230230
let variants = ty::tag_variants(ccx.tcx, did);
231-
if vec::len(variants) == 0u { ret tk_complex; }
232-
for v: ty::variant_info in variants {
231+
if vec::len(*variants) == 0u { ret tk_complex; }
232+
for v: ty::variant_info in *variants {
233233
if vec::len(v.args) > 0u { ret tk_complex; }
234234
}
235-
if vec::len(variants) == 1u { ret tk_unit; }
235+
if vec::len(*variants) == 1u { ret tk_unit; }
236236
ret tk_enum;
237237
}
238238

@@ -452,7 +452,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
452452
let item_tyt = ty::lookup_item_type(ccx.tcx, did);
453453
let ty_param_count = vec::len(item_tyt.kinds);
454454

455-
for v: ty::variant_info in variants {
455+
for v: ty::variant_info in *variants {
456456
offsets += [vec::len(data) as u16];
457457

458458
let variant_shape = shape_of_variant(ccx, v, ty_param_count);
@@ -476,7 +476,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
476476
let did = did_; // Satisfy alias checker.
477477
let variants = ty::tag_variants(ccx.tcx, did);
478478
add_u16(header, header_sz + info_sz);
479-
info_sz += 2u16 * ((vec::len(variants) as u16) + 2u16) + 3u16;
479+
info_sz += 2u16 * ((vec::len(*variants) as u16) + 2u16) + 3u16;
480480
}
481481

482482
// Construct the info tables, which contain offsets to the shape of each
@@ -488,7 +488,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
488488
for did_: ast::def_id in ccx.shape_cx.tag_order {
489489
let did = did_; // Satisfy alias checker.
490490
let variants = ty::tag_variants(ccx.tcx, did);
491-
add_u16(info, vec::len(variants) as u16);
491+
add_u16(info, vec::len(*variants) as u16);
492492

493493
// Construct the largest-variants table.
494494
add_u16(info,
@@ -500,7 +500,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
500500

501501
// Determine whether the tag has dynamic size.
502502
let dynamic = false;
503-
for variant: ty::variant_info in variants {
503+
for variant: ty::variant_info in *variants {
504504
for typ: ty::t in variant.args {
505505
if ty::type_has_dynamic_size(ccx.tcx, typ) { dynamic = true; }
506506
}
@@ -516,7 +516,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
516516
info += [size_align.align];
517517

518518
// Now write in the offset of each variant.
519-
for v: ty::variant_info in variants {
519+
for v: ty::variant_info in *variants {
520520
add_u16(info, header_sz + info_sz + offsets[i]);
521521
i += 1u;
522522
}

src/comp/middle/trans.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
211211

212212
fn type_of_tag(cx: @crate_ctxt, sp: span, did: ast::def_id, t: ty::t)
213213
-> TypeRef {
214-
let degen = vec::len(ty::tag_variants(cx.tcx, did)) == 1u;
214+
let degen = vec::len(*ty::tag_variants(cx.tcx, did)) == 1u;
215215
if check type_has_static_size(cx, t) {
216216
let size = static_size_of_tag(cx, sp, t);
217217
if !degen { T_tag(cx, size) }
@@ -511,7 +511,7 @@ fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t)
511511

512512
let max_size = 0u;
513513
let variants = ty::tag_variants(cx.tcx, tid);
514-
for variant: ty::variant_info in variants {
514+
for variant: ty::variant_info in *variants {
515515
let tup_ty = simplify_type(cx, ty::mk_tup(cx.tcx, variant.args));
516516
// Perform any type parameter substitutions.
517517

@@ -592,7 +592,7 @@ fn dynamic_size_of(cx: @block_ctxt, t: ty::t, mode: align_mode) -> result {
592592
let max_size: ValueRef = alloca(bcx, ccx.int_type);
593593
Store(bcx, C_int(ccx, 0), max_size);
594594
let variants = ty::tag_variants(bcx_tcx(bcx), tid);
595-
for variant: ty::variant_info in variants {
595+
for variant: ty::variant_info in *variants {
596596
// Perform type substitution on the raw argument types.
597597

598598
let raw_tys: [ty::t] = variant.args;
@@ -609,7 +609,7 @@ fn dynamic_size_of(cx: @block_ctxt, t: ty::t, mode: align_mode) -> result {
609609
}
610610
let max_size_val = Load(bcx, max_size);
611611
let total_size =
612-
if vec::len(variants) != 1u {
612+
if vec::len(*variants) != 1u {
613613
Add(bcx, max_size_val, llsize_of(ccx, ccx.int_type))
614614
} else { max_size_val };
615615
ret rslt(bcx, total_size);
@@ -1693,7 +1693,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
16931693
}
16941694
ty::ty_tag(tid, tps) {
16951695
let variants = ty::tag_variants(bcx_tcx(cx), tid);
1696-
let n_variants = vec::len(variants);
1696+
let n_variants = vec::len(*variants);
16971697

16981698
// Cast the tags to types we can GEP into.
16991699
if n_variants == 1u {
@@ -1715,7 +1715,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
17151715
let llswitch = Switch(cx, lldiscrim_a, unr_cx.llbb, n_variants);
17161716
let next_cx = new_sub_block_ctxt(cx, "tag-iter-next");
17171717
let i = 0u;
1718-
for variant: ty::variant_info in variants {
1718+
for variant: ty::variant_info in *variants {
17191719
let variant_cx =
17201720
new_sub_block_ctxt(cx,
17211721
"tag-iter-variant-" +
@@ -2340,7 +2340,7 @@ fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t {
23402340
}
23412341
ty::ty_tag(did, tps) {
23422342
let variants = ty::tag_variants(ccx.tcx, did);
2343-
if vec::len(variants) != 1u ||
2343+
if vec::len(*variants) != 1u ||
23442344
vec::len(variants[0].args) != 1u {
23452345
break;
23462346
}
@@ -2714,7 +2714,7 @@ fn trans_var(cx: @block_ctxt, sp: span, def: ast::def, id: ast::node_id)
27142714
let bcx = alloc_result.bcx;
27152715
let lltagptr = PointerCast(bcx, lltagblob, T_ptr(lltagty));
27162716
let lldiscrimptr = GEPi(bcx, lltagptr, [0, 0]);
2717-
let d = if vec::len(ty::tag_variants(ccx.tcx, tid)) != 1u {
2717+
let d = if vec::len(*ty::tag_variants(ccx.tcx, tid)) != 1u {
27182718
let lldiscrim_gv = lookup_discriminant(bcx.fcx.lcx, vid);
27192719
let lldiscrim = Load(bcx, lldiscrim_gv);
27202720
lldiscrim

src/comp/middle/trans_alt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn variant_opt(ccx: @crate_ctxt, pat_id: ast::node_id) -> opt {
6565
let vdef = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat_id));
6666
let variants = ty::tag_variants(ccx.tcx, vdef.tg);
6767
let i = 0u;
68-
for v: ty::variant_info in variants {
68+
for v: ty::variant_info in *variants {
6969
if vdef.var == v.id { ret var(i, vdef); }
7070
i += 1u;
7171
}
@@ -265,7 +265,7 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
265265
let args = [];
266266
let size =
267267
vec::len(ty::tag_variant_with_id(ccx.tcx, vdefs.tg, vdefs.var).args);
268-
if size > 0u && vec::len(variants) != 1u {
268+
if size > 0u && vec::len(*variants) != 1u {
269269
let tagptr =
270270
PointerCast(bcx, val, trans_common::T_opaque_tag_ptr(ccx));
271271
blobptr = GEPi(bcx, tagptr, [0, 1]);
@@ -470,7 +470,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
470470
if vec::len(opts) > 0u {
471471
alt opts[0] {
472472
var(_, vdef) {
473-
if vec::len(ty::tag_variants(ccx.tcx, vdef.tg)) == 1u {
473+
if vec::len(*ty::tag_variants(ccx.tcx, vdef.tg)) == 1u {
474474
kind = single;
475475
} else {
476476
let tagptr =

src/comp/middle/ty.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
962962
}
963963
ty_tag(did, tps) {
964964
let variants = tag_variants(cx, did);
965-
for variant in variants {
965+
for variant in *variants {
966966
for aty in variant.args {
967967
// Perform any type parameter substitutions.
968968
let arg_ty = substitute_type_params(cx, tps, aty);
@@ -1031,7 +1031,7 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
10311031
// Tags lower to the lowest of their variants.
10321032
ty_tag(did, tps) {
10331033
let lowest = ast::kind_sendable;
1034-
for variant in tag_variants(cx, did) {
1034+
for variant in *tag_variants(cx, did) {
10351035
for aty in variant.args {
10361036
// Perform any type parameter substitutions.
10371037
let arg_ty = substitute_type_params(cx, tps, aty);
@@ -1063,7 +1063,7 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) ->
10631063
if test(sty) { ret true; }
10641064
alt sty {
10651065
ty_tag(did, tps) {
1066-
for variant in tag_variants(cx, did) {
1066+
for variant in *tag_variants(cx, did) {
10671067
for aty in variant.args {
10681068
let sty = substitute_type_params(cx, tps, aty);
10691069
if type_structurally_contains(cx, sty, test) { ret true; }
@@ -1187,7 +1187,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
11871187
// Structural types
11881188
ty_tag(did, tps) {
11891189
let variants = tag_variants(cx, did);
1190-
for variant: variant_info in variants {
1190+
for variant: variant_info in *variants {
11911191
let tup_ty = mk_tup(cx, variant.args);
11921192

11931193
// Perform any type parameter substitutions.
@@ -1247,7 +1247,7 @@ fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t {
12471247
}
12481248
ty_tag(did, tps) {
12491249
let variants = tag_variants(cx, did);
1250-
if vec::len(variants) != 1u || vec::len(variants[0].args) != 1u {
1250+
if vec::len(*variants) != 1u || vec::len(variants[0].args) != 1u {
12511251
break;
12521252
}
12531253
t1 = substitute_type_params(cx, tps, variants[0].args[0]);
@@ -2723,11 +2723,13 @@ fn def_has_ty_params(def: ast::def) -> bool {
27232723
// Tag information
27242724
type variant_info = {args: [ty::t], ctor_ty: ty::t, id: ast::def_id};
27252725

2726-
fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
2727-
if ast::local_crate != id.crate { ret csearch::get_tag_variants(cx, id); }
2726+
fn tag_variants(cx: ctxt, id: ast::def_id) -> @mutable [variant_info] {
2727+
if ast::local_crate != id.crate {
2728+
ret @mutable csearch::get_tag_variants(cx, id);
2729+
}
27282730
assert (id.node >= 0);
27292731
alt smallintmap::find(*cx.tag_var_cache, id.node as uint) {
2730-
option::some(variants) { ret *variants; }
2732+
option::some(variants) { ret variants; }
27312733
_ { /* fallthrough */ }
27322734
}
27332735
let item =
@@ -2755,7 +2757,7 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
27552757
id: ast_util::local_def(did)}];
27562758
}
27572759
smallintmap::insert(*cx.tag_var_cache, id.node as uint, result);
2758-
ret *result;
2760+
ret result;
27592761
}
27602762
}
27612763
}
@@ -2768,7 +2770,7 @@ fn tag_variant_with_id(cx: ctxt, tag_id: ast::def_id, variant_id: ast::def_id)
27682770
-> variant_info {
27692771
let variants = tag_variants(cx, tag_id);
27702772
let i = 0u;
2771-
while i < vec::len::<variant_info>(variants) {
2773+
while i < vec::len::<variant_info>(*variants) {
27722774
let variant = variants[i];
27732775
if def_eq(variant.id, variant_id) { ret variant; }
27742776
i += 1u;

src/comp/middle/typeck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t {
817817
}
818818
ty::ty_tag(did, tps) {
819819
let variants = ty::tag_variants(fcx.ccx.tcx, did);
820-
if vec::len(variants) != 1u || vec::len(variants[0].args) != 1u {
820+
if vec::len(*variants) != 1u || vec::len(variants[0].args) != 1u {
821821
ret t1;
822822
}
823823
t1 =
@@ -1693,7 +1693,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
16931693
ty::ty_res(_, inner, _) { oper_t = inner; }
16941694
ty::ty_tag(id, tps) {
16951695
let variants = ty::tag_variants(tcx, id);
1696-
if vec::len(variants) != 1u ||
1696+
if vec::len(*variants) != 1u ||
16971697
vec::len(variants[0].args) != 1u {
16981698
tcx.sess.span_fatal(expr.span,
16991699
"can only dereference tags " +

0 commit comments

Comments
 (0)