Skip to content

Commit 59c441a

Browse files
committed
Encode, decode, and thread through typechecking all the param kinds, not just the counts.
1 parent a684f60 commit 59c441a

File tree

8 files changed

+143
-104
lines changed

8 files changed

+143
-104
lines changed

src/comp/metadata/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const tag_items_data: uint = 0x08u;
2020

2121
const tag_items_data_item: uint = 0x09u;
2222

23-
const tag_items_data_item_kind: uint = 0x0au;
23+
const tag_items_data_item_family: uint = 0x0au;
2424

25-
const tag_items_data_item_ty_param_count: uint = 0x0bu;
25+
const tag_items_data_item_ty_param_kinds: uint = 0x0bu;
2626

2727
const tag_items_data_item_type: uint = 0x0cu;
2828

src/comp/metadata/csearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> ty::variant_info[] {
3535
ret decoder::get_tag_variants(cdata, def, tcx, resolver)
3636
}
3737

38-
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_count_and_ty {
38+
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_kinds_and_ty {
3939
let cstore = tcx.sess.get_cstore();
4040
let cnum = def.crate;
4141
let cdata = cstore::get_crate_data(cstore, cnum).data;

src/comp/metadata/decoder.rs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export get_symbol;
2020
export get_tag_variants;
2121
export get_type;
2222
export get_type_param_count;
23+
export get_type_param_kinds;
2324
export lookup_defs;
2425
export get_crate_attributes;
2526
export list_crate_metadata;
@@ -77,9 +78,9 @@ fn lookup_item(item_id: int, data: &@u8[]) -> ebmlivec::doc {
7778
ret find_item(item_id, items);
7879
}
7980

80-
fn item_kind(item: &ebmlivec::doc) -> u8 {
81-
let kind = ebmlivec::get_doc(item, tag_items_data_item_kind);
82-
ret ebmlivec::doc_as_uint(kind) as u8;
81+
fn item_family(item: &ebmlivec::doc) -> u8 {
82+
let fam = ebmlivec::get_doc(item, tag_items_data_item_family);
83+
ret ebmlivec::doc_as_uint(fam) as u8;
8384
}
8485

8586
fn item_symbol(item: &ebmlivec::doc) -> str {
@@ -113,13 +114,24 @@ fn item_type(item: &ebmlivec::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
113114
def_parser, tcx);
114115
}
115116

116-
fn item_ty_param_count(item: &ebmlivec::doc) -> uint {
117-
let ty_param_count: uint = 0u;
118-
let tp = tag_items_data_item_ty_param_count;
119-
for each p: ebmlivec::doc in ebmlivec::tagged_docs(item, tp) {
120-
ty_param_count = ebmlivec::vint_at(ebmlivec::doc_data(p), 0u).val;
117+
fn item_ty_param_kinds(item: &ebmlivec::doc) -> ast::kind[] {
118+
let ks: ast::kind[] = ~[];
119+
let tp = tag_items_data_item_ty_param_kinds;
120+
for each p: ebmlivec::doc in ebmlivec::tagged_docs(item, tp) {
121+
let dat : u8[] = ebmlivec::doc_data(p);
122+
let vi = ebmlivec::vint_at(dat, 0u);
123+
let i = 0u;
124+
while i < vi.val {
125+
let k = alt dat.(vi.next + i) as char {
126+
'u' { ast::kind_unique }
127+
's' { ast::kind_shared }
128+
'p' { ast::kind_pinned }
129+
};
130+
ks += ~[k];
131+
i += 1u;
132+
}
121133
}
122-
ret ty_param_count;
134+
ret ks;
123135
}
124136

125137
fn tag_variant_ids(item: &ebmlivec::doc, this_cnum: ast::crate_num) ->
@@ -162,11 +174,11 @@ fn lookup_defs(data: &@u8[], cnum: ast::crate_num, path: &ast::ident[]) ->
162174
fn lookup_def(cnum: ast::crate_num, data: @u8[], did_: &ast::def_id) ->
163175
ast::def {
164176
let item = lookup_item(did_.node, data);
165-
let kind_ch = item_kind(item);
177+
let fam_ch = item_family(item);
166178
let did = {crate: cnum, node: did_.node};
167179
// We treat references to tags as references to types.
168180
let def =
169-
alt kind_ch as char {
181+
alt fam_ch as char {
170182
'c' { ast::def_const(did) }
171183
'f' { ast::def_fn(did, ast::impure_fn) }
172184
'p' { ast::def_fn(did, ast::pure_fn) }
@@ -186,22 +198,26 @@ fn lookup_def(cnum: ast::crate_num, data: @u8[], did_: &ast::def_id) ->
186198
}
187199

188200
fn get_type(data: @u8[], def: ast::def_id, tcx: &ty::ctxt,
189-
extres: &external_resolver) -> ty::ty_param_count_and_ty {
201+
extres: &external_resolver) -> ty::ty_param_kinds_and_ty {
190202
let this_cnum = def.crate;
191203
let node_id = def.node;
192204
let item = lookup_item(node_id, data);
193205
let t = item_type(item, this_cnum, tcx, extres);
194-
let tp_count;
195-
let kind_ch = item_kind(item);
196-
let has_ty_params = kind_has_type_params(kind_ch);
206+
let tp_kinds : ast::kind[];
207+
let fam_ch = item_family(item);
208+
let has_ty_params = family_has_type_params(fam_ch);
197209
if has_ty_params {
198-
tp_count = item_ty_param_count(item);
199-
} else { tp_count = 0u; }
200-
ret {count: tp_count, ty: t};
210+
tp_kinds = item_ty_param_kinds(item);
211+
} else { tp_kinds = ~[]; }
212+
ret {kinds: tp_kinds, ty: t};
201213
}
202214

203215
fn get_type_param_count(data: @u8[], id: ast::node_id) -> uint {
204-
ret item_ty_param_count(lookup_item(id, data));
216+
ret ivec::len(get_type_param_kinds(data, id));
217+
}
218+
219+
fn get_type_param_kinds(data: @u8[], id: ast::node_id) -> ast::kind[] {
220+
ret item_ty_param_kinds(lookup_item(id, data));
205221
}
206222

207223
fn get_symbol(data: @u8[], id: ast::node_id) -> str {
@@ -235,8 +251,8 @@ fn get_tag_variants(data: &@u8[], def: ast::def_id, tcx: &ty::ctxt,
235251
ret infos;
236252
}
237253

238-
fn kind_has_type_params(kind_ch: u8) -> bool {
239-
ret alt kind_ch as char {
254+
fn family_has_type_params(fam_ch: u8) -> bool {
255+
ret alt fam_ch as char {
240256
'c' { false }
241257
'f' { true }
242258
'p' { true }
@@ -260,11 +276,11 @@ fn read_path(d: &ebmlivec::doc) -> {path: str, pos: uint} {
260276

261277
fn describe_def(items: &ebmlivec::doc, id: ast::def_id) -> str {
262278
if id.crate != ast::local_crate { ret "external"; }
263-
ret item_kind_to_str(item_kind(find_item(id.node, items)));
279+
ret item_family_to_str(item_family(find_item(id.node, items)));
264280
}
265281

266-
fn item_kind_to_str(kind: u8) -> str {
267-
alt kind as char {
282+
fn item_family_to_str(fam: u8) -> str {
283+
alt fam as char {
268284
'c' { ret "const"; }
269285
'f' { ret "fn"; }
270286
'p' { ret "pred"; }

src/comp/metadata/encoder.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,25 @@ fn encode_item_paths(ebml_w: &ebmlivec::writer, crate: &@crate) ->
160160

161161

162162
// Item info table encoding
163-
fn encode_kind(ebml_w: &ebmlivec::writer, c: u8) {
164-
ebmlivec::start_tag(ebml_w, tag_items_data_item_kind);
163+
fn encode_family(ebml_w: &ebmlivec::writer, c: u8) {
164+
ebmlivec::start_tag(ebml_w, tag_items_data_item_family);
165165
ebml_w.writer.write(~[c]);
166166
ebmlivec::end_tag(ebml_w);
167167
}
168168

169169
fn def_to_str(did: &def_id) -> str { ret #fmt("%d:%d", did.crate, did.node); }
170170

171-
fn encode_type_param_count(ebml_w: &ebmlivec::writer, tps: &ty_param[]) {
172-
ebmlivec::start_tag(ebml_w, tag_items_data_item_ty_param_count);
171+
fn encode_type_param_kinds(ebml_w: &ebmlivec::writer, tps: &ty_param[]) {
172+
ebmlivec::start_tag(ebml_w, tag_items_data_item_ty_param_kinds);
173173
ebmlivec::write_vint(ebml_w.writer, ivec::len[ty_param](tps));
174+
for tp: ty_param in tps {
175+
let c = alt tp.kind {
176+
kind_unique. { 'u' }
177+
kind_shared. { 's' }
178+
kind_pinned. { 'p' }
179+
};
180+
ebml_w.writer.write(~[c as u8]);
181+
}
174182
ebmlivec::end_tag(ebml_w);
175183
}
176184

@@ -218,15 +226,15 @@ fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
218226
index += ~[{val: variant.node.id, pos: ebml_w.writer.tell()}];
219227
ebmlivec::start_tag(ebml_w, tag_items_data_item);
220228
encode_def_id(ebml_w, local_def(variant.node.id));
221-
encode_kind(ebml_w, 'v' as u8);
229+
encode_family(ebml_w, 'v' as u8);
222230
encode_tag_id(ebml_w, local_def(id));
223231
encode_type(ecx, ebml_w,
224232
node_id_to_monotype(ecx.ccx.tcx, variant.node.id));
225233
if ivec::len[variant_arg](variant.node.args) > 0u {
226234
encode_symbol(ecx, ebml_w, variant.node.id);
227235
}
228236
encode_discriminant(ecx, ebml_w, variant.node.id);
229-
encode_type_param_count(ebml_w, ty_params);
237+
encode_type_param_kinds(ebml_w, ty_params);
230238
ebmlivec::end_tag(ebml_w);
231239
}
232240
}
@@ -237,47 +245,47 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
237245
item_const(_, _) {
238246
ebmlivec::start_tag(ebml_w, tag_items_data_item);
239247
encode_def_id(ebml_w, local_def(item.id));
240-
encode_kind(ebml_w, 'c' as u8);
248+
encode_family(ebml_w, 'c' as u8);
241249
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
242250
encode_symbol(ecx, ebml_w, item.id);
243251
ebmlivec::end_tag(ebml_w);
244252
}
245253
item_fn(fd, tps) {
246254
ebmlivec::start_tag(ebml_w, tag_items_data_item);
247255
encode_def_id(ebml_w, local_def(item.id));
248-
encode_kind(ebml_w,
256+
encode_family(ebml_w,
249257
alt fd.decl.purity { pure_fn. { 'p' } impure_fn. { 'f' } }
250258
as u8);
251-
encode_type_param_count(ebml_w, tps);
259+
encode_type_param_kinds(ebml_w, tps);
252260
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
253261
encode_symbol(ecx, ebml_w, item.id);
254262
ebmlivec::end_tag(ebml_w);
255263
}
256264
item_mod(_) {
257265
ebmlivec::start_tag(ebml_w, tag_items_data_item);
258266
encode_def_id(ebml_w, local_def(item.id));
259-
encode_kind(ebml_w, 'm' as u8);
267+
encode_family(ebml_w, 'm' as u8);
260268
ebmlivec::end_tag(ebml_w);
261269
}
262270
item_native_mod(_) {
263271
ebmlivec::start_tag(ebml_w, tag_items_data_item);
264272
encode_def_id(ebml_w, local_def(item.id));
265-
encode_kind(ebml_w, 'n' as u8);
273+
encode_family(ebml_w, 'n' as u8);
266274
ebmlivec::end_tag(ebml_w);
267275
}
268276
item_ty(_, tps) {
269277
ebmlivec::start_tag(ebml_w, tag_items_data_item);
270278
encode_def_id(ebml_w, local_def(item.id));
271-
encode_kind(ebml_w, 'y' as u8);
272-
encode_type_param_count(ebml_w, tps);
279+
encode_family(ebml_w, 'y' as u8);
280+
encode_type_param_kinds(ebml_w, tps);
273281
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
274282
ebmlivec::end_tag(ebml_w);
275283
}
276284
item_tag(variants, tps) {
277285
ebmlivec::start_tag(ebml_w, tag_items_data_item);
278286
encode_def_id(ebml_w, local_def(item.id));
279-
encode_kind(ebml_w, 't' as u8);
280-
encode_type_param_count(ebml_w, tps);
287+
encode_family(ebml_w, 't' as u8);
288+
encode_type_param_kinds(ebml_w, tps);
281289
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
282290
for v: variant in variants {
283291
encode_variant_id(ebml_w, local_def(v.node.id));
@@ -290,17 +298,17 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
290298

291299
ebmlivec::start_tag(ebml_w, tag_items_data_item);
292300
encode_def_id(ebml_w, local_def(ctor_id));
293-
encode_kind(ebml_w, 'y' as u8);
294-
encode_type_param_count(ebml_w, tps);
301+
encode_family(ebml_w, 'y' as u8);
302+
encode_type_param_kinds(ebml_w, tps);
295303
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
296304
encode_symbol(ecx, ebml_w, item.id);
297305
ebmlivec::end_tag(ebml_w);
298306

299307
index += ~[{val: ctor_id, pos: ebml_w.writer.tell()}];
300308
ebmlivec::start_tag(ebml_w, tag_items_data_item);
301309
encode_def_id(ebml_w, local_def(ctor_id));
302-
encode_kind(ebml_w, 'f' as u8);
303-
encode_type_param_count(ebml_w, tps);
310+
encode_family(ebml_w, 'f' as u8);
311+
encode_type_param_kinds(ebml_w, tps);
304312
encode_type(ecx, ebml_w, fn_ty);
305313
encode_symbol(ecx, ebml_w, ctor_id);
306314
ebmlivec::end_tag(ebml_w);
@@ -310,16 +318,16 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
310318

311319
ebmlivec::start_tag(ebml_w, tag_items_data_item);
312320
encode_def_id(ebml_w, local_def(item.id));
313-
encode_kind(ebml_w, 'y' as u8);
314-
encode_type_param_count(ebml_w, tps);
321+
encode_family(ebml_w, 'y' as u8);
322+
encode_type_param_kinds(ebml_w, tps);
315323
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
316324
ebmlivec::end_tag(ebml_w);
317325

318326
index += ~[{val: ctor_id, pos: ebml_w.writer.tell()}];
319327
ebmlivec::start_tag(ebml_w, tag_items_data_item);
320328
encode_def_id(ebml_w, local_def(ctor_id));
321-
encode_kind(ebml_w, 'f' as u8);
322-
encode_type_param_count(ebml_w, tps);
329+
encode_family(ebml_w, 'f' as u8);
330+
encode_type_param_kinds(ebml_w, tps);
323331
encode_type(ecx, ebml_w, fn_ty);
324332
encode_symbol(ecx, ebml_w, ctor_id);
325333
ebmlivec::end_tag(ebml_w);
@@ -333,14 +341,14 @@ fn encode_info_for_native_item(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
333341
alt nitem.node {
334342
native_item_ty. {
335343
encode_def_id(ebml_w, local_def(nitem.id));
336-
encode_kind(ebml_w, 'T' as u8);
344+
encode_family(ebml_w, 'T' as u8);
337345
encode_type(ecx, ebml_w,
338346
ty::mk_native(ecx.ccx.tcx, local_def(nitem.id)));
339347
}
340348
native_item_fn(_, _, tps) {
341349
encode_def_id(ebml_w, local_def(nitem.id));
342-
encode_kind(ebml_w, 'F' as u8);
343-
encode_type_param_count(ebml_w, tps);
350+
encode_family(ebml_w, 'F' as u8);
351+
encode_type_param_kinds(ebml_w, tps);
344352
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, nitem.id));
345353
encode_symbol(ecx, ebml_w, nitem.id);
346354
}

src/comp/middle/kind.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ fn check_expr(tcx: &ty::ctxt, e: &@ast::expr) {
138138
ast::expr_move(a, b) { need_shared_lhs_rhs(tcx, a, b, "<-"); }
139139
ast::expr_assign(a, b) { need_shared_lhs_rhs(tcx, a, b, "="); }
140140
ast::expr_swap(a, b) { need_shared_lhs_rhs(tcx, a, b, "<->"); }
141+
ast::expr_call(callee, args) {
142+
// FIXME: when ready, start checking param kinds against args.
143+
// This will break stdlib again.
144+
// let tpt = ty::expr_ty_params_and_ty(tcx, callee);
145+
}
141146
_ { }
142147
}
143148
}

src/comp/middle/trans.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,12 @@ fn type_of_arg(cx: @local_ctxt, sp: &span, arg: &ty::arg) -> TypeRef {
296296
ret typ;
297297
}
298298

299-
fn type_of_ty_param_count_and_ty(lcx: @local_ctxt, sp: &span,
300-
tpt: &ty::ty_param_count_and_ty) -> TypeRef {
299+
fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: &span,
300+
tpt: &ty::ty_param_kinds_and_ty) -> TypeRef {
301301
alt ty::struct(lcx.ccx.tcx, tpt.ty) {
302302
ty::ty_fn(_, _, _, _, _) {
303-
let llfnty = type_of_fn_from_ty(lcx.ccx, sp, tpt.ty, tpt.count);
303+
let llfnty = type_of_fn_from_ty(lcx.ccx, sp, tpt.ty,
304+
std::ivec::len(tpt.kinds));
304305
ret T_fn_pair(*lcx.ccx, llfnty);
305306
}
306307
_ {
@@ -3970,14 +3971,14 @@ fn lval_val(cx: &@block_ctxt, val: ValueRef) -> lval_result {
39703971
}
39713972

39723973
fn trans_external_path(cx: &@block_ctxt, did: &ast::def_id,
3973-
tpt: &ty::ty_param_count_and_ty) -> ValueRef {
3974+
tpt: &ty::ty_param_kinds_and_ty) -> ValueRef {
39743975
let lcx = cx.fcx.lcx;
39753976
let name = csearch::get_symbol(lcx.ccx.sess.get_cstore(), did);
39763977
ret get_extern_const(lcx.ccx.externs, lcx.ccx.llmod, name,
3977-
type_of_ty_param_count_and_ty(lcx, cx.sp, tpt));
3978+
type_of_ty_param_kinds_and_ty(lcx, cx.sp, tpt));
39783979
}
39793980

3980-
fn lval_generic_fn(cx: &@block_ctxt, tpt: &ty::ty_param_count_and_ty,
3981+
fn lval_generic_fn(cx: &@block_ctxt, tpt: &ty::ty_param_kinds_and_ty,
39813982
fn_id: &ast::def_id, id: ast::node_id) -> lval_result {
39823983
let lv;
39833984
if fn_id.crate == ast::local_crate {
@@ -4101,10 +4102,11 @@ fn trans_var(cx: &@block_ctxt, sp: &span, id: ast::node_id) ->
41014102
ret lval_mem(cx, ccx.consts.get(did.node));
41024103
} else {
41034104
let tp = ty::node_id_to_monotype(ccx.tcx, id);
4105+
let k: ast::kind[] = ~[];
41044106
ret lval_val(cx,
41054107
load_if_immediate(cx,
41064108
trans_external_path(cx, did,
4107-
{count: 0u,
4109+
{kinds: k,
41084110
ty: tp}),
41094111
tp));
41104112
}

0 commit comments

Comments
 (0)