Skip to content

Commit 77f5d14

Browse files
committed
Track def_ids of native types so that they can be distinguished
Closes #526
1 parent d863cdb commit 77f5d14

File tree

7 files changed

+49
-30
lines changed

7 files changed

+49
-30
lines changed

src/comp/metadata/encoder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ fn encode_info_for_native_item(&@crate_ctxt cx, &ebml::writer ebml_w,
330330
case (native_item_ty) {
331331
encode_def_id(ebml_w, local_def(nitem.id));
332332
encode_kind(ebml_w, 'T' as u8);
333-
encode_type(cx, ebml_w, ty::mk_native(cx.tcx));
333+
encode_type(cx, ebml_w,
334+
ty::mk_native(cx.tcx, local_def(nitem.id)));
334335
}
335336
case (native_item_fn(_, _, ?tps)) {
336337
encode_def_id(ebml_w, local_def(nitem.id));

src/comp/metadata/tydecode.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
263263
ret ty::mk_res(st.tcx, def, inner, params);
264264
}
265265
case ('X') { ret ty::mk_var(st.tcx, parse_int(st)); }
266-
case ('E') { ret ty::mk_native(st.tcx); }
266+
case ('E') {
267+
auto def = parse_def(st, sd);
268+
ret ty::mk_native(st.tcx, def);
269+
}
267270
case ('Y') { ret ty::mk_type(st.tcx); }
268271
case ('#') {
269272
auto pos = parse_hex(st);

src/comp/metadata/tyencode.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ fn enc_sty(&io::writer w, &@ctxt cx, &ty::sty st) {
184184
w.write_char('X');
185185
w.write_str(common::istr(id));
186186
}
187-
case (ty::ty_native) { w.write_char('E'); }
187+
case (ty::ty_native(?def)) {
188+
w.write_char('E');
189+
w.write_str(cx.ds(def));
190+
w.write_char('|');
191+
}
188192
case (ty::ty_param(?id)) {
189193
w.write_char('p');
190194
w.write_str(common::uistr(id));

src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
783783
if (cx.lltypes.contains_key(t)) { ret cx.lltypes.get(t); }
784784
let TypeRef llty = 0 as TypeRef;
785785
alt (ty::struct(cx.tcx, t)) {
786-
case (ty::ty_native) { llty = T_ptr(T_i8()); }
786+
case (ty::ty_native(_)) { llty = T_ptr(T_i8()); }
787787
case (ty::ty_nil) { llty = T_nil(); }
788788
case (ty::ty_bot) {
789789
llty = T_nil(); /* ...I guess? */
@@ -2411,7 +2411,7 @@ fn compare_scalar_types(@block_ctxt cx, ValueRef lhs, ValueRef rhs, &ty::t t,
24112411
ret rslt(new_sub_block_ctxt(cx, "after_fail_dummy"),
24122412
C_bool(false));
24132413
}
2414-
case (ty::ty_native) {
2414+
case (ty::ty_native(_)) {
24152415
trans_fail(cx, none[common::span],
24162416
"attempt to compare values of type native");
24172417
ret rslt(new_sub_block_ctxt(cx, "after_fail_dummy"),

src/comp/middle/ty.rs

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ tag sty {
273273
ty_var(int); // type variable
274274
ty_param(uint); // fn/tag type param
275275
ty_type;
276-
ty_native;
276+
ty_native(def_id);
277277
// TODO: ty_fn_arg(t), for a possibly-aliased function argument
278278
}
279279

@@ -342,13 +342,11 @@ const uint idx_istr = 17u;
342342

343343
const uint idx_task = 18u;
344344

345-
const uint idx_native = 19u;
345+
const uint idx_type = 19u;
346346

347-
const uint idx_type = 20u;
347+
const uint idx_bot = 20u;
348348

349-
const uint idx_bot = 21u;
350-
351-
const uint idx_first_others = 22u;
349+
const uint idx_first_others = 21u;
352350

353351
type type_store = interner::interner[raw_t];
354352

@@ -377,7 +375,6 @@ fn populate_type_store(&ctxt cx) {
377375
intern(cx, ty_str, none[str]);
378376
intern(cx, ty_istr, none[str]);
379377
intern(cx, ty_task, none[str]);
380-
intern(cx, ty_native, none[str]);
381378
intern(cx, ty_type, none[str]);
382379
intern(cx, ty_bot, none[str]);
383380
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 {
462459
case (ty_istr) {/* no-op */ }
463460
case (ty_task) {/* no-op */ }
464461
case (ty_type) {/* no-op */ }
465-
case (ty_native) {/* no-op */ }
462+
case (ty_native(_)) {/* no-op */ }
466463
case (ty_param(_)) { has_params = true; }
467464
case (ty_var(_)) { has_vars = true; }
468465
case (ty_tag(_, ?tys)) {
@@ -620,7 +617,7 @@ fn mk_param(&ctxt cx, uint n) -> t { ret gen_ty(cx, ty_param(n)); }
620617

621618
fn mk_type(&ctxt cx) -> t { ret idx_type; }
622619

623-
fn mk_native(&ctxt cx) -> t { ret idx_native; }
620+
fn mk_native(&ctxt cx, &def_id did) -> t { ret gen_ty(cx, ty_native(did)); }
624621

625622

626623
// 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) {
664661
case (ty_str) {/* no-op */ }
665662
case (ty_istr) {/* no-op */ }
666663
case (ty_type) {/* no-op */ }
667-
case (ty_native) {/* no-op */ }
664+
case (ty_native(_)) {/* no-op */ }
668665
case (ty_box(?tm)) { walk_ty(cx, walker, tm.ty); }
669666
case (ty_vec(?tm)) { walk_ty(cx, walker, tm.ty); }
670667
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 {
731728
case (ty_str) {/* no-op */ }
732729
case (ty_istr) {/* no-op */ }
733730
case (ty_type) {/* no-op */ }
734-
case (ty_native) {/* no-op */ }
731+
case (ty_native(_)) {/* no-op */ }
735732
case (ty_task) {/* no-op */ }
736733
case (ty_box(?tm)) {
737734
ty =
@@ -1017,7 +1014,7 @@ fn type_is_scalar(&ctxt cx, &t ty) -> bool {
10171014
case (ty_machine(_)) { ret true; }
10181015
case (ty_char) { ret true; }
10191016
case (ty_type) { ret true; }
1020-
case (ty_native) { ret true; }
1017+
case (ty_native(_)) { ret true; }
10211018
case (ty_ptr(_)) { ret true; }
10221019
case (_) { ret false; }
10231020
}
@@ -1041,7 +1038,7 @@ fn type_has_pointers(&ctxt cx, &t ty) -> bool {
10411038
case (ty_machine(_)) { /* no-op */ }
10421039
case (ty_char) { /* no-op */ }
10431040
case (ty_type) { /* no-op */ }
1044-
case (ty_native) { /* no-op */ }
1041+
case (ty_native(_)) { /* no-op */ }
10451042
case (ty_tup(?elts)) {
10461043
for (mt m in elts) {
10471044
if (type_has_pointers(cx, m.ty)) { result = true; }
@@ -1082,7 +1079,7 @@ fn type_has_pointers(&ctxt cx, &t ty) -> bool {
10821079
// type_is_scalar?
10831080
fn type_is_native(&ctxt cx, &t ty) -> bool {
10841081
alt (struct(cx, ty)) {
1085-
case (ty_native) { ret true; }
1082+
case (ty_native(_)) { ret true; }
10861083
case (_) { ret false; }
10871084
}
10881085
}
@@ -1142,7 +1139,7 @@ fn type_has_dynamic_size(&ctxt cx, &t ty) -> bool {
11421139
case (ty_var(_)) { fail "ty_var in type_has_dynamic_size()"; }
11431140
case (ty_param(_)) { ret true; }
11441141
case (ty_type) { ret false; }
1145-
case (ty_native) { ret false; }
1142+
case (ty_native(_)) { ret false; }
11461143
}
11471144
}
11481145

@@ -1219,7 +1216,7 @@ fn type_owns_heap_mem(&ctxt cx, &t ty) -> bool {
12191216
case (ty_machine(_)) { result = false; }
12201217
case (ty_char) { result = false; }
12211218
case (ty_type) { result = false; }
1222-
case (ty_native) { result = false; }
1219+
case (ty_native(_)) { result = false; }
12231220

12241221
// boxed types
12251222
case (ty_str) { result = false; }
@@ -1388,7 +1385,7 @@ fn hash_type_structure(&sty st) -> uint {
13881385
case (ty_var(?v)) { ret hash_uint(30u, v as uint); }
13891386
case (ty_param(?pid)) { ret hash_uint(31u, pid); }
13901387
case (ty_type) { ret 32u; }
1391-
case (ty_native) { ret 33u; }
1388+
case (ty_native(?did)) { ret hash_def(33u, did); }
13921389
case (ty_bot) { ret 34u; }
13931390
case (ty_ptr(?mt)) { ret hash_subty(35u, mt.ty); }
13941391
case (ty_res(?did, ?sub, ?tps)) {
@@ -1687,8 +1684,12 @@ fn equal_type_structures(&sty a, &sty b) -> bool {
16871684
case (ty_type) {
16881685
alt (b) { case (ty_type) { ret true; } case (_) { ret false; } }
16891686
}
1690-
case (ty_native) {
1691-
alt (b) { case (ty_native) { ret true; } case (_) { ret false; } }
1687+
case (ty_native(?a_id)) {
1688+
alt (b) {
1689+
case (ty_native(?b_id)) {
1690+
ret a_id._0 == b_id._0 && a_id._1 == b_id._1;
1691+
}
1692+
case (_) { ret false; } }
16921693
}
16931694
}
16941695
}
@@ -2313,9 +2314,8 @@ mod unify {
23132314
}
23142315
alt (struct(cx.tcx, expected)) {
23152316
case (ty::ty_nil) { ret struct_cmp(cx, expected, actual); }
2316-
case (
2317-
// _|_ unifies with anything
2318-
ty::ty_bot) {
2317+
// _|_ unifies with anything
2318+
case (ty::ty_bot) {
23192319
ret ures_ok(actual);
23202320
}
23212321
case (ty::ty_bool) { ret struct_cmp(cx, expected, actual); }
@@ -2327,7 +2327,18 @@ mod unify {
23272327
case (ty::ty_str) { ret struct_cmp(cx, expected, actual); }
23282328
case (ty::ty_istr) { ret struct_cmp(cx, expected, actual); }
23292329
case (ty::ty_type) { ret struct_cmp(cx, expected, actual); }
2330-
case (ty::ty_native) { ret struct_cmp(cx, expected, actual); }
2330+
case (ty::ty_native(?ex_id)) {
2331+
alt (struct(cx.tcx, actual)) {
2332+
case (ty_native(?act_id)) {
2333+
if (ex_id._0 == act_id._0 && ex_id._1 == act_id._1) {
2334+
ret ures_ok(actual);
2335+
} else {
2336+
ret ures_err(terr_mismatch);
2337+
}
2338+
}
2339+
case (_) { ret ures_err(terr_mismatch); }
2340+
}
2341+
}
23312342
case (ty::ty_param(_)) { ret struct_cmp(cx, expected, actual); }
23322343
case (ty::ty_tag(?expected_id, ?expected_tps)) {
23332344
alt (struct(cx.tcx, actual)) {

src/comp/middle/typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ mod collect {
640640
case (some(?tpt)) { ret tpt; }
641641
case (none) { }
642642
}
643-
auto t = ty::mk_native(cx.tcx);
643+
auto t = ty::mk_native(cx.tcx, ast::local_def(it.id));
644644
auto tpt = tup(0u, t);
645645
cx.tcx.tcache.insert(local_def(it.id), tpt);
646646
ret tpt;

src/comp/pretty/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
8989
alt (cname(cx, typ)) { case (some(?cs)) { ret cs; } case (_) { } }
9090
auto s = "";
9191
alt (struct(cx, typ)) {
92-
case (ty_native) { s += "native"; }
92+
case (ty_native(_)) { s += "native"; }
9393
case (ty_nil) { s += "()"; }
9494
case (ty_bot) { s += "_|_"; }
9595
case (ty_bool) { s += "bool"; }

0 commit comments

Comments
 (0)