mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
rustc: Pass a type store around, which does nothing yet
This commit is contained in:
parent
3dbfc9310a
commit
5dbf554bb3
@ -68,16 +68,19 @@ fn compile_input(session.session sess,
|
||||
auto p = parser.new_parser(sess, env, def, input, 0u);
|
||||
auto crate = parse_input(sess, p, input);
|
||||
if (ot == trans.output_type_none) {ret;}
|
||||
|
||||
crate = creader.read_crates(sess, crate, library_search_paths);
|
||||
crate = resolve.resolve_crate(sess, crate);
|
||||
capture.check_for_captures(sess, crate);
|
||||
auto typeck_result = typeck.check_crate(sess, crate);
|
||||
|
||||
auto tystore = ty.mk_type_store();
|
||||
auto typeck_result = typeck.check_crate(sess, tystore, crate);
|
||||
crate = typeck_result._0;
|
||||
auto type_cache = typeck_result._1;
|
||||
// FIXME: uncomment once typestate_check works
|
||||
// crate = typestate_check.check_crate(crate);
|
||||
trans.trans_crate(sess, crate, type_cache, output, shared, optimize,
|
||||
verify, ot);
|
||||
trans.trans_crate(sess, crate, tystore, type_cache, output, shared,
|
||||
optimize, verify, ot);
|
||||
}
|
||||
|
||||
fn pretty_print_input(session.session sess,
|
||||
|
@ -49,22 +49,23 @@ tag resolve_result {
|
||||
// Callback to translate defs to strs or back.
|
||||
type str_def = fn(str) -> ast.def_id;
|
||||
|
||||
type pstate = rec(str rep, mutable uint pos, uint len);
|
||||
type pstate = rec(str rep, mutable uint pos, uint len,
|
||||
@ty.type_store tystore);
|
||||
|
||||
fn peek(@pstate st) -> u8 {
|
||||
if (st.pos < st.len) {ret st.rep.(st.pos) as u8;}
|
||||
else {ret ' ' as u8;}
|
||||
}
|
||||
fn next(@pstate st) -> u8 { // ?? somehow not recognized as impure
|
||||
fn next(@pstate st) -> u8 {
|
||||
if (st.pos >= st.len) {fail;}
|
||||
auto ch = st.rep.(st.pos);
|
||||
st.pos = st.pos + 1u;
|
||||
ret ch as u8;
|
||||
}
|
||||
|
||||
fn parse_ty_str(str rep, str_def sd) -> @ty.t {
|
||||
fn parse_ty_str(str rep, str_def sd, @ty.type_store tystore) -> @ty.t {
|
||||
auto len = _str.byte_len(rep);
|
||||
auto st = @rec(rep=rep, mutable pos=0u, len=len);
|
||||
auto st = @rec(rep=rep, mutable pos=0u, len=len, tystore=tystore);
|
||||
auto result = parse_ty(st, sd);
|
||||
if (st.pos != len) {
|
||||
log_err "parse_ty_str: incomplete parse, stopped at byte "
|
||||
@ -76,27 +77,27 @@ fn parse_ty_str(str rep, str_def sd) -> @ty.t {
|
||||
|
||||
fn parse_ty(@pstate st, str_def sd) -> @ty.t {
|
||||
alt (next(st) as char) {
|
||||
case ('n') { ret ty.mk_nil(); }
|
||||
case ('b') { ret ty.mk_bool(); }
|
||||
case ('i') { ret ty.mk_int(); }
|
||||
case ('u') { ret ty.mk_uint(); }
|
||||
case ('l') { ret ty.mk_float(); }
|
||||
case ('n') { ret ty.mk_nil(st.tystore); }
|
||||
case ('b') { ret ty.mk_bool(st.tystore); }
|
||||
case ('i') { ret ty.mk_int(st.tystore); }
|
||||
case ('u') { ret ty.mk_uint(st.tystore); }
|
||||
case ('l') { ret ty.mk_float(st.tystore); }
|
||||
case ('M') {
|
||||
alt (next(st) as char) {
|
||||
case ('b') { ret ty.mk_mach(common.ty_u8); }
|
||||
case ('w') { ret ty.mk_mach(common.ty_u16); }
|
||||
case ('l') { ret ty.mk_mach(common.ty_u32); }
|
||||
case ('d') { ret ty.mk_mach(common.ty_u64); }
|
||||
case ('B') { ret ty.mk_mach(common.ty_i8); }
|
||||
case ('W') { ret ty.mk_mach(common.ty_i16); }
|
||||
case ('L') { ret ty.mk_mach(common.ty_i32); }
|
||||
case ('D') { ret ty.mk_mach(common.ty_i64); }
|
||||
case ('f') { ret ty.mk_mach(common.ty_f32); }
|
||||
case ('F') { ret ty.mk_mach(common.ty_f64); }
|
||||
case ('b') { ret ty.mk_mach(st.tystore, common.ty_u8); }
|
||||
case ('w') { ret ty.mk_mach(st.tystore, common.ty_u16); }
|
||||
case ('l') { ret ty.mk_mach(st.tystore, common.ty_u32); }
|
||||
case ('d') { ret ty.mk_mach(st.tystore, common.ty_u64); }
|
||||
case ('B') { ret ty.mk_mach(st.tystore, common.ty_i8); }
|
||||
case ('W') { ret ty.mk_mach(st.tystore, common.ty_i16); }
|
||||
case ('L') { ret ty.mk_mach(st.tystore, common.ty_i32); }
|
||||
case ('D') { ret ty.mk_mach(st.tystore, common.ty_i64); }
|
||||
case ('f') { ret ty.mk_mach(st.tystore, common.ty_f32); }
|
||||
case ('F') { ret ty.mk_mach(st.tystore, common.ty_f64); }
|
||||
}
|
||||
}
|
||||
case ('c') { ret ty.mk_char(); }
|
||||
case ('s') { ret ty.mk_str(); }
|
||||
case ('c') { ret ty.mk_char(st.tystore); }
|
||||
case ('s') { ret ty.mk_str(st.tystore); }
|
||||
case ('t') {
|
||||
check(next(st) as char == '[');
|
||||
auto def = parse_def(st, sd);
|
||||
@ -105,13 +106,13 @@ fn parse_ty(@pstate st, str_def sd) -> @ty.t {
|
||||
params += vec(parse_ty(st, sd));
|
||||
}
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty.mk_tag(def, params);
|
||||
ret ty.mk_tag(st.tystore, def, params);
|
||||
}
|
||||
case ('p') { ret ty.mk_param(parse_int(st) as uint); }
|
||||
case ('@') { ret ty.mk_box(parse_mt(st, sd)); }
|
||||
case ('V') { ret ty.mk_vec(parse_mt(st, sd)); }
|
||||
case ('P') { ret ty.mk_port(parse_ty(st, sd)); }
|
||||
case ('C') { ret ty.mk_chan(parse_ty(st, sd)); }
|
||||
case ('p') { ret ty.mk_param(st.tystore, parse_int(st) as uint); }
|
||||
case ('@') { ret ty.mk_box(st.tystore, parse_mt(st, sd)); }
|
||||
case ('V') { ret ty.mk_vec(st.tystore, parse_mt(st, sd)); }
|
||||
case ('P') { ret ty.mk_port(st.tystore, parse_ty(st, sd)); }
|
||||
case ('C') { ret ty.mk_chan(st.tystore, parse_ty(st, sd)); }
|
||||
case ('T') {
|
||||
check(next(st) as char == '[');
|
||||
let vec[ty.mt] params = vec();
|
||||
@ -119,7 +120,7 @@ fn parse_ty(@pstate st, str_def sd) -> @ty.t {
|
||||
params += vec(parse_mt(st, sd));
|
||||
}
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty.mk_tup(params);
|
||||
ret ty.mk_tup(st.tystore, params);
|
||||
}
|
||||
case ('R') {
|
||||
check(next(st) as char == '[');
|
||||
@ -133,15 +134,15 @@ fn parse_ty(@pstate st, str_def sd) -> @ty.t {
|
||||
fields += vec(rec(ident=name, mt=parse_mt(st, sd)));
|
||||
}
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty.mk_rec(fields);
|
||||
ret ty.mk_rec(st.tystore, fields);
|
||||
}
|
||||
case ('F') {
|
||||
auto func = parse_ty_fn(st, sd);
|
||||
ret ty.mk_fn(ast.proto_fn, func._0, func._1);
|
||||
ret ty.mk_fn(st.tystore, ast.proto_fn, func._0, func._1);
|
||||
}
|
||||
case ('W') {
|
||||
auto func = parse_ty_fn(st, sd);
|
||||
ret ty.mk_fn(ast.proto_iter, func._0, func._1);
|
||||
ret ty.mk_fn(st.tystore, ast.proto_iter, func._0, func._1);
|
||||
}
|
||||
case ('N') {
|
||||
auto abi;
|
||||
@ -151,7 +152,7 @@ fn parse_ty(@pstate st, str_def sd) -> @ty.t {
|
||||
case ('l') {abi = ast.native_abi_llvm;}
|
||||
}
|
||||
auto func = parse_ty_fn(st, sd);
|
||||
ret ty.mk_native_fn(abi,func._0,func._1);
|
||||
ret ty.mk_native_fn(st.tystore,abi,func._0,func._1);
|
||||
}
|
||||
case ('O') {
|
||||
check(next(st) as char == '[');
|
||||
@ -173,11 +174,11 @@ fn parse_ty(@pstate st, str_def sd) -> @ty.t {
|
||||
output=func._1));
|
||||
}
|
||||
st.pos += 1u;
|
||||
ret ty.mk_obj(methods);
|
||||
ret ty.mk_obj(st.tystore, methods);
|
||||
}
|
||||
case ('X') { ret ty.mk_var(parse_int(st)); }
|
||||
case ('E') { ret ty.mk_native(); }
|
||||
case ('Y') { ret ty.mk_type(); }
|
||||
case ('X') { ret ty.mk_var(st.tystore, parse_int(st)); }
|
||||
case ('E') { ret ty.mk_native(st.tystore); }
|
||||
case ('Y') { ret ty.mk_type(st.tystore); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,7 +331,7 @@ fn variant_tag_id(&ebml.doc d) -> ast.def_id {
|
||||
ret parse_def_id(ebml.doc_data(tagdoc));
|
||||
}
|
||||
|
||||
fn item_type(&ebml.doc item, int this_cnum) -> @ty.t {
|
||||
fn item_type(&ebml.doc item, int this_cnum, @ty.type_store tystore) -> @ty.t {
|
||||
fn parse_external_def_id(int this_cnum, str s) -> ast.def_id {
|
||||
// FIXME: This is completely wrong when linking against a crate
|
||||
// that, in turn, links against another crate. We need a mapping
|
||||
@ -343,7 +344,7 @@ fn item_type(&ebml.doc item, int this_cnum) -> @ty.t {
|
||||
|
||||
auto tp = ebml.get_doc(item, metadata.tag_items_data_item_type);
|
||||
auto s = _str.unsafe_from_bytes(ebml.doc_data(tp));
|
||||
ret parse_ty_str(s, bind parse_external_def_id(this_cnum, _));
|
||||
ret parse_ty_str(s, bind parse_external_def_id(this_cnum, _), tystore);
|
||||
}
|
||||
|
||||
fn item_ty_param_count(&ebml.doc item, int this_cnum) -> uint {
|
||||
@ -505,12 +506,12 @@ fn lookup_def(session.session sess, int cnum, vec[ast.ident] path)
|
||||
ret some[ast.def](def);
|
||||
}
|
||||
|
||||
fn get_type(session.session sess, ast.def_id def)
|
||||
fn get_type(session.session sess, @ty.type_store tystore, ast.def_id def)
|
||||
-> ty.ty_param_count_and_ty {
|
||||
auto external_crate_id = def._0;
|
||||
auto data = sess.get_external_crate(external_crate_id).data;
|
||||
auto item = lookup_item(def._1, data);
|
||||
auto t = item_type(item, external_crate_id);
|
||||
auto t = item_type(item, external_crate_id, tystore);
|
||||
|
||||
auto tp_count;
|
||||
auto kind_ch = item_kind(item);
|
||||
@ -531,8 +532,9 @@ fn get_symbol(session.session sess, ast.def_id def) -> str {
|
||||
ret item_symbol(item);
|
||||
}
|
||||
|
||||
fn get_tag_variants(session.session sess, ast.def_id def)
|
||||
-> vec[trans.variant_info] {
|
||||
fn get_tag_variants(session.session sess,
|
||||
@ty.type_store tystore,
|
||||
ast.def_id def) -> vec[trans.variant_info] {
|
||||
auto external_crate_id = def._0;
|
||||
auto data = sess.get_external_crate(external_crate_id).data;
|
||||
auto items = ebml.get_doc(ebml.new_doc(data), metadata.tag_items);
|
||||
@ -542,7 +544,7 @@ fn get_tag_variants(session.session sess, ast.def_id def)
|
||||
auto variant_ids = tag_variant_ids(item, external_crate_id);
|
||||
for (ast.def_id did in variant_ids) {
|
||||
auto item = find_item(did._1, items);
|
||||
auto ctor_ty = item_type(item, external_crate_id);
|
||||
auto ctor_ty = item_type(item, external_crate_id, tystore);
|
||||
let vec[@ty.t] arg_tys = vec();
|
||||
alt (ctor_ty.struct) {
|
||||
case (ty.ty_fn(_, ?args, _)) {
|
||||
|
@ -461,7 +461,7 @@ fn encode_info_for_native_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
|
||||
case (ast.native_item_ty(_, ?did)) {
|
||||
encode_def_id(ebml_w, did);
|
||||
encode_kind(ebml_w, 'T' as u8);
|
||||
encode_type(ebml_w, ty.mk_native());
|
||||
encode_type(ebml_w, ty.mk_native(cx.tystore));
|
||||
}
|
||||
case (ast.native_item_fn(_, _, _, ?tps, ?did, ?ann)) {
|
||||
encode_def_id(ebml_w, did);
|
||||
|
@ -112,7 +112,8 @@ state type crate_ctxt = rec(session.session sess,
|
||||
hashmap[@ty.t, TypeRef] lltypes,
|
||||
@glue_fns glues,
|
||||
namegen names,
|
||||
std.sha1.sha1 sha);
|
||||
std.sha1.sha1 sha,
|
||||
@ty.type_store tystore);
|
||||
|
||||
type local_ctxt = rec(vec[str] path,
|
||||
vec[str] module_path,
|
||||
@ -638,7 +639,7 @@ fn type_of_fn_full(@crate_ctxt cx,
|
||||
vec(T_fn_pair(cx.tn,
|
||||
type_of_fn_full(cx, ast.proto_fn, none[TypeRef],
|
||||
vec(rec(mode=ast.val, ty=output)),
|
||||
ty.mk_nil(), 0u)));
|
||||
ty.mk_nil(cx.tystore), 0u)));
|
||||
}
|
||||
|
||||
// ... then explicit args.
|
||||
@ -1145,17 +1146,17 @@ fn array_alloca(@block_ctxt cx, TypeRef t, ValueRef n) -> ValueRef {
|
||||
// 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.
|
||||
fn simplify_type(@ty.t typ) -> @ty.t {
|
||||
fn simplifier(@ty.t typ) -> @ty.t {
|
||||
fn simplify_type(@crate_ctxt ccx, @ty.t typ) -> @ty.t {
|
||||
fn simplifier(@crate_ctxt ccx, @ty.t typ) -> @ty.t {
|
||||
alt (typ.struct) {
|
||||
case (ty.ty_box(_)) {
|
||||
ret ty.mk_imm_box(ty.mk_nil());
|
||||
ret ty.mk_imm_box(ccx.tystore, ty.mk_nil(ccx.tystore));
|
||||
}
|
||||
case (_) { ret typ; }
|
||||
}
|
||||
}
|
||||
auto f = simplifier;
|
||||
ret ty.fold_ty(f, typ);
|
||||
auto f = bind simplifier(ccx, _);
|
||||
ret ty.fold_ty(ccx.tystore, f, typ);
|
||||
}
|
||||
|
||||
// Computes the size of the data part of a non-dynamically-sized tag.
|
||||
@ -1186,11 +1187,12 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint {
|
||||
auto max_size = 0u;
|
||||
auto variants = tag_variants(cx, tid);
|
||||
for (variant_info variant in variants) {
|
||||
auto tup_ty = simplify_type(ty.mk_imm_tup(variant.args));
|
||||
auto tup_ty = simplify_type(cx,
|
||||
ty.mk_imm_tup(cx.tystore, variant.args));
|
||||
|
||||
// Perform any type parameter substitutions.
|
||||
tup_ty = ty.bind_params_in_type(tup_ty);
|
||||
tup_ty = ty.substitute_type_params(subtys, tup_ty);
|
||||
tup_ty = ty.bind_params_in_type(cx.tystore, tup_ty);
|
||||
tup_ty = ty.substitute_type_params(cx.tystore, subtys, tup_ty);
|
||||
|
||||
// Here we possibly do a recursive call.
|
||||
auto this_size = llsize_of_real(cx, type_of(cx, tup_ty));
|
||||
@ -1262,8 +1264,10 @@ fn dynamic_size_of(@block_ctxt cx, @ty.t t) -> result {
|
||||
let vec[@ty.t] raw_tys = variant.args;
|
||||
let vec[@ty.t] tys = vec();
|
||||
for (@ty.t raw_ty in raw_tys) {
|
||||
auto t = ty.bind_params_in_type(raw_ty);
|
||||
t = ty.substitute_type_params(tps, t);
|
||||
auto t = ty.bind_params_in_type(cx.fcx.lcx.ccx.tystore,
|
||||
raw_ty);
|
||||
t = ty.substitute_type_params(cx.fcx.lcx.ccx.tystore, tps,
|
||||
t);
|
||||
tys += vec(t);
|
||||
}
|
||||
|
||||
@ -1402,7 +1406,7 @@ fn GEP_tup_like(@block_ctxt cx, @ty.t t,
|
||||
// flattened the incoming structure.
|
||||
|
||||
auto s = split_type(t, ixs, 0u);
|
||||
auto prefix_ty = ty.mk_imm_tup(s.prefix);
|
||||
auto prefix_ty = ty.mk_imm_tup(cx.fcx.lcx.ccx.tystore, s.prefix);
|
||||
auto bcx = cx;
|
||||
auto sz = size_of(bcx, prefix_ty);
|
||||
bcx = sz.bcx;
|
||||
@ -1433,12 +1437,13 @@ fn GEP_tag(@block_ctxt cx,
|
||||
// Synthesize a tuple type so that GEP_tup_like() can work its magic.
|
||||
// Separately, store the type of the element we're interested in.
|
||||
auto arg_tys = variant.args;
|
||||
auto elem_ty = ty.mk_nil(); // typestate infelicity
|
||||
auto elem_ty = ty.mk_nil(cx.fcx.lcx.ccx.tystore); // typestate infelicity
|
||||
auto i = 0;
|
||||
let vec[@ty.t] true_arg_tys = vec();
|
||||
for (@ty.t aty in arg_tys) {
|
||||
auto arg_ty = ty.bind_params_in_type(aty);
|
||||
arg_ty = ty.substitute_type_params(ty_substs, arg_ty);
|
||||
auto arg_ty = ty.bind_params_in_type(cx.fcx.lcx.ccx.tystore, aty);
|
||||
arg_ty = ty.substitute_type_params(cx.fcx.lcx.ccx.tystore, ty_substs,
|
||||
arg_ty);
|
||||
true_arg_tys += vec(arg_ty);
|
||||
if (i == ix) {
|
||||
elem_ty = arg_ty;
|
||||
@ -1447,7 +1452,7 @@ fn GEP_tag(@block_ctxt cx,
|
||||
i += 1;
|
||||
}
|
||||
|
||||
auto tup_ty = ty.mk_imm_tup(true_arg_tys);
|
||||
auto tup_ty = ty.mk_imm_tup(cx.fcx.lcx.ccx.tystore, true_arg_tys);
|
||||
|
||||
// Cast the blob pointer to the appropriate type, if we need to (i.e. if
|
||||
// the blob pointer isn't dynamically sized).
|
||||
@ -1487,8 +1492,10 @@ fn trans_raw_malloc(@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize)
|
||||
fn trans_malloc_boxed(@block_ctxt cx, @ty.t t) -> result {
|
||||
// Synthesize a fake box type structurally so we have something
|
||||
// to measure the size of.
|
||||
auto boxed_body = ty.mk_imm_tup(vec(ty.mk_int(), t));
|
||||
auto box_ptr = ty.mk_imm_box(t);
|
||||
auto boxed_body = ty.mk_imm_tup(cx.fcx.lcx.ccx.tystore,
|
||||
vec(ty.mk_int(cx.fcx.lcx.ccx.tystore),
|
||||
t));
|
||||
auto box_ptr = ty.mk_imm_box(cx.fcx.lcx.ccx.tystore, t);
|
||||
auto sz = size_of(cx, boxed_body);
|
||||
auto llty = type_of(cx.fcx.lcx.ccx, box_ptr);
|
||||
ret trans_raw_malloc(sz.bcx, llty, sz.val);
|
||||
@ -2116,7 +2123,7 @@ fn make_cmp_glue(@block_ctxt cx,
|
||||
auto min_len = umin(r.bcx, vec_fill(r.bcx, lhs),
|
||||
vec_fill(r.bcx, rhs));
|
||||
auto rhs_lim = r.bcx.build.GEP(rhs_p0, vec(min_len));
|
||||
auto elt_ty = ty.sequence_element_type(t);
|
||||
auto elt_ty = ty.sequence_element_type(cx.fcx.lcx.ccx.tystore, t);
|
||||
r = size_of(r.bcx, elt_ty);
|
||||
r = iter_sequence_raw(r.bcx, lhs_p0, rhs_p0, rhs_lim, r.val,
|
||||
bind inner(next, true, flag, llop,
|
||||
@ -2250,7 +2257,7 @@ type variant_info = rec(vec[@ty.t] args, @ty.t ctor_ty, ast.def_id id);
|
||||
// Returns information about the variants in a tag.
|
||||
fn tag_variants(@crate_ctxt cx, ast.def_id id) -> vec[variant_info] {
|
||||
if (cx.sess.get_targ_crate_num() != id._0) {
|
||||
ret creader.get_tag_variants(cx.sess, id);
|
||||
ret creader.get_tag_variants(cx.sess, cx.tystore, id);
|
||||
}
|
||||
|
||||
check (cx.items.contains_key(id));
|
||||
@ -2333,8 +2340,8 @@ fn iter_structural_ty_full(@block_ctxt cx,
|
||||
val_pair_and_ty_fn f) -> result {
|
||||
auto box_a_ptr = cx.build.Load(box_a_cell);
|
||||
auto box_b_ptr = cx.build.Load(box_b_cell);
|
||||
auto tnil = ty.mk_nil();
|
||||
auto tbox = ty.mk_imm_box(tnil);
|
||||
auto tnil = ty.mk_nil(cx.fcx.lcx.ccx.tystore);
|
||||
auto tbox = ty.mk_imm_box(cx.fcx.lcx.ccx.tystore, tnil);
|
||||
|
||||
auto inner_cx = new_sub_block_ctxt(cx, "iter box");
|
||||
auto next_cx = new_sub_block_ctxt(cx, "next");
|
||||
@ -2399,7 +2406,8 @@ fn iter_structural_ty_full(@block_ctxt cx,
|
||||
// NB: we must hit the discriminant first so that structural
|
||||
// comparison know not to proceed when the discriminants differ.
|
||||
auto bcx = cx;
|
||||
bcx = f(bcx, lldiscrim_a, lldiscrim_b, ty.mk_int()).bcx;
|
||||
bcx = f(bcx, lldiscrim_a, lldiscrim_b,
|
||||
ty.mk_int(cx.fcx.lcx.ccx.tystore)).bcx;
|
||||
|
||||
auto unr_cx = new_sub_block_ctxt(bcx, "tag-iter-unr");
|
||||
unr_cx.build.Unreachable();
|
||||
@ -2435,9 +2443,10 @@ fn iter_structural_ty_full(@block_ctxt cx,
|
||||
auto llfldp_b = rslt.val;
|
||||
variant_cx = rslt.bcx;
|
||||
|
||||
auto ty_subst = ty.bind_params_in_type(a.ty);
|
||||
ty_subst =
|
||||
ty.substitute_type_params(tps, ty_subst);
|
||||
auto ty_subst = ty.bind_params_in_type(
|
||||
cx.fcx.lcx.ccx.tystore, a.ty);
|
||||
ty_subst = ty.substitute_type_params(
|
||||
cx.fcx.lcx.ccx.tystore, tps, ty_subst);
|
||||
|
||||
auto llfld_a =
|
||||
load_if_immediate(variant_cx,
|
||||
@ -2619,7 +2628,7 @@ fn iter_sequence(@block_ctxt cx,
|
||||
ret iter_sequence_body(cx, v, elt.ty, f, false);
|
||||
}
|
||||
case (ty.ty_str) {
|
||||
auto et = ty.mk_mach(common.ty_u8);
|
||||
auto et = ty.mk_mach(cx.fcx.lcx.ccx.tystore, common.ty_u8);
|
||||
ret iter_sequence_body(cx, v, et, f, true);
|
||||
}
|
||||
case (_) { fail; }
|
||||
@ -2843,11 +2852,13 @@ fn trans_lit(@crate_ctxt cx, &ast.lit lit, &ast.ann ann) -> ValueRef {
|
||||
fn target_type(@crate_ctxt cx, @ty.t t) -> @ty.t {
|
||||
alt (t.struct) {
|
||||
case (ty.ty_int) {
|
||||
auto struct_ty = ty.mk_mach(cx.sess.get_targ_cfg().int_type);
|
||||
auto struct_ty = ty.mk_mach(cx.tystore,
|
||||
cx.sess.get_targ_cfg().int_type);
|
||||
ret ty.copy_cname(struct_ty, t);
|
||||
}
|
||||
case (ty.ty_uint) {
|
||||
auto struct_ty = ty.mk_mach(cx.sess.get_targ_cfg().uint_type);
|
||||
auto struct_ty = ty.mk_mach(cx.tystore,
|
||||
cx.sess.get_targ_cfg().uint_type);
|
||||
ret ty.copy_cname(struct_ty, t);
|
||||
}
|
||||
case (_) { /* fall through */ }
|
||||
@ -2858,7 +2869,7 @@ fn target_type(@crate_ctxt cx, @ty.t t) -> @ty.t {
|
||||
|
||||
// Converts an annotation to a type
|
||||
fn node_ann_type(@crate_ctxt cx, &ast.ann a) -> @ty.t {
|
||||
ret target_type(cx, ty.ann_to_monotype(a));
|
||||
ret target_type(cx, ty.ann_to_monotype(cx.tystore, a));
|
||||
}
|
||||
|
||||
fn node_ann_ty_params(&ast.ann a) -> vec[@ty.t] {
|
||||
@ -2887,19 +2898,22 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
|
||||
@ast.expr e, &ast.ann a) -> result {
|
||||
|
||||
auto sub = trans_expr(cx, e);
|
||||
auto e_ty = ty.expr_ty(e);
|
||||
auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, e);
|
||||
|
||||
alt (op) {
|
||||
case (ast.bitnot) {
|
||||
sub = autoderef(sub.bcx, sub.val, ty.expr_ty(e));
|
||||
sub = autoderef(sub.bcx, sub.val,
|
||||
ty.expr_ty(cx.fcx.lcx.ccx.tystore, e));
|
||||
ret res(sub.bcx, sub.bcx.build.Not(sub.val));
|
||||
}
|
||||
case (ast.not) {
|
||||
sub = autoderef(sub.bcx, sub.val, ty.expr_ty(e));
|
||||
sub = autoderef(sub.bcx, sub.val,
|
||||
ty.expr_ty(cx.fcx.lcx.ccx.tystore, e));
|
||||
ret res(sub.bcx, sub.bcx.build.Not(sub.val));
|
||||
}
|
||||
case (ast.neg) {
|
||||
sub = autoderef(sub.bcx, sub.val, ty.expr_ty(e));
|
||||
sub = autoderef(sub.bcx, sub.val,
|
||||
ty.expr_ty(cx.fcx.lcx.ccx.tystore, e));
|
||||
if(e_ty.struct == ty.ty_float) {
|
||||
ret res(sub.bcx, sub.bcx.build.FNeg(sub.val));
|
||||
}
|
||||
@ -2908,7 +2922,7 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
|
||||
}
|
||||
}
|
||||
case (ast.box(_)) {
|
||||
auto e_ty = ty.expr_ty(e);
|
||||
auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, e);
|
||||
auto e_val = sub.val;
|
||||
auto box_ty = node_ann_type(sub.bcx.fcx.lcx.ccx, a);
|
||||
sub = trans_malloc_boxed(sub.bcx, e_ty);
|
||||
@ -2988,7 +3002,7 @@ fn trans_compare(@block_ctxt cx0, ast.binop op, @ty.t t0,
|
||||
fn trans_vec_append(@block_ctxt cx, @ty.t t,
|
||||
ValueRef lhs, ValueRef rhs) -> result {
|
||||
|
||||
auto elt_ty = ty.sequence_element_type(t);
|
||||
auto elt_ty = ty.sequence_element_type(cx.fcx.lcx.ccx.tystore, t);
|
||||
|
||||
auto skip_null = C_bool(false);
|
||||
alt (t.struct) {
|
||||
@ -3160,11 +3174,13 @@ fn trans_binary(@block_ctxt cx, ast.binop op,
|
||||
case (ast.and) {
|
||||
// Lazy-eval and
|
||||
auto lhs_res = trans_expr(cx, a);
|
||||
lhs_res = autoderef(lhs_res.bcx, lhs_res.val, ty.expr_ty(a));
|
||||
lhs_res = autoderef(lhs_res.bcx, lhs_res.val,
|
||||
ty.expr_ty(cx.fcx.lcx.ccx.tystore, a));
|
||||
|
||||
auto rhs_cx = new_scope_block_ctxt(cx, "rhs");
|
||||
auto rhs_res = trans_expr(rhs_cx, b);
|
||||
rhs_res = autoderef(rhs_res.bcx, rhs_res.val, ty.expr_ty(b));
|
||||
rhs_res = autoderef(rhs_res.bcx, rhs_res.val,
|
||||
ty.expr_ty(cx.fcx.lcx.ccx.tystore, b));
|
||||
|
||||
auto lhs_false_cx = new_scope_block_ctxt(cx, "lhs false");
|
||||
auto lhs_false_res = res(lhs_false_cx, C_bool(false));
|
||||
@ -3180,11 +3196,13 @@ fn trans_binary(@block_ctxt cx, ast.binop op,
|
||||
case (ast.or) {
|
||||
// Lazy-eval or
|
||||
auto lhs_res = trans_expr(cx, a);
|
||||
lhs_res = autoderef(lhs_res.bcx, lhs_res.val, ty.expr_ty(a));
|
||||
lhs_res = autoderef(lhs_res.bcx, lhs_res.val,
|
||||
ty.expr_ty(cx.fcx.lcx.ccx.tystore, a));
|
||||
|
||||
auto rhs_cx = new_scope_block_ctxt(cx, "rhs");
|
||||
auto rhs_res = trans_expr(rhs_cx, b);
|
||||
rhs_res = autoderef(rhs_res.bcx, rhs_res.val, ty.expr_ty(b));
|
||||
rhs_res = autoderef(rhs_res.bcx, rhs_res.val,
|
||||
ty.expr_ty(cx.fcx.lcx.ccx.tystore, b));
|
||||
|
||||
auto lhs_true_cx = new_scope_block_ctxt(cx, "lhs true");
|
||||
auto lhs_true_res = res(lhs_true_cx, C_bool(true));
|
||||
@ -3200,10 +3218,10 @@ fn trans_binary(@block_ctxt cx, ast.binop op,
|
||||
case (_) {
|
||||
// Remaining cases are eager:
|
||||
auto lhs = trans_expr(cx, a);
|
||||
auto lhty = ty.expr_ty(a);
|
||||
auto lhty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, a);
|
||||
lhs = autoderef(lhs.bcx, lhs.val, lhty);
|
||||
auto rhs = trans_expr(lhs.bcx, b);
|
||||
auto rhty = ty.expr_ty(b);
|
||||
auto rhty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, b);
|
||||
rhs = autoderef(rhs.bcx, rhs.val, rhty);
|
||||
ret trans_eager_binop(rhs.bcx, op,
|
||||
autoderefed_ty(lhty),
|
||||
@ -3281,7 +3299,7 @@ fn trans_if(@block_ctxt cx, @ast.expr cond,
|
||||
// If we have an else expression, then the entire
|
||||
// if expression can have a non-nil type.
|
||||
// FIXME: This isn't quite right, particularly re: dynamic types
|
||||
auto expr_ty = ty.expr_ty(elexpr);
|
||||
auto expr_ty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, elexpr);
|
||||
if (ty.type_has_dynamic_size(expr_ty)) {
|
||||
expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn);
|
||||
} else {
|
||||
@ -3338,7 +3356,7 @@ fn trans_for(@block_ctxt cx,
|
||||
}
|
||||
|
||||
auto next_cx = new_sub_block_ctxt(cx, "next");
|
||||
auto seq_ty = ty.expr_ty(seq);
|
||||
auto seq_ty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, seq);
|
||||
auto seq_res = trans_expr(cx, seq);
|
||||
auto it = iter_sequence(seq_res.bcx, seq_res.val, seq_ty,
|
||||
bind inner(_, local, _, _, body, next_cx));
|
||||
@ -3440,7 +3458,7 @@ fn trans_for_each(@block_ctxt cx,
|
||||
|
||||
auto lcx = cx.fcx.lcx;
|
||||
// FIXME: possibly support alias-mode here?
|
||||
auto decl_ty = ty.mk_nil();
|
||||
auto decl_ty = ty.mk_nil(lcx.ccx.tystore);
|
||||
auto decl_id;
|
||||
alt (decl.node) {
|
||||
case (ast.decl_local(?local)) {
|
||||
@ -3527,7 +3545,7 @@ fn trans_for_each(@block_ctxt cx,
|
||||
auto iter_body_llty = type_of_fn_full(lcx.ccx, ast.proto_fn,
|
||||
none[TypeRef],
|
||||
vec(rec(mode=ast.val, ty=decl_ty)),
|
||||
ty.mk_nil(), 0u);
|
||||
ty.mk_nil(lcx.ccx.tystore), 0u);
|
||||
|
||||
let ValueRef lliterbody = decl_internal_fastcall_fn(lcx.ccx.llmod,
|
||||
s, iter_body_llty);
|
||||
@ -3715,8 +3733,7 @@ fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval,
|
||||
matched_cx = rslt.bcx;
|
||||
|
||||
auto llsubval = load_if_immediate(matched_cx,
|
||||
llsubvalptr,
|
||||
pat_ty(subpat));
|
||||
llsubvalptr, pat_ty(cx.fcx.lcx.ccx.tystore, subpat));
|
||||
auto subpat_res = trans_pat_match(matched_cx, subpat,
|
||||
llsubval, next_cx);
|
||||
matched_cx = subpat_res.bcx;
|
||||
@ -3770,7 +3787,7 @@ fn trans_pat_binding(@block_ctxt cx, @ast.pat pat, ValueRef llval)
|
||||
auto llsubvalptr = rslt.val;
|
||||
|
||||
auto llsubval = load_if_immediate(this_cx, llsubvalptr,
|
||||
pat_ty(subpat));
|
||||
pat_ty(cx.fcx.lcx.ccx.tystore, subpat));
|
||||
auto subpat_res = trans_pat_binding(this_cx, subpat,
|
||||
llsubval);
|
||||
this_cx = subpat_res.bcx;
|
||||
@ -3959,16 +3976,19 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
|
||||
}
|
||||
case (ast.def_fn(?did)) {
|
||||
auto tyt = ty.lookup_item_type(cx.fcx.lcx.ccx.sess,
|
||||
cx.fcx.lcx.ccx.tystore,
|
||||
cx.fcx.lcx.ccx.type_cache, did);
|
||||
ret lval_generic_fn(cx, tyt, did, ann);
|
||||
}
|
||||
case (ast.def_obj(?did)) {
|
||||
auto tyt = ty.lookup_item_type(cx.fcx.lcx.ccx.sess,
|
||||
cx.fcx.lcx.ccx.tystore,
|
||||
cx.fcx.lcx.ccx.type_cache, did);
|
||||
ret lval_generic_fn(cx, tyt, did, ann);
|
||||
}
|
||||
case (ast.def_variant(?tid, ?vid)) {
|
||||
auto v_tyt = ty.lookup_item_type(cx.fcx.lcx.ccx.sess,
|
||||
cx.fcx.lcx.ccx.tystore,
|
||||
cx.fcx.lcx.ccx.type_cache, vid);
|
||||
alt (v_tyt._1.struct) {
|
||||
case (ty.ty_fn(_, _, _)) {
|
||||
@ -4010,6 +4030,7 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
|
||||
}
|
||||
case (ast.def_native_fn(?did)) {
|
||||
auto tyt = ty.lookup_item_type(cx.fcx.lcx.ccx.sess,
|
||||
cx.fcx.lcx.ccx.tystore,
|
||||
cx.fcx.lcx.ccx.type_cache, did);
|
||||
ret lval_generic_fn(cx, tyt, did, ann);
|
||||
}
|
||||
@ -4054,7 +4075,8 @@ fn trans_field(@block_ctxt cx, &ast.span sp, ValueRef v, @ty.t t0,
|
||||
C_int(ix as int)));
|
||||
|
||||
auto lvo = lval_mem(r.bcx, v);
|
||||
let @ty.t fn_ty = ty.method_ty_to_fn_ty(methods.(ix));
|
||||
let @ty.t fn_ty = ty.method_ty_to_fn_ty(cx.fcx.lcx.ccx.tystore,
|
||||
methods.(ix));
|
||||
ret rec(llobj = some[ValueRef](r.val),
|
||||
method_ty = some[@ty.t](fn_ty)
|
||||
with lvo);
|
||||
@ -4068,7 +4090,7 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
|
||||
@ast.expr idx, &ast.ann ann) -> lval_result {
|
||||
|
||||
auto lv = trans_expr(cx, base);
|
||||
lv = autoderef(lv.bcx, lv.val, ty.expr_ty(base));
|
||||
lv = autoderef(lv.bcx, lv.val, ty.expr_ty(cx.fcx.lcx.ccx.tystore, base));
|
||||
auto ix = trans_expr(lv.bcx, idx);
|
||||
auto v = lv.val;
|
||||
auto bcx = ix.bcx;
|
||||
@ -4134,7 +4156,7 @@ fn trans_lval(@block_ctxt cx, @ast.expr e) -> lval_result {
|
||||
}
|
||||
case (ast.expr_field(?base, ?ident, ?ann)) {
|
||||
auto r = trans_expr(cx, base);
|
||||
auto t = ty.expr_ty(base);
|
||||
auto t = ty.expr_ty(cx.fcx.lcx.ccx.tystore, base);
|
||||
ret trans_field(r.bcx, e.span, r.val, t, ident, ann);
|
||||
}
|
||||
case (ast.expr_index(?base, ?idx, ?ann)) {
|
||||
@ -4178,7 +4200,7 @@ fn trans_cast(@block_ctxt cx, @ast.expr e, &ast.ann ann) -> result {
|
||||
auto lldsttype = type_of(cx.fcx.lcx.ccx, t);
|
||||
if (!ty.type_is_fp(t)) {
|
||||
// TODO: native-to-native casts
|
||||
if (ty.type_is_native(ty.expr_ty(e))) {
|
||||
if (ty.type_is_native(ty.expr_ty(cx.fcx.lcx.ccx.tystore, e))) {
|
||||
e_res.val = e_res.bcx.build.PtrToInt(e_res.val, lldsttype);
|
||||
} else if (ty.type_is_native(t)) {
|
||||
e_res.val = e_res.bcx.build.IntToPtr(e_res.val, lldsttype);
|
||||
@ -4226,7 +4248,8 @@ fn trans_bind_thunk(@local_ctxt cx,
|
||||
auto bcx = new_top_block_ctxt(fcx);
|
||||
auto lltop = bcx.llbb;
|
||||
|
||||
auto llclosure_ptr_ty = type_of(cx.ccx, ty.mk_imm_box(closure_ty));
|
||||
auto llclosure_ptr_ty =
|
||||
type_of(cx.ccx, ty.mk_imm_box(cx.ccx.tystore, closure_ty));
|
||||
auto llclosure = bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty);
|
||||
|
||||
auto lltarget = GEP_tup_like(bcx, closure_ty, llclosure,
|
||||
@ -4368,7 +4391,7 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
|
||||
let vec[ValueRef] lltydescs;
|
||||
alt (f_res.generic) {
|
||||
case (none[generic_info]) {
|
||||
outgoing_fty = ty.expr_ty(f);
|
||||
outgoing_fty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, f);
|
||||
lltydescs = vec();
|
||||
}
|
||||
case (some[generic_info](?ginfo)) {
|
||||
@ -4395,18 +4418,20 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
|
||||
bcx = arg.bcx;
|
||||
|
||||
_vec.push[ValueRef](bound_vals, arg.val);
|
||||
_vec.push[@ty.t](bound_tys, ty.expr_ty(e));
|
||||
_vec.push[@ty.t](bound_tys,
|
||||
ty.expr_ty(cx.fcx.lcx.ccx.tystore, e));
|
||||
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
// Synthesize a closure type.
|
||||
let @ty.t bindings_ty = ty.mk_imm_tup(bound_tys);
|
||||
let @ty.t bindings_ty = ty.mk_imm_tup(cx.fcx.lcx.ccx.tystore,
|
||||
bound_tys);
|
||||
|
||||
// NB: keep this in sync with T_closure_ptr; we're making
|
||||
// a ty.t structure that has the same "shape" as the LLVM type
|
||||
// it constructs.
|
||||
let @ty.t tydesc_ty = ty.mk_type();
|
||||
let @ty.t tydesc_ty = ty.mk_type(cx.fcx.lcx.ccx.tystore);
|
||||
|
||||
let vec[@ty.t] captured_tys =
|
||||
_vec.init_elt[@ty.t](tydesc_ty, ty_param_count);
|
||||
@ -4415,9 +4440,10 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
|
||||
vec(tydesc_ty,
|
||||
outgoing_fty,
|
||||
bindings_ty,
|
||||
ty.mk_imm_tup(captured_tys));
|
||||
ty.mk_imm_tup(cx.fcx.lcx.ccx.tystore, captured_tys));
|
||||
|
||||
let @ty.t closure_ty = ty.mk_imm_tup(closure_tys);
|
||||
let @ty.t closure_ty = ty.mk_imm_tup(cx.fcx.lcx.ccx.tystore,
|
||||
closure_tys);
|
||||
|
||||
auto r = trans_malloc_boxed(bcx, closure_ty);
|
||||
auto box = r.val;
|
||||
@ -4622,7 +4648,7 @@ fn trans_args(@block_ctxt cx,
|
||||
auto mode = args.(i).mode;
|
||||
|
||||
auto val;
|
||||
if (ty.type_is_structural(ty.expr_ty(e))) {
|
||||
if (ty.type_is_structural(ty.expr_ty(cx.fcx.lcx.ccx.tystore, e))) {
|
||||
auto re = trans_expr(bcx, e);
|
||||
val = re.val;
|
||||
bcx = re.bcx;
|
||||
@ -4632,7 +4658,8 @@ fn trans_args(@block_ctxt cx,
|
||||
lv = trans_lval(bcx, e);
|
||||
} else {
|
||||
auto r = trans_expr(bcx, e);
|
||||
if (type_is_immediate(ty.expr_ty(e))) {
|
||||
if (type_is_immediate(ty.expr_ty(cx.fcx.lcx.ccx.tystore,
|
||||
e))) {
|
||||
lv = lval_val(r.bcx, r.val);
|
||||
} else {
|
||||
lv = lval_mem(r.bcx, r.val);
|
||||
@ -4658,7 +4685,8 @@ fn trans_args(@block_ctxt cx,
|
||||
auto lldestty = arg_tys.(i);
|
||||
if (mode == ast.val) {
|
||||
// FIXME: we'd prefer to use &&, but rustboot doesn't like it
|
||||
if (ty.type_is_structural(ty.expr_ty(e))) {
|
||||
if (ty.type_is_structural(ty.expr_ty(cx.fcx.lcx.ccx.tystore,
|
||||
e))) {
|
||||
lldestty = T_ptr(lldestty);
|
||||
}
|
||||
}
|
||||
@ -4668,7 +4696,8 @@ fn trans_args(@block_ctxt cx,
|
||||
|
||||
if (mode == ast.val) {
|
||||
// FIXME: we'd prefer to use &&, but rustboot doesn't like it
|
||||
if (ty.type_is_structural(ty.expr_ty(e))) {
|
||||
if (ty.type_is_structural(ty.expr_ty(cx.fcx.lcx.ccx.tystore,
|
||||
e))) {
|
||||
// Until here we've been treating structures by pointer;
|
||||
// we are now passing it as an arg, so need to load it.
|
||||
val = bcx.build.Load(val);
|
||||
@ -4723,7 +4752,7 @@ fn trans_call(@block_ctxt cx, @ast.expr f,
|
||||
}
|
||||
|
||||
case (_) {
|
||||
fn_ty = ty.expr_ty(f);
|
||||
fn_ty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, f);
|
||||
|
||||
}
|
||||
|
||||
@ -4776,7 +4805,7 @@ fn trans_tup(@block_ctxt cx, vec[ast.elt] elts,
|
||||
let int i = 0;
|
||||
|
||||
for (ast.elt e in elts) {
|
||||
auto e_ty = ty.expr_ty(e.expr);
|
||||
auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, e.expr);
|
||||
auto src_res = trans_expr(bcx, e.expr);
|
||||
bcx = src_res.bcx;
|
||||
auto dst_res = GEP_tup_like(bcx, t, tup_val, vec(0, i));
|
||||
@ -4819,7 +4848,8 @@ fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
|
||||
C_int(abi.vec_elt_data)));
|
||||
|
||||
auto pseudo_tup_ty =
|
||||
ty.mk_imm_tup(_vec.init_elt[@ty.t](unit_ty,
|
||||
ty.mk_imm_tup(cx.fcx.lcx.ccx.tystore,
|
||||
_vec.init_elt[@ty.t](unit_ty,
|
||||
_vec.len[@ast.expr](args)));
|
||||
let int i = 0;
|
||||
|
||||
@ -5076,7 +5106,7 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
|
||||
// lval cases fall through to trans_lval and then
|
||||
// possibly load the result (if it's non-structural).
|
||||
|
||||
auto t = ty.expr_ty(e);
|
||||
auto t = ty.expr_ty(cx.fcx.lcx.ccx.tystore, e);
|
||||
auto sub = trans_lval(cx, e);
|
||||
ret res(sub.res.bcx, load_if_immediate(sub.res.bcx, sub.res.val, t));
|
||||
}
|
||||
@ -5135,7 +5165,7 @@ fn trans_log(int lvl, @block_ctxt cx, @ast.expr e) -> result {
|
||||
cx.build.CondBr(test, log_cx.llbb, after_cx.llbb);
|
||||
|
||||
auto sub = trans_expr(log_cx, e);
|
||||
auto e_ty = ty.expr_ty(e);
|
||||
auto e_ty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, e);
|
||||
|
||||
if (ty.type_is_fp(e_ty)) {
|
||||
let TypeRef tr;
|
||||
@ -5251,7 +5281,8 @@ fn trans_put(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
|
||||
|
||||
auto llarg = r.val;
|
||||
bcx = r.bcx;
|
||||
if (ty.type_is_structural(ty.expr_ty(x))) {
|
||||
if (ty.type_is_structural(ty.expr_ty(cx.fcx.lcx.ccx.tystore,
|
||||
x))) {
|
||||
// Until here we've been treating structures by pointer; we
|
||||
// are now passing it as an arg, so need to load it.
|
||||
llarg = bcx.build.Load(llarg);
|
||||
@ -5311,7 +5342,7 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
|
||||
|
||||
alt (e) {
|
||||
case (some[@ast.expr](?x)) {
|
||||
auto t = ty.expr_ty(x);
|
||||
auto t = ty.expr_ty(cx.fcx.lcx.ccx.tystore, x);
|
||||
auto r = trans_expr(cx, x);
|
||||
bcx = r.bcx;
|
||||
val = r.val;
|
||||
@ -5686,7 +5717,7 @@ fn trans_block(@block_ctxt cx, &ast.block b) -> result {
|
||||
if (is_terminated(bcx)) {
|
||||
ret r;
|
||||
} else {
|
||||
auto r_ty = ty.expr_ty(e);
|
||||
auto r_ty = ty.expr_ty(cx.fcx.lcx.ccx.tystore, e);
|
||||
if (!ty.type_is_nil(r_ty)) {
|
||||
// The value resulting from the block gets copied into an
|
||||
// alloca created in an outer scope and its refcount
|
||||
@ -5917,7 +5948,7 @@ fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, self_vt llself) {
|
||||
|
||||
// Synthesize a tuple type for the fields so that GEP_tup_like() can work
|
||||
// its magic.
|
||||
auto fields_tup_ty = ty.mk_imm_tup(field_tys);
|
||||
auto fields_tup_ty = ty.mk_imm_tup(fcx.lcx.ccx.tystore, field_tys);
|
||||
|
||||
auto n_typarams = _vec.len[ast.ty_param](bcx.fcx.lcx.obj_typarams);
|
||||
let TypeRef llobj_box_ty = T_obj_ptr(bcx.fcx.lcx.ccx.tn, n_typarams);
|
||||
@ -6142,18 +6173,19 @@ fn trans_obj(@local_ctxt cx, &ast._obj ob, ast.def_id oid,
|
||||
}
|
||||
|
||||
// Synthesize an obj body type.
|
||||
auto tydesc_ty = ty.mk_type();
|
||||
auto tydesc_ty = ty.mk_type(cx.ccx.tystore);
|
||||
let vec[@ty.t] tps = vec();
|
||||
for (ast.ty_param tp in ty_params) {
|
||||
_vec.push[@ty.t](tps, tydesc_ty);
|
||||
}
|
||||
|
||||
let @ty.t typarams_ty = ty.mk_imm_tup(tps);
|
||||
let @ty.t fields_ty = ty.mk_imm_tup(obj_fields);
|
||||
let @ty.t body_ty = ty.mk_imm_tup(vec(tydesc_ty,
|
||||
let @ty.t typarams_ty = ty.mk_imm_tup(cx.ccx.tystore, tps);
|
||||
let @ty.t fields_ty = ty.mk_imm_tup(cx.ccx.tystore, obj_fields);
|
||||
let @ty.t body_ty = ty.mk_imm_tup(cx.ccx.tystore,
|
||||
vec(tydesc_ty,
|
||||
typarams_ty,
|
||||
fields_ty));
|
||||
let @ty.t boxed_body_ty = ty.mk_imm_box(body_ty);
|
||||
let @ty.t boxed_body_ty = ty.mk_imm_box(cx.ccx.tystore, body_ty);
|
||||
|
||||
// Malloc a box for the body.
|
||||
auto box = trans_malloc_boxed(bcx, body_ty);
|
||||
@ -6255,7 +6287,7 @@ fn trans_tag_variant(@local_ctxt cx, ast.def_id tag_id,
|
||||
let vec[@ty.t] ty_param_substs = vec();
|
||||
i = 0u;
|
||||
for (ast.ty_param tp in ty_params) {
|
||||
ty_param_substs += vec(ty.mk_param(i));
|
||||
ty_param_substs += vec(ty.mk_param(cx.ccx.tystore, i));
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
@ -7450,7 +7482,7 @@ fn create_crate_map(@crate_ctxt ccx) -> ValueRef {
|
||||
ret map;
|
||||
}
|
||||
|
||||
fn trans_crate(session.session sess, @ast.crate crate,
|
||||
fn trans_crate(session.session sess, @ast.crate crate, @ty.type_store tystore,
|
||||
&ty.type_cache type_cache, str output, bool shared,
|
||||
bool optimize, bool verify, output_type ot) {
|
||||
auto llmod =
|
||||
@ -7496,7 +7528,8 @@ fn trans_crate(session.session sess, @ast.crate crate,
|
||||
lltypes = lltypes,
|
||||
glues = glues,
|
||||
names = namegen(0),
|
||||
sha = std.sha1.mk_sha1());
|
||||
sha = std.sha1.mk_sha1(),
|
||||
tystore = tystore);
|
||||
auto cx = new_local_ctxt(ccx);
|
||||
|
||||
create_typedefs(ccx);
|
||||
|
@ -31,8 +31,8 @@ type mt = rec(@t ty, ast.mutability mut);
|
||||
|
||||
// Convert from method type to function type. Pretty easy; we just drop
|
||||
// 'ident'.
|
||||
fn method_ty_to_fn_ty(method m) -> @ty.t {
|
||||
ret mk_fn(m.proto, m.inputs, m.output);
|
||||
fn method_ty_to_fn_ty(@type_store tystore, method m) -> @ty.t {
|
||||
ret mk_fn(tystore, m.proto, m.inputs, m.output);
|
||||
}
|
||||
|
||||
// Do not construct these manually. Soon we want to intern these, at which
|
||||
@ -100,62 +100,99 @@ type ty_param_count_and_ty = tup(uint, @t);
|
||||
type type_cache = hashmap[ast.def_id,ty_param_count_and_ty];
|
||||
|
||||
|
||||
type type_store = hashmap[@t,()];
|
||||
|
||||
fn mk_type_store() -> @hashmap[@t,()] {
|
||||
auto hasher = hash_ty;
|
||||
auto eqer = eq_ty;
|
||||
ret @map.mk_hashmap[@t,()](hasher, eqer);
|
||||
}
|
||||
|
||||
// Type constructors
|
||||
|
||||
// This is a private constructor to this module. External users should always
|
||||
// use the mk_foo() functions below.
|
||||
fn gen_ty(&sty st) -> @t {
|
||||
fn gen_ty(@type_store tystore, &sty st) -> @t {
|
||||
// TODO: Intern the type.
|
||||
ret @rec(struct=st, cname=none[str], hash=hash_type_structure(st));
|
||||
}
|
||||
|
||||
fn mk_nil() -> @t { ret gen_ty(ty_nil); }
|
||||
fn mk_bool() -> @t { ret gen_ty(ty_bool); }
|
||||
fn mk_int() -> @t { ret gen_ty(ty_int); }
|
||||
fn mk_float() -> @t { ret gen_ty(ty_float); }
|
||||
fn mk_uint() -> @t { ret gen_ty(ty_uint); }
|
||||
fn mk_mach(util.common.ty_mach tm) -> @t { ret gen_ty(ty_machine(tm)); }
|
||||
fn mk_char() -> @t { ret gen_ty(ty_char); }
|
||||
fn mk_str() -> @t { ret gen_ty(ty_str); }
|
||||
fn mk_nil(@type_store ts) -> @t { ret gen_ty(ts, ty_nil); }
|
||||
fn mk_bool(@type_store ts) -> @t { ret gen_ty(ts, ty_bool); }
|
||||
fn mk_int(@type_store ts) -> @t { ret gen_ty(ts, ty_int); }
|
||||
fn mk_float(@type_store ts) -> @t { ret gen_ty(ts, ty_float); }
|
||||
fn mk_uint(@type_store ts) -> @t { ret gen_ty(ts, ty_uint); }
|
||||
|
||||
fn mk_tag(ast.def_id did, vec[@t] tys) -> @t {
|
||||
ret gen_ty(ty_tag(did, tys));
|
||||
fn mk_mach(@type_store ts, util.common.ty_mach tm) -> @t {
|
||||
ret gen_ty(ts, ty_machine(tm));
|
||||
}
|
||||
|
||||
fn mk_box(mt tm) -> @t { ret gen_ty(ty_box(tm)); }
|
||||
fn mk_imm_box(@t ty) -> @t { ret mk_box(rec(ty=ty, mut=ast.imm)); }
|
||||
fn mk_char(@type_store ts) -> @t { ret gen_ty(ts, ty_char); }
|
||||
fn mk_str(@type_store ts) -> @t { ret gen_ty(ts, ty_str); }
|
||||
|
||||
fn mk_vec(mt tm) -> @t { ret gen_ty(ty_vec(tm)); }
|
||||
fn mk_port(@t ty) -> @t { ret gen_ty(ty_port(ty)); }
|
||||
fn mk_chan(@t ty) -> @t { ret gen_ty(ty_chan(ty)); }
|
||||
fn mk_task() -> @t { ret gen_ty(ty_task); }
|
||||
fn mk_tag(@type_store ts, ast.def_id did, vec[@t] tys) -> @t {
|
||||
ret gen_ty(ts, ty_tag(did, tys));
|
||||
}
|
||||
|
||||
fn mk_tup(vec[mt] tms) -> @t { ret gen_ty(ty_tup(tms)); }
|
||||
fn mk_imm_tup(vec[@t] tys) -> @t {
|
||||
fn mk_box(@type_store ts, mt tm) -> @t {
|
||||
ret gen_ty(ts, ty_box(tm));
|
||||
}
|
||||
|
||||
fn mk_imm_box(@type_store ts, @t ty) -> @t {
|
||||
ret mk_box(ts, rec(ty=ty, mut=ast.imm));
|
||||
}
|
||||
|
||||
fn mk_vec(@type_store ts, mt tm) -> @t { ret gen_ty(ts, ty_vec(tm)); }
|
||||
fn mk_port(@type_store ts, @t ty) -> @t { ret gen_ty(ts, ty_port(ty)); }
|
||||
fn mk_chan(@type_store ts, @t ty) -> @t { ret gen_ty(ts, ty_chan(ty)); }
|
||||
fn mk_task(@type_store ts) -> @t { ret gen_ty(ts, ty_task); }
|
||||
|
||||
fn mk_tup(@type_store ts, vec[mt] tms) -> @t {
|
||||
ret gen_ty(ts, ty_tup(tms));
|
||||
}
|
||||
|
||||
fn mk_imm_tup(@type_store ts, vec[@t] tys) -> @t {
|
||||
// TODO: map
|
||||
let vec[ty.mt] mts = vec();
|
||||
for (@ty.t typ in tys) {
|
||||
mts += vec(rec(ty=typ, mut=ast.imm));
|
||||
}
|
||||
ret mk_tup(mts);
|
||||
ret mk_tup(ts, mts);
|
||||
}
|
||||
|
||||
fn mk_rec(vec[field] fs) -> @t { ret gen_ty(ty_rec(fs)); }
|
||||
|
||||
fn mk_fn(ast.proto proto, vec[arg] args, @t ty) -> @t {
|
||||
ret gen_ty(ty_fn(proto, args, ty));
|
||||
fn mk_rec(@type_store ts, vec[field] fs) -> @t {
|
||||
ret gen_ty(ts, ty_rec(fs));
|
||||
}
|
||||
|
||||
fn mk_native_fn(ast.native_abi abi, vec[arg] args, @t ty) -> @t {
|
||||
ret gen_ty(ty_native_fn(abi, args, ty));
|
||||
fn mk_fn(@type_store ts, ast.proto proto, vec[arg] args, @t ty) -> @t {
|
||||
ret gen_ty(ts, ty_fn(proto, args, ty));
|
||||
}
|
||||
|
||||
fn mk_obj(vec[method] meths) -> @t { ret gen_ty(ty_obj(meths)); }
|
||||
fn mk_var(int v) -> @t { ret gen_ty(ty_var(v)); }
|
||||
fn mk_local(ast.def_id did) -> @t { ret gen_ty(ty_local(did)); }
|
||||
fn mk_param(uint n) -> @t { ret gen_ty(ty_param(n)); }
|
||||
fn mk_bound_param(uint n) -> @t { ret gen_ty(ty_bound_param(n)); }
|
||||
fn mk_type() -> @t { ret gen_ty(ty_type); }
|
||||
fn mk_native() -> @t { ret gen_ty(ty_native); }
|
||||
fn mk_native_fn(@type_store ts, ast.native_abi abi, vec[arg] args, @t ty)
|
||||
-> @t {
|
||||
ret gen_ty(ts, ty_native_fn(abi, args, ty));
|
||||
}
|
||||
|
||||
fn mk_obj(@type_store ts, vec[method] meths) -> @t {
|
||||
ret gen_ty(ts, ty_obj(meths));
|
||||
}
|
||||
|
||||
fn mk_var(@type_store ts, int v) -> @t { ret gen_ty(ts, ty_var(v)); }
|
||||
|
||||
fn mk_local(@type_store ts, ast.def_id did) -> @t {
|
||||
ret gen_ty(ts, ty_local(did));
|
||||
}
|
||||
|
||||
fn mk_param(@type_store ts, uint n) -> @t {
|
||||
ret gen_ty(ts, ty_param(n));
|
||||
}
|
||||
|
||||
fn mk_bound_param(@type_store ts, uint n) -> @t {
|
||||
ret gen_ty(ts, ty_bound_param(n));
|
||||
}
|
||||
|
||||
fn mk_type(@type_store ts) -> @t { ret gen_ty(ts, ty_type); }
|
||||
fn mk_native(@type_store ts) -> @t { ret gen_ty(ts, ty_native); }
|
||||
|
||||
|
||||
// Stringification
|
||||
@ -386,7 +423,7 @@ fn walk_ty(ty_walk walker, @t ty) {
|
||||
|
||||
type ty_fold = fn(@t) -> @t;
|
||||
|
||||
fn fold_ty(ty_fold fld, @t ty_0) -> @t {
|
||||
fn fold_ty(@type_store tystore, ty_fold fld, @t ty_0) -> @t {
|
||||
auto ty = ty_0;
|
||||
alt (ty.struct) {
|
||||
case (ty_nil) { /* no-op */ }
|
||||
@ -400,58 +437,65 @@ fn fold_ty(ty_fold fld, @t ty_0) -> @t {
|
||||
case (ty_type) { /* no-op */ }
|
||||
case (ty_native) { /* no-op */ }
|
||||
case (ty_box(?tm)) {
|
||||
ty = copy_cname(mk_box(rec(ty=fold_ty(fld, tm.ty), mut=tm.mut)),
|
||||
ty);
|
||||
ty = copy_cname(mk_box(tystore,
|
||||
rec(ty=fold_ty(tystore, fld, tm.ty),
|
||||
mut=tm.mut)), ty);
|
||||
}
|
||||
case (ty_vec(?tm)) {
|
||||
ty = copy_cname(mk_vec(rec(ty=fold_ty(fld, tm.ty), mut=tm.mut)),
|
||||
ty);
|
||||
ty = copy_cname(mk_vec(tystore,
|
||||
rec(ty=fold_ty(tystore, fld, tm.ty),
|
||||
mut=tm.mut)), ty);
|
||||
}
|
||||
case (ty_port(?subty)) {
|
||||
ty = copy_cname(mk_port(fold_ty(fld, subty)), ty);
|
||||
ty = copy_cname(mk_port(tystore, fold_ty(tystore, fld, subty)),
|
||||
ty);
|
||||
}
|
||||
case (ty_chan(?subty)) {
|
||||
ty = copy_cname(mk_chan(fold_ty(fld, subty)), ty);
|
||||
ty = copy_cname(mk_chan(tystore, fold_ty(tystore, fld, subty)),
|
||||
ty);
|
||||
}
|
||||
case (ty_tag(?tid, ?subtys)) {
|
||||
let vec[@t] new_subtys = vec();
|
||||
for (@t subty in subtys) {
|
||||
new_subtys += vec(fold_ty(fld, subty));
|
||||
new_subtys += vec(fold_ty(tystore, fld, subty));
|
||||
}
|
||||
ty = copy_cname(mk_tag(tid, new_subtys), ty);
|
||||
ty = copy_cname(mk_tag(tystore, tid, new_subtys), ty);
|
||||
}
|
||||
case (ty_tup(?mts)) {
|
||||
let vec[mt] new_mts = vec();
|
||||
for (mt tm in mts) {
|
||||
auto new_subty = fold_ty(fld, tm.ty);
|
||||
auto new_subty = fold_ty(tystore, fld, tm.ty);
|
||||
new_mts += vec(rec(ty=new_subty, mut=tm.mut));
|
||||
}
|
||||
ty = copy_cname(mk_tup(new_mts), ty);
|
||||
ty = copy_cname(mk_tup(tystore, new_mts), ty);
|
||||
}
|
||||
case (ty_rec(?fields)) {
|
||||
let vec[field] new_fields = vec();
|
||||
for (field fl in fields) {
|
||||
auto new_ty = fold_ty(fld, fl.mt.ty);
|
||||
auto new_ty = fold_ty(tystore, fld, fl.mt.ty);
|
||||
auto new_mt = rec(ty=new_ty, mut=fl.mt.mut);
|
||||
new_fields += vec(rec(ident=fl.ident, mt=new_mt));
|
||||
}
|
||||
ty = copy_cname(mk_rec(new_fields), ty);
|
||||
ty = copy_cname(mk_rec(tystore, new_fields), ty);
|
||||
}
|
||||
case (ty_fn(?proto, ?args, ?ret_ty)) {
|
||||
let vec[arg] new_args = vec();
|
||||
for (arg a in args) {
|
||||
auto new_ty = fold_ty(fld, a.ty);
|
||||
auto new_ty = fold_ty(tystore, fld, a.ty);
|
||||
new_args += vec(rec(mode=a.mode, ty=new_ty));
|
||||
}
|
||||
ty = copy_cname(mk_fn(proto, new_args, fold_ty(fld, ret_ty)), ty);
|
||||
ty = copy_cname(mk_fn(tystore, proto, new_args,
|
||||
fold_ty(tystore, fld, ret_ty)),
|
||||
ty);
|
||||
}
|
||||
case (ty_native_fn(?abi, ?args, ?ret_ty)) {
|
||||
let vec[arg] new_args = vec();
|
||||
for (arg a in args) {
|
||||
auto new_ty = fold_ty(fld, a.ty);
|
||||
auto new_ty = fold_ty(tystore, fld, a.ty);
|
||||
new_args += vec(rec(mode=a.mode, ty=new_ty));
|
||||
}
|
||||
ty = copy_cname(mk_native_fn(abi, new_args, fold_ty(fld, ret_ty)),
|
||||
ty = copy_cname(mk_native_fn(tystore, abi, new_args,
|
||||
fold_ty(tystore, fld, ret_ty)),
|
||||
ty);
|
||||
}
|
||||
case (ty_obj(?methods)) {
|
||||
@ -459,13 +503,15 @@ fn fold_ty(ty_fold fld, @t ty_0) -> @t {
|
||||
for (method m in methods) {
|
||||
let vec[arg] new_args = vec();
|
||||
for (arg a in m.inputs) {
|
||||
new_args += vec(rec(mode=a.mode, ty=fold_ty(fld, a.ty)));
|
||||
new_args += vec(rec(mode=a.mode,
|
||||
ty=fold_ty(tystore, fld, a.ty)));
|
||||
}
|
||||
new_methods += vec(rec(proto=m.proto, ident=m.ident,
|
||||
inputs=new_args,
|
||||
output=fold_ty(fld, m.output)));
|
||||
output=fold_ty(tystore, fld,
|
||||
m.output)));
|
||||
}
|
||||
ty = copy_cname(mk_obj(new_methods), ty);
|
||||
ty = copy_cname(mk_obj(tystore, new_methods), ty);
|
||||
}
|
||||
case (ty_var(_)) { /* no-op */ }
|
||||
case (ty_local(_)) { /* no-op */ }
|
||||
@ -536,9 +582,9 @@ fn type_is_sequence(@t ty) -> bool {
|
||||
fail;
|
||||
}
|
||||
|
||||
fn sequence_element_type(@t ty) -> @t {
|
||||
fn sequence_element_type(@type_store tystore, @t ty) -> @t {
|
||||
alt (ty.struct) {
|
||||
case (ty_str) { ret mk_mach(common.ty_u8); }
|
||||
case (ty_str) { ret mk_mach(tystore, common.ty_u8); }
|
||||
case (ty_vec(?mt)) { ret mt.ty; }
|
||||
}
|
||||
fail;
|
||||
@ -1158,7 +1204,7 @@ fn ann_to_type_params(&ast.ann ann) -> vec[@t] {
|
||||
|
||||
// Returns the type of an annotation, with type parameter substitutions
|
||||
// performed if applicable.
|
||||
fn ann_to_monotype(ast.ann a) -> @ty.t {
|
||||
fn ann_to_monotype(@type_store tystore, ast.ann a) -> @ty.t {
|
||||
// TODO: Refactor to use recursive pattern matching when we're more
|
||||
// confident that it works.
|
||||
alt (a) {
|
||||
@ -1170,7 +1216,7 @@ fn ann_to_monotype(ast.ann a) -> @ty.t {
|
||||
alt (tps_opt) {
|
||||
case (none[vec[@ty.t]]) { ret typ; }
|
||||
case (some[vec[@ty.t]](?tps)) {
|
||||
ret substitute_type_params(tps, typ);
|
||||
ret substitute_type_params(tystore, tps, typ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1312,32 +1358,32 @@ fn item_ty(@ast.item it) -> ty_param_count_and_ty {
|
||||
ret tup(ty_param_count, result_ty);
|
||||
}
|
||||
|
||||
fn stmt_ty(@ast.stmt s) -> @t {
|
||||
fn stmt_ty(@type_store tystore, @ast.stmt s) -> @t {
|
||||
alt (s.node) {
|
||||
case (ast.stmt_expr(?e,_)) {
|
||||
ret expr_ty(e);
|
||||
ret expr_ty(tystore, e);
|
||||
}
|
||||
case (_) {
|
||||
ret mk_nil();
|
||||
ret mk_nil(tystore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn block_ty(&ast.block b) -> @t {
|
||||
fn block_ty(@type_store tystore, &ast.block b) -> @t {
|
||||
alt (b.node.expr) {
|
||||
case (some[@ast.expr](?e)) { ret expr_ty(e); }
|
||||
case (none[@ast.expr]) { ret mk_nil(); }
|
||||
case (some[@ast.expr](?e)) { ret expr_ty(tystore, e); }
|
||||
case (none[@ast.expr]) { ret mk_nil(tystore); }
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
|
||||
// doesn't provide type parameter substitutions.
|
||||
fn pat_ty(@ast.pat pat) -> @t {
|
||||
fn pat_ty(@type_store ts, @ast.pat pat) -> @t {
|
||||
alt (pat.node) {
|
||||
case (ast.pat_wild(?ann)) { ret ann_to_monotype(ann); }
|
||||
case (ast.pat_lit(_, ?ann)) { ret ann_to_monotype(ann); }
|
||||
case (ast.pat_bind(_, _, ?ann)) { ret ann_to_monotype(ann); }
|
||||
case (ast.pat_tag(_, _, _, ?ann)) { ret ann_to_monotype(ann); }
|
||||
case (ast.pat_wild(?ann)) { ret ann_to_monotype(ts, ann); }
|
||||
case (ast.pat_lit(_, ?ann)) { ret ann_to_monotype(ts, ann); }
|
||||
case (ast.pat_bind(_, _, ?ann)) { ret ann_to_monotype(ts, ann); }
|
||||
case (ast.pat_tag(_, _, _, ?ann)) { ret ann_to_monotype(ts, ann); }
|
||||
}
|
||||
fail; // not reached
|
||||
}
|
||||
@ -1394,18 +1440,19 @@ fn expr_ann(@ast.expr expr) -> option.t[ast.ann] {
|
||||
// ask for the type of "id" in "id(3)", it will return "fn(&int) -> int"
|
||||
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see
|
||||
// expr_ty_params_and_ty() below.
|
||||
fn expr_ty(@ast.expr expr) -> @t {
|
||||
fn expr_ty(@type_store tystore, @ast.expr expr) -> @t {
|
||||
alt (expr_ann(expr)) {
|
||||
case (none[ast.ann]) { ret mk_nil(); }
|
||||
case (some[ast.ann](?a)) { ret ann_to_monotype(a); }
|
||||
case (none[ast.ann]) { ret mk_nil(tystore); }
|
||||
case (some[ast.ann](?a)) { ret ann_to_monotype(tystore, a); }
|
||||
}
|
||||
}
|
||||
|
||||
fn expr_ty_params_and_ty(@ast.expr expr) -> tup(vec[@t], @t) {
|
||||
fn expr_ty_params_and_ty(@type_store tystore, @ast.expr expr)
|
||||
-> tup(vec[@t], @t) {
|
||||
alt (expr_ann(expr)) {
|
||||
case (none[ast.ann]) {
|
||||
let vec[@t] tps = vec();
|
||||
ret tup(tps, mk_nil());
|
||||
ret tup(tps, mk_nil(tystore));
|
||||
}
|
||||
case (some[ast.ann](?a)) {
|
||||
ret tup(ann_to_type_params(a), ann_to_type(a));
|
||||
@ -1555,7 +1602,8 @@ mod Unify {
|
||||
type ctxt = rec(UFind.ufind sets,
|
||||
hashmap[int,uint] var_ids,
|
||||
mutable vec[mutable vec[@t]] types,
|
||||
unify_handler handler);
|
||||
unify_handler handler,
|
||||
@type_store tystore);
|
||||
|
||||
// Wraps the given type in an appropriate cname.
|
||||
//
|
||||
@ -1670,7 +1718,7 @@ mod Unify {
|
||||
ret r;
|
||||
}
|
||||
case (fn_common_res_ok(?result_ins, ?result_out)) {
|
||||
auto t2 = mk_fn(e_proto, result_ins, result_out);
|
||||
auto t2 = mk_fn(cx.tystore, e_proto, result_ins, result_out);
|
||||
ret ures_ok(t2);
|
||||
}
|
||||
}
|
||||
@ -1696,7 +1744,8 @@ mod Unify {
|
||||
ret r;
|
||||
}
|
||||
case (fn_common_res_ok(?result_ins, ?result_out)) {
|
||||
auto t2 = mk_native_fn(e_abi, result_ins, result_out);
|
||||
auto t2 = mk_native_fn(cx.tystore, e_abi, result_ins,
|
||||
result_out);
|
||||
ret ures_ok(t2);
|
||||
}
|
||||
}
|
||||
@ -1744,7 +1793,7 @@ mod Unify {
|
||||
}
|
||||
i += 1u;
|
||||
}
|
||||
auto t = mk_obj(result_meths);
|
||||
auto t = mk_obj(cx.tystore, result_meths);
|
||||
ret ures_ok(t);
|
||||
}
|
||||
|
||||
@ -1868,7 +1917,8 @@ mod Unify {
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
ret ures_ok(mk_tag(expected_id, result_tps));
|
||||
ret ures_ok(mk_tag(cx.tystore, expected_id,
|
||||
result_tps));
|
||||
}
|
||||
case (_) { /* fall through */ }
|
||||
}
|
||||
@ -1894,7 +1944,7 @@ mod Unify {
|
||||
alt (result) {
|
||||
case (ures_ok(?result_sub)) {
|
||||
auto mt = rec(ty=result_sub, mut=mut);
|
||||
ret ures_ok(mk_box(mt));
|
||||
ret ures_ok(mk_box(cx.tystore, mt));
|
||||
}
|
||||
case (_) {
|
||||
ret result;
|
||||
@ -1926,7 +1976,7 @@ mod Unify {
|
||||
alt (result) {
|
||||
case (ures_ok(?result_sub)) {
|
||||
auto mt = rec(ty=result_sub, mut=mut);
|
||||
ret ures_ok(mk_vec(mt));
|
||||
ret ures_ok(mk_vec(cx.tystore, mt));
|
||||
}
|
||||
case (_) {
|
||||
ret result;
|
||||
@ -1948,7 +1998,7 @@ mod Unify {
|
||||
actual_sub);
|
||||
alt (result) {
|
||||
case (ures_ok(?result_sub)) {
|
||||
ret ures_ok(mk_port(result_sub));
|
||||
ret ures_ok(mk_port(cx.tystore, result_sub));
|
||||
}
|
||||
case (_) {
|
||||
ret result;
|
||||
@ -1970,7 +2020,7 @@ mod Unify {
|
||||
actual_sub);
|
||||
alt (result) {
|
||||
case (ures_ok(?result_sub)) {
|
||||
ret ures_ok(mk_chan(result_sub));
|
||||
ret ures_ok(mk_chan(cx.tystore, result_sub));
|
||||
}
|
||||
case (_) {
|
||||
ret result;
|
||||
@ -2029,7 +2079,7 @@ mod Unify {
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
ret ures_ok(mk_tup(result_elems));
|
||||
ret ures_ok(mk_tup(cx.tystore, result_elems));
|
||||
}
|
||||
|
||||
case (_) {
|
||||
@ -2093,7 +2143,7 @@ mod Unify {
|
||||
i += 1u;
|
||||
}
|
||||
|
||||
ret ures_ok(mk_rec(result_fields));
|
||||
ret ures_ok(mk_rec(cx.tystore, result_fields));
|
||||
}
|
||||
|
||||
case (_) {
|
||||
@ -2202,7 +2252,7 @@ mod Unify {
|
||||
}
|
||||
|
||||
auto f = bind substituter(cx, set_types, _);
|
||||
ret fold_ty(f, typ);
|
||||
ret fold_ty(cx.tystore, f, typ);
|
||||
}
|
||||
|
||||
fn unify_sets(@ctxt cx) -> vec[@t] {
|
||||
@ -2235,8 +2285,10 @@ mod Unify {
|
||||
ret result;
|
||||
}
|
||||
|
||||
fn unify(@ty.t expected, @ty.t actual, &unify_handler handler)
|
||||
-> result {
|
||||
fn unify(@ty.t expected,
|
||||
@ty.t actual,
|
||||
&unify_handler handler,
|
||||
@type_store tystore) -> result {
|
||||
let vec[@t] throwaway = vec();
|
||||
let vec[mutable vec[@t]] types = vec(mutable throwaway);
|
||||
_vec.pop[mutable vec[@t]](types); // FIXME: botch
|
||||
@ -2244,7 +2296,8 @@ mod Unify {
|
||||
auto cx = @rec(sets=UFind.make(),
|
||||
var_ids=common.new_int_hash[uint](),
|
||||
mutable types=types,
|
||||
handler=handler);
|
||||
handler=handler,
|
||||
tystore=tystore);
|
||||
|
||||
auto ures = unify_step(cx, expected, actual);
|
||||
alt (ures) {
|
||||
@ -2307,7 +2360,9 @@ fn type_err_to_str(&ty.type_err err) -> str {
|
||||
|
||||
// Performs bound type parameter replacement using the supplied mapping from
|
||||
// parameter IDs to types.
|
||||
fn substitute_type_params(vec[@t] bindings, @t typ) -> @t {
|
||||
fn substitute_type_params(@type_store tystore,
|
||||
vec[@t] bindings,
|
||||
@t typ) -> @t {
|
||||
fn replacer(vec[@t] bindings, @t typ) -> @t {
|
||||
alt (typ.struct) {
|
||||
case (ty_bound_param(?param_index)) {
|
||||
@ -2318,25 +2373,25 @@ fn substitute_type_params(vec[@t] bindings, @t typ) -> @t {
|
||||
}
|
||||
|
||||
auto f = bind replacer(bindings, _);
|
||||
ret fold_ty(f, typ);
|
||||
ret fold_ty(tystore, f, typ);
|
||||
}
|
||||
|
||||
// Converts type parameters in a type to bound type parameters.
|
||||
fn bind_params_in_type(@t typ) -> @t {
|
||||
fn binder(@t typ) -> @t {
|
||||
fn bind_params_in_type(@type_store tystore, @t typ) -> @t {
|
||||
fn binder(@type_store tystore, @t typ) -> @t {
|
||||
alt (typ.struct) {
|
||||
case (ty_bound_param(?index)) {
|
||||
log_err "bind_params_in_type() called on type that already " +
|
||||
"has bound params in it";
|
||||
fail;
|
||||
}
|
||||
case (ty_param(?index)) { ret mk_bound_param(index); }
|
||||
case (ty_param(?index)) { ret mk_bound_param(tystore, index); }
|
||||
case (_) { ret typ; }
|
||||
}
|
||||
}
|
||||
|
||||
auto f = binder;
|
||||
ret fold_ty(f, typ);
|
||||
auto f = bind binder(tystore, _);
|
||||
ret fold_ty(tystore, f, typ);
|
||||
}
|
||||
|
||||
|
||||
@ -2361,7 +2416,9 @@ fn def_has_ty_params(&ast.def def) -> bool {
|
||||
|
||||
// If the given item is in an external crate, looks up its type and adds it to
|
||||
// the type cache. Returns the type parameters and type.
|
||||
fn lookup_item_type(session.session sess, &type_cache cache,
|
||||
fn lookup_item_type(session.session sess,
|
||||
@type_store tystore,
|
||||
&type_cache cache,
|
||||
ast.def_id did) -> ty_param_count_and_ty {
|
||||
if (did._0 == sess.get_targ_crate_num()) {
|
||||
// The item is in this crate. The caller should have added it to the
|
||||
@ -2374,7 +2431,7 @@ fn lookup_item_type(session.session sess, &type_cache cache,
|
||||
ret cache.get(did);
|
||||
}
|
||||
|
||||
auto tyt = creader.get_type(sess, did);
|
||||
auto tyt = creader.get_type(sess, tystore, did);
|
||||
cache.insert(did, tyt);
|
||||
ret tyt;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -110,8 +110,8 @@ fn field_exprs(vec[ast.field] fields) -> vec [@ast.expr] {
|
||||
ret _vec.map[ast.field, @ast.expr](f, fields);
|
||||
}
|
||||
|
||||
fn plain_ann() -> ast.ann {
|
||||
ret ast.ann_type(middle.ty.mk_nil(),
|
||||
fn plain_ann(@middle.ty.type_store tystore) -> ast.ann {
|
||||
ret ast.ann_type(middle.ty.mk_nil(tystore),
|
||||
none[vec[@middle.ty.t]], none[@ts_ann]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user