mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
rustc: Box the vectors returned from ty::tag_variants
This commit is contained in:
parent
a1b3e3ea10
commit
26db74c811
@ -149,7 +149,7 @@ fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
|
||||
}
|
||||
pat_tag(_, args) {
|
||||
let vdef = variant_def_ids(tcx.def_map.get(pat.id));
|
||||
if vec::len(ty::tag_variants(tcx, vdef.tg)) != 1u { ret true; }
|
||||
if vec::len(*ty::tag_variants(tcx, vdef.tg)) != 1u { ret true; }
|
||||
for p: @pat in args { if is_refutable(tcx, p) { ret true; } }
|
||||
false
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
|
||||
|
||||
ty::ty_tag(did, tps) {
|
||||
let variants = ty::tag_variants(cx, did);
|
||||
for variant in variants {
|
||||
for variant in *variants {
|
||||
for aty in variant.args {
|
||||
let arg_ty = ty::substitute_type_params(cx, tps, aty);
|
||||
if type_is_gc_relevant(cx, arg_ty) { ret true; }
|
||||
|
@ -32,7 +32,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
|
||||
}
|
||||
ty::ty_tag(did, tps) {
|
||||
let variants = ty::tag_variants(tcx, did);
|
||||
if vec::len(variants) != 1u ||
|
||||
if vec::len(*variants) != 1u ||
|
||||
vec::len(variants[0].args) != 1u {
|
||||
break;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
|
||||
// just T.
|
||||
let ranges = [];
|
||||
let variants = ty::tag_variants(ccx.tcx, tag_id);
|
||||
for variant: ty::variant_info in variants {
|
||||
for variant: ty::variant_info in *variants {
|
||||
let bounded = true;
|
||||
let {a: min_size, b: min_align} = {a: 0u, b: 0u};
|
||||
for elem_t: ty::t in variant.args {
|
||||
@ -134,7 +134,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
|
||||
|
||||
// Initialize the candidate set to contain all variants.
|
||||
let candidates = [mutable];
|
||||
for variant in variants { candidates += [mutable true]; }
|
||||
for variant in *variants { candidates += [mutable true]; }
|
||||
|
||||
// Do a pairwise comparison among all variants still in the candidate set.
|
||||
// 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],
|
||||
// Add space for the tag if applicable.
|
||||
// FIXME (issue #792): This is wrong. If the tag starts with an 8 byte
|
||||
// aligned quantity, we don't align it.
|
||||
if vec::len(variants) > 1u {
|
||||
if vec::len(*variants) > 1u {
|
||||
let variant_t = T_tag_variant(ccx);
|
||||
max_size += trans::llsize_of_real(ccx, variant_t) as u16;
|
||||
let align = trans::llalign_of_real(ccx, variant_t) as u8;
|
||||
@ -228,11 +228,11 @@ tag tag_kind { tk_unit; tk_enum; tk_complex; }
|
||||
|
||||
fn tag_kind(ccx: @crate_ctxt, did: ast::def_id) -> tag_kind {
|
||||
let variants = ty::tag_variants(ccx.tcx, did);
|
||||
if vec::len(variants) == 0u { ret tk_complex; }
|
||||
for v: ty::variant_info in variants {
|
||||
if vec::len(*variants) == 0u { ret tk_complex; }
|
||||
for v: ty::variant_info in *variants {
|
||||
if vec::len(v.args) > 0u { ret tk_complex; }
|
||||
}
|
||||
if vec::len(variants) == 1u { ret tk_unit; }
|
||||
if vec::len(*variants) == 1u { ret tk_unit; }
|
||||
ret tk_enum;
|
||||
}
|
||||
|
||||
@ -452,7 +452,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
|
||||
let item_tyt = ty::lookup_item_type(ccx.tcx, did);
|
||||
let ty_param_count = vec::len(item_tyt.kinds);
|
||||
|
||||
for v: ty::variant_info in variants {
|
||||
for v: ty::variant_info in *variants {
|
||||
offsets += [vec::len(data) as u16];
|
||||
|
||||
let variant_shape = shape_of_variant(ccx, v, ty_param_count);
|
||||
@ -476,7 +476,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
|
||||
let did = did_; // Satisfy alias checker.
|
||||
let variants = ty::tag_variants(ccx.tcx, did);
|
||||
add_u16(header, header_sz + info_sz);
|
||||
info_sz += 2u16 * ((vec::len(variants) as u16) + 2u16) + 3u16;
|
||||
info_sz += 2u16 * ((vec::len(*variants) as u16) + 2u16) + 3u16;
|
||||
}
|
||||
|
||||
// Construct the info tables, which contain offsets to the shape of each
|
||||
@ -488,7 +488,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
|
||||
for did_: ast::def_id in ccx.shape_cx.tag_order {
|
||||
let did = did_; // Satisfy alias checker.
|
||||
let variants = ty::tag_variants(ccx.tcx, did);
|
||||
add_u16(info, vec::len(variants) as u16);
|
||||
add_u16(info, vec::len(*variants) as u16);
|
||||
|
||||
// Construct the largest-variants table.
|
||||
add_u16(info,
|
||||
@ -500,7 +500,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
|
||||
|
||||
// Determine whether the tag has dynamic size.
|
||||
let dynamic = false;
|
||||
for variant: ty::variant_info in variants {
|
||||
for variant: ty::variant_info in *variants {
|
||||
for typ: ty::t in variant.args {
|
||||
if ty::type_has_dynamic_size(ccx.tcx, typ) { dynamic = true; }
|
||||
}
|
||||
@ -516,7 +516,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
|
||||
info += [size_align.align];
|
||||
|
||||
// Now write in the offset of each variant.
|
||||
for v: ty::variant_info in variants {
|
||||
for v: ty::variant_info in *variants {
|
||||
add_u16(info, header_sz + info_sz + offsets[i]);
|
||||
i += 1u;
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
|
||||
|
||||
fn type_of_tag(cx: @crate_ctxt, sp: span, did: ast::def_id, t: ty::t)
|
||||
-> TypeRef {
|
||||
let degen = vec::len(ty::tag_variants(cx.tcx, did)) == 1u;
|
||||
let degen = vec::len(*ty::tag_variants(cx.tcx, did)) == 1u;
|
||||
if check type_has_static_size(cx, t) {
|
||||
let size = static_size_of_tag(cx, sp, t);
|
||||
if !degen { T_tag(cx, size) }
|
||||
@ -511,7 +511,7 @@ fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t)
|
||||
|
||||
let max_size = 0u;
|
||||
let variants = ty::tag_variants(cx.tcx, tid);
|
||||
for variant: ty::variant_info in variants {
|
||||
for variant: ty::variant_info in *variants {
|
||||
let tup_ty = simplify_type(cx, ty::mk_tup(cx.tcx, variant.args));
|
||||
// Perform any type parameter substitutions.
|
||||
|
||||
@ -592,7 +592,7 @@ fn dynamic_size_of(cx: @block_ctxt, t: ty::t, mode: align_mode) -> result {
|
||||
let max_size: ValueRef = alloca(bcx, ccx.int_type);
|
||||
Store(bcx, C_int(ccx, 0), max_size);
|
||||
let variants = ty::tag_variants(bcx_tcx(bcx), tid);
|
||||
for variant: ty::variant_info in variants {
|
||||
for variant: ty::variant_info in *variants {
|
||||
// Perform type substitution on the raw argument types.
|
||||
|
||||
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 {
|
||||
}
|
||||
let max_size_val = Load(bcx, max_size);
|
||||
let total_size =
|
||||
if vec::len(variants) != 1u {
|
||||
if vec::len(*variants) != 1u {
|
||||
Add(bcx, max_size_val, llsize_of(ccx, ccx.int_type))
|
||||
} else { max_size_val };
|
||||
ret rslt(bcx, total_size);
|
||||
@ -1693,7 +1693,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
|
||||
}
|
||||
ty::ty_tag(tid, tps) {
|
||||
let variants = ty::tag_variants(bcx_tcx(cx), tid);
|
||||
let n_variants = vec::len(variants);
|
||||
let n_variants = vec::len(*variants);
|
||||
|
||||
// Cast the tags to types we can GEP into.
|
||||
if n_variants == 1u {
|
||||
@ -1715,7 +1715,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
|
||||
let llswitch = Switch(cx, lldiscrim_a, unr_cx.llbb, n_variants);
|
||||
let next_cx = new_sub_block_ctxt(cx, "tag-iter-next");
|
||||
let i = 0u;
|
||||
for variant: ty::variant_info in variants {
|
||||
for variant: ty::variant_info in *variants {
|
||||
let variant_cx =
|
||||
new_sub_block_ctxt(cx,
|
||||
"tag-iter-variant-" +
|
||||
@ -2340,7 +2340,7 @@ fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t {
|
||||
}
|
||||
ty::ty_tag(did, tps) {
|
||||
let variants = ty::tag_variants(ccx.tcx, did);
|
||||
if vec::len(variants) != 1u ||
|
||||
if vec::len(*variants) != 1u ||
|
||||
vec::len(variants[0].args) != 1u {
|
||||
break;
|
||||
}
|
||||
@ -2714,7 +2714,7 @@ fn trans_var(cx: @block_ctxt, sp: span, def: ast::def, id: ast::node_id)
|
||||
let bcx = alloc_result.bcx;
|
||||
let lltagptr = PointerCast(bcx, lltagblob, T_ptr(lltagty));
|
||||
let lldiscrimptr = GEPi(bcx, lltagptr, [0, 0]);
|
||||
let d = if vec::len(ty::tag_variants(ccx.tcx, tid)) != 1u {
|
||||
let d = if vec::len(*ty::tag_variants(ccx.tcx, tid)) != 1u {
|
||||
let lldiscrim_gv = lookup_discriminant(bcx.fcx.lcx, vid);
|
||||
let lldiscrim = Load(bcx, lldiscrim_gv);
|
||||
lldiscrim
|
||||
|
@ -65,7 +65,7 @@ fn variant_opt(ccx: @crate_ctxt, pat_id: ast::node_id) -> opt {
|
||||
let vdef = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat_id));
|
||||
let variants = ty::tag_variants(ccx.tcx, vdef.tg);
|
||||
let i = 0u;
|
||||
for v: ty::variant_info in variants {
|
||||
for v: ty::variant_info in *variants {
|
||||
if vdef.var == v.id { ret var(i, vdef); }
|
||||
i += 1u;
|
||||
}
|
||||
@ -265,7 +265,7 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
|
||||
let args = [];
|
||||
let size =
|
||||
vec::len(ty::tag_variant_with_id(ccx.tcx, vdefs.tg, vdefs.var).args);
|
||||
if size > 0u && vec::len(variants) != 1u {
|
||||
if size > 0u && vec::len(*variants) != 1u {
|
||||
let tagptr =
|
||||
PointerCast(bcx, val, trans_common::T_opaque_tag_ptr(ccx));
|
||||
blobptr = GEPi(bcx, tagptr, [0, 1]);
|
||||
@ -470,7 +470,7 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
|
||||
if vec::len(opts) > 0u {
|
||||
alt opts[0] {
|
||||
var(_, vdef) {
|
||||
if vec::len(ty::tag_variants(ccx.tcx, vdef.tg)) == 1u {
|
||||
if vec::len(*ty::tag_variants(ccx.tcx, vdef.tg)) == 1u {
|
||||
kind = single;
|
||||
} else {
|
||||
let tagptr =
|
||||
|
@ -962,7 +962,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
|
||||
}
|
||||
ty_tag(did, tps) {
|
||||
let variants = tag_variants(cx, did);
|
||||
for variant in variants {
|
||||
for variant in *variants {
|
||||
for aty in variant.args {
|
||||
// Perform any type parameter substitutions.
|
||||
let arg_ty = substitute_type_params(cx, tps, aty);
|
||||
@ -1031,7 +1031,7 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
|
||||
// Tags lower to the lowest of their variants.
|
||||
ty_tag(did, tps) {
|
||||
let lowest = ast::kind_sendable;
|
||||
for variant in tag_variants(cx, did) {
|
||||
for variant in *tag_variants(cx, did) {
|
||||
for aty in variant.args {
|
||||
// Perform any type parameter substitutions.
|
||||
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) ->
|
||||
if test(sty) { ret true; }
|
||||
alt sty {
|
||||
ty_tag(did, tps) {
|
||||
for variant in tag_variants(cx, did) {
|
||||
for variant in *tag_variants(cx, did) {
|
||||
for aty in variant.args {
|
||||
let sty = substitute_type_params(cx, tps, aty);
|
||||
if type_structurally_contains(cx, sty, test) { ret true; }
|
||||
@ -1187,7 +1187,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
|
||||
// Structural types
|
||||
ty_tag(did, tps) {
|
||||
let variants = tag_variants(cx, did);
|
||||
for variant: variant_info in variants {
|
||||
for variant: variant_info in *variants {
|
||||
let tup_ty = mk_tup(cx, variant.args);
|
||||
|
||||
// Perform any type parameter substitutions.
|
||||
@ -1247,7 +1247,7 @@ fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t {
|
||||
}
|
||||
ty_tag(did, tps) {
|
||||
let variants = tag_variants(cx, did);
|
||||
if vec::len(variants) != 1u || vec::len(variants[0].args) != 1u {
|
||||
if vec::len(*variants) != 1u || vec::len(variants[0].args) != 1u {
|
||||
break;
|
||||
}
|
||||
t1 = substitute_type_params(cx, tps, variants[0].args[0]);
|
||||
@ -2723,11 +2723,13 @@ fn def_has_ty_params(def: ast::def) -> bool {
|
||||
// Tag information
|
||||
type variant_info = {args: [ty::t], ctor_ty: ty::t, id: ast::def_id};
|
||||
|
||||
fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
|
||||
if ast::local_crate != id.crate { ret csearch::get_tag_variants(cx, id); }
|
||||
fn tag_variants(cx: ctxt, id: ast::def_id) -> @mutable [variant_info] {
|
||||
if ast::local_crate != id.crate {
|
||||
ret @mutable csearch::get_tag_variants(cx, id);
|
||||
}
|
||||
assert (id.node >= 0);
|
||||
alt smallintmap::find(*cx.tag_var_cache, id.node as uint) {
|
||||
option::some(variants) { ret *variants; }
|
||||
option::some(variants) { ret variants; }
|
||||
_ { /* fallthrough */ }
|
||||
}
|
||||
let item =
|
||||
@ -2755,7 +2757,7 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] {
|
||||
id: ast_util::local_def(did)}];
|
||||
}
|
||||
smallintmap::insert(*cx.tag_var_cache, id.node as uint, result);
|
||||
ret *result;
|
||||
ret result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2768,7 +2770,7 @@ fn tag_variant_with_id(cx: ctxt, tag_id: ast::def_id, variant_id: ast::def_id)
|
||||
-> variant_info {
|
||||
let variants = tag_variants(cx, tag_id);
|
||||
let i = 0u;
|
||||
while i < vec::len::<variant_info>(variants) {
|
||||
while i < vec::len::<variant_info>(*variants) {
|
||||
let variant = variants[i];
|
||||
if def_eq(variant.id, variant_id) { ret variant; }
|
||||
i += 1u;
|
||||
|
@ -817,7 +817,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t {
|
||||
}
|
||||
ty::ty_tag(did, tps) {
|
||||
let variants = ty::tag_variants(fcx.ccx.tcx, did);
|
||||
if vec::len(variants) != 1u || vec::len(variants[0].args) != 1u {
|
||||
if vec::len(*variants) != 1u || vec::len(variants[0].args) != 1u {
|
||||
ret t1;
|
||||
}
|
||||
t1 =
|
||||
@ -1693,7 +1693,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
||||
ty::ty_res(_, inner, _) { oper_t = inner; }
|
||||
ty::ty_tag(id, tps) {
|
||||
let variants = ty::tag_variants(tcx, id);
|
||||
if vec::len(variants) != 1u ||
|
||||
if vec::len(*variants) != 1u ||
|
||||
vec::len(variants[0].args) != 1u {
|
||||
tcx.sess.span_fatal(expr.span,
|
||||
"can only dereference tags " +
|
||||
|
Loading…
Reference in New Issue
Block a user