Encode, decode, and thread through typechecking all the param kinds, not just the counts.
This commit is contained in:
parent
a684f6078f
commit
59c441a66a
8 changed files with 143 additions and 104 deletions
|
|
@ -20,9 +20,9 @@ const tag_items_data: uint = 0x08u;
|
|||
|
||||
const tag_items_data_item: uint = 0x09u;
|
||||
|
||||
const tag_items_data_item_kind: uint = 0x0au;
|
||||
const tag_items_data_item_family: uint = 0x0au;
|
||||
|
||||
const tag_items_data_item_ty_param_count: uint = 0x0bu;
|
||||
const tag_items_data_item_ty_param_kinds: uint = 0x0bu;
|
||||
|
||||
const tag_items_data_item_type: uint = 0x0cu;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> ty::variant_info[] {
|
|||
ret decoder::get_tag_variants(cdata, def, tcx, resolver)
|
||||
}
|
||||
|
||||
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_count_and_ty {
|
||||
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_kinds_and_ty {
|
||||
let cstore = tcx.sess.get_cstore();
|
||||
let cnum = def.crate;
|
||||
let cdata = cstore::get_crate_data(cstore, cnum).data;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export get_symbol;
|
|||
export get_tag_variants;
|
||||
export get_type;
|
||||
export get_type_param_count;
|
||||
export get_type_param_kinds;
|
||||
export lookup_defs;
|
||||
export get_crate_attributes;
|
||||
export list_crate_metadata;
|
||||
|
|
@ -77,9 +78,9 @@ fn lookup_item(item_id: int, data: &@u8[]) -> ebmlivec::doc {
|
|||
ret find_item(item_id, items);
|
||||
}
|
||||
|
||||
fn item_kind(item: &ebmlivec::doc) -> u8 {
|
||||
let kind = ebmlivec::get_doc(item, tag_items_data_item_kind);
|
||||
ret ebmlivec::doc_as_uint(kind) as u8;
|
||||
fn item_family(item: &ebmlivec::doc) -> u8 {
|
||||
let fam = ebmlivec::get_doc(item, tag_items_data_item_family);
|
||||
ret ebmlivec::doc_as_uint(fam) as u8;
|
||||
}
|
||||
|
||||
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,
|
|||
def_parser, tcx);
|
||||
}
|
||||
|
||||
fn item_ty_param_count(item: &ebmlivec::doc) -> uint {
|
||||
let ty_param_count: uint = 0u;
|
||||
let tp = tag_items_data_item_ty_param_count;
|
||||
for each p: ebmlivec::doc in ebmlivec::tagged_docs(item, tp) {
|
||||
ty_param_count = ebmlivec::vint_at(ebmlivec::doc_data(p), 0u).val;
|
||||
fn item_ty_param_kinds(item: &ebmlivec::doc) -> ast::kind[] {
|
||||
let ks: ast::kind[] = ~[];
|
||||
let tp = tag_items_data_item_ty_param_kinds;
|
||||
for each p: ebmlivec::doc in ebmlivec::tagged_docs(item, tp) {
|
||||
let dat : u8[] = ebmlivec::doc_data(p);
|
||||
let vi = ebmlivec::vint_at(dat, 0u);
|
||||
let i = 0u;
|
||||
while i < vi.val {
|
||||
let k = alt dat.(vi.next + i) as char {
|
||||
'u' { ast::kind_unique }
|
||||
's' { ast::kind_shared }
|
||||
'p' { ast::kind_pinned }
|
||||
};
|
||||
ks += ~[k];
|
||||
i += 1u;
|
||||
}
|
||||
}
|
||||
ret ty_param_count;
|
||||
ret ks;
|
||||
}
|
||||
|
||||
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[]) ->
|
|||
fn lookup_def(cnum: ast::crate_num, data: @u8[], did_: &ast::def_id) ->
|
||||
ast::def {
|
||||
let item = lookup_item(did_.node, data);
|
||||
let kind_ch = item_kind(item);
|
||||
let fam_ch = item_family(item);
|
||||
let did = {crate: cnum, node: did_.node};
|
||||
// We treat references to tags as references to types.
|
||||
let def =
|
||||
alt kind_ch as char {
|
||||
alt fam_ch as char {
|
||||
'c' { ast::def_const(did) }
|
||||
'f' { ast::def_fn(did, ast::impure_fn) }
|
||||
'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) ->
|
|||
}
|
||||
|
||||
fn get_type(data: @u8[], def: ast::def_id, tcx: &ty::ctxt,
|
||||
extres: &external_resolver) -> ty::ty_param_count_and_ty {
|
||||
extres: &external_resolver) -> ty::ty_param_kinds_and_ty {
|
||||
let this_cnum = def.crate;
|
||||
let node_id = def.node;
|
||||
let item = lookup_item(node_id, data);
|
||||
let t = item_type(item, this_cnum, tcx, extres);
|
||||
let tp_count;
|
||||
let kind_ch = item_kind(item);
|
||||
let has_ty_params = kind_has_type_params(kind_ch);
|
||||
let tp_kinds : ast::kind[];
|
||||
let fam_ch = item_family(item);
|
||||
let has_ty_params = family_has_type_params(fam_ch);
|
||||
if has_ty_params {
|
||||
tp_count = item_ty_param_count(item);
|
||||
} else { tp_count = 0u; }
|
||||
ret {count: tp_count, ty: t};
|
||||
tp_kinds = item_ty_param_kinds(item);
|
||||
} else { tp_kinds = ~[]; }
|
||||
ret {kinds: tp_kinds, ty: t};
|
||||
}
|
||||
|
||||
fn get_type_param_count(data: @u8[], id: ast::node_id) -> uint {
|
||||
ret item_ty_param_count(lookup_item(id, data));
|
||||
ret ivec::len(get_type_param_kinds(data, id));
|
||||
}
|
||||
|
||||
fn get_type_param_kinds(data: @u8[], id: ast::node_id) -> ast::kind[] {
|
||||
ret item_ty_param_kinds(lookup_item(id, data));
|
||||
}
|
||||
|
||||
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,
|
|||
ret infos;
|
||||
}
|
||||
|
||||
fn kind_has_type_params(kind_ch: u8) -> bool {
|
||||
ret alt kind_ch as char {
|
||||
fn family_has_type_params(fam_ch: u8) -> bool {
|
||||
ret alt fam_ch as char {
|
||||
'c' { false }
|
||||
'f' { true }
|
||||
'p' { true }
|
||||
|
|
@ -260,11 +276,11 @@ fn read_path(d: &ebmlivec::doc) -> {path: str, pos: uint} {
|
|||
|
||||
fn describe_def(items: &ebmlivec::doc, id: ast::def_id) -> str {
|
||||
if id.crate != ast::local_crate { ret "external"; }
|
||||
ret item_kind_to_str(item_kind(find_item(id.node, items)));
|
||||
ret item_family_to_str(item_family(find_item(id.node, items)));
|
||||
}
|
||||
|
||||
fn item_kind_to_str(kind: u8) -> str {
|
||||
alt kind as char {
|
||||
fn item_family_to_str(fam: u8) -> str {
|
||||
alt fam as char {
|
||||
'c' { ret "const"; }
|
||||
'f' { ret "fn"; }
|
||||
'p' { ret "pred"; }
|
||||
|
|
|
|||
|
|
@ -160,17 +160,25 @@ fn encode_item_paths(ebml_w: &ebmlivec::writer, crate: &@crate) ->
|
|||
|
||||
|
||||
// Item info table encoding
|
||||
fn encode_kind(ebml_w: &ebmlivec::writer, c: u8) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item_kind);
|
||||
fn encode_family(ebml_w: &ebmlivec::writer, c: u8) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item_family);
|
||||
ebml_w.writer.write(~[c]);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn def_to_str(did: &def_id) -> str { ret #fmt("%d:%d", did.crate, did.node); }
|
||||
|
||||
fn encode_type_param_count(ebml_w: &ebmlivec::writer, tps: &ty_param[]) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item_ty_param_count);
|
||||
fn encode_type_param_kinds(ebml_w: &ebmlivec::writer, tps: &ty_param[]) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item_ty_param_kinds);
|
||||
ebmlivec::write_vint(ebml_w.writer, ivec::len[ty_param](tps));
|
||||
for tp: ty_param in tps {
|
||||
let c = alt tp.kind {
|
||||
kind_unique. { 'u' }
|
||||
kind_shared. { 's' }
|
||||
kind_pinned. { 'p' }
|
||||
};
|
||||
ebml_w.writer.write(~[c as u8]);
|
||||
}
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +226,7 @@ fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
index += ~[{val: variant.node.id, pos: ebml_w.writer.tell()}];
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(variant.node.id));
|
||||
encode_kind(ebml_w, 'v' as u8);
|
||||
encode_family(ebml_w, 'v' as u8);
|
||||
encode_tag_id(ebml_w, local_def(id));
|
||||
encode_type(ecx, ebml_w,
|
||||
node_id_to_monotype(ecx.ccx.tcx, variant.node.id));
|
||||
|
|
@ -226,7 +234,7 @@ fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
encode_symbol(ecx, ebml_w, variant.node.id);
|
||||
}
|
||||
encode_discriminant(ecx, ebml_w, variant.node.id);
|
||||
encode_type_param_count(ebml_w, ty_params);
|
||||
encode_type_param_kinds(ebml_w, ty_params);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
|
|
@ -237,7 +245,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
item_const(_, _) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'c' as u8);
|
||||
encode_family(ebml_w, 'c' as u8);
|
||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
||||
encode_symbol(ecx, ebml_w, item.id);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
|
|
@ -245,10 +253,10 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
item_fn(fd, tps) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w,
|
||||
encode_family(ebml_w,
|
||||
alt fd.decl.purity { pure_fn. { 'p' } impure_fn. { 'f' } }
|
||||
as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_type_param_kinds(ebml_w, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
||||
encode_symbol(ecx, ebml_w, item.id);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
|
|
@ -256,28 +264,28 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
item_mod(_) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'm' as u8);
|
||||
encode_family(ebml_w, 'm' as u8);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
item_native_mod(_) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'n' as u8);
|
||||
encode_family(ebml_w, 'n' as u8);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
item_ty(_, tps) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'y' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_family(ebml_w, 'y' as u8);
|
||||
encode_type_param_kinds(ebml_w, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
}
|
||||
item_tag(variants, tps) {
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 't' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_family(ebml_w, 't' as u8);
|
||||
encode_type_param_kinds(ebml_w, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
||||
for v: variant in variants {
|
||||
encode_variant_id(ebml_w, local_def(v.node.id));
|
||||
|
|
@ -290,8 +298,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
encode_kind(ebml_w, 'y' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_family(ebml_w, 'y' as u8);
|
||||
encode_type_param_kinds(ebml_w, tps);
|
||||
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
|
||||
encode_symbol(ecx, ebml_w, item.id);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
|
|
@ -299,8 +307,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
index += ~[{val: ctor_id, pos: ebml_w.writer.tell()}];
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
encode_kind(ebml_w, 'f' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_family(ebml_w, 'f' as u8);
|
||||
encode_type_param_kinds(ebml_w, tps);
|
||||
encode_type(ecx, ebml_w, fn_ty);
|
||||
encode_symbol(ecx, ebml_w, ctor_id);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
|
|
@ -310,16 +318,16 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'y' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_family(ebml_w, 'y' as u8);
|
||||
encode_type_param_kinds(ebml_w, tps);
|
||||
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
|
||||
index += ~[{val: ctor_id, pos: ebml_w.writer.tell()}];
|
||||
ebmlivec::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
encode_kind(ebml_w, 'f' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_family(ebml_w, 'f' as u8);
|
||||
encode_type_param_kinds(ebml_w, tps);
|
||||
encode_type(ecx, ebml_w, fn_ty);
|
||||
encode_symbol(ecx, ebml_w, ctor_id);
|
||||
ebmlivec::end_tag(ebml_w);
|
||||
|
|
@ -333,14 +341,14 @@ fn encode_info_for_native_item(ecx: &@encode_ctxt, ebml_w: &ebmlivec::writer,
|
|||
alt nitem.node {
|
||||
native_item_ty. {
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
encode_kind(ebml_w, 'T' as u8);
|
||||
encode_family(ebml_w, 'T' as u8);
|
||||
encode_type(ecx, ebml_w,
|
||||
ty::mk_native(ecx.ccx.tcx, local_def(nitem.id)));
|
||||
}
|
||||
native_item_fn(_, _, tps) {
|
||||
encode_def_id(ebml_w, local_def(nitem.id));
|
||||
encode_kind(ebml_w, 'F' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_family(ebml_w, 'F' as u8);
|
||||
encode_type_param_kinds(ebml_w, tps);
|
||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, nitem.id));
|
||||
encode_symbol(ecx, ebml_w, nitem.id);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue