Track def_ids of native types so that they can be distinguished
Closes #526
This commit is contained in:
parent
d863cdb98f
commit
77f5d14f14
|
@ -330,7 +330,8 @@ fn encode_info_for_native_item(&@crate_ctxt cx, &ebml::writer ebml_w,
|
|||
case (native_item_ty) {
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
encode_kind(ebml_w, 'T' as u8);
|
||||
encode_type(cx, ebml_w, ty::mk_native(cx.tcx));
|
||||
encode_type(cx, ebml_w,
|
||||
ty::mk_native(cx.tcx, local_def(nitem.id)));
|
||||
}
|
||||
case (native_item_fn(_, _, ?tps)) {
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
|
|
|
@ -263,7 +263,10 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
|
|||
ret ty::mk_res(st.tcx, def, inner, params);
|
||||
}
|
||||
case ('X') { ret ty::mk_var(st.tcx, parse_int(st)); }
|
||||
case ('E') { ret ty::mk_native(st.tcx); }
|
||||
case ('E') {
|
||||
auto def = parse_def(st, sd);
|
||||
ret ty::mk_native(st.tcx, def);
|
||||
}
|
||||
case ('Y') { ret ty::mk_type(st.tcx); }
|
||||
case ('#') {
|
||||
auto pos = parse_hex(st);
|
||||
|
|
|
@ -184,7 +184,11 @@ fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
|
|||
w.write_char('X');
|
||||
w.write_str(common::istr(id));
|
||||
}
|
||||
case (ty::ty_native) { w.write_char('E'); }
|
||||
case (ty::ty_native(?def)) {
|
||||
w.write_char('E');
|
||||
w.write_str(cx.ds(def));
|
||||
w.write_char('|');
|
||||
}
|
||||
case (ty::ty_param(?id)) {
|
||||
w.write_char('p');
|
||||
w.write_str(common::uistr(id));
|
||||
|
|
|
@ -783,7 +783,7 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
|
|||
if (cx.lltypes.contains_key(t)) { ret cx.lltypes.get(t); }
|
||||
let TypeRef llty = 0 as TypeRef;
|
||||
alt (ty::struct(cx.tcx, t)) {
|
||||
case (ty::ty_native) { llty = T_ptr(T_i8()); }
|
||||
case (ty::ty_native(_)) { llty = T_ptr(T_i8()); }
|
||||
case (ty::ty_nil) { llty = T_nil(); }
|
||||
case (ty::ty_bot) {
|
||||
llty = T_nil(); /* ...I guess? */
|
||||
|
@ -2411,7 +2411,7 @@ fn compare_scalar_types(@block_ctxt cx, ValueRef lhs, ValueRef rhs, &ty::t t,
|
|||
ret rslt(new_sub_block_ctxt(cx, "after_fail_dummy"),
|
||||
C_bool(false));
|
||||
}
|
||||
case (ty::ty_native) {
|
||||
case (ty::ty_native(_)) {
|
||||
trans_fail(cx, none[common::span],
|
||||
"attempt to compare values of type native");
|
||||
ret rslt(new_sub_block_ctxt(cx, "after_fail_dummy"),
|
||||
|
|
|
@ -273,7 +273,7 @@ tag sty {
|
|||
ty_var(int); // type variable
|
||||
ty_param(uint); // fn/tag type param
|
||||
ty_type;
|
||||
ty_native;
|
||||
ty_native(def_id);
|
||||
// TODO: ty_fn_arg(t), for a possibly-aliased function argument
|
||||
}
|
||||
|
||||
|
@ -342,13 +342,11 @@ const uint idx_istr = 17u;
|
|||
|
||||
const uint idx_task = 18u;
|
||||
|
||||
const uint idx_native = 19u;
|
||||
const uint idx_type = 19u;
|
||||
|
||||
const uint idx_type = 20u;
|
||||
const uint idx_bot = 20u;
|
||||
|
||||
const uint idx_bot = 21u;
|
||||
|
||||
const uint idx_first_others = 22u;
|
||||
const uint idx_first_others = 21u;
|
||||
|
||||
type type_store = interner::interner[raw_t];
|
||||
|
||||
|
@ -377,7 +375,6 @@ fn populate_type_store(&ctxt cx) {
|
|||
intern(cx, ty_str, none[str]);
|
||||
intern(cx, ty_istr, none[str]);
|
||||
intern(cx, ty_task, none[str]);
|
||||
intern(cx, ty_native, none[str]);
|
||||
intern(cx, ty_type, none[str]);
|
||||
intern(cx, ty_bot, none[str]);
|
||||
assert (vec::len(cx.ts.vect) == idx_first_others);
|
||||
|
@ -462,7 +459,7 @@ fn mk_raw_ty(&ctxt cx, &sty st, &option::t[str] cname) -> raw_t {
|
|||
case (ty_istr) {/* no-op */ }
|
||||
case (ty_task) {/* no-op */ }
|
||||
case (ty_type) {/* no-op */ }
|
||||
case (ty_native) {/* no-op */ }
|
||||
case (ty_native(_)) {/* no-op */ }
|
||||
case (ty_param(_)) { has_params = true; }
|
||||
case (ty_var(_)) { has_vars = true; }
|
||||
case (ty_tag(_, ?tys)) {
|
||||
|
@ -620,7 +617,7 @@ fn mk_param(&ctxt cx, uint n) -> t { ret gen_ty(cx, ty_param(n)); }
|
|||
|
||||
fn mk_type(&ctxt cx) -> t { ret idx_type; }
|
||||
|
||||
fn mk_native(&ctxt cx) -> t { ret idx_native; }
|
||||
fn mk_native(&ctxt cx, &def_id did) -> t { ret gen_ty(cx, ty_native(did)); }
|
||||
|
||||
|
||||
// Returns the one-level-deep type structure of the given type.
|
||||
|
@ -664,7 +661,7 @@ fn walk_ty(&ctxt cx, ty_walk walker, t ty) {
|
|||
case (ty_str) {/* no-op */ }
|
||||
case (ty_istr) {/* no-op */ }
|
||||
case (ty_type) {/* no-op */ }
|
||||
case (ty_native) {/* no-op */ }
|
||||
case (ty_native(_)) {/* no-op */ }
|
||||
case (ty_box(?tm)) { walk_ty(cx, walker, tm.ty); }
|
||||
case (ty_vec(?tm)) { walk_ty(cx, walker, tm.ty); }
|
||||
case (ty_ivec(?tm)) { walk_ty(cx, walker, tm.ty); }
|
||||
|
@ -731,7 +728,7 @@ fn fold_ty(&ctxt cx, fold_mode fld, t ty_0) -> t {
|
|||
case (ty_str) {/* no-op */ }
|
||||
case (ty_istr) {/* no-op */ }
|
||||
case (ty_type) {/* no-op */ }
|
||||
case (ty_native) {/* no-op */ }
|
||||
case (ty_native(_)) {/* no-op */ }
|
||||
case (ty_task) {/* no-op */ }
|
||||
case (ty_box(?tm)) {
|
||||
ty =
|
||||
|
@ -1017,7 +1014,7 @@ fn type_is_scalar(&ctxt cx, &t ty) -> bool {
|
|||
case (ty_machine(_)) { ret true; }
|
||||
case (ty_char) { ret true; }
|
||||
case (ty_type) { ret true; }
|
||||
case (ty_native) { ret true; }
|
||||
case (ty_native(_)) { ret true; }
|
||||
case (ty_ptr(_)) { ret true; }
|
||||
case (_) { ret false; }
|
||||
}
|
||||
|
@ -1041,7 +1038,7 @@ fn type_has_pointers(&ctxt cx, &t ty) -> bool {
|
|||
case (ty_machine(_)) { /* no-op */ }
|
||||
case (ty_char) { /* no-op */ }
|
||||
case (ty_type) { /* no-op */ }
|
||||
case (ty_native) { /* no-op */ }
|
||||
case (ty_native(_)) { /* no-op */ }
|
||||
case (ty_tup(?elts)) {
|
||||
for (mt m in elts) {
|
||||
if (type_has_pointers(cx, m.ty)) { result = true; }
|
||||
|
@ -1082,7 +1079,7 @@ fn type_has_pointers(&ctxt cx, &t ty) -> bool {
|
|||
// type_is_scalar?
|
||||
fn type_is_native(&ctxt cx, &t ty) -> bool {
|
||||
alt (struct(cx, ty)) {
|
||||
case (ty_native) { ret true; }
|
||||
case (ty_native(_)) { ret true; }
|
||||
case (_) { ret false; }
|
||||
}
|
||||
}
|
||||
|
@ -1142,7 +1139,7 @@ fn type_has_dynamic_size(&ctxt cx, &t ty) -> bool {
|
|||
case (ty_var(_)) { fail "ty_var in type_has_dynamic_size()"; }
|
||||
case (ty_param(_)) { ret true; }
|
||||
case (ty_type) { ret false; }
|
||||
case (ty_native) { ret false; }
|
||||
case (ty_native(_)) { ret false; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1219,7 +1216,7 @@ fn type_owns_heap_mem(&ctxt cx, &t ty) -> bool {
|
|||
case (ty_machine(_)) { result = false; }
|
||||
case (ty_char) { result = false; }
|
||||
case (ty_type) { result = false; }
|
||||
case (ty_native) { result = false; }
|
||||
case (ty_native(_)) { result = false; }
|
||||
|
||||
// boxed types
|
||||
case (ty_str) { result = false; }
|
||||
|
@ -1388,7 +1385,7 @@ fn hash_type_structure(&sty st) -> uint {
|
|||
case (ty_var(?v)) { ret hash_uint(30u, v as uint); }
|
||||
case (ty_param(?pid)) { ret hash_uint(31u, pid); }
|
||||
case (ty_type) { ret 32u; }
|
||||
case (ty_native) { ret 33u; }
|
||||
case (ty_native(?did)) { ret hash_def(33u, did); }
|
||||
case (ty_bot) { ret 34u; }
|
||||
case (ty_ptr(?mt)) { ret hash_subty(35u, mt.ty); }
|
||||
case (ty_res(?did, ?sub, ?tps)) {
|
||||
|
@ -1687,8 +1684,12 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
|
|||
case (ty_type) {
|
||||
alt (b) { case (ty_type) { ret true; } case (_) { ret false; } }
|
||||
}
|
||||
case (ty_native) {
|
||||
alt (b) { case (ty_native) { ret true; } case (_) { ret false; } }
|
||||
case (ty_native(?a_id)) {
|
||||
alt (b) {
|
||||
case (ty_native(?b_id)) {
|
||||
ret a_id._0 == b_id._0 && a_id._1 == b_id._1;
|
||||
}
|
||||
case (_) { ret false; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2313,9 +2314,8 @@ mod unify {
|
|||
}
|
||||
alt (struct(cx.tcx, expected)) {
|
||||
case (ty::ty_nil) { ret struct_cmp(cx, expected, actual); }
|
||||
case (
|
||||
// _|_ unifies with anything
|
||||
ty::ty_bot) {
|
||||
// _|_ unifies with anything
|
||||
case (ty::ty_bot) {
|
||||
ret ures_ok(actual);
|
||||
}
|
||||
case (ty::ty_bool) { ret struct_cmp(cx, expected, actual); }
|
||||
|
@ -2327,7 +2327,18 @@ mod unify {
|
|||
case (ty::ty_str) { ret struct_cmp(cx, expected, actual); }
|
||||
case (ty::ty_istr) { ret struct_cmp(cx, expected, actual); }
|
||||
case (ty::ty_type) { ret struct_cmp(cx, expected, actual); }
|
||||
case (ty::ty_native) { ret struct_cmp(cx, expected, actual); }
|
||||
case (ty::ty_native(?ex_id)) {
|
||||
alt (struct(cx.tcx, actual)) {
|
||||
case (ty_native(?act_id)) {
|
||||
if (ex_id._0 == act_id._0 && ex_id._1 == act_id._1) {
|
||||
ret ures_ok(actual);
|
||||
} else {
|
||||
ret ures_err(terr_mismatch);
|
||||
}
|
||||
}
|
||||
case (_) { ret ures_err(terr_mismatch); }
|
||||
}
|
||||
}
|
||||
case (ty::ty_param(_)) { ret struct_cmp(cx, expected, actual); }
|
||||
case (ty::ty_tag(?expected_id, ?expected_tps)) {
|
||||
alt (struct(cx.tcx, actual)) {
|
||||
|
|
|
@ -640,7 +640,7 @@ mod collect {
|
|||
case (some(?tpt)) { ret tpt; }
|
||||
case (none) { }
|
||||
}
|
||||
auto t = ty::mk_native(cx.tcx);
|
||||
auto t = ty::mk_native(cx.tcx, ast::local_def(it.id));
|
||||
auto tpt = tup(0u, t);
|
||||
cx.tcx.tcache.insert(local_def(it.id), tpt);
|
||||
ret tpt;
|
||||
|
|
|
@ -89,7 +89,7 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
|
|||
alt (cname(cx, typ)) { case (some(?cs)) { ret cs; } case (_) { } }
|
||||
auto s = "";
|
||||
alt (struct(cx, typ)) {
|
||||
case (ty_native) { s += "native"; }
|
||||
case (ty_native(_)) { s += "native"; }
|
||||
case (ty_nil) { s += "()"; }
|
||||
case (ty_bot) { s += "_|_"; }
|
||||
case (ty_bool) { s += "bool"; }
|
||||
|
|
Loading…
Reference in New Issue