2011-08-04 12:46:10 -05:00
|
|
|
// A "shape" is a compact encoding of a type that is used by interpreted glue.
|
|
|
|
// This substitutes for the runtime tags used by e.g. MLs.
|
|
|
|
|
2012-01-19 12:21:42 -06:00
|
|
|
import lib::llvm::llvm;
|
2012-02-01 04:04:56 -06:00
|
|
|
import lib::llvm::{True, False, ModuleRef, TypeRef, ValueRef};
|
2011-11-14 21:37:35 -06:00
|
|
|
import driver::session;
|
2012-01-19 12:21:42 -06:00
|
|
|
import driver::session::session;
|
2012-01-27 06:17:06 -06:00
|
|
|
import trans::base;
|
2012-02-21 07:20:18 -06:00
|
|
|
import middle::trans::common::*;
|
2012-01-19 12:21:42 -06:00
|
|
|
import back::abi;
|
2011-08-04 12:46:10 -05:00
|
|
|
import middle::ty;
|
2011-11-10 10:41:42 -06:00
|
|
|
import middle::ty::field;
|
2011-08-04 12:46:10 -05:00
|
|
|
import syntax::ast;
|
2011-08-21 23:44:41 -05:00
|
|
|
import syntax::ast_util::dummy_sp;
|
2011-08-04 12:46:10 -05:00
|
|
|
import syntax::util::interner;
|
|
|
|
import util::common;
|
2012-01-27 06:17:06 -06:00
|
|
|
import trans::build::{Load, Store, Add, GEPi};
|
2012-01-19 12:21:42 -06:00
|
|
|
import syntax::codemap::span;
|
2011-08-04 12:46:10 -05:00
|
|
|
|
|
|
|
import std::map::hashmap;
|
|
|
|
|
|
|
|
import ty_ctxt = middle::ty::ctxt;
|
|
|
|
|
2012-03-08 14:16:04 -06:00
|
|
|
type res_info = {did: ast::def_id, tps: [ty::t]};
|
2011-08-19 17:16:48 -05:00
|
|
|
|
|
|
|
type ctxt =
|
|
|
|
{mutable next_tag_id: u16,
|
|
|
|
pad: u16,
|
|
|
|
tag_id_to_index: hashmap<ast::def_id, u16>,
|
|
|
|
mutable tag_order: [ast::def_id],
|
|
|
|
resources: interner::interner<res_info>,
|
|
|
|
llshapetablesty: TypeRef,
|
|
|
|
llshapetables: ValueRef};
|
|
|
|
|
|
|
|
const shape_u8: u8 = 0u8;
|
|
|
|
const shape_u16: u8 = 1u8;
|
|
|
|
const shape_u32: u8 = 2u8;
|
|
|
|
const shape_u64: u8 = 3u8;
|
|
|
|
const shape_i8: u8 = 4u8;
|
|
|
|
const shape_i16: u8 = 5u8;
|
|
|
|
const shape_i32: u8 = 6u8;
|
|
|
|
const shape_i64: u8 = 7u8;
|
|
|
|
const shape_f32: u8 = 8u8;
|
|
|
|
const shape_f64: u8 = 9u8;
|
2012-02-08 14:06:08 -06:00
|
|
|
const shape_box: u8 = 10u8;
|
2011-09-02 09:09:41 -05:00
|
|
|
const shape_vec: u8 = 11u8;
|
2012-01-25 07:34:31 -06:00
|
|
|
const shape_enum: u8 = 12u8;
|
2012-02-08 14:06:08 -06:00
|
|
|
const shape_box_old: u8 = 13u8; // deprecated, remove after snapshot
|
2011-08-19 17:16:48 -05:00
|
|
|
const shape_struct: u8 = 17u8;
|
2012-01-11 23:31:36 -06:00
|
|
|
const shape_box_fn: u8 = 18u8;
|
2012-01-13 03:58:31 -06:00
|
|
|
const shape_UNUSED: u8 = 19u8;
|
2011-08-19 17:16:48 -05:00
|
|
|
const shape_res: u8 = 20u8;
|
|
|
|
const shape_var: u8 = 21u8;
|
|
|
|
const shape_uniq: u8 = 22u8;
|
2012-01-05 18:19:12 -06:00
|
|
|
const shape_opaque_closure_ptr: u8 = 23u8; // the closure itself.
|
2012-01-11 23:31:36 -06:00
|
|
|
const shape_uniq_fn: u8 = 25u8;
|
|
|
|
const shape_stack_fn: u8 = 26u8;
|
|
|
|
const shape_bare_fn: u8 = 27u8;
|
|
|
|
const shape_tydesc: u8 = 28u8;
|
|
|
|
const shape_send_tydesc: u8 = 29u8;
|
2012-02-09 16:16:12 -06:00
|
|
|
const shape_class: u8 = 30u8;
|
2012-03-08 16:05:16 -06:00
|
|
|
const shape_rptr: u8 = 31u8;
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn hash_res_info(ri: res_info) -> uint {
|
2011-08-04 12:46:10 -05:00
|
|
|
let h = 5381u;
|
2011-08-19 17:16:48 -05:00
|
|
|
h *= 33u;
|
|
|
|
h += ri.did.crate as uint;
|
|
|
|
h *= 33u;
|
|
|
|
h += ri.did.node as uint;
|
2012-03-08 14:16:04 -06:00
|
|
|
for t in ri.tps {
|
|
|
|
h *= 33u;
|
|
|
|
h += ty::type_id(t);
|
|
|
|
}
|
2011-08-04 12:46:10 -05:00
|
|
|
ret h;
|
|
|
|
}
|
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) ->
|
2011-10-12 15:31:41 -05:00
|
|
|
ValueRef {
|
2011-09-02 17:34:58 -05:00
|
|
|
let llglobal =
|
2012-03-14 17:10:34 -05:00
|
|
|
str::as_c_str(name,
|
2011-09-02 17:34:58 -05:00
|
|
|
{|buf|
|
|
|
|
lib::llvm::llvm::LLVMAddGlobal(ccx.llmod,
|
|
|
|
val_ty(llval), buf)
|
|
|
|
});
|
2011-08-04 12:46:10 -05:00
|
|
|
lib::llvm::llvm::LLVMSetInitializer(llglobal, llval);
|
|
|
|
lib::llvm::llvm::LLVMSetGlobalConstant(llglobal, True);
|
2011-08-20 16:22:09 -05:00
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
if internal {
|
2012-02-01 04:04:56 -06:00
|
|
|
lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage);
|
2011-08-20 16:22:09 -05:00
|
|
|
}
|
|
|
|
|
2011-08-04 12:46:10 -05:00
|
|
|
ret llglobal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-19 16:24:03 -06:00
|
|
|
// Computes a set of variants of a enum that are guaranteed to have size and
|
|
|
|
// alignment at least as large as any other variant of the enum. This is an
|
2011-08-04 12:46:10 -05:00
|
|
|
// important performance optimization.
|
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
|
2011-08-04 12:46:10 -05:00
|
|
|
// Compute the minimum and maximum size and alignment for each variant.
|
|
|
|
//
|
2012-02-21 07:20:18 -06:00
|
|
|
// FIXME: We could do better here; e.g. we know that any variant that
|
2011-08-04 12:46:10 -05:00
|
|
|
// contains (T,T) must be as least as large as any variant that contains
|
|
|
|
// just T.
|
2011-08-19 17:16:48 -05:00
|
|
|
let ranges = [];
|
2012-01-25 07:34:31 -06:00
|
|
|
let variants = ty::enum_variants(ccx.tcx, tag_id);
|
2011-12-15 19:14:58 -06:00
|
|
|
for variant: ty::variant_info in *variants {
|
2011-08-04 12:46:10 -05:00
|
|
|
let bounded = true;
|
2012-03-12 04:05:15 -05:00
|
|
|
let min_size = 0u, min_align = 0u;
|
2011-08-19 17:16:48 -05:00
|
|
|
for elem_t: ty::t in variant.args {
|
2012-02-03 08:15:28 -06:00
|
|
|
if ty::type_has_params(elem_t) {
|
2012-02-21 07:20:18 -06:00
|
|
|
// FIXME: We could do better here; this causes us to
|
2011-08-04 12:46:10 -05:00
|
|
|
// conservatively assume that (int, T) has minimum size 0,
|
|
|
|
// when in fact it has minimum size sizeof(int).
|
|
|
|
bounded = false;
|
|
|
|
} else {
|
2012-02-21 08:22:55 -06:00
|
|
|
let llty = type_of::type_of(ccx, elem_t);
|
2012-01-19 12:21:42 -06:00
|
|
|
min_size += llsize_of_real(ccx, llty);
|
|
|
|
min_align += llalign_of_real(ccx, llty);
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
ranges +=
|
|
|
|
[{size: {min: min_size, bounded: bounded},
|
|
|
|
align: {min: min_align, bounded: bounded}}];
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the candidate set to contain all variants.
|
2011-08-19 17:16:48 -05:00
|
|
|
let candidates = [mutable];
|
2011-12-15 19:14:58 -06:00
|
|
|
for variant in *variants { candidates += [mutable true]; }
|
2011-08-04 12:46:10 -05:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// small as some other variant.
|
|
|
|
let i = 0u;
|
2011-08-15 18:38:23 -05:00
|
|
|
while i < vec::len(ranges) - 1u {
|
2011-08-19 17:16:48 -05:00
|
|
|
if candidates[i] {
|
2011-08-04 12:46:10 -05:00
|
|
|
let j = i + 1u;
|
2011-08-19 17:16:48 -05:00
|
|
|
while j < vec::len(ranges) {
|
|
|
|
if candidates[j] {
|
|
|
|
if ranges[i].size.bounded && ranges[i].align.bounded &&
|
|
|
|
ranges[j].size.bounded && ranges[j].align.bounded {
|
|
|
|
if ranges[i].size >= ranges[j].size &&
|
|
|
|
ranges[i].align >= ranges[j].align {
|
2011-08-04 12:46:10 -05:00
|
|
|
// Throw out j.
|
2011-08-19 17:16:48 -05:00
|
|
|
candidates[j] = false;
|
|
|
|
} else if ranges[j].size >= ranges[i].size &&
|
|
|
|
ranges[j].align >= ranges[j].align {
|
2011-08-04 12:46:10 -05:00
|
|
|
// Throw out i.
|
2011-08-19 17:16:48 -05:00
|
|
|
candidates[i] = false;
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
j += 1u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the resulting set.
|
2011-08-19 17:16:48 -05:00
|
|
|
let result = [];
|
2011-08-04 12:46:10 -05:00
|
|
|
i = 0u;
|
2011-08-15 18:38:23 -05:00
|
|
|
while i < vec::len(candidates) {
|
2011-08-19 17:16:48 -05:00
|
|
|
if candidates[i] { result += [i]; }
|
2011-08-04 12:46:10 -05:00
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret result;
|
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
fn round_up(size: u16, align: u8) -> u16 {
|
|
|
|
assert (align >= 1u8);
|
2011-08-04 12:46:10 -05:00
|
|
|
let alignment = align as u16;
|
2011-08-19 17:16:48 -05:00
|
|
|
ret size - 1u16 + alignment & !(alignment - 1u16);
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
type size_align = {size: u16, align: u8};
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn compute_static_enum_size(ccx: @crate_ctxt, largest_variants: [uint],
|
2012-03-12 04:05:15 -05:00
|
|
|
did: ast::def_id) -> size_align {
|
2011-08-19 17:16:48 -05:00
|
|
|
let max_size = 0u16;
|
|
|
|
let max_align = 1u8;
|
2012-01-25 07:34:31 -06:00
|
|
|
let variants = ty::enum_variants(ccx.tcx, did);
|
2011-08-19 17:16:48 -05:00
|
|
|
for vid: uint in largest_variants {
|
2011-08-04 12:46:10 -05:00
|
|
|
// We increment a "virtual data pointer" to compute the size.
|
2011-08-19 17:16:48 -05:00
|
|
|
let lltys = [];
|
|
|
|
for typ: ty::t in variants[vid].args {
|
2012-02-21 08:22:55 -06:00
|
|
|
lltys += [type_of::type_of(ccx, typ)];
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2012-01-27 06:17:06 -06:00
|
|
|
let llty = trans::common::T_struct(lltys);
|
2012-01-19 12:21:42 -06:00
|
|
|
let dp = llsize_of_real(ccx, llty) as u16;
|
|
|
|
let variant_align = llalign_of_real(ccx, llty) as u8;
|
2011-08-04 12:46:10 -05:00
|
|
|
|
|
|
|
if max_size < dp { max_size = dp; }
|
|
|
|
if max_align < variant_align { max_align = variant_align; }
|
|
|
|
}
|
|
|
|
|
2012-01-19 16:24:03 -06:00
|
|
|
// Add space for the enum if applicable.
|
|
|
|
// FIXME (issue #792): This is wrong. If the enum starts with an 8 byte
|
2011-08-04 12:46:10 -05:00
|
|
|
// aligned quantity, we don't align it.
|
2011-12-15 19:14:58 -06:00
|
|
|
if vec::len(*variants) > 1u {
|
2012-01-25 07:34:31 -06:00
|
|
|
let variant_t = T_enum_variant(ccx);
|
2012-01-19 12:21:42 -06:00
|
|
|
max_size += llsize_of_real(ccx, variant_t) as u16;
|
|
|
|
let align = llalign_of_real(ccx, variant_t) as u8;
|
2011-11-23 14:01:15 -06:00
|
|
|
if max_align < align { max_align = align; }
|
|
|
|
}
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
ret {size: max_size, align: max_align};
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2012-01-25 07:34:31 -06:00
|
|
|
enum enum_kind {
|
2012-01-19 12:37:40 -06:00
|
|
|
tk_unit, // 1 variant, no data
|
|
|
|
tk_enum, // N variants, no data
|
|
|
|
tk_newtype, // 1 variant, data
|
|
|
|
tk_complex // N variants, no data
|
|
|
|
}
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn enum_kind(ccx: @crate_ctxt, did: ast::def_id) -> enum_kind {
|
2012-01-25 07:34:31 -06:00
|
|
|
let variants = ty::enum_variants(ccx.tcx, did);
|
2012-01-19 12:37:40 -06:00
|
|
|
if vec::any(*variants) {|v| vec::len(v.args) > 0u} {
|
|
|
|
if vec::len(*variants) == 1u { tk_newtype }
|
|
|
|
else { tk_complex }
|
|
|
|
} else {
|
|
|
|
if vec::len(*variants) <= 1u { tk_unit }
|
|
|
|
else { tk_enum }
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the code corresponding to the pointer size on this architecture.
|
2011-11-14 21:37:35 -06:00
|
|
|
fn s_int(tcx: ty_ctxt) -> u8 {
|
2012-01-12 10:59:49 -06:00
|
|
|
ret alt tcx.sess.targ_cfg.arch {
|
2012-01-19 03:03:57 -06:00
|
|
|
session::arch_x86 { shape_i32 }
|
|
|
|
session::arch_x86_64 { shape_i64 }
|
|
|
|
session::arch_arm { shape_i32 }
|
2011-11-14 21:37:35 -06:00
|
|
|
};
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2011-11-14 21:37:35 -06:00
|
|
|
fn s_uint(tcx: ty_ctxt) -> u8 {
|
2012-01-12 10:59:49 -06:00
|
|
|
ret alt tcx.sess.targ_cfg.arch {
|
2012-01-19 03:03:57 -06:00
|
|
|
session::arch_x86 { shape_u32 }
|
|
|
|
session::arch_x86_64 { shape_u64 }
|
|
|
|
session::arch_arm { shape_u32 }
|
2011-11-14 21:37:35 -06:00
|
|
|
};
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2011-11-14 21:37:35 -06:00
|
|
|
fn s_float(tcx: ty_ctxt) -> u8 {
|
2012-01-12 10:59:49 -06:00
|
|
|
ret alt tcx.sess.targ_cfg.arch {
|
2012-01-19 03:03:57 -06:00
|
|
|
session::arch_x86 { shape_f64 }
|
|
|
|
session::arch_x86_64 { shape_f64 }
|
|
|
|
session::arch_arm { shape_f64 }
|
2011-11-14 21:37:35 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-01-25 07:34:31 -06:00
|
|
|
fn s_variant_enum_t(tcx: ty_ctxt) -> u8 {
|
2011-11-14 21:37:35 -06:00
|
|
|
ret s_int(tcx);
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2012-01-11 23:31:36 -06:00
|
|
|
fn s_tydesc(_tcx: ty_ctxt) -> u8 {
|
|
|
|
ret shape_tydesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn s_send_tydesc(_tcx: ty_ctxt) -> u8 {
|
|
|
|
ret shape_send_tydesc;
|
|
|
|
}
|
|
|
|
|
2011-10-12 15:31:41 -05:00
|
|
|
fn mk_ctxt(llmod: ModuleRef) -> ctxt {
|
2012-01-27 06:17:06 -06:00
|
|
|
let llshapetablesty = trans::common::T_named_struct("shapes");
|
2012-03-14 17:10:34 -05:00
|
|
|
let llshapetables = str::as_c_str("shapes", {|buf|
|
2012-01-27 06:17:06 -06:00
|
|
|
lib::llvm::llvm::LLVMAddGlobal(llmod, llshapetablesty, buf)
|
|
|
|
});
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
ret {mutable next_tag_id: 0u16,
|
|
|
|
pad: 0u16,
|
|
|
|
tag_id_to_index: common::new_def_hash(),
|
|
|
|
mutable tag_order: [],
|
2012-03-08 14:16:04 -06:00
|
|
|
resources: interner::mk(hash_res_info, {|a, b| a == b}),
|
2011-08-19 17:16:48 -05:00
|
|
|
llshapetablesty: llshapetablesty,
|
|
|
|
llshapetables: llshapetables};
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 05:39:38 -05:00
|
|
|
fn add_bool(&dest: [u8], val: bool) { dest += [if val { 1u8 } else { 0u8 }]; }
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2011-09-12 05:39:38 -05:00
|
|
|
fn add_u16(&dest: [u8], val: u16) {
|
2012-02-09 04:50:54 -06:00
|
|
|
dest += [(val & 0xffu16) as u8, (val >> 8u16) as u8];
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 05:39:38 -05:00
|
|
|
fn add_substr(&dest: [u8], src: [u8]) {
|
2011-08-15 18:38:23 -05:00
|
|
|
add_u16(dest, vec::len(src) as u16);
|
2011-08-04 12:46:10 -05:00
|
|
|
dest += src;
|
|
|
|
}
|
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
|
2012-02-03 08:15:28 -06:00
|
|
|
alt ty::get(t).struct {
|
2012-01-19 00:37:22 -06:00
|
|
|
ty::ty_nil | ty::ty_bool | ty::ty_uint(ast::ty_u8) |
|
2012-03-12 04:05:15 -05:00
|
|
|
ty::ty_bot { [shape_u8] }
|
|
|
|
ty::ty_int(ast::ty_i) { [s_int(ccx.tcx)] }
|
|
|
|
ty::ty_float(ast::ty_f) { [s_float(ccx.tcx)] }
|
|
|
|
ty::ty_uint(ast::ty_u) | ty::ty_ptr(_) { [s_uint(ccx.tcx)] }
|
|
|
|
ty::ty_type { [s_tydesc(ccx.tcx)] }
|
|
|
|
ty::ty_int(ast::ty_i8) { [shape_i8] }
|
|
|
|
ty::ty_uint(ast::ty_u16) { [shape_u16] }
|
|
|
|
ty::ty_int(ast::ty_i16) { [shape_i16] }
|
|
|
|
ty::ty_uint(ast::ty_u32) { [shape_u32] }
|
|
|
|
ty::ty_int(ast::ty_i32) | ty::ty_int(ast::ty_char) { [shape_i32] }
|
|
|
|
ty::ty_uint(ast::ty_u64) { [shape_u64] }
|
|
|
|
ty::ty_int(ast::ty_i64) { [shape_i64] }
|
|
|
|
ty::ty_float(ast::ty_f32) { [shape_f32] }
|
|
|
|
ty::ty_float(ast::ty_f64) { [shape_f64] }
|
2012-01-19 00:37:22 -06:00
|
|
|
ty::ty_str {
|
2012-03-12 04:05:15 -05:00
|
|
|
let s = [shape_vec];
|
2011-08-22 18:12:42 -05:00
|
|
|
add_bool(s, true); // type is POD
|
2011-12-07 14:06:12 -06:00
|
|
|
let unit_ty = ty::mk_mach_uint(ccx.tcx, ast::ty_u8);
|
2012-01-13 03:58:31 -06:00
|
|
|
add_substr(s, shape_of(ccx, unit_ty, ty_param_map));
|
2012-03-12 04:05:15 -05:00
|
|
|
s
|
2011-08-22 18:12:42 -05:00
|
|
|
}
|
2012-01-25 07:34:31 -06:00
|
|
|
ty::ty_enum(did, tps) {
|
|
|
|
alt enum_kind(ccx, did) {
|
2012-03-12 04:05:15 -05:00
|
|
|
// FIXME: For now we do this.
|
|
|
|
tk_unit { [s_variant_enum_t(ccx.tcx)] }
|
|
|
|
tk_enum { [s_variant_enum_t(ccx.tcx)] }
|
2012-01-19 12:37:40 -06:00
|
|
|
tk_newtype | tk_complex {
|
2012-03-12 04:05:15 -05:00
|
|
|
let s = [shape_enum], id;
|
2011-08-04 12:46:10 -05:00
|
|
|
alt ccx.shape_cx.tag_id_to_index.find(did) {
|
2012-01-19 00:37:22 -06:00
|
|
|
none {
|
2011-08-04 12:46:10 -05:00
|
|
|
id = ccx.shape_cx.next_tag_id;
|
|
|
|
ccx.shape_cx.tag_id_to_index.insert(did, id);
|
2011-08-19 17:16:48 -05:00
|
|
|
ccx.shape_cx.tag_order += [did];
|
2011-08-04 12:46:10 -05:00
|
|
|
ccx.shape_cx.next_tag_id += 1u16;
|
|
|
|
}
|
|
|
|
some(existing_id) { id = existing_id; }
|
|
|
|
}
|
2012-03-12 04:05:15 -05:00
|
|
|
add_u16(s, id as u16);
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2012-03-12 04:05:15 -05:00
|
|
|
add_u16(s, vec::len(tps) as u16);
|
2011-08-19 17:16:48 -05:00
|
|
|
for tp: ty::t in tps {
|
2012-01-13 03:58:31 -06:00
|
|
|
let subshape = shape_of(ccx, tp, ty_param_map);
|
2012-03-12 04:05:15 -05:00
|
|
|
add_u16(s, vec::len(subshape) as u16);
|
|
|
|
s += subshape;
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
2012-03-12 04:05:15 -05:00
|
|
|
s
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 04:05:15 -05:00
|
|
|
ty::ty_box(_) | ty::ty_opaque_box { [shape_box] }
|
2011-09-21 20:54:54 -05:00
|
|
|
ty::ty_uniq(mt) {
|
2012-03-12 04:05:15 -05:00
|
|
|
let s = [shape_uniq];
|
2012-01-13 03:58:31 -06:00
|
|
|
add_substr(s, shape_of(ccx, mt.ty, ty_param_map));
|
2012-03-12 04:05:15 -05:00
|
|
|
s
|
2011-08-10 19:23:46 -05:00
|
|
|
}
|
2011-08-18 16:11:06 -05:00
|
|
|
ty::ty_vec(mt) {
|
2012-03-12 04:05:15 -05:00
|
|
|
let s = [shape_vec];
|
2011-08-04 12:46:10 -05:00
|
|
|
add_bool(s, ty::type_is_pod(ccx.tcx, mt.ty));
|
2012-01-13 03:58:31 -06:00
|
|
|
add_substr(s, shape_of(ccx, mt.ty, ty_param_map));
|
2012-03-12 04:05:15 -05:00
|
|
|
s
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
ty::ty_rec(fields) {
|
2012-03-12 04:05:15 -05:00
|
|
|
let s = [shape_struct], sub = [];
|
2011-09-02 12:16:41 -05:00
|
|
|
for f: field in fields {
|
2012-01-13 03:58:31 -06:00
|
|
|
sub += shape_of(ccx, f.mt.ty, ty_param_map);
|
2011-09-02 12:16:41 -05:00
|
|
|
}
|
2011-08-04 12:46:10 -05:00
|
|
|
add_substr(s, sub);
|
2012-03-12 04:05:15 -05:00
|
|
|
s
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
2011-08-15 04:40:26 -05:00
|
|
|
ty::ty_tup(elts) {
|
2012-03-12 04:05:15 -05:00
|
|
|
let s = [shape_struct], sub = [];
|
2011-09-22 18:10:48 -05:00
|
|
|
for elt in elts {
|
2012-01-13 03:58:31 -06:00
|
|
|
sub += shape_of(ccx, elt, ty_param_map);
|
2011-09-22 18:10:48 -05:00
|
|
|
}
|
2011-08-15 04:40:26 -05:00
|
|
|
add_substr(s, sub);
|
2012-03-12 04:05:15 -05:00
|
|
|
s
|
2011-08-15 04:40:26 -05:00
|
|
|
}
|
2012-03-12 04:05:15 -05:00
|
|
|
ty::ty_iface(_, _) { [shape_box_fn] }
|
|
|
|
ty::ty_class(_, _) { [shape_class] }
|
2012-03-08 16:05:16 -06:00
|
|
|
ty::ty_rptr(_, tm) {
|
2012-03-12 04:05:15 -05:00
|
|
|
let s = [shape_rptr];
|
2012-03-08 16:05:16 -06:00
|
|
|
add_substr(s, shape_of(ccx, tm.ty, ty_param_map));
|
2012-03-12 04:05:15 -05:00
|
|
|
s
|
2012-03-08 16:05:16 -06:00
|
|
|
}
|
2011-08-04 12:46:10 -05:00
|
|
|
ty::ty_res(did, raw_subt, tps) {
|
|
|
|
let subt = ty::substitute_type_params(ccx.tcx, tps, raw_subt);
|
2012-03-08 14:16:04 -06:00
|
|
|
let ri = {did: did, tps: tps};
|
2011-08-04 12:46:10 -05:00
|
|
|
let id = interner::intern(ccx.shape_cx.resources, ri);
|
|
|
|
|
2012-03-12 04:05:15 -05:00
|
|
|
let s = [shape_res];
|
2011-08-04 12:46:10 -05:00
|
|
|
add_u16(s, id as u16);
|
2011-08-15 18:38:23 -05:00
|
|
|
add_u16(s, vec::len(tps) as u16);
|
2011-09-02 12:16:41 -05:00
|
|
|
for tp: ty::t in tps {
|
2012-01-13 03:58:31 -06:00
|
|
|
add_substr(s, shape_of(ccx, tp, ty_param_map));
|
2011-09-02 12:16:41 -05:00
|
|
|
}
|
2012-01-13 03:58:31 -06:00
|
|
|
add_substr(s, shape_of(ccx, subt, ty_param_map));
|
2012-03-12 04:05:15 -05:00
|
|
|
s
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
2011-09-02 12:16:41 -05:00
|
|
|
ty::ty_param(n, _) {
|
2012-01-13 03:58:31 -06:00
|
|
|
// Find the type parameter in the parameter list.
|
2012-03-18 19:14:43 -05:00
|
|
|
alt vec::position_elem(ty_param_map, n) {
|
2012-03-12 04:05:15 -05:00
|
|
|
some(i) { [shape_var, i as u8] }
|
2012-01-19 00:37:22 -06:00
|
|
|
none { fail "ty param not found in ty_param_map"; }
|
2011-09-02 12:16:41 -05:00
|
|
|
}
|
|
|
|
}
|
2012-03-12 04:05:15 -05:00
|
|
|
ty::ty_fn({proto: ast::proto_box, _}) { [shape_box_fn] }
|
|
|
|
ty::ty_fn({proto: ast::proto_uniq, _}) { [shape_uniq_fn] }
|
2012-01-18 14:04:07 -06:00
|
|
|
ty::ty_fn({proto: ast::proto_block, _}) |
|
2012-03-12 04:05:15 -05:00
|
|
|
ty::ty_fn({proto: ast::proto_any, _}) { [shape_stack_fn] }
|
|
|
|
ty::ty_fn({proto: ast::proto_bare, _}) { [shape_bare_fn] }
|
|
|
|
ty::ty_opaque_closure_ptr(_) { [shape_opaque_closure_ptr] }
|
|
|
|
ty::ty_constr(inner_t, _) { shape_of(ccx, inner_t, ty_param_map) }
|
2012-02-03 08:15:28 -06:00
|
|
|
ty::ty_var(_) | ty::ty_self(_) {
|
2012-02-21 07:25:53 -06:00
|
|
|
ccx.sess.bug("shape_of: unexpected type struct found");
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: We might discover other variants as we traverse these. Handle this.
|
2012-03-14 19:31:16 -05:00
|
|
|
fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info,
|
2011-09-02 12:16:41 -05:00
|
|
|
ty_param_count: uint) -> [u8] {
|
|
|
|
let ty_param_map = [];
|
|
|
|
let i = 0u;
|
2011-09-02 17:34:58 -05:00
|
|
|
while i < ty_param_count { ty_param_map += [i]; i += 1u; }
|
2011-09-02 12:16:41 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let s = [];
|
2012-01-13 03:58:31 -06:00
|
|
|
for t: ty::t in v.args { s += shape_of(ccx, t, ty_param_map); }
|
2011-08-04 12:46:10 -05:00
|
|
|
ret s;
|
|
|
|
}
|
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
|
2012-01-25 07:34:31 -06:00
|
|
|
// Loop over all the enum variants and write their shapes into a
|
|
|
|
// data buffer. As we do this, it's possible for us to discover
|
|
|
|
// new enums, so we must do this first.
|
2011-08-04 12:46:10 -05:00
|
|
|
let i = 0u;
|
2011-08-19 17:16:48 -05:00
|
|
|
let data = [];
|
|
|
|
let offsets = [];
|
|
|
|
while i < vec::len(ccx.shape_cx.tag_order) {
|
|
|
|
let did = ccx.shape_cx.tag_order[i];
|
2012-01-25 07:34:31 -06:00
|
|
|
let variants = ty::enum_variants(ccx.tcx, did);
|
2011-09-02 12:16:41 -05:00
|
|
|
let item_tyt = ty::lookup_item_type(ccx.tcx, did);
|
2012-01-02 05:09:26 -06:00
|
|
|
let ty_param_count = vec::len(*item_tyt.bounds);
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2012-01-15 23:42:10 -06:00
|
|
|
vec::iter(*variants) {|v|
|
2011-08-19 17:16:48 -05:00
|
|
|
offsets += [vec::len(data) as u16];
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2011-09-02 12:16:41 -05:00
|
|
|
let variant_shape = shape_of_variant(ccx, v, ty_param_count);
|
2011-08-04 12:46:10 -05:00
|
|
|
add_substr(data, variant_shape);
|
2012-01-15 23:42:10 -06:00
|
|
|
|
|
|
|
let zname = str::bytes(v.name) + [0u8];
|
|
|
|
add_substr(data, zname);
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now calculate the sizes of the header space (which contains offsets to
|
2012-01-19 16:24:03 -06:00
|
|
|
// info records for each enum) and the info space (which contains offsets
|
2011-08-04 12:46:10 -05:00
|
|
|
// to each variant shape). As we do so, build up the header.
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let header = [];
|
|
|
|
let info = [];
|
2011-08-04 12:46:10 -05:00
|
|
|
let header_sz = 2u16 * ccx.shape_cx.next_tag_id;
|
2011-08-15 18:38:23 -05:00
|
|
|
let data_sz = vec::len(data) as u16;
|
2011-08-04 12:46:10 -05:00
|
|
|
|
|
|
|
let info_sz = 0u16;
|
2011-08-19 17:16:48 -05:00
|
|
|
for did_: ast::def_id in ccx.shape_cx.tag_order {
|
|
|
|
let did = did_; // Satisfy alias checker.
|
2012-01-25 07:34:31 -06:00
|
|
|
let num_variants = vec::len(*ty::enum_variants(ccx.tcx, did)) as u16;
|
2011-08-04 12:46:10 -05:00
|
|
|
add_u16(header, header_sz + info_sz);
|
2012-01-17 22:59:49 -06:00
|
|
|
info_sz += 2u16 * (num_variants + 2u16) + 3u16;
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the info tables, which contain offsets to the shape of each
|
2012-01-19 16:24:03 -06:00
|
|
|
// variant. Also construct the largest-variant table for each enum, which
|
2011-08-04 12:46:10 -05:00
|
|
|
// contains the variants that the size-of operation needs to look at.
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let lv_table = [];
|
2011-08-04 12:46:10 -05:00
|
|
|
i = 0u;
|
2011-08-19 17:16:48 -05:00
|
|
|
for did_: ast::def_id in ccx.shape_cx.tag_order {
|
|
|
|
let did = did_; // Satisfy alias checker.
|
2012-01-25 07:34:31 -06:00
|
|
|
let variants = ty::enum_variants(ccx.tcx, did);
|
2011-12-15 19:14:58 -06:00
|
|
|
add_u16(info, vec::len(*variants) as u16);
|
2011-08-04 12:46:10 -05:00
|
|
|
|
|
|
|
// Construct the largest-variants table.
|
2011-08-19 17:16:48 -05:00
|
|
|
add_u16(info,
|
|
|
|
header_sz + info_sz + data_sz + (vec::len(lv_table) as u16));
|
2011-08-04 12:46:10 -05:00
|
|
|
|
|
|
|
let lv = largest_variants(ccx, did);
|
2011-08-15 18:38:23 -05:00
|
|
|
add_u16(lv_table, vec::len(lv) as u16);
|
2011-08-19 17:16:48 -05:00
|
|
|
for v: uint in lv { add_u16(lv_table, v as u16); }
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2012-01-19 16:24:03 -06:00
|
|
|
// Determine whether the enum has dynamic size.
|
2012-03-12 04:05:15 -05:00
|
|
|
let dynamic = vec::any(*variants, {|v|
|
|
|
|
vec::any(v.args, {|t| ty::type_has_params(t)})
|
|
|
|
});
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2012-01-19 16:24:03 -06:00
|
|
|
// If we can, write in the static size and alignment of the enum.
|
2011-08-04 12:46:10 -05:00
|
|
|
// Otherwise, write a placeholder.
|
2012-03-12 04:05:15 -05:00
|
|
|
let size_align = if dynamic { {size: 0u16, align: 0u8} }
|
|
|
|
else { compute_static_enum_size(ccx, lv, did) };
|
|
|
|
// Write in the static size and alignment of the enum.
|
2011-08-04 12:46:10 -05:00
|
|
|
add_u16(info, size_align.size);
|
2011-08-19 17:16:48 -05:00
|
|
|
info += [size_align.align];
|
2011-08-04 12:46:10 -05:00
|
|
|
|
|
|
|
// Now write in the offset of each variant.
|
2011-12-15 19:14:58 -06:00
|
|
|
for v: ty::variant_info in *variants {
|
2011-08-19 17:16:48 -05:00
|
|
|
add_u16(info, header_sz + info_sz + offsets[i]);
|
2011-08-04 12:46:10 -05:00
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:38:23 -05:00
|
|
|
assert (i == vec::len(offsets));
|
2011-08-19 17:16:48 -05:00
|
|
|
assert (header_sz == vec::len(header) as u16);
|
|
|
|
assert (info_sz == vec::len(info) as u16);
|
|
|
|
assert (data_sz == vec::len(data) as u16);
|
2011-08-04 12:46:10 -05:00
|
|
|
|
|
|
|
header += info;
|
|
|
|
header += data;
|
|
|
|
header += lv_table;
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
ret mk_global(ccx, "tag_shapes", C_bytes(header), true);
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
|
2011-08-19 17:16:48 -05:00
|
|
|
let dtors = [];
|
2011-08-04 12:46:10 -05:00
|
|
|
let i = 0u;
|
|
|
|
let len = interner::len(ccx.shape_cx.resources);
|
|
|
|
while i < len {
|
|
|
|
let ri = interner::get(ccx.shape_cx.resources, i);
|
2012-03-08 14:16:04 -06:00
|
|
|
dtors += [trans::base::get_res_dtor(ccx, ri.did, ri.tps)];
|
2011-08-04 12:46:10 -05:00
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
ret mk_global(ccx, "resource_shapes", C_struct(dtors), true);
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn gen_shape_tables(ccx: @crate_ctxt) {
|
2012-01-25 07:34:31 -06:00
|
|
|
let lltagstable = gen_enum_shapes(ccx);
|
2011-08-04 12:46:10 -05:00
|
|
|
let llresourcestable = gen_resource_shapes(ccx);
|
2012-01-27 06:17:06 -06:00
|
|
|
trans::common::set_struct_body(ccx.shape_cx.llshapetablesty,
|
|
|
|
[val_ty(lltagstable),
|
|
|
|
val_ty(llresourcestable)]);
|
2011-08-04 12:46:10 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let lltables =
|
|
|
|
C_named_struct(ccx.shape_cx.llshapetablesty,
|
|
|
|
[lltagstable, llresourcestable]);
|
2011-08-04 12:46:10 -05:00
|
|
|
lib::llvm::llvm::LLVMSetInitializer(ccx.shape_cx.llshapetables, lltables);
|
|
|
|
lib::llvm::llvm::LLVMSetGlobalConstant(ccx.shape_cx.llshapetables, True);
|
2012-02-01 04:04:56 -06:00
|
|
|
lib::llvm::SetLinkage(ccx.shape_cx.llshapetables,
|
|
|
|
lib::llvm::InternalLinkage);
|
2011-08-04 12:46:10 -05:00
|
|
|
}
|
|
|
|
|
2012-01-19 12:21:42 -06:00
|
|
|
// ______________________________________________________________________
|
|
|
|
// compute sizeof / alignof
|
|
|
|
|
2012-01-19 12:37:40 -06:00
|
|
|
type metrics = {
|
2012-02-17 06:17:40 -06:00
|
|
|
bcx: block,
|
2012-01-19 12:37:40 -06:00
|
|
|
sz: ValueRef,
|
|
|
|
align: ValueRef
|
|
|
|
};
|
|
|
|
|
|
|
|
type tag_metrics = {
|
2012-02-17 06:17:40 -06:00
|
|
|
bcx: block,
|
2012-01-19 12:37:40 -06:00
|
|
|
sz: ValueRef,
|
|
|
|
align: ValueRef,
|
|
|
|
payload_align: ValueRef
|
|
|
|
};
|
|
|
|
|
2012-01-19 12:21:42 -06:00
|
|
|
// Returns the real size of the given type for the current target.
|
2012-03-14 19:31:16 -05:00
|
|
|
fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
|
2012-01-19 12:21:42 -06:00
|
|
|
ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t) as uint;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the real alignment of the given type for the current target.
|
2012-03-14 19:31:16 -05:00
|
|
|
fn llalign_of_real(cx: @crate_ctxt, t: TypeRef) -> uint {
|
2012-01-19 12:21:42 -06:00
|
|
|
ret llvm::LLVMPreferredAlignmentOfType(cx.td.lltd, t) as uint;
|
|
|
|
}
|
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn llsize_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
|
2012-01-19 12:21:42 -06:00
|
|
|
ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMSizeOf(t), cx.int_type,
|
|
|
|
False);
|
|
|
|
}
|
|
|
|
|
2012-03-14 19:31:16 -05:00
|
|
|
fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
|
2012-01-19 12:21:42 -06:00
|
|
|
ret llvm::LLVMConstIntCast(lib::llvm::llvm::LLVMAlignOf(t), cx.int_type,
|
|
|
|
False);
|
|
|
|
}
|
|
|
|
|
2012-02-21 07:25:53 -06:00
|
|
|
// Computes the static size of a enum, without using mk_tup(), which is
|
|
|
|
// bad for performance.
|
|
|
|
//
|
|
|
|
// FIXME: Migrate trans over to use this.
|
|
|
|
|
2012-03-12 04:05:15 -05:00
|
|
|
// Computes the size of the data part of an enum.
|
2012-03-14 19:31:16 -05:00
|
|
|
fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint {
|
2012-01-25 07:34:31 -06:00
|
|
|
if cx.enum_sizes.contains_key(t) { ret cx.enum_sizes.get(t); }
|
2012-02-03 08:15:28 -06:00
|
|
|
alt ty::get(t).struct {
|
2012-01-25 07:34:31 -06:00
|
|
|
ty::ty_enum(tid, subtys) {
|
2012-01-19 12:21:42 -06:00
|
|
|
// Compute max(variant sizes).
|
|
|
|
let max_size = 0u;
|
2012-01-25 07:34:31 -06:00
|
|
|
let variants = ty::enum_variants(cx.tcx, tid);
|
2012-01-19 12:21:42 -06:00
|
|
|
for variant: ty::variant_info in *variants {
|
2012-02-13 07:10:03 -06:00
|
|
|
let tup_ty = simplify_type(cx.tcx,
|
|
|
|
ty::mk_tup(cx.tcx, variant.args));
|
2012-01-19 12:21:42 -06:00
|
|
|
// Perform any type parameter substitutions.
|
|
|
|
tup_ty = ty::substitute_type_params(cx.tcx, subtys, tup_ty);
|
|
|
|
// Here we possibly do a recursive call.
|
2012-01-19 23:15:32 -06:00
|
|
|
let this_size =
|
2012-02-21 08:22:55 -06:00
|
|
|
llsize_of_real(cx, type_of::type_of(cx, tup_ty));
|
2012-01-19 12:21:42 -06:00
|
|
|
if max_size < this_size { max_size = this_size; }
|
|
|
|
}
|
2012-01-25 07:34:31 -06:00
|
|
|
cx.enum_sizes.insert(t, max_size);
|
2012-01-19 12:21:42 -06:00
|
|
|
ret max_size;
|
|
|
|
}
|
2012-02-21 07:25:53 -06:00
|
|
|
_ { cx.sess.bug("static_size_of_enum called on non-enum"); }
|
2012-01-19 12:21:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates a simpler, size-equivalent type. The resulting type is guaranteed
|
|
|
|
// to have (a) the same size as the type that was passed in; (b) to be non-
|
|
|
|
// recursive. This is done by replacing all boxes in a type with boxed unit
|
|
|
|
// types.
|
2012-02-13 07:10:03 -06:00
|
|
|
// This should reduce all pointers to some simple pointer type, to
|
|
|
|
// ensure that we don't recurse endlessly when computing the size of a
|
|
|
|
// nominal type that has pointers to itself in it.
|
|
|
|
fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
|
|
|
|
fn nilptr(tcx: ty::ctxt) -> ty::t {
|
2012-02-15 13:25:39 -06:00
|
|
|
ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mutbl: ast::m_imm})
|
2012-02-13 07:10:03 -06:00
|
|
|
}
|
|
|
|
fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t {
|
2012-02-03 08:15:28 -06:00
|
|
|
alt ty::get(typ).struct {
|
2012-02-13 07:10:03 -06:00
|
|
|
ty::ty_box(_) | ty::ty_opaque_box | ty::ty_uniq(_) | ty::ty_vec(_) |
|
|
|
|
ty::ty_ptr(_) { nilptr(tcx) }
|
|
|
|
ty::ty_fn(_) { ty::mk_tup(tcx, [nilptr(tcx), nilptr(tcx)]) }
|
2012-01-19 12:21:42 -06:00
|
|
|
ty::ty_res(_, sub, tps) {
|
2012-02-13 07:10:03 -06:00
|
|
|
let sub1 = ty::substitute_type_params(tcx, tps, sub);
|
|
|
|
ty::mk_tup(tcx, [ty::mk_int(tcx), simplify_type(tcx, sub1)])
|
2012-01-19 12:21:42 -06:00
|
|
|
}
|
2012-02-13 07:10:03 -06:00
|
|
|
_ { typ }
|
2012-01-19 12:21:42 -06:00
|
|
|
}
|
|
|
|
}
|
2012-02-13 07:10:03 -06:00
|
|
|
ty::fold_ty(tcx, ty::fm_general(bind simplifier(tcx, _)), typ)
|
2012-01-19 12:21:42 -06:00
|
|
|
}
|
2012-01-19 12:37:40 -06:00
|
|
|
|
|
|
|
// Given a tag type `ty`, returns the offset of the payload.
|
2012-02-17 06:17:40 -06:00
|
|
|
//fn tag_payload_offs(bcx: block, tag_id: ast::def_id, tps: [ty::t])
|
2012-01-19 12:37:40 -06:00
|
|
|
// -> ValueRef {
|
|
|
|
// alt tag_kind(tag_id) {
|
2012-02-21 07:20:18 -06:00
|
|
|
// tk_unit | tk_enum | tk_newtype { C_int(bcx.ccx(), 0) }
|
2012-01-19 12:37:40 -06:00
|
|
|
// tk_complex {
|
|
|
|
// compute_tag_metrics(tag_id, tps)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|