Skip to content

Commit 3e63fdc

Browse files
committed
Thread kinds into the type system. Don't quite activate yet, since it breaks stdlib and snapshot isn't ready to compile modified stdlib.
1 parent 5c0fd04 commit 3e63fdc

File tree

9 files changed

+72
-44
lines changed

9 files changed

+72
-44
lines changed

src/comp/metadata/tydecode.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,18 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
202202
st.pos = st.pos + 1u;
203203
ret ty::mk_tag(st.tcx, def, params);
204204
}
205-
'p' { ret ty::mk_param(st.tcx, parse_int(st) as uint); }
205+
'p' {
206+
let k = alt next(st) as char {
207+
'u' { kind_unique }
208+
's' { kind_shared }
209+
'p' { kind_pinned }
210+
c {
211+
log_err "unexpected char in encoded type param: ";
212+
log_err c; fail
213+
}
214+
};
215+
ret ty::mk_param(st.tcx, parse_int(st) as uint, k);
216+
}
206217
'@' { ret ty::mk_box(st.tcx, parse_mt(st, sd)); }
207218
'*' { ret ty::mk_ptr(st.tcx, parse_mt(st, sd)); }
208219
'V' { ret ty::mk_vec(st.tcx, parse_mt(st, sd)); }

src/comp/metadata/tyencode.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,14 @@ fn enc_sty(w: &ioivec::writer, cx: &@ctxt, st: &ty::sty) {
173173
w.write_str(cx.ds(def));
174174
w.write_char('|');
175175
}
176-
ty::ty_param(id) { w.write_char('p'); w.write_str(uint::str(id)); }
176+
ty::ty_param(id,k) {
177+
alt k {
178+
kind_unique. { w.write_str("pu"); }
179+
kind_shared. { w.write_str("ps"); }
180+
kind_pinned. { w.write_str("pp"); }
181+
}
182+
w.write_str(uint::str(id));
183+
}
177184
ty::ty_type. { w.write_char('Y'); }
178185
ty::ty_task. { w.write_char('a'); }
179186
ty::ty_constr(ty, cs) {

src/comp/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t,
682682
// treated as opaque downstream, and is thus safe unless we
683683
// saw mutable fields, in which case the whole thing can be
684684
// overwritten.
685-
ty::ty_param(_) {
685+
ty::ty_param(_,_) {
686686
ret mut;
687687
}
688688
_ { ret false; }

src/comp/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ fn def_is_obj_field(d: &def) -> bool {
610610
}
611611

612612
fn def_is_ty_arg(d: &def) -> bool {
613-
ret alt d { ast::def_ty_arg(_) { true } _ { false } };
613+
ret alt d { ast::def_ty_arg(_,_) { true } _ { false } };
614614
}
615615

616616
fn lookup_in_scope(e: &env, sc: scopes, sp: &span, name: &ident,
@@ -710,7 +710,7 @@ fn lookup_in_ty_params(name: &ident, ty_params: &ast::ty_param[]) ->
710710
option::t[def] {
711711
let i = 0u;
712712
for tp: ast::ty_param in ty_params {
713-
if str::eq(tp.ident, name) { ret some(ast::def_ty_arg(i)); }
713+
if str::eq(tp.ident, name) { ret some(ast::def_ty_arg(i,tp.kind)); }
714714
i += 1u;
715715
}
716716
ret none[def];

src/comp/middle/trans.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ fn type_of_inner(cx: &@crate_ctxt, sp: &span, t: &ty::t) -> TypeRef {
256256
ty::ty_var(_) {
257257
cx.tcx.sess.span_fatal(sp, "trans::type_of called on ty_var");
258258
}
259-
ty::ty_param(_) { llty = T_i8(); }
259+
ty::ty_param(_, _) { llty = T_i8(); }
260260
ty::ty_type. { llty = T_ptr(cx.tydesc_type); }
261261
}
262262
assert (llty as int != 0);
@@ -281,7 +281,7 @@ fn type_of_tag(cx: &@crate_ctxt, sp: &span, did: &ast::def_id, t: &ty::t) ->
281281

282282
fn type_of_arg(cx: @local_ctxt, sp: &span, arg: &ty::arg) -> TypeRef {
283283
alt ty::struct(cx.ccx.tcx, arg.ty) {
284-
ty::ty_param(_) {
284+
ty::ty_param(_, _) {
285285
if arg.mode != ty::mo_val { ret T_typaram_ptr(cx.ccx.tn); }
286286
}
287287
_ {
@@ -581,7 +581,7 @@ fn dynamic_size_of(cx: &@block_ctxt, t: ty::t) -> result {
581581
ret rslt(bcx, off);
582582
}
583583
alt ty::struct(bcx_tcx(cx), t) {
584-
ty::ty_param(p) {
584+
ty::ty_param(p,_) {
585585
let szptr = field_of_tydesc(cx, t, false, abi::tydesc_field_size);
586586
ret rslt(szptr.bcx, szptr.bcx.build.Load(szptr.val));
587587
}
@@ -634,7 +634,7 @@ fn dynamic_size_of(cx: &@block_ctxt, t: ty::t) -> result {
634634

635635
fn dynamic_align_of(cx: &@block_ctxt, t: &ty::t) -> result {
636636
alt ty::struct(bcx_tcx(cx), t) {
637-
ty::ty_param(p) {
637+
ty::ty_param(p,_) {
638638
let aptr = field_of_tydesc(cx, t, false, abi::tydesc_field_align);
639639
ret rslt(aptr.bcx, aptr.bcx.build.Load(aptr.val));
640640
}
@@ -878,7 +878,7 @@ fn linearize_ty_params(cx: &@block_ctxt, t: &ty::t) ->
878878

879879
fn linearizer(r: @rr, t: ty::t) {
880880
alt ty::struct(bcx_tcx(r.cx), t) {
881-
ty::ty_param(pid) {
881+
ty::ty_param(pid,_) {
882882
let seen: bool = false;
883883
for d: uint in r.defs { if d == pid { seen = true; } }
884884
if !seen {
@@ -7279,7 +7279,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
72797279
let ty_param_substs: ty::t[] = ~[];
72807280
i = 0u;
72817281
for tp: ast::ty_param in ty_params {
7282-
ty_param_substs += ~[ty::mk_param(cx.ccx.tcx, i)];
7282+
ty_param_substs += ~[ty::mk_param(cx.ccx.tcx, i, tp.kind)];
72837283
i += 1u;
72847284
}
72857285
let arg_tys = arg_tys_of_fn(cx.ccx, variant.node.id);

src/comp/middle/ty.rs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ tag sty {
272272
ty_res(def_id, t, t[]);
273273
ty_var(int); // type variable
274274

275-
ty_param(uint); // fn/tag type param
275+
ty_param(uint, ast::kind); // fn/tag type param
276276

277277
ty_type;
278278
ty_native(def_id);
@@ -459,7 +459,7 @@ fn mk_raw_ty(cx: &ctxt, st: &sty, in_cname: &option::t[str]) -> @raw_t {
459459
ty_task. {/* no-op */ }
460460
ty_type. {/* no-op */ }
461461
ty_native(_) {/* no-op */ }
462-
ty_param(_) { has_params = true; }
462+
ty_param(_,_) { has_params = true; }
463463
ty_var(_) { has_vars = true; }
464464
ty_tag(_, tys) {
465465
for tt: t in tys { derive_flags_t(cx, has_params, has_vars, tt); }
@@ -605,7 +605,9 @@ fn mk_res(cx: &ctxt, did: &ast::def_id, inner: &t, tps: &t[]) -> t {
605605

606606
fn mk_var(cx: &ctxt, v: int) -> t { ret gen_ty(cx, ty_var(v)); }
607607

608-
fn mk_param(cx: &ctxt, n: uint) -> t { ret gen_ty(cx, ty_param(n)); }
608+
fn mk_param(cx: &ctxt, n: uint, k: ast::kind) -> t {
609+
ret gen_ty(cx, ty_param(n, k));
610+
}
609611

610612
fn mk_type(cx: &ctxt) -> t { ret idx_type; }
611613

@@ -672,14 +674,14 @@ fn walk_ty(cx: &ctxt, walker: ty_walk, ty: t) {
672674
for tp: t in tps { walk_ty(cx, walker, tp); }
673675
}
674676
ty_var(_) {/* no-op */ }
675-
ty_param(_) {/* no-op */ }
677+
ty_param(_,_) {/* no-op */ }
676678
}
677679
walker(ty);
678680
}
679681

680682
tag fold_mode {
681683
fm_var(fn(int) -> t );
682-
fm_param(fn(uint) -> t );
684+
fm_param(fn(uint,ast::kind) -> t );
683685
fm_general(fn(t) -> t );
684686
}
685687

@@ -800,8 +802,8 @@ fn fold_ty(cx: &ctxt, fld: fold_mode, ty_0: t) -> t {
800802
ty_var(id) {
801803
alt fld { fm_var(folder) { ty = folder(id); } _ {/* no-op */ } }
802804
}
803-
ty_param(id) {
804-
alt fld { fm_param(folder) { ty = folder(id); } _ {/* no-op */ } }
805+
ty_param(id,k) {
806+
alt fld { fm_param(folder) { ty = folder(id,k); } _ {/* no-op */ } }
805807
}
806808
}
807809

@@ -1118,9 +1120,11 @@ fn type_kind(cx: &ctxt, ty: &t) -> ast::kind {
11181120

11191121
ty_var(_) { fail; }
11201122

1121-
ty_param(_) {
1122-
// FIXME: this should contribute the kind-bound of the typaram,
1123-
// when those exist.
1123+
ty_param(_,k) {
1124+
// FIXME: when you turn this on, the stdlib will break; be sure
1125+
// to have a snapshot done that understands kinds before doing so.
1126+
1127+
// result = kind::lower_kind(result, k);
11241128
}
11251129

11261130
ty_constr(t, _) {
@@ -1187,7 +1191,7 @@ fn type_has_dynamic_size(cx: &ctxt, ty: &t) -> bool {
11871191
ret type_has_dynamic_size(cx, sub);
11881192
}
11891193
ty_var(_) { fail "ty_var in type_has_dynamic_size()"; }
1190-
ty_param(_) { ret true; }
1194+
ty_param(_,_) { ret true; }
11911195
ty_type. { ret false; }
11921196
ty_native(_) { ret false; }
11931197
}
@@ -1313,7 +1317,7 @@ fn type_owns_heap_mem(cx: &ctxt, ty: &t) -> bool {
13131317
ty_chan(_) { result = false; }
13141318
ty_task. { result = false; }
13151319
ty_var(_) { fail "ty_var in type_owns_heap_mem"; }
1316-
ty_param(_) { result = false; }
1320+
ty_param(_,_) { result = false; }
13171321
}
13181322

13191323
cx.owns_heap_mem_cache.insert(ty, result);
@@ -1322,7 +1326,7 @@ fn type_owns_heap_mem(cx: &ctxt, ty: &t) -> bool {
13221326

13231327
fn type_param(cx: &ctxt, ty: &t) -> option::t[uint] {
13241328
alt struct(cx, ty) {
1325-
ty_param(id) { ret some(id); }
1329+
ty_param(id,_) { ret some(id); }
13261330
_ {/* fall through */ }
13271331
}
13281332
ret none;
@@ -1450,7 +1454,7 @@ fn hash_type_structure(st: &sty) -> uint {
14501454
ret h;
14511455
}
14521456
ty_var(v) { ret hash_uint(30u, v as uint); }
1453-
ty_param(pid) { ret hash_uint(31u, pid); }
1457+
ty_param(pid,_) { ret hash_uint(31u, pid); }
14541458
ty_type. { ret 32u; }
14551459
ty_native(did) { ret hash_def(33u, did); }
14561460
ty_bot. { ret 34u; }
@@ -1676,8 +1680,9 @@ fn equal_type_structures(a: &sty, b: &sty) -> bool {
16761680
ty_var(v_a) {
16771681
alt b { ty_var(v_b) { ret v_a == v_b; } _ { ret false; } }
16781682
}
1679-
ty_param(pid_a) {
1680-
alt b { ty_param(pid_b) { ret pid_a == pid_b; } _ { ret false; } }
1683+
ty_param(pid_a,k_a) {
1684+
alt b { ty_param(pid_b,k_b) { ret pid_a == pid_b && k_a == k_b; }
1685+
_ { ret false; } }
16811686
}
16821687
ty_type. { alt b { ty_type. { ret true; } _ { ret false; } } }
16831688
ty_native(a_id) {
@@ -1777,7 +1782,7 @@ fn node_id_to_monotype(cx: &ctxt, id: ast::node_id) -> t {
17771782
fn count_ty_params(cx: &ctxt, ty: t) -> uint {
17781783
fn counter(cx: &ctxt, param_indices: @mutable uint[], ty: t) {
17791784
alt struct(cx, ty) {
1780-
ty_param(param_idx) {
1785+
ty_param(param_idx,_) {
17811786
let seen = false;
17821787
for other_param_idx: uint in *param_indices {
17831788
if param_idx == other_param_idx { seen = true; }
@@ -2333,7 +2338,7 @@ mod unify {
23332338
_ { ret ures_err(terr_mismatch); }
23342339
}
23352340
}
2336-
ty::ty_param(_) { ret struct_cmp(cx, expected, actual); }
2341+
ty::ty_param(_,_) { ret struct_cmp(cx, expected, actual); }
23372342
ty::ty_tag(expected_id, expected_tps) {
23382343
alt struct(cx.tcx, actual) {
23392344
ty::ty_tag(actual_id, actual_tps) {
@@ -2719,7 +2724,7 @@ fn bind_params_in_type(sp: &span, cx: &ctxt, next_ty_var: fn() -> int ,
27192724
let i = 0u;
27202725
while i < ty_param_count { *param_var_ids += ~[next_ty_var()]; i += 1u; }
27212726
fn binder(sp: span, cx: ctxt, param_var_ids: @mutable int[],
2722-
next_ty_var: fn() -> int , index: uint) -> t {
2727+
next_ty_var: fn() -> int , index: uint, kind: ast::kind) -> t {
27232728
if index < ivec::len(*param_var_ids) {
27242729
ret mk_var(cx, param_var_ids.(index));
27252730
} else {
@@ -2728,7 +2733,8 @@ fn bind_params_in_type(sp: &span, cx: &ctxt, next_ty_var: fn() -> int ,
27282733
}
27292734
let new_typ =
27302735
fold_ty(cx,
2731-
fm_param(bind binder(sp, cx, param_var_ids, next_ty_var, _)),
2736+
fm_param(bind binder(sp, cx, param_var_ids, next_ty_var,
2737+
_, _)),
27322738
typ);
27332739
ret {ids: *param_var_ids, ty: new_typ};
27342740
}
@@ -2738,11 +2744,12 @@ fn bind_params_in_type(sp: &span, cx: &ctxt, next_ty_var: fn() -> int ,
27382744
// substitions.
27392745
fn substitute_type_params(cx: &ctxt, substs: &ty::t[], typ: t) -> t {
27402746
if !type_contains_params(cx, typ) { ret typ; }
2741-
fn substituter(cx: ctxt, substs: @ty::t[], idx: uint) -> t {
2747+
fn substituter(cx: ctxt, substs: @ty::t[], idx: uint,
2748+
kind: ast::kind) -> t {
27422749
// FIXME: bounds check can fail
27432750
ret substs.(idx);
27442751
}
2745-
ret fold_ty(cx, fm_param(bind substituter(cx, @substs, _)), typ);
2752+
ret fold_ty(cx, fm_param(bind substituter(cx, @substs, _, _)), typ);
27462753
}
27472754

27482755
fn def_has_ty_params(def: &ast::def) -> bool {
@@ -2755,7 +2762,7 @@ fn def_has_ty_params(def: &ast::def) -> bool {
27552762
ast::def_local(_) { ret false; }
27562763
ast::def_variant(_, _) { ret true; }
27572764
ast::def_ty(_) { ret false; }
2758-
ast::def_ty_arg(_) { ret false; }
2765+
ast::def_ty_arg(_,_) { ret false; }
27592766
ast::def_binding(_) { ret false; }
27602767
ast::def_use(_) { ret false; }
27612768
ast::def_native_ty(_) { ret false; }

src/comp/middle/typeck.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) ->
367367
typ = instantiate(tcx, ast_ty.span, getter, id, path.node.types);
368368
}
369369
some(ast::def_native_ty(id)) { typ = getter(id).ty; }
370-
some(ast::def_ty_arg(id)) { typ = ty::mk_param(tcx, id); }
370+
some(ast::def_ty_arg(id,k)) { typ = ty::mk_param(tcx, id, k); }
371371
some(_) {
372372
tcx.sess.span_fatal(ast_ty.span,
373373
"found type name used as a variable");
@@ -505,10 +505,13 @@ fn proto_to_ty_proto(proto: &ast::proto) -> ast::proto {
505505
mod collect {
506506
type ctxt = {tcx: ty::ctxt};
507507

508-
fn mk_ty_params(cx: &@ctxt, n: uint) -> ty::t[] {
508+
fn mk_ty_params(cx: &@ctxt, atps: &ast::ty_param[]) -> ty::t[] {
509509
let tps = ~[];
510510
let i = 0u;
511-
while i < n { tps += ~[ty::mk_param(cx.tcx, i)]; i += 1u; }
511+
for atp: ast::ty_param in atps {
512+
tps += ~[ty::mk_param(cx.tcx, i, atp.kind)];
513+
i += 1u;
514+
}
512515
ret tps;
513516
}
514517
fn ty_of_fn_decl(cx: &@ctxt, convert: &fn(&@ast::ty) -> ty::t ,
@@ -667,7 +670,7 @@ mod collect {
667670
{count: ivec::len(tps),
668671
ty:
669672
ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
670-
mk_ty_params(cx, ivec::len(tps)))};
673+
mk_ty_params(cx, tps))};
671674
cx.tcx.tcache.insert(local_def(it.id), t_res);
672675
ret t_res;
673676
}
@@ -676,7 +679,7 @@ mod collect {
676679

677680
let ty_param_count = ivec::len[ast::ty_param](tps);
678681

679-
let subtys: ty::t[] = mk_ty_params(cx, ty_param_count);
682+
let subtys: ty::t[] = mk_ty_params(cx, tps);
680683
let t = ty::mk_tag(cx.tcx, local_def(it.id), subtys);
681684
let tpt = {count: ty_param_count, ty: t};
682685
cx.tcx.tcache.insert(local_def(it.id), tpt);
@@ -714,7 +717,7 @@ mod collect {
714717
// Create a set of parameter types shared among all the variants.
715718

716719
let ty_param_count = ivec::len[ast::ty_param](ty_params);
717-
let ty_param_tys: ty::t[] = mk_ty_params(cx, ty_param_count);
720+
let ty_param_tys: ty::t[] = mk_ty_params(cx, ty_params);
718721
for variant: ast::variant in variants {
719722
// Nullary tag constructors get turned into constants; n-ary tag
720723
// constructors get turned into functions.
@@ -820,7 +823,7 @@ mod collect {
820823
let t_arg = ty_of_arg(cx, f.decl.inputs.(0));
821824
let t_res =
822825
ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
823-
mk_ty_params(cx, ivec::len(tps)));
826+
mk_ty_params(cx, tps));
824827
let t_ctor =
825828
ty::mk_fn(cx.tcx, ast::proto_fn, ~[t_arg], t_res, ast::return,
826829
~[]);

src/comp/syntax/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tag def {
4646

4747
/* variant */
4848
def_ty(def_id);
49-
def_ty_arg(uint);
49+
def_ty_arg(uint, kind);
5050
def_binding(def_id);
5151
def_use(def_id);
5252
def_native_ty(def_id);
@@ -74,7 +74,7 @@ fn def_id_of_def(d: def) -> def_id {
7474
def_local(id) { ret id; }
7575
def_variant(_, id) { ret id; }
7676
def_ty(id) { ret id; }
77-
def_ty_arg(_) { fail; }
77+
def_ty_arg(_,_) { fail; }
7878
def_binding(id) { ret id; }
7979
def_use(id) { ret id; }
8080
def_native_ty(id) { ret id; }

src/comp/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
130130
"<resource#" + int::str(id.node) + ":" + int::str(id.crate) + ">";
131131
}
132132
ty_var(v) { s += "<T" + int::str(v) + ">"; }
133-
ty_param(id) {
133+
ty_param(id,_) {
134134
s += "'" + str::unsafe_from_bytes([('a' as u8) + (id as u8)]);
135135
}
136136
_ { s += ty_to_short_str(cx, typ); }

0 commit comments

Comments
 (0)