Merge branch 'master' into kmath
This commit is contained in:
@@ -66,7 +66,9 @@ const tag_crate_hash: uint = 0x28u;
|
|||||||
|
|
||||||
const tag_mod_impl: uint = 0x30u;
|
const tag_mod_impl: uint = 0x30u;
|
||||||
|
|
||||||
const tag_impl_method: uint = 0x31u;
|
const tag_item_method: uint = 0x31u;
|
||||||
|
const tag_impl_iface: uint = 0x32u;
|
||||||
|
const tag_impl_iface_did: uint = 0x33u;
|
||||||
|
|
||||||
// djb's cdb hashes.
|
// djb's cdb hashes.
|
||||||
fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }
|
fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ export get_type_param_count;
|
|||||||
export lookup_defs;
|
export lookup_defs;
|
||||||
export get_tag_variants;
|
export get_tag_variants;
|
||||||
export get_impls_for_mod;
|
export get_impls_for_mod;
|
||||||
export get_impl_methods;
|
export get_iface_methods;
|
||||||
export get_type;
|
export get_type;
|
||||||
export get_item_name;
|
export get_item_name;
|
||||||
|
export get_impl_iface;
|
||||||
|
|
||||||
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
|
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
|
||||||
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
||||||
@@ -65,33 +66,23 @@ fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
|
|||||||
|
|
||||||
fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,
|
fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,
|
||||||
name: option::t<ast::ident>)
|
name: option::t<ast::ident>)
|
||||||
-> [@middle::resolve::_impl] {
|
-> @[@middle::resolve::_impl] {
|
||||||
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
||||||
let result = [];
|
let resolver = bind translate_def_id(cstore, def.crate, _);
|
||||||
for did in decoder::get_impls_for_mod(cdata, def.node, def.crate) {
|
decoder::get_impls_for_mod(cdata, def, name, resolver)
|
||||||
let nm = decoder::lookup_item_name(cdata, did.node);
|
|
||||||
if alt name { some(n) { n == nm } none. { true } } {
|
|
||||||
result += [@{did: did,
|
|
||||||
iface_did: none::<ast::def_id>, // FIXME[impl]
|
|
||||||
ident: nm,
|
|
||||||
methods: decoder::lookup_impl_methods(
|
|
||||||
cdata, did.node, did.crate)}];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_impl_methods(cstore: cstore::cstore, def: ast::def_id)
|
fn get_iface_methods(tcx: ty::ctxt, def: ast::def_id) -> @[ty::method] {
|
||||||
-> [@middle::resolve::method_info] {
|
let cstore = tcx.sess.get_cstore();
|
||||||
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
||||||
decoder::lookup_impl_methods(cdata, def.node, def.crate)
|
let resolver = bind translate_def_id(cstore, def.crate, _);
|
||||||
|
decoder::get_iface_methods(cdata, def, tcx, resolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
|
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
|
||||||
let cstore = tcx.sess.get_cstore();
|
let cstore = tcx.sess.get_cstore();
|
||||||
let cnum = def.crate;
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
||||||
let cdata = cstore::get_crate_data(cstore, cnum).data;
|
let resolver = bind translate_def_id(cstore, def.crate, _);
|
||||||
let resolver = bind translate_def_id(cstore, cnum, _);
|
|
||||||
decoder::get_type(cdata, def, tcx, resolver)
|
decoder::get_type(cdata, def, tcx, resolver)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +91,14 @@ fn get_item_name(cstore: cstore::cstore, cnum: int, id: int) -> ast::ident {
|
|||||||
ret decoder::lookup_item_name(cdata, id);
|
ret decoder::lookup_item_name(cdata, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_impl_iface(tcx: ty::ctxt, def: ast::def_id)
|
||||||
|
-> option::t<ty::t> {
|
||||||
|
let cstore = tcx.sess.get_cstore();
|
||||||
|
let cdata = cstore::get_crate_data(cstore, def.crate).data;
|
||||||
|
let resolver = bind translate_def_id(cstore, def.crate, _);
|
||||||
|
decoder::get_impl_iface(cdata, def, tcx, resolver)
|
||||||
|
}
|
||||||
|
|
||||||
// Translates a def_id from an external crate to a def_id for the current
|
// Translates a def_id from an external crate to a def_id for the current
|
||||||
// compilation environment. We use this when trying to load types from
|
// compilation environment. We use this when trying to load types from
|
||||||
// external crates - if those types further refer to types in other crates
|
// external crates - if those types further refer to types in other crates
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ export get_symbol;
|
|||||||
export get_tag_variants;
|
export get_tag_variants;
|
||||||
export get_type;
|
export get_type;
|
||||||
export get_type_param_count;
|
export get_type_param_count;
|
||||||
|
export get_impl_iface;
|
||||||
export lookup_def;
|
export lookup_def;
|
||||||
export lookup_item_name;
|
export lookup_item_name;
|
||||||
|
export get_impl_iface;
|
||||||
export resolve_path;
|
export resolve_path;
|
||||||
export get_crate_attributes;
|
export get_crate_attributes;
|
||||||
export list_crate_metadata;
|
export list_crate_metadata;
|
||||||
@@ -24,7 +26,7 @@ export get_crate_deps;
|
|||||||
export get_crate_hash;
|
export get_crate_hash;
|
||||||
export external_resolver;
|
export external_resolver;
|
||||||
export get_impls_for_mod;
|
export get_impls_for_mod;
|
||||||
export lookup_impl_methods;
|
export get_iface_methods;
|
||||||
// A function that takes a def_id relative to the crate being searched and
|
// A function that takes a def_id relative to the crate being searched and
|
||||||
// returns a def_id relative to the compilation environment, i.e. if we hit a
|
// returns a def_id relative to the compilation environment, i.e. if we hit a
|
||||||
// def_id for an item defined in another crate, somebody needs to figure out
|
// def_id for an item defined in another crate, somebody needs to figure out
|
||||||
@@ -103,16 +105,42 @@ fn parse_external_def_id(this_cnum: ast::crate_num,
|
|||||||
} else { ret extres(external_def_id); }
|
} else { ret extres(external_def_id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn doc_type(doc: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
||||||
|
extres: external_resolver) -> ty::t {
|
||||||
|
let tp = ebml::get_doc(doc, tag_items_data_item_type);
|
||||||
|
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
|
||||||
|
parse_ty_data(tp.data, this_cnum, tp.start, def_parser, tcx)
|
||||||
|
}
|
||||||
|
|
||||||
fn item_type(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
fn item_type(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
||||||
extres: external_resolver) -> ty::t {
|
extres: external_resolver) -> ty::t {
|
||||||
let tp = ebml::get_doc(item, tag_items_data_item_type);
|
let t = doc_type(item, this_cnum, tcx, extres);
|
||||||
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
|
|
||||||
let t = parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
|
|
||||||
def_parser, tcx);
|
|
||||||
if family_names_type(item_family(item)) {
|
if family_names_type(item_family(item)) {
|
||||||
t = ty::mk_named(tcx, t, @item_name(item));
|
ty::mk_named(tcx, t, @item_name(item))
|
||||||
|
} else { t }
|
||||||
}
|
}
|
||||||
t
|
|
||||||
|
fn item_impl_iface(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
|
||||||
|
extres: external_resolver) -> option::t<ty::t> {
|
||||||
|
let result = none;
|
||||||
|
ebml::tagged_docs(item, tag_impl_iface) {|ity|
|
||||||
|
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
|
||||||
|
let t = parse_ty_data(ity.data, this_cnum, ity.start, def_parser,
|
||||||
|
tcx);
|
||||||
|
result = some(t);
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn item_impl_iface_did(item: ebml::doc, this_cnum: ast::crate_num,
|
||||||
|
extres: external_resolver)
|
||||||
|
-> option::t<ast::def_id> {
|
||||||
|
let result = none;
|
||||||
|
ebml::tagged_docs(item, tag_impl_iface_did) {|doc|
|
||||||
|
let s = str::unsafe_from_bytes(ebml::doc_data(doc));
|
||||||
|
result = some(parse_external_def_id(this_cnum, extres, s));
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn item_ty_param_bounds(item: ebml::doc, this_cnum: ast::crate_num,
|
fn item_ty_param_bounds(item: ebml::doc, this_cnum: ast::crate_num,
|
||||||
@@ -121,8 +149,8 @@ fn item_ty_param_bounds(item: ebml::doc, this_cnum: ast::crate_num,
|
|||||||
let bounds = [];
|
let bounds = [];
|
||||||
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
|
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
|
||||||
ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds) {|p|
|
ebml::tagged_docs(item, tag_items_data_item_ty_param_bounds) {|p|
|
||||||
bounds += [tydecode::parse_bounds_data(@ebml::doc_data(p), this_cnum,
|
bounds += [tydecode::parse_bounds_data(p.data, p.start,
|
||||||
def_parser, tcx)];
|
this_cnum, def_parser, tcx)];
|
||||||
}
|
}
|
||||||
@bounds
|
@bounds
|
||||||
}
|
}
|
||||||
@@ -197,18 +225,17 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
|
|||||||
tid = {crate: cnum, node: tid.node};
|
tid = {crate: cnum, node: tid.node};
|
||||||
ast::def_variant(tid, did)
|
ast::def_variant(tid, did)
|
||||||
}
|
}
|
||||||
|
'I' { ast::def_ty(did) }
|
||||||
};
|
};
|
||||||
ret def;
|
ret def;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_type(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
|
fn get_type(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
|
||||||
extres: external_resolver) -> ty::ty_param_bounds_and_ty {
|
extres: external_resolver) -> ty::ty_param_bounds_and_ty {
|
||||||
let this_cnum = def.crate;
|
let item = lookup_item(def.node, data);
|
||||||
let node_id = def.node;
|
let t = item_type(item, def.crate, tcx, extres);
|
||||||
let item = lookup_item(node_id, data);
|
|
||||||
let t = item_type(item, this_cnum, tcx, extres);
|
|
||||||
let tp_bounds = if family_has_type_params(item_family(item)) {
|
let tp_bounds = if family_has_type_params(item_family(item)) {
|
||||||
item_ty_param_bounds(item, this_cnum, tcx, extres)
|
item_ty_param_bounds(item, def.crate, tcx, extres)
|
||||||
} else { @[] };
|
} else { @[] };
|
||||||
ret {bounds: tp_bounds, ty: t};
|
ret {bounds: tp_bounds, ty: t};
|
||||||
}
|
}
|
||||||
@@ -217,6 +244,11 @@ fn get_type_param_count(data: @[u8], id: ast::node_id) -> uint {
|
|||||||
item_ty_param_count(lookup_item(id, data))
|
item_ty_param_count(lookup_item(id, data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_impl_iface(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
|
||||||
|
extres: external_resolver) -> option::t<ty::t> {
|
||||||
|
item_impl_iface(lookup_item(def.node, data), def.crate, tcx, extres)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_symbol(data: @[u8], id: ast::node_id) -> str {
|
fn get_symbol(data: @[u8], id: ast::node_id) -> str {
|
||||||
ret item_symbol(lookup_item(id, data));
|
ret item_symbol(lookup_item(id, data));
|
||||||
}
|
}
|
||||||
@@ -245,52 +277,59 @@ fn get_tag_variants(_data: @[u8], def: ast::def_id, tcx: ty::ctxt,
|
|||||||
ret infos;
|
ret infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_impls_for_mod(data: @[u8], node: ast::node_id, cnum: ast::crate_num)
|
fn item_impl_methods(data: @[u8], item: ebml::doc, base_tps: uint)
|
||||||
-> [ast::def_id] {
|
|
||||||
let mod_item = lookup_item(node, data), result = [];
|
|
||||||
ebml::tagged_docs(mod_item, tag_mod_impl) {|doc|
|
|
||||||
let did = parse_def_id(ebml::doc_data(doc));
|
|
||||||
result += [{crate: cnum with did}];
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lookup_impl_methods(data: @[u8], node: ast::node_id, cnum: ast::crate_num)
|
|
||||||
-> [@middle::resolve::method_info] {
|
-> [@middle::resolve::method_info] {
|
||||||
let impl_item = lookup_item(node, data), rslt = [];
|
let rslt = [];
|
||||||
let base_tps = item_ty_param_count(impl_item);
|
ebml::tagged_docs(item, tag_item_method) {|doc|
|
||||||
ebml::tagged_docs(impl_item, tag_impl_method) {|doc|
|
|
||||||
let m_did = parse_def_id(ebml::doc_data(doc));
|
let m_did = parse_def_id(ebml::doc_data(doc));
|
||||||
let mth_item = lookup_item(m_did.node, data);
|
let mth_item = lookup_item(m_did.node, data);
|
||||||
rslt += [@{did: {crate: cnum, node: m_did.node},
|
rslt += [@{did: m_did,
|
||||||
n_tps: item_ty_param_count(mth_item) - base_tps,
|
n_tps: item_ty_param_count(mth_item) - base_tps,
|
||||||
ident: item_name(mth_item)}];
|
ident: item_name(mth_item)}];
|
||||||
}
|
}
|
||||||
rslt
|
rslt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_impls_for_mod(data: @[u8], m_def: ast::def_id,
|
||||||
|
name: option::t<ast::ident>, extres: external_resolver)
|
||||||
|
-> @[@middle::resolve::_impl] {
|
||||||
|
let mod_item = lookup_item(m_def.node, data), result = [];
|
||||||
|
ebml::tagged_docs(mod_item, tag_mod_impl) {|doc|
|
||||||
|
let did = parse_external_def_id(
|
||||||
|
m_def.crate, extres, str::unsafe_from_bytes(ebml::doc_data(doc)));
|
||||||
|
let item = lookup_item(did.node, data), nm = item_name(item);
|
||||||
|
if alt name { some(n) { n == nm } none. { true } } {
|
||||||
|
let base_tps = item_ty_param_count(doc);
|
||||||
|
let i_did = item_impl_iface_did(item, m_def.crate, extres);
|
||||||
|
result += [@{did: did, iface_did: i_did, ident: nm,
|
||||||
|
methods: item_impl_methods(data, doc, base_tps)}];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_iface_methods(data: @[u8], def: ast::def_id, tcx: ty::ctxt,
|
||||||
|
extres: external_resolver) -> @[ty::method] {
|
||||||
|
let item = lookup_item(def.node, data), result = [];
|
||||||
|
ebml::tagged_docs(item, tag_item_method) {|mth|
|
||||||
|
let bounds = item_ty_param_bounds(mth, def.crate, tcx, extres);
|
||||||
|
let name = item_name(mth);
|
||||||
|
let ty = doc_type(mth, def.crate, tcx, extres);
|
||||||
|
let fty = alt ty::struct(tcx, ty) { ty::ty_fn(f) { f } };
|
||||||
|
result += [{ident: name, tps: bounds, fty: fty}];
|
||||||
|
}
|
||||||
|
@result
|
||||||
|
}
|
||||||
|
|
||||||
fn family_has_type_params(fam_ch: u8) -> bool {
|
fn family_has_type_params(fam_ch: u8) -> bool {
|
||||||
ret alt fam_ch as char {
|
alt fam_ch as char {
|
||||||
'c' { false }
|
'c' | 'T' | 'm' | 'n' { false }
|
||||||
'f' { true }
|
'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' { true }
|
||||||
'u' { true }
|
}
|
||||||
'p' { true }
|
|
||||||
'F' { true }
|
|
||||||
'U' { true }
|
|
||||||
'P' { true }
|
|
||||||
'y' { true }
|
|
||||||
't' { true }
|
|
||||||
'T' { false }
|
|
||||||
'm' { false }
|
|
||||||
'n' { false }
|
|
||||||
'v' { true }
|
|
||||||
'i' { true }
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn family_names_type(fam_ch: u8) -> bool {
|
fn family_names_type(fam_ch: u8) -> bool {
|
||||||
alt fam_ch as char { 'y' | 't' { true } _ { false } }
|
alt fam_ch as char { 'y' | 't' | 'I' { true } _ { false } }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_path(d: ebml::doc) -> {path: str, pos: uint} {
|
fn read_path(d: ebml::doc) -> {path: str, pos: uint} {
|
||||||
@@ -321,6 +360,8 @@ fn item_family_to_str(fam: u8) -> str {
|
|||||||
'm' { ret "mod"; }
|
'm' { ret "mod"; }
|
||||||
'n' { ret "native mod"; }
|
'n' { ret "native mod"; }
|
||||||
'v' { ret "tag"; }
|
'v' { ret "tag"; }
|
||||||
|
'i' { ret "impl"; }
|
||||||
|
'I' { ret "iface"; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -202,13 +202,17 @@ fn encode_variant_id(ebml_w: ebml::writer, vid: def_id) {
|
|||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
|
fn write_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
|
||||||
ebml::start_tag(ebml_w, tag_items_data_item_type);
|
|
||||||
let ty_str_ctxt =
|
let ty_str_ctxt =
|
||||||
@{ds: def_to_str,
|
@{ds: def_to_str,
|
||||||
tcx: ecx.ccx.tcx,
|
tcx: ecx.ccx.tcx,
|
||||||
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
|
abbrevs: tyencode::ac_use_abbrevs(ecx.type_abbrevs)};
|
||||||
tyencode::enc_ty(io::new_writer(ebml_w.writer), ty_str_ctxt, typ);
|
tyencode::enc_ty(io::new_writer(ebml_w.writer), ty_str_ctxt, typ);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
|
||||||
|
ebml::start_tag(ebml_w, tag_items_data_item_type);
|
||||||
|
write_type(ecx, ebml_w, typ);
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,12 +277,13 @@ fn encode_info_for_mod(ebml_w: ebml::writer, md: _mod,
|
|||||||
|
|
||||||
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
||||||
&index: [entry<int>]) {
|
&index: [entry<int>]) {
|
||||||
|
let tcx = ecx.ccx.tcx;
|
||||||
alt item.node {
|
alt item.node {
|
||||||
item_const(_, _) {
|
item_const(_, _) {
|
||||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||||
encode_def_id(ebml_w, local_def(item.id));
|
encode_def_id(ebml_w, local_def(item.id));
|
||||||
encode_family(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_type(ecx, ebml_w, node_id_to_monotype(tcx, item.id));
|
||||||
encode_symbol(ecx, ebml_w, item.id);
|
encode_symbol(ecx, ebml_w, item.id);
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
@@ -292,7 +297,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
|||||||
impure_fn. { 'f' }
|
impure_fn. { 'f' }
|
||||||
} as u8);
|
} as u8);
|
||||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
encode_type(ecx, ebml_w, node_id_to_monotype(tcx, item.id));
|
||||||
encode_symbol(ecx, ebml_w, item.id);
|
encode_symbol(ecx, ebml_w, item.id);
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
@@ -311,7 +316,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
|||||||
encode_def_id(ebml_w, local_def(item.id));
|
encode_def_id(ebml_w, local_def(item.id));
|
||||||
encode_family(ebml_w, 'y' as u8);
|
encode_family(ebml_w, 'y' as u8);
|
||||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
encode_type(ecx, ebml_w, node_id_to_monotype(tcx, item.id));
|
||||||
encode_name(ebml_w, item.ident);
|
encode_name(ebml_w, item.ident);
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
@@ -320,7 +325,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
|||||||
encode_def_id(ebml_w, local_def(item.id));
|
encode_def_id(ebml_w, local_def(item.id));
|
||||||
encode_family(ebml_w, 't' as u8);
|
encode_family(ebml_w, 't' as u8);
|
||||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
encode_type(ecx, ebml_w, node_id_to_monotype(tcx, item.id));
|
||||||
encode_name(ebml_w, item.ident);
|
encode_name(ebml_w, item.ident);
|
||||||
for v: variant in variants {
|
for v: variant in variants {
|
||||||
encode_variant_id(ebml_w, local_def(v.node.id));
|
encode_variant_id(ebml_w, local_def(v.node.id));
|
||||||
@@ -329,13 +334,13 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
|||||||
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index, tps);
|
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index, tps);
|
||||||
}
|
}
|
||||||
item_res(_, tps, _, _, ctor_id) {
|
item_res(_, tps, _, _, ctor_id) {
|
||||||
let fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
|
let fn_ty = node_id_to_monotype(tcx, ctor_id);
|
||||||
|
|
||||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||||
encode_def_id(ebml_w, local_def(ctor_id));
|
encode_def_id(ebml_w, local_def(ctor_id));
|
||||||
encode_family(ebml_w, 'y' as u8);
|
encode_family(ebml_w, 'y' as u8);
|
||||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||||
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
|
encode_type(ecx, ebml_w, ty::ty_fn_ret(tcx, fn_ty));
|
||||||
encode_name(ebml_w, item.ident);
|
encode_name(ebml_w, item.ident);
|
||||||
encode_symbol(ecx, ebml_w, item.id);
|
encode_symbol(ecx, ebml_w, item.id);
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
@@ -350,13 +355,13 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
|||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
item_obj(_, tps, ctor_id) {
|
item_obj(_, tps, ctor_id) {
|
||||||
let fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
|
let fn_ty = node_id_to_monotype(tcx, ctor_id);
|
||||||
|
|
||||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||||
encode_def_id(ebml_w, local_def(item.id));
|
encode_def_id(ebml_w, local_def(item.id));
|
||||||
encode_family(ebml_w, 'y' as u8);
|
encode_family(ebml_w, 'y' as u8);
|
||||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||||
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
|
encode_type(ecx, ebml_w, ty::ty_fn_ret(tcx, fn_ty));
|
||||||
encode_name(ebml_w, item.ident);
|
encode_name(ebml_w, item.ident);
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
|
|
||||||
@@ -369,18 +374,35 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
|||||||
encode_symbol(ecx, ebml_w, ctor_id);
|
encode_symbol(ecx, ebml_w, ctor_id);
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
item_impl(tps, _, _, methods) {
|
item_impl(tps, ifce, _, methods) {
|
||||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||||
encode_def_id(ebml_w, local_def(item.id));
|
encode_def_id(ebml_w, local_def(item.id));
|
||||||
encode_family(ebml_w, 'i' as u8);
|
encode_family(ebml_w, 'i' as u8);
|
||||||
encode_type_param_bounds(ebml_w, ecx, tps);
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||||
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
|
encode_type(ecx, ebml_w, node_id_to_monotype(tcx, item.id));
|
||||||
encode_name(ebml_w, item.ident);
|
encode_name(ebml_w, item.ident);
|
||||||
for m in methods {
|
for m in methods {
|
||||||
ebml::start_tag(ebml_w, tag_impl_method);
|
ebml::start_tag(ebml_w, tag_item_method);
|
||||||
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
|
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
|
alt ifce {
|
||||||
|
some(_) {
|
||||||
|
encode_symbol(ecx, ebml_w, item.id);
|
||||||
|
let i_ty = ty::lookup_item_type(tcx, local_def(item.id)).ty;
|
||||||
|
ebml::start_tag(ebml_w, tag_impl_iface);
|
||||||
|
write_type(ecx, ebml_w, i_ty);
|
||||||
|
ebml::end_tag(ebml_w);
|
||||||
|
ebml::start_tag(ebml_w, tag_impl_iface_did);
|
||||||
|
alt ty::struct(tcx, i_ty) {
|
||||||
|
ty::ty_iface(did, _) {
|
||||||
|
ebml_w.writer.write(str::bytes(def_to_str(did)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ebml::end_tag(ebml_w);
|
||||||
|
}
|
||||||
|
_ {}
|
||||||
|
}
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
|
|
||||||
for m in methods {
|
for m in methods {
|
||||||
@@ -390,13 +412,30 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
|
|||||||
encode_family(ebml_w, 'f' as u8);
|
encode_family(ebml_w, 'f' as u8);
|
||||||
encode_type_param_bounds(ebml_w, ecx, tps + m.tps);
|
encode_type_param_bounds(ebml_w, ecx, tps + m.tps);
|
||||||
encode_type(ecx, ebml_w,
|
encode_type(ecx, ebml_w,
|
||||||
node_id_to_monotype(ecx.ccx.tcx, m.id));
|
node_id_to_monotype(tcx, m.id));
|
||||||
encode_name(ebml_w, m.ident);
|
encode_name(ebml_w, m.ident);
|
||||||
encode_symbol(ecx, ebml_w, m.id);
|
encode_symbol(ecx, ebml_w, m.id);
|
||||||
ebml::end_tag(ebml_w);
|
ebml::end_tag(ebml_w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item_iface(_, _) { /* FIXME[impl] */ }
|
item_iface(tps, ms) {
|
||||||
|
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||||
|
encode_def_id(ebml_w, local_def(item.id));
|
||||||
|
encode_family(ebml_w, 'I' as u8);
|
||||||
|
encode_type_param_bounds(ebml_w, ecx, tps);
|
||||||
|
encode_type(ecx, ebml_w, node_id_to_monotype(tcx, item.id));
|
||||||
|
encode_name(ebml_w, item.ident);
|
||||||
|
let i = 0u;
|
||||||
|
for mty in *ty::iface_methods(tcx, local_def(item.id)) {
|
||||||
|
ebml::start_tag(ebml_w, tag_item_method);
|
||||||
|
encode_name(ebml_w, mty.ident);
|
||||||
|
encode_type_param_bounds(ebml_w, ecx, ms[i].tps);
|
||||||
|
encode_type(ecx, ebml_w, ty::mk_fn(tcx, mty.fty));
|
||||||
|
ebml::end_tag(ebml_w);
|
||||||
|
i += 1u;
|
||||||
|
}
|
||||||
|
ebml::end_tag(ebml_w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,10 @@ export parse_bounds_data;
|
|||||||
// Callback to translate defs to strs or back:
|
// Callback to translate defs to strs or back:
|
||||||
type str_def = fn@(str) -> ast::def_id;
|
type str_def = fn@(str) -> ast::def_id;
|
||||||
|
|
||||||
type pstate =
|
type pstate = {data: @[u8], crate: int, mutable pos: uint, tcx: ty::ctxt};
|
||||||
{data: @[u8], crate: int, mutable pos: uint, len: uint, tcx: ty::ctxt};
|
|
||||||
|
|
||||||
fn peek(st: @pstate) -> u8 {
|
fn peek(st: @pstate) -> u8 {
|
||||||
if st.pos < vec::len(*st.data) { st.data[st.pos] } else { 0u8 }
|
st.data[st.pos]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next(st: @pstate) -> u8 {
|
fn next(st: @pstate) -> u8 {
|
||||||
@@ -47,10 +46,9 @@ fn parse_ident_(st: @pstate, _sd: str_def, is_last: fn@(char) -> bool) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn parse_ty_data(data: @[u8], crate_num: int, pos: uint, len: uint,
|
fn parse_ty_data(data: @[u8], crate_num: int, pos: uint, sd: str_def,
|
||||||
sd: str_def, tcx: ty::ctxt) -> ty::t {
|
tcx: ty::ctxt) -> ty::t {
|
||||||
let st =
|
let st = @{data: data, crate: crate_num, mutable pos: pos, tcx: tcx};
|
||||||
@{data: data, crate: crate_num, mutable pos: pos, len: len, tcx: tcx};
|
|
||||||
parse_ty(st, sd)
|
parse_ty(st, sd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +293,7 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
|
|||||||
alt st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
|
alt st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
|
||||||
some(tt) { ret tt; }
|
some(tt) { ret tt; }
|
||||||
none. {
|
none. {
|
||||||
let ps = @{pos: pos, len: len with *st};
|
let ps = @{pos: pos with *st};
|
||||||
let tt = parse_ty(ps, sd);
|
let tt = parse_ty(ps, sd);
|
||||||
st.tcx.rcache.insert({cnum: st.crate, pos: pos, len: len}, tt);
|
st.tcx.rcache.insert({cnum: st.crate, pos: pos, len: len}, tt);
|
||||||
ret tt;
|
ret tt;
|
||||||
@@ -381,7 +379,7 @@ fn parse_ty_fn(st: @pstate, sd: str_def) -> ty::fn_ty {
|
|||||||
// Rust metadata parsing
|
// Rust metadata parsing
|
||||||
fn parse_def_id(buf: [u8]) -> ast::def_id {
|
fn parse_def_id(buf: [u8]) -> ast::def_id {
|
||||||
let colon_idx = 0u;
|
let colon_idx = 0u;
|
||||||
let len = vec::len::<u8>(buf);
|
let len = vec::len(buf);
|
||||||
while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; }
|
while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; }
|
||||||
if colon_idx == len {
|
if colon_idx == len {
|
||||||
#error("didn't find ':' when parsing def id");
|
#error("didn't find ':' when parsing def id");
|
||||||
@@ -400,20 +398,21 @@ fn parse_def_id(buf: [u8]) -> ast::def_id {
|
|||||||
ret {crate: crate_num, node: def_num};
|
ret {crate: crate_num, node: def_num};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_bounds_data(data: @[u8], crate_num: int, sd: str_def, tcx: ty::ctxt)
|
fn parse_bounds_data(data: @[u8], start: uint,
|
||||||
|
crate_num: int, sd: str_def, tcx: ty::ctxt)
|
||||||
-> @[ty::param_bound] {
|
-> @[ty::param_bound] {
|
||||||
let st = @{data: data, crate: crate_num, mutable pos: 0u,
|
let st = @{data: data, crate: crate_num, mutable pos: start, tcx: tcx};
|
||||||
len: vec::len(*data), tcx: tcx};
|
|
||||||
parse_bounds(st, sd)
|
parse_bounds(st, sd)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_bounds(st: @pstate, sd: str_def) -> @[ty::param_bound] {
|
fn parse_bounds(st: @pstate, sd: str_def) -> @[ty::param_bound] {
|
||||||
let bounds = [];
|
let bounds = [];
|
||||||
while peek(st) != 0u8 {
|
while true {
|
||||||
bounds += [alt next(st) as char {
|
bounds += [alt next(st) as char {
|
||||||
'S' { ty::bound_send }
|
'S' { ty::bound_send }
|
||||||
'C' { ty::bound_copy }
|
'C' { ty::bound_copy }
|
||||||
'I' { ty::bound_iface(parse_ty(st, sd)) }
|
'I' { ty::bound_iface(parse_ty(st, sd)) }
|
||||||
|
'.' { break; }
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@bounds
|
@bounds
|
||||||
|
|||||||
@@ -66,9 +66,7 @@ fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
|
|||||||
let abbrev_len = 3u + estimate_sz(pos) + estimate_sz(len);
|
let abbrev_len = 3u + estimate_sz(pos) + estimate_sz(len);
|
||||||
if abbrev_len < len {
|
if abbrev_len < len {
|
||||||
// I.e. it's actually an abbreviation.
|
// I.e. it's actually an abbreviation.
|
||||||
|
let s = "#" + uint::to_str(pos, 16u) + ":" +
|
||||||
let s =
|
|
||||||
"#" + uint::to_str(pos, 16u) + ":" +
|
|
||||||
uint::to_str(len, 16u) + "#";
|
uint::to_str(len, 16u) + "#";
|
||||||
let a = {pos: pos, len: len, s: @s};
|
let a = {pos: pos, len: len, s: @s};
|
||||||
abbrevs.insert(t, a);
|
abbrevs.insert(t, a);
|
||||||
@@ -282,6 +280,7 @@ fn enc_bounds(w: io::writer, cx: @ctxt, bs: @[ty::param_bound]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
w.write_char('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -88,6 +88,14 @@ fn map_native_item(cx: ctx, i: @native_item) {
|
|||||||
|
|
||||||
fn map_expr(cx: ctx, ex: @expr) {
|
fn map_expr(cx: ctx, ex: @expr) {
|
||||||
cx.map.insert(ex.id, node_expr(ex));
|
cx.map.insert(ex.id, node_expr(ex));
|
||||||
|
alt ex.node {
|
||||||
|
expr_anon_obj(ao) {
|
||||||
|
for m in ao.methods {
|
||||||
|
cx.map.insert(m.id, node_obj_method(m));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_smallintmap_int_adapter<copy V>() -> std::map::hashmap<int, V> {
|
fn new_smallintmap_int_adapter<copy V>() -> std::map::hashmap<int, V> {
|
||||||
|
|||||||
@@ -726,7 +726,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_map::node_obj_method(method) {
|
ast_map::node_obj_method(method) | ast_map::node_method(method) {
|
||||||
(method.ident, method.decl.output, method.id)
|
(method.ident, method.decl.output, method.id)
|
||||||
}
|
}
|
||||||
ast_map::node_res_ctor(item) {
|
ast_map::node_res_ctor(item) {
|
||||||
|
|||||||
@@ -1827,7 +1827,7 @@ fn find_impls_in_mod(e: env, m: def, &impls: [@_impl],
|
|||||||
}
|
}
|
||||||
@tmp
|
@tmp
|
||||||
} else {
|
} else {
|
||||||
@csearch::get_impls_for_mod(e.cstore, defid, name)
|
csearch::get_impls_for_mod(e.sess.get_cstore(), defid, name)
|
||||||
};
|
};
|
||||||
e.impl_cache.insert(defid, cached);
|
e.impl_cache.insert(defid, cached);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5039,8 +5039,8 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
|
|||||||
with *extend_path(cx, item.ident)};
|
with *extend_path(cx, item.ident)};
|
||||||
trans_obj(sub_cx, item.span, ob, ctor_id, tps);
|
trans_obj(sub_cx, item.span, ob, ctor_id, tps);
|
||||||
}
|
}
|
||||||
ast::item_impl(tps, ifce, _, ms) {
|
ast::item_impl(tps, _, _, ms) {
|
||||||
trans_impl::trans_impl(cx, item.ident, ms, item.id, tps, ifce);
|
trans_impl::trans_impl(cx, item.ident, ms, item.id, tps);
|
||||||
}
|
}
|
||||||
ast::item_res(decl, tps, body, dtor_id, ctor_id) {
|
ast::item_res(decl, tps, body, dtor_id, ctor_id) {
|
||||||
trans_res_ctor(cx, item.span, decl, ctor_id, tps);
|
trans_res_ctor(cx, item.span, decl, ctor_id, tps);
|
||||||
@@ -5436,6 +5436,7 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
|
|||||||
llvm::LLVMSetInitializer(vt_gvar, tbl);
|
llvm::LLVMSetInitializer(vt_gvar, tbl);
|
||||||
llvm::LLVMSetGlobalConstant(vt_gvar, True);
|
llvm::LLVMSetGlobalConstant(vt_gvar, True);
|
||||||
ccx.item_ids.insert(it.id, vt_gvar);
|
ccx.item_ids.insert(it.id, vt_gvar);
|
||||||
|
ccx.item_symbols.insert(it.id, s);
|
||||||
}
|
}
|
||||||
_ { }
|
_ { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import trans_common::*;
|
|||||||
import trans_build::*;
|
import trans_build::*;
|
||||||
import option::{some, none};
|
import option::{some, none};
|
||||||
import syntax::{ast, ast_util};
|
import syntax::{ast, ast_util};
|
||||||
|
import metadata::csearch;
|
||||||
import back::link;
|
import back::link;
|
||||||
import lib::llvm;
|
import lib::llvm;
|
||||||
import llvm::llvm::{ValueRef, TypeRef, LLVMGetParam};
|
import llvm::llvm::{ValueRef, TypeRef, LLVMGetParam};
|
||||||
|
|
||||||
fn trans_impl(cx: @local_ctxt, name: ast::ident, methods: [@ast::method],
|
fn trans_impl(cx: @local_ctxt, name: ast::ident, methods: [@ast::method],
|
||||||
id: ast::node_id, tps: [ast::ty_param],
|
id: ast::node_id, tps: [ast::ty_param]) {
|
||||||
_ifce: option::t<@ast::ty>) {
|
|
||||||
let sub_cx = extend_path(cx, name);
|
let sub_cx = extend_path(cx, name);
|
||||||
for m in methods {
|
for m in methods {
|
||||||
alt cx.ccx.item_ids.find(m.id) {
|
alt cx.ccx.item_ids.find(m.id) {
|
||||||
@@ -136,8 +136,12 @@ fn get_dict(bcx: @block_ctxt, origin: typeck::dict_origin) -> result {
|
|||||||
let bcx = bcx, ccx = bcx_ccx(bcx);
|
let bcx = bcx, ccx = bcx_ccx(bcx);
|
||||||
alt origin {
|
alt origin {
|
||||||
typeck::dict_static(impl_did, tys, sub_origins) {
|
typeck::dict_static(impl_did, tys, sub_origins) {
|
||||||
assert impl_did.crate == ast::local_crate; // FIXME[impl]
|
let vtable = if impl_did.crate == ast::local_crate {
|
||||||
let vtable = ccx.item_ids.get(impl_did.node);
|
ccx.item_ids.get(impl_did.node)
|
||||||
|
} else {
|
||||||
|
let name = csearch::get_symbol(ccx.sess.get_cstore(), impl_did);
|
||||||
|
get_extern_const(ccx.externs, ccx.llmod, name, T_ptr(T_i8()))
|
||||||
|
};
|
||||||
let impl_params = ty::lookup_item_type(ccx.tcx, impl_did).bounds;
|
let impl_params = ty::lookup_item_type(ccx.tcx, impl_did).bounds;
|
||||||
let ptrs = [vtable], i = 0u, origin = 0u, ti = none;
|
let ptrs = [vtable], i = 0u, origin = 0u, ti = none;
|
||||||
for param in *impl_params {
|
for param in *impl_params {
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ export node_id_to_ty_param_substs_opt_and_ty;
|
|||||||
export arg;
|
export arg;
|
||||||
export args_eq;
|
export args_eq;
|
||||||
export ast_constr_to_constr;
|
export ast_constr_to_constr;
|
||||||
export bind_params_in_type;
|
|
||||||
export block_ty;
|
export block_ty;
|
||||||
export constr;
|
export constr;
|
||||||
export constr_general;
|
export constr_general;
|
||||||
@@ -103,7 +102,7 @@ export substitute_type_params;
|
|||||||
export t;
|
export t;
|
||||||
export new_ty_hash;
|
export new_ty_hash;
|
||||||
export tag_variants;
|
export tag_variants;
|
||||||
export iface_methods, store_iface_methods;
|
export iface_methods, store_iface_methods, impl_iface;
|
||||||
export tag_variant_with_id;
|
export tag_variant_with_id;
|
||||||
export ty_param_substs_opt_and_ty;
|
export ty_param_substs_opt_and_ty;
|
||||||
export ty_param_bounds_and_ty;
|
export ty_param_bounds_and_ty;
|
||||||
@@ -2632,23 +2631,6 @@ fn type_err_to_str(err: ty::type_err) -> str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Converts type parameters in a type to type variables and returns the
|
|
||||||
// resulting type along with a list of type variable IDs.
|
|
||||||
fn bind_params_in_type(cx: ctxt, next_ty_var: block() -> int, typ: t,
|
|
||||||
ty_param_count: uint) -> {ids: [int], ty: t} {
|
|
||||||
let param_var_ids = [], i = 0u;
|
|
||||||
while i < ty_param_count { param_var_ids += [next_ty_var()]; i += 1u; }
|
|
||||||
let param_var_ids = @param_var_ids;
|
|
||||||
fn binder(cx: ctxt, param_var_ids: @[int], index: uint,
|
|
||||||
_did: def_id) -> t {
|
|
||||||
ret mk_var(cx, param_var_ids[index]);
|
|
||||||
}
|
|
||||||
{ids: *param_var_ids,
|
|
||||||
ty: fold_ty(cx, fm_param(bind binder(cx, param_var_ids, _, _)), typ)}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Replaces type parameters in the given type using the given list of
|
// Replaces type parameters in the given type using the given list of
|
||||||
// substitions.
|
// substitions.
|
||||||
fn substitute_type_params(cx: ctxt, substs: [ty::t], typ: t) -> t {
|
fn substitute_type_params(cx: ctxt, substs: [ty::t], typ: t) -> t {
|
||||||
@@ -2683,11 +2665,19 @@ fn iface_methods(cx: ctxt, id: ast::def_id) -> @[method] {
|
|||||||
}
|
}
|
||||||
// Local interfaces are supposed to have been added explicitly.
|
// Local interfaces are supposed to have been added explicitly.
|
||||||
assert id.crate != ast::local_crate;
|
assert id.crate != ast::local_crate;
|
||||||
let result = @[]; // FIXME[impl]
|
let result = csearch::get_iface_methods(cx, id);
|
||||||
cx.iface_method_cache.insert(id, result);
|
cx.iface_method_cache.insert(id, result);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn impl_iface(cx: ctxt, id: ast::def_id) -> option::t<t> {
|
||||||
|
if id.crate == ast::local_crate {
|
||||||
|
option::map(cx.tcache.find(id), {|it| it.ty})
|
||||||
|
} else {
|
||||||
|
csearch::get_impl_iface(cx, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tag information
|
// Tag information
|
||||||
type variant_info = @{args: [ty::t], ctor_ty: ty::t, id: ast::def_id};
|
type variant_info = @{args: [ty::t], ctor_ty: ty::t, id: ast::def_id};
|
||||||
|
|
||||||
|
|||||||
@@ -138,23 +138,16 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bind_params(fcx: @fn_ctxt, tp: ty::t, count: uint)
|
|
||||||
-> {ids: [int], ty: ty::t} {
|
|
||||||
ty::bind_params_in_type(fcx.ccx.tcx, {|| next_ty_var_id(fcx)}, tp, count)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Instantiates the given path, which must refer to an item with the given
|
// Instantiates the given path, which must refer to an item with the given
|
||||||
// number of type parameters and type.
|
// number of type parameters and type.
|
||||||
fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
|
fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
|
||||||
tpt: ty_param_bounds_and_ty, sp: span)
|
tpt: ty_param_bounds_and_ty, sp: span)
|
||||||
-> ty_param_substs_opt_and_ty {
|
-> ty_param_substs_opt_and_ty {
|
||||||
let ty_param_count = vec::len(*tpt.bounds);
|
let ty_param_count = vec::len(*tpt.bounds);
|
||||||
let bind_result = bind_params(fcx, tpt.ty, ty_param_count);
|
let vars = vec::init_fn({|_i| next_ty_var(fcx)}, ty_param_count);
|
||||||
let ty_param_vars = bind_result.ids;
|
let ty_substs_len = vec::len(pth.node.types);
|
||||||
let ty_substs_opt;
|
|
||||||
let ty_substs_len = vec::len::<@ast::ty>(pth.node.types);
|
|
||||||
if ty_substs_len > 0u {
|
if ty_substs_len > 0u {
|
||||||
let param_var_len = vec::len(ty_param_vars);
|
let param_var_len = vec::len(vars);
|
||||||
if param_var_len == 0u {
|
if param_var_len == 0u {
|
||||||
fcx.ccx.tcx.sess.span_fatal
|
fcx.ccx.tcx.sess.span_fatal
|
||||||
(sp, "this item does not take type parameters");
|
(sp, "this item does not take type parameters");
|
||||||
@@ -165,32 +158,16 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
|
|||||||
fcx.ccx.tcx.sess.span_fatal
|
fcx.ccx.tcx.sess.span_fatal
|
||||||
(sp, "not enough type parameters provided for this item");
|
(sp, "not enough type parameters provided for this item");
|
||||||
}
|
}
|
||||||
let ty_substs: [ty::t] = [];
|
vec::iter2(pth.node.types, vars) {|sub, var|
|
||||||
let i = 0u;
|
let ty_subst = ast_ty_to_ty_crate(fcx.ccx, sub);
|
||||||
while i < ty_substs_len {
|
demand::simple(fcx, pth.span, var, ty_subst);
|
||||||
let ty_var = ty::mk_var(fcx.ccx.tcx, ty_param_vars[i]);
|
|
||||||
let ty_subst = ast_ty_to_ty_crate(fcx.ccx, pth.node.types[i]);
|
|
||||||
let res_ty = demand::simple(fcx, pth.span, ty_var, ty_subst);
|
|
||||||
ty_substs += [res_ty];
|
|
||||||
i += 1u;
|
|
||||||
}
|
}
|
||||||
ty_substs_opt = some::<[ty::t]>(ty_substs);
|
|
||||||
if ty_param_count == 0u {
|
if ty_param_count == 0u {
|
||||||
fcx.ccx.tcx.sess.span_fatal(sp,
|
fcx.ccx.tcx.sess.span_fatal(
|
||||||
"this item does not take type \
|
sp, "this item does not take type parameters");
|
||||||
parameters");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// We will acquire the type parameters through unification.
|
|
||||||
let ty_substs: [ty::t] = [];
|
|
||||||
let i = 0u;
|
|
||||||
while i < ty_param_count {
|
|
||||||
ty_substs += [ty::mk_var(fcx.ccx.tcx, ty_param_vars[i])];
|
|
||||||
i += 1u;
|
|
||||||
}
|
}
|
||||||
ty_substs_opt = some::<[ty::t]>(ty_substs);
|
{substs: some(vars), ty: tpt.ty}
|
||||||
}
|
|
||||||
ret {substs: ty_substs_opt, ty: tpt.ty};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type tests
|
// Type tests
|
||||||
@@ -529,8 +506,17 @@ fn ty_param_bounds(tcx: ty::ctxt, mode: mode, params: [ast::ty_param])
|
|||||||
bounds += [alt b {
|
bounds += [alt b {
|
||||||
ast::bound_send. { ty::bound_send }
|
ast::bound_send. { ty::bound_send }
|
||||||
ast::bound_copy. { ty::bound_copy }
|
ast::bound_copy. { ty::bound_copy }
|
||||||
ast::bound_iface(ifc) {
|
ast::bound_iface(t) {
|
||||||
ty::bound_iface(ast_ty_to_ty(tcx, mode, ifc))
|
let ity = ast_ty_to_ty(tcx, mode, t);
|
||||||
|
alt ty::struct(tcx, ity) {
|
||||||
|
ty::ty_iface(_, _) {}
|
||||||
|
_ {
|
||||||
|
tcx.sess.span_fatal(
|
||||||
|
t.span, "type parameter bounds must be \
|
||||||
|
interface types");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ty::bound_iface(ity)
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@@ -650,6 +636,30 @@ fn mk_ty_params(tcx: ty::ctxt, atps: [ast::ty_param])
|
|||||||
})}
|
})}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
|
||||||
|
impl_tps: uint, if_m: ty::method, substs: [ty::t]) {
|
||||||
|
if impl_m.tps != if_m.tps {
|
||||||
|
tcx.sess.span_err(sp, "method `" + if_m.ident +
|
||||||
|
"` has an incompatible set of type parameters");
|
||||||
|
} else {
|
||||||
|
let impl_fty = ty::mk_fn(tcx, impl_m.fty);
|
||||||
|
// Add dummy substs for the parameters of the impl method
|
||||||
|
let substs = substs + vec::init_fn({|i|
|
||||||
|
ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0})
|
||||||
|
}, vec::len(*if_m.tps));
|
||||||
|
let if_fty = ty::substitute_type_params(tcx, substs,
|
||||||
|
ty::mk_fn(tcx, if_m.fty));
|
||||||
|
alt ty::unify::unify(impl_fty, if_fty, ty::unify::precise, tcx) {
|
||||||
|
ty::unify::ures_err(err) {
|
||||||
|
tcx.sess.span_err(sp, "method `" + if_m.ident +
|
||||||
|
"` has an incompatible type: " +
|
||||||
|
ty::type_err_to_str(err));
|
||||||
|
}
|
||||||
|
_ {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Item collection - a pair of bootstrap passes:
|
// Item collection - a pair of bootstrap passes:
|
||||||
//
|
//
|
||||||
// (1) Collect the IDs of all type items (typedefs) and store them in a table.
|
// (1) Collect the IDs of all type items (typedefs) and store them in a table.
|
||||||
@@ -707,20 +717,50 @@ mod collect {
|
|||||||
write::ty_only(cx.tcx, it.id, tpt.ty);
|
write::ty_only(cx.tcx, it.id, tpt.ty);
|
||||||
get_tag_variant_types(cx, tpt.ty, variants, ty_params);
|
get_tag_variant_types(cx, tpt.ty, variants, ty_params);
|
||||||
}
|
}
|
||||||
ast::item_impl(tps, _, selfty, ms) {
|
ast::item_impl(tps, ifce, selfty, ms) {
|
||||||
let i_bounds = ty_param_bounds(cx.tcx, m_collect, tps);
|
let i_bounds = ty_param_bounds(cx.tcx, m_collect, tps);
|
||||||
|
let my_methods = [];
|
||||||
for m in ms {
|
for m in ms {
|
||||||
let bounds = ty_param_bounds(cx.tcx, m_collect, m.tps);
|
let bounds = ty_param_bounds(cx.tcx, m_collect, m.tps);
|
||||||
let ty = ty::mk_fn(cx.tcx,
|
let mty = ty_of_method(cx.tcx, m_collect, m);
|
||||||
ty_of_fn_decl(cx.tcx, m_collect,
|
my_methods += [mty];
|
||||||
ast::proto_bare, m.decl));
|
let fty = ty::mk_fn(cx.tcx, mty.fty);
|
||||||
cx.tcx.tcache.insert(local_def(m.id),
|
cx.tcx.tcache.insert(local_def(m.id),
|
||||||
{bounds: @(*i_bounds + *bounds),
|
{bounds: @(*i_bounds + *bounds),
|
||||||
ty: ty});
|
ty: fty});
|
||||||
write::ty_only(cx.tcx, m.id, ty);
|
write::ty_only(cx.tcx, m.id, fty);
|
||||||
}
|
}
|
||||||
write::ty_only(cx.tcx, it.id, ast_ty_to_ty(cx.tcx, m_collect,
|
write::ty_only(cx.tcx, it.id, ast_ty_to_ty(cx.tcx, m_collect,
|
||||||
selfty));
|
selfty));
|
||||||
|
alt ifce {
|
||||||
|
some(t) {
|
||||||
|
let iface_ty = ast_ty_to_ty(cx.tcx, m_collect, t);
|
||||||
|
cx.tcx.tcache.insert(local_def(it.id),
|
||||||
|
{bounds: i_bounds, ty: iface_ty});
|
||||||
|
alt ty::struct(cx.tcx, iface_ty) {
|
||||||
|
ty::ty_iface(did, tys) {
|
||||||
|
for if_m in *ty::iface_methods(cx.tcx, did) {
|
||||||
|
alt vec::find(my_methods,
|
||||||
|
{|m| if_m.ident == m.ident}) {
|
||||||
|
some(m) {
|
||||||
|
compare_impl_method(cx.tcx, t.span, m,
|
||||||
|
vec::len(tps), if_m, tys);
|
||||||
|
}
|
||||||
|
none. {
|
||||||
|
cx.tcx.sess.span_err(t.span, "missing method `" +
|
||||||
|
if_m.ident + "`");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ {
|
||||||
|
cx.tcx.sess.span_fatal(t.span, "can only implement \
|
||||||
|
interface types");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast::item_obj(object, ty_params, ctor_id) {
|
ast::item_obj(object, ty_params, ctor_id) {
|
||||||
// Now we need to call ty_of_obj_ctor(); this is the type that
|
// Now we need to call ty_of_obj_ctor(); this is the type that
|
||||||
@@ -1514,7 +1554,6 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
|
|||||||
ty::bound_iface(t) {
|
ty::bound_iface(t) {
|
||||||
let (iid, tps) = alt ty::struct(tcx, t) {
|
let (iid, tps) = alt ty::struct(tcx, t) {
|
||||||
ty::ty_iface(i, tps) { (i, tps) }
|
ty::ty_iface(i, tps) { (i, tps) }
|
||||||
_ { cont; }
|
|
||||||
};
|
};
|
||||||
let ifce_methods = ty::iface_methods(tcx, iid);
|
let ifce_methods = ty::iface_methods(tcx, iid);
|
||||||
alt vec::position_pred(*ifce_methods, {|m| m.ident == name}) {
|
alt vec::position_pred(*ifce_methods, {|m| m.ident == name}) {
|
||||||
@@ -1555,9 +1594,9 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
|
|||||||
alt vec::find(methods, {|m| m.ident == name}) {
|
alt vec::find(methods, {|m| m.ident == name}) {
|
||||||
some(m) {
|
some(m) {
|
||||||
let {n_tps, ty: self_ty} = impl_self_ty(tcx, did);
|
let {n_tps, ty: self_ty} = impl_self_ty(tcx, did);
|
||||||
let {ids, ty: self_ty} = if n_tps > 0u {
|
let {vars, ty: self_ty} = if n_tps > 0u {
|
||||||
bind_params(fcx, self_ty, n_tps)
|
bind_params(fcx, self_ty, n_tps)
|
||||||
} else { {ids: [], ty: self_ty} };
|
} else { {vars: [], ty: self_ty} };
|
||||||
alt unify::unify(fcx, ty, self_ty) {
|
alt unify::unify(fcx, ty, self_ty) {
|
||||||
ures_ok(_) {
|
ures_ok(_) {
|
||||||
if option::is_some(result) {
|
if option::is_some(result) {
|
||||||
@@ -1568,7 +1607,7 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
|
|||||||
result = some({
|
result = some({
|
||||||
method_ty: ty_from_did(tcx, m.did),
|
method_ty: ty_from_did(tcx, m.did),
|
||||||
n_tps: m.n_tps,
|
n_tps: m.n_tps,
|
||||||
substs: vec::map(ids, {|id| ty::mk_var(tcx, id)}),
|
substs: vars,
|
||||||
origin: method_static(m.did)
|
origin: method_static(m.did)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2451,6 +2490,12 @@ fn next_ty_var(fcx: @fn_ctxt) -> ty::t {
|
|||||||
ret ty::mk_var(fcx.ccx.tcx, next_ty_var_id(fcx));
|
ret ty::mk_var(fcx.ccx.tcx, next_ty_var_id(fcx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bind_params(fcx: @fn_ctxt, tp: ty::t, count: uint)
|
||||||
|
-> {vars: [ty::t], ty: ty::t} {
|
||||||
|
let vars = vec::init_fn({|_i| next_ty_var(fcx)}, count);
|
||||||
|
{vars: vars, ty: ty::substitute_type_params(fcx.ccx.tcx, vars, tp)}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_self_info(ccx: @crate_ctxt) -> option::t<self_info> {
|
fn get_self_info(ccx: @crate_ctxt) -> option::t<self_info> {
|
||||||
ret vec::last(ccx.self_infos);
|
ret vec::last(ccx.self_infos);
|
||||||
}
|
}
|
||||||
@@ -2737,30 +2782,6 @@ fn check_method(ccx: @crate_ctxt, method: @ast::method) {
|
|||||||
check_fn(ccx, ast::proto_bare, method.decl, method.body, method.id, none);
|
check_fn(ccx, ast::proto_bare, method.decl, method.body, method.id, none);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
|
|
||||||
impl_tps: uint, if_m: ty::method, substs: [ty::t]) {
|
|
||||||
if impl_m.tps != if_m.tps {
|
|
||||||
tcx.sess.span_err(sp, "method `" + if_m.ident +
|
|
||||||
"` has an incompatible set of type parameters");
|
|
||||||
} else {
|
|
||||||
let impl_fty = ty::mk_fn(tcx, impl_m.fty);
|
|
||||||
// Add dummy substs for the parameters of the impl method
|
|
||||||
let substs = substs + vec::init_fn({|i|
|
|
||||||
ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0})
|
|
||||||
}, vec::len(*if_m.tps));
|
|
||||||
let if_fty = ty::substitute_type_params(tcx, substs,
|
|
||||||
ty::mk_fn(tcx, if_m.fty));
|
|
||||||
alt ty::unify::unify(impl_fty, if_fty, ty::unify::precise, tcx) {
|
|
||||||
ty::unify::ures_err(err) {
|
|
||||||
tcx.sess.span_err(sp, "method `" + if_m.ident +
|
|
||||||
"` has an incompatible type: " +
|
|
||||||
ty::type_err_to_str(err));
|
|
||||||
}
|
|
||||||
_ {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_item(ccx: @crate_ctxt, it: @ast::item) {
|
fn check_item(ccx: @crate_ctxt, it: @ast::item) {
|
||||||
alt it.node {
|
alt it.node {
|
||||||
ast::item_const(_, e) { check_const(ccx, it.span, e, it.id); }
|
ast::item_const(_, e) { check_const(ccx, it.span, e, it.id); }
|
||||||
@@ -2779,70 +2800,15 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
|
|||||||
// Now remove the info from the stack.
|
// Now remove the info from the stack.
|
||||||
vec::pop(ccx.self_infos);
|
vec::pop(ccx.self_infos);
|
||||||
}
|
}
|
||||||
ast::item_impl(tps, ifce, ty, ms) {
|
ast::item_impl(tps, _, ty, ms) {
|
||||||
ccx.self_infos += [self_impl(ast_ty_to_ty(ccx.tcx, m_check, ty))];
|
ccx.self_infos += [self_impl(ast_ty_to_ty(ccx.tcx, m_check, ty))];
|
||||||
let my_methods = vec::map(ms, {|m|
|
for m in ms { check_method(ccx, m); }
|
||||||
check_method(ccx, m);
|
|
||||||
ty_of_method(ccx.tcx, m_check, m)
|
|
||||||
});
|
|
||||||
vec::pop(ccx.self_infos);
|
vec::pop(ccx.self_infos);
|
||||||
alt ifce {
|
|
||||||
some(ty) {
|
|
||||||
let iface_ty = ast_ty_to_ty(ccx.tcx, m_check, ty);
|
|
||||||
alt ty::struct(ccx.tcx, iface_ty) {
|
|
||||||
ty::ty_iface(did, tys) {
|
|
||||||
for if_m in *ty::iface_methods(ccx.tcx, did) {
|
|
||||||
alt vec::find(my_methods, {|m| if_m.ident == m.ident}) {
|
|
||||||
some(m) {
|
|
||||||
compare_impl_method(ccx.tcx, ty.span, m,
|
|
||||||
vec::len(tps), if_m, tys);
|
|
||||||
}
|
|
||||||
none. {
|
|
||||||
ccx.tcx.sess.span_err(ty.span, "missing method `" +
|
|
||||||
if_m.ident + "`");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let tpt = {bounds: ty_param_bounds(ccx.tcx, m_check, tps),
|
|
||||||
ty: iface_ty};
|
|
||||||
ccx.tcx.tcache.insert(local_def(it.id), tpt);
|
|
||||||
}
|
|
||||||
_ {
|
|
||||||
ccx.tcx.sess.span_err(ty.span, "can only implement interface \
|
|
||||||
types");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ {/* nothing to do */ }
|
_ {/* nothing to do */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_ty_params(ccx: @crate_ctxt, tps: [ast::ty_param]) {
|
|
||||||
for tp in tps {
|
|
||||||
let i = 0u;
|
|
||||||
for bound in *tp.bounds {
|
|
||||||
alt bound {
|
|
||||||
ast::bound_iface(at) {
|
|
||||||
let tbound = ccx.tcx.ty_param_bounds.get(tp.id)[i];
|
|
||||||
let bound_ty = alt tbound { ty::bound_iface(t) { t } };
|
|
||||||
alt ty::struct(ccx.tcx, bound_ty) {
|
|
||||||
ty::ty_iface(_, _) {}
|
|
||||||
_ {
|
|
||||||
ccx.tcx.sess.span_err(at.span, "type parameter bounds \
|
|
||||||
must be interface types");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ {}
|
|
||||||
}
|
|
||||||
i += 1u;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn arg_is_argv_ty(tcx: ty::ctxt, a: ty::arg) -> bool {
|
fn arg_is_argv_ty(tcx: ty::ctxt, a: ty::arg) -> bool {
|
||||||
alt ty::struct(tcx, a.ty) {
|
alt ty::struct(tcx, a.ty) {
|
||||||
ty::ty_vec(mt) {
|
ty::ty_vec(mt) {
|
||||||
@@ -2924,7 +2890,6 @@ mod dict {
|
|||||||
let tcx = fcx.ccx.tcx;
|
let tcx = fcx.ccx.tcx;
|
||||||
let (iface_id, iface_tps) = alt ty::struct(tcx, iface_ty) {
|
let (iface_id, iface_tps) = alt ty::struct(tcx, iface_ty) {
|
||||||
ty::ty_iface(did, tps) { (did, tps) }
|
ty::ty_iface(did, tps) { (did, tps) }
|
||||||
_ { tcx.sess.abort_if_errors(); fail; }
|
|
||||||
};
|
};
|
||||||
let ty = fixup_ty(fcx, sp, ty);
|
let ty = fixup_ty(fcx, sp, ty);
|
||||||
alt ty::struct(tcx, ty) {
|
alt ty::struct(tcx, ty) {
|
||||||
@@ -2951,10 +2916,9 @@ mod dict {
|
|||||||
for im in *impls {
|
for im in *impls {
|
||||||
if im.iface_did == some(iface_id) {
|
if im.iface_did == some(iface_id) {
|
||||||
let {n_tps, ty: self_ty} = impl_self_ty(tcx, im.did);
|
let {n_tps, ty: self_ty} = impl_self_ty(tcx, im.did);
|
||||||
let {ids, ty: self_ty} = if n_tps > 0u {
|
let {vars, ty: self_ty} = if n_tps > 0u {
|
||||||
bind_params(fcx, self_ty, n_tps)
|
bind_params(fcx, self_ty, n_tps)
|
||||||
} else { {ids: [], ty: self_ty} };
|
} else { {vars: [], ty: self_ty} };
|
||||||
let vars = vec::map(ids, {|id| ty::mk_var(tcx, id)});
|
|
||||||
let im_bs = ty::lookup_item_type(tcx, im.did).bounds;
|
let im_bs = ty::lookup_item_type(tcx, im.did).bounds;
|
||||||
// FIXME[impl] don't do this in fcx (or make
|
// FIXME[impl] don't do this in fcx (or make
|
||||||
// unify transactional by scrubbing bindings on fail)
|
// unify transactional by scrubbing bindings on fail)
|
||||||
@@ -3007,13 +2971,7 @@ mod dict {
|
|||||||
fn connect_iface_tps(fcx: @fn_ctxt, sp: span, impl_tys: [ty::t],
|
fn connect_iface_tps(fcx: @fn_ctxt, sp: span, impl_tys: [ty::t],
|
||||||
iface_tys: [ty::t], impl_did: ast::def_id) {
|
iface_tys: [ty::t], impl_did: ast::def_id) {
|
||||||
let tcx = fcx.ccx.tcx;
|
let tcx = fcx.ccx.tcx;
|
||||||
// FIXME[impl]
|
let ity = option::get(ty::impl_iface(tcx, impl_did));
|
||||||
assert impl_did.crate == ast::local_crate;
|
|
||||||
let ity = alt tcx.items.get(impl_did.node) {
|
|
||||||
ast_map::node_item(@{node: ast::item_impl(_, some(ity), _, _), _}) {
|
|
||||||
ast_ty_to_ty(tcx, m_check, ity)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let iface_ty = ty::substitute_type_params(tcx, impl_tys, ity);
|
let iface_ty = ty::substitute_type_params(tcx, impl_tys, ity);
|
||||||
alt ty::struct(tcx, iface_ty) {
|
alt ty::struct(tcx, iface_ty) {
|
||||||
ty::ty_iface(_, tps) {
|
ty::ty_iface(_, tps) {
|
||||||
@@ -3086,8 +3044,7 @@ fn check_crate(tcx: ty::ctxt, impl_map: resolve::impl_map,
|
|||||||
dict_map: std::map::new_int_hash(),
|
dict_map: std::map::new_int_hash(),
|
||||||
tcx: tcx};
|
tcx: tcx};
|
||||||
let visit = visit::mk_simple_visitor(@{
|
let visit = visit::mk_simple_visitor(@{
|
||||||
visit_item: bind check_item(ccx, _),
|
visit_item: bind check_item(ccx, _)
|
||||||
visit_ty_params: bind check_ty_params(ccx, _)
|
|
||||||
with *visit::default_simple_visitor()
|
with *visit::default_simple_visitor()
|
||||||
});
|
});
|
||||||
visit::visit_crate(*crate, (), visit);
|
visit::visit_crate(*crate, (), visit);
|
||||||
|
|||||||
@@ -394,16 +394,14 @@ fn parse_type_constraints(p: parser) -> [@ast::ty_constr] {
|
|||||||
ret parse_constrs(parse_constr_in_type, p);
|
ret parse_constrs(parse_constr_in_type, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool)
|
fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool,
|
||||||
-> @ast::ty {
|
lo: uint) -> @ast::ty {
|
||||||
let lo = p.get_lo_pos();
|
|
||||||
|
|
||||||
if colons_before_params && p.peek() == token::MOD_SEP {
|
if colons_before_params && p.peek() == token::MOD_SEP {
|
||||||
p.bump();
|
p.bump();
|
||||||
expect(p, token::LT);
|
expect(p, token::LT);
|
||||||
} else if !colons_before_params && p.peek() == token::LT {
|
} else if !colons_before_params && p.peek() == token::LT {
|
||||||
p.bump();
|
p.bump();
|
||||||
} else { ret @spanned(lo, p.get_lo_pos(), orig_t); }
|
} else { ret @spanned(lo, p.get_last_hi_pos(), orig_t); }
|
||||||
|
|
||||||
// If we're here, we have explicit type parameter instantiation.
|
// If we're here, we have explicit type parameter instantiation.
|
||||||
let seq = parse_seq_to_gt(some(token::COMMA), {|p| parse_ty(p, false)},
|
let seq = parse_seq_to_gt(some(token::COMMA), {|p| parse_ty(p, false)},
|
||||||
@@ -411,9 +409,8 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool)
|
|||||||
|
|
||||||
alt orig_t {
|
alt orig_t {
|
||||||
ast::ty_path(pth, ann) {
|
ast::ty_path(pth, ann) {
|
||||||
let hi = p.get_hi_pos();
|
ret @spanned(lo, p.get_last_hi_pos(),
|
||||||
ret @spanned(lo, hi,
|
ast::ty_path(@spanned(lo, p.get_last_hi_pos(),
|
||||||
ast::ty_path(@spanned(lo, hi,
|
|
||||||
{global: pth.node.global,
|
{global: pth.node.global,
|
||||||
idents: pth.node.idents,
|
idents: pth.node.idents,
|
||||||
types: seq}), ann));
|
types: seq}), ann));
|
||||||
@@ -527,7 +524,7 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
|
|||||||
let path = parse_path(p);
|
let path = parse_path(p);
|
||||||
t = ast::ty_path(path, p.get_id());
|
t = ast::ty_path(path, p.get_id());
|
||||||
} else { p.fatal("expecting type"); }
|
} else { p.fatal("expecting type"); }
|
||||||
ret parse_ty_postfix(t, p, colons_before_params);
|
ret parse_ty_postfix(t, p, colons_before_params, lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_arg_mode(p: parser) -> ast::mode {
|
fn parse_arg_mode(p: parser) -> ast::mode {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ mod util;
|
|||||||
mod header;
|
mod header;
|
||||||
mod runtest;
|
mod runtest;
|
||||||
mod common;
|
mod common;
|
||||||
|
mod errors;
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// fill-column: 78;
|
// fill-column: 78;
|
||||||
// indent-tabs-mode: nil
|
// indent-tabs-mode: nil
|
||||||
// c-basic-offset: 4
|
// c-basic-offset: 4
|
||||||
// buffer-file-coding-system: utf-8-unix
|
// buffer-file-coding-system: utf-8-unix
|
||||||
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
||||||
// End:
|
// End:
|
||||||
|
|||||||
54
src/compiletest/errors.rs
Normal file
54
src/compiletest/errors.rs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import option;
|
||||||
|
import str;
|
||||||
|
import std::io;
|
||||||
|
import std::fs;
|
||||||
|
|
||||||
|
import common::config;
|
||||||
|
|
||||||
|
export load_errors;
|
||||||
|
export expected_error;
|
||||||
|
|
||||||
|
type expected_error = { line: uint, kind: str, msg: str };
|
||||||
|
|
||||||
|
// Load any test directives embedded in the file
|
||||||
|
fn load_errors(testfile: str) -> [expected_error] {
|
||||||
|
let error_patterns = [];
|
||||||
|
let rdr = result::get(io::file_reader(testfile));
|
||||||
|
let line_num = 1u;
|
||||||
|
while !rdr.eof() {
|
||||||
|
let ln = rdr.read_line();
|
||||||
|
error_patterns += parse_expected(line_num, ln);
|
||||||
|
line_num += 1u;
|
||||||
|
}
|
||||||
|
ret error_patterns;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_expected(line_num: uint, line: str) -> [expected_error] {
|
||||||
|
let error_tag = "//!";
|
||||||
|
let idx0 = str::find(line, error_tag);
|
||||||
|
if idx0 < 0 { ret []; }
|
||||||
|
let idx = (idx0 as uint) + str::byte_len(error_tag);
|
||||||
|
|
||||||
|
// "//!^^^ kind msg" denotes a message expected
|
||||||
|
// three lines above current line:
|
||||||
|
let adjust_line = 0u;
|
||||||
|
let len = str::byte_len(line);
|
||||||
|
while idx < len && line[idx] == ('^' as u8) {
|
||||||
|
adjust_line += 1u;
|
||||||
|
idx += 1u;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract kind:
|
||||||
|
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
||||||
|
let start_kind = idx;
|
||||||
|
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
|
||||||
|
let kind = str::to_lower(str::slice(line, start_kind, idx));
|
||||||
|
|
||||||
|
// Extract msg:
|
||||||
|
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
||||||
|
let msg = str::slice(line, idx, len);
|
||||||
|
|
||||||
|
#debug("line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg);
|
||||||
|
|
||||||
|
ret [{line: line_num - adjust_line, kind: kind, msg: msg}];
|
||||||
|
}
|
||||||
@@ -42,8 +42,17 @@ fn run_cfail_test(cx: cx, props: test_props, testfile: str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_correct_failure_status(procres);
|
check_correct_failure_status(procres);
|
||||||
|
|
||||||
|
let expected_errors = errors::load_errors(testfile);
|
||||||
|
if vec::is_not_empty(expected_errors) {
|
||||||
|
if vec::is_not_empty(props.error_patterns) {
|
||||||
|
fatal("both error pattern and expected errors specified");
|
||||||
|
}
|
||||||
|
check_expected_errors(expected_errors, testfile, procres);
|
||||||
|
} else {
|
||||||
check_error_patterns(props, testfile, procres);
|
check_error_patterns(props, testfile, procres);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn run_rfail_test(cx: cx, props: test_props, testfile: str) {
|
fn run_rfail_test(cx: cx, props: test_props, testfile: str) {
|
||||||
let procres = compile_test(cx, props, testfile);
|
let procres = compile_test(cx, props, testfile);
|
||||||
@@ -181,7 +190,9 @@ actual:\n\
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_error_patterns(props: test_props, testfile: str, procres: procres) {
|
fn check_error_patterns(props: test_props,
|
||||||
|
testfile: str,
|
||||||
|
procres: procres) {
|
||||||
if vec::is_empty(props.error_patterns) {
|
if vec::is_empty(props.error_patterns) {
|
||||||
fatal("no error pattern specified in " + testfile);
|
fatal("no error pattern specified in " + testfile);
|
||||||
}
|
}
|
||||||
@@ -218,6 +229,63 @@ fn check_error_patterns(props: test_props, testfile: str, procres: procres) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_expected_errors(expected_errors: [errors::expected_error],
|
||||||
|
testfile: str,
|
||||||
|
procres: procres) {
|
||||||
|
|
||||||
|
// true if we found the error in question
|
||||||
|
let found_flags = vec::init_elt_mut(false, vec::len(expected_errors));
|
||||||
|
|
||||||
|
if procres.status == 0 {
|
||||||
|
fatal("process did not return an error status");
|
||||||
|
}
|
||||||
|
|
||||||
|
let prefixes = vec::map(expected_errors, {|ee|
|
||||||
|
#fmt("%s:%u:", testfile, ee.line)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Scan and extract our error/warning messages,
|
||||||
|
// which look like:
|
||||||
|
// filename:line1:col1: line2:col2: *error:* msg
|
||||||
|
// filename:line1:col1: line2:col2: *warning:* msg
|
||||||
|
// where line1:col1: is the starting point, line2:col2:
|
||||||
|
// is the ending point, and * represents ANSI color codes.
|
||||||
|
for line: str in str::split(procres.stdout, '\n' as u8) {
|
||||||
|
let was_expected = false;
|
||||||
|
vec::iteri(expected_errors) {|i, ee|
|
||||||
|
if !found_flags[i] {
|
||||||
|
#debug["prefix=%s ee.kind=%s ee.msg=%s line=%s",
|
||||||
|
prefixes[i], ee.kind, ee.msg, line];
|
||||||
|
if (str::starts_with(line, prefixes[i]) &&
|
||||||
|
str::contains(line, ee.kind) &&
|
||||||
|
str::contains(line, ee.msg)) {
|
||||||
|
found_flags[i] = true;
|
||||||
|
was_expected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore this msg which gets printed at the end
|
||||||
|
if str::contains(line, "aborting due to previous errors") {
|
||||||
|
was_expected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !was_expected && (str::contains(line, "error") ||
|
||||||
|
str::contains(line, "warning")) {
|
||||||
|
fatal_procres(#fmt["unexpected error pattern '%s'!", line],
|
||||||
|
procres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint::range(0u, vec::len(found_flags)) {|i|
|
||||||
|
if !found_flags[i] {
|
||||||
|
let ee = expected_errors[i];
|
||||||
|
fatal_procres(#fmt["expected %s on line %u not found: %s",
|
||||||
|
ee.kind, ee.line, ee.msg], procres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type procargs = {prog: str, args: [str]};
|
type procargs = {prog: str, args: [str]};
|
||||||
|
|
||||||
type procres = {status: int, stdout: str, stderr: str, cmdline: str};
|
type procres = {status: int, stdout: str, stderr: str, cmdline: str};
|
||||||
|
|||||||
@@ -63,11 +63,11 @@ int main(int argc, char** argv) {
|
|||||||
printf("}\n\n");
|
printf("}\n\n");
|
||||||
|
|
||||||
printf("mod c_float_targ_consts {\n");
|
printf("mod c_float_targ_consts {\n");
|
||||||
printf(" const radix: uint = %u;\n", FLT_RADIX);
|
printf(" const radix: uint = %uu;\n", FLT_RADIX);
|
||||||
printf(" const mantissa_digits: uint = %u;\n", FLT_MANT_DIG);
|
printf(" const mantissa_digits: uint = %uu;\n", FLT_MANT_DIG);
|
||||||
printf(" const digits: uint = %u;\n", FLT_DIG);
|
printf(" const digits: uint = %uu;\n", FLT_DIG);
|
||||||
printf(" const min_exp: uint = %i;\n", FLT_MIN_EXP);
|
printf(" const min_exp: int = %i;\n", FLT_MIN_EXP);
|
||||||
printf(" const max_exp: uint = %i;\n", FLT_MAX_EXP);
|
printf(" const max_exp: int = %i;\n", FLT_MAX_EXP);
|
||||||
printf(" const min_10_exp: int = %i;\n", FLT_MIN_10_EXP);
|
printf(" const min_10_exp: int = %i;\n", FLT_MIN_10_EXP);
|
||||||
printf(" const max_10_exp: int = %i;\n", FLT_MAX_10_EXP);
|
printf(" const max_10_exp: int = %i;\n", FLT_MAX_10_EXP);
|
||||||
printf(" const min_value: c_float = %a_%s;\n", C_FLT(FLT_MIN), c_flt);
|
printf(" const min_value: c_float = %a_%s;\n", C_FLT(FLT_MIN), c_flt);
|
||||||
@@ -76,11 +76,11 @@ int main(int argc, char** argv) {
|
|||||||
printf("}\n\n");
|
printf("}\n\n");
|
||||||
|
|
||||||
printf("mod c_double_targ_consts {\n");
|
printf("mod c_double_targ_consts {\n");
|
||||||
printf(" const radix: uint = %u;\n", FLT_RADIX);
|
printf(" const radix: uint = %uu;\n", FLT_RADIX);
|
||||||
printf(" const mantissa_digits: uint = %u;\n", DBL_MANT_DIG);
|
printf(" const mantissa_digits: uint = %uu;\n", DBL_MANT_DIG);
|
||||||
printf(" const digits: uint = %u;\n", DBL_DIG);
|
printf(" const digits: uint = %uu;\n", DBL_DIG);
|
||||||
printf(" const min_exp: uint = %i;\n", DBL_MIN_EXP);
|
printf(" const min_exp: int = %i;\n", DBL_MIN_EXP);
|
||||||
printf(" const max_exp: uint = %i;\n", DBL_MAX_EXP);
|
printf(" const max_exp: int = %i;\n", DBL_MAX_EXP);
|
||||||
printf(" const min_10_exp: int = %i;\n", DBL_MIN_10_EXP);
|
printf(" const min_10_exp: int = %i;\n", DBL_MIN_10_EXP);
|
||||||
printf(" const max_10_exp: int = %i;\n", DBL_MAX_10_EXP);
|
printf(" const max_10_exp: int = %i;\n", DBL_MAX_10_EXP);
|
||||||
printf(" const min_value: c_double = %a_%s;\n", C_DBL(DBL_MIN), c_dbl);
|
printf(" const min_value: c_double = %a_%s;\n", C_DBL(DBL_MIN), c_dbl);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ native mod c_double {
|
|||||||
#[cfg(target_os="macos")]
|
#[cfg(target_os="macos")]
|
||||||
#[cfg(target_os="win32")]
|
#[cfg(target_os="win32")]
|
||||||
pure fn log2(n: c_double) -> c_double;
|
pure fn log2(n: c_double) -> c_double;
|
||||||
#[link_name="ilogb"] pure fn ilogradix(n: c_double) -> c_int;
|
#[link_name="ilogb"] pure fn ilog_radix(n: c_double) -> c_int;
|
||||||
pure fn modf(n: c_double, &iptr: c_double) -> c_double;
|
pure fn modf(n: c_double, &iptr: c_double) -> c_double;
|
||||||
pure fn pow(n: c_double, e: c_double) -> c_double;
|
pure fn pow(n: c_double, e: c_double) -> c_double;
|
||||||
// FIXME enable when rounding modes become available
|
// FIXME enable when rounding modes become available
|
||||||
@@ -139,7 +139,8 @@ native mod c_float {
|
|||||||
// FIXME enable when rounding modes become available
|
// FIXME enable when rounding modes become available
|
||||||
// #[link_name="rintf"] pure fn rint(n: c_float) -> c_float;
|
// #[link_name="rintf"] pure fn rint(n: c_float) -> c_float;
|
||||||
#[link_name="roundf"] pure fn round(n: c_float) -> c_float;
|
#[link_name="roundf"] pure fn round(n: c_float) -> c_float;
|
||||||
#[link_name="scalbnf"] pure fn ldexp_radix(n: c_float, i: c_int) -> c_float;
|
#[link_name="scalbnf"] pure fn ldexp_radix(n: c_float, i: c_int)
|
||||||
|
-> c_float;
|
||||||
#[link_name="sinf"] pure fn sin(n: c_float) -> c_float;
|
#[link_name="sinf"] pure fn sin(n: c_float) -> c_float;
|
||||||
#[link_name="sinhf"] pure fn sinh(n: c_float) -> c_float;
|
#[link_name="sinhf"] pure fn sinh(n: c_float) -> c_float;
|
||||||
#[link_name="sqrtf"] pure fn sqrt(n: c_float) -> c_float;
|
#[link_name="sqrtf"] pure fn sqrt(n: c_float) -> c_float;
|
||||||
@@ -154,11 +155,11 @@ native mod c_float {
|
|||||||
// FIXME obtain machine float/math constants automatically
|
// FIXME obtain machine float/math constants automatically
|
||||||
|
|
||||||
mod c_float_targ_consts {
|
mod c_float_targ_consts {
|
||||||
const radix: uint = 2;
|
const radix: uint = 2u;
|
||||||
const mantissa_digits: uint = 24;
|
const mantissa_digits: uint = 24u;
|
||||||
const digits: uint = 6;
|
const digits: uint = 6u;
|
||||||
const min_exp: uint = -125;
|
const min_exp: uint = -125u;
|
||||||
const max_exp: uint = 128;
|
const max_exp: uint = 128u;
|
||||||
const min_10_exp: int = -37;
|
const min_10_exp: int = -37;
|
||||||
const max_10_exp: int = 38;
|
const max_10_exp: int = 38;
|
||||||
// FIXME this is wrong! replace with hexadecimal (%a) constants below
|
// FIXME this is wrong! replace with hexadecimal (%a) constants below
|
||||||
@@ -168,11 +169,11 @@ mod c_float_targ_consts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod c_double_targ_consts {
|
mod c_double_targ_consts {
|
||||||
const radix: uint = 2;
|
const radix: uint = 2u;
|
||||||
const mantissa_digits: uint = 53;
|
const mantissa_digits: uint = 53u;
|
||||||
const digits: uint = 15;
|
const digits: uint = 15u;
|
||||||
const min_exp: uint = -1021;
|
const min_exp: uint = -1021u;
|
||||||
const max_exp: uint = 1024;
|
const max_exp: uint = 1024u;
|
||||||
const min_10_exp: int = -307;
|
const min_10_exp: int = -307;
|
||||||
const max_10_exp: int = 308;
|
const max_10_exp: int = 308;
|
||||||
// FIXME this is wrong! replace with hexadecimal (%a) constants below
|
// FIXME this is wrong! replace with hexadecimal (%a) constants below
|
||||||
@@ -218,11 +219,11 @@ mod c_double_math_consts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod c_float_targ_consts {
|
mod c_float_targ_consts {
|
||||||
const radix: uint = 2;
|
const radix: uint = 2u;
|
||||||
const mantissa_digits: uint = 24;
|
const mantissa_digits: uint = 24u;
|
||||||
const digits: uint = 6;
|
const digits: uint = 6u;
|
||||||
const min_exp: uint = -125;
|
const min_exp: int = -125;
|
||||||
const max_exp: uint = 128;
|
const max_exp: int = 128;
|
||||||
const min_10_exp: int = -37;
|
const min_10_exp: int = -37;
|
||||||
const max_10_exp: int = 38;
|
const max_10_exp: int = 38;
|
||||||
const min_value: c_float = 0x1p-126_f32;
|
const min_value: c_float = 0x1p-126_f32;
|
||||||
@@ -231,17 +232,18 @@ mod c_float_targ_consts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod c_double_targ_consts {
|
mod c_double_targ_consts {
|
||||||
const radix: uint = 2;
|
const radix: uint = 2u;
|
||||||
const mantissa_digits: uint = 53;
|
const mantissa_digits: uint = 53u;
|
||||||
const digits: uint = 15;
|
const digits: uint = 15u;
|
||||||
const min_exp: uint = -1021;
|
const min_exp: int = -1021;
|
||||||
const max_exp: uint = 1024;
|
const max_exp: int = 1024;
|
||||||
const min_10_exp: int = -307;
|
const min_10_exp: int = -307;
|
||||||
const max_10_exp: int = 308;
|
const max_10_exp: int = 308;
|
||||||
const min_value: c_double = 0x1p-1022_f64;
|
const min_value: c_double = 0x1p-1022_f64;
|
||||||
const max_value: c_double = 0x1.fffffffffffffp+1023_f64;
|
const max_value: c_double = 0x1.fffffffffffffp+1023_f64;
|
||||||
const epsilon: c_double = 0x1p-52_f64;
|
const epsilon: c_double = 0x1p-52_f64;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ Predicate: is_finite
|
|||||||
Returns true if `x`is a finite numer
|
Returns true if `x`is a finite numer
|
||||||
*/
|
*/
|
||||||
pure fn is_finite(x: f32) -> bool {
|
pure fn is_finite(x: f32) -> bool {
|
||||||
ret !(is_nan(x) || is_infinite(x));
|
ret !(is_NaN(x) || is_infinite(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME add is_normal, is_subnormal, and fpclassify
|
// FIXME add is_normal, is_subnormal, and fpclassify
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ Predicate: is_finite
|
|||||||
Returns true if `x`is a finite numer
|
Returns true if `x`is a finite numer
|
||||||
*/
|
*/
|
||||||
pure fn is_finite(x: f64) -> bool {
|
pure fn is_finite(x: f64) -> bool {
|
||||||
ret !(is_nan(x) || is_infinite(x));
|
ret !(is_NaN(x) || is_infinite(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME add is_normal, is_subnormal, and fpclassify
|
// FIXME add is_normal, is_subnormal, and fpclassify
|
||||||
|
|||||||
@@ -2,10 +2,29 @@
|
|||||||
Module: float
|
Module: float
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// FIXME find out why these have to be exported explicitly
|
||||||
|
|
||||||
|
export to_str_common, to_str_exact, to_str, from_str, min, max;
|
||||||
|
export add, sub, mul, div, rem, lt, le, gt, eq, eq, ne;
|
||||||
|
export is_positive, is_negative, is_nonpositive, is_nonnegative;
|
||||||
|
export is_zero, is_infinite, is_finite;
|
||||||
|
export NaN, is_NaN, infinity, neg_infinity;
|
||||||
|
export consts;
|
||||||
|
export logarithm;
|
||||||
|
export acos, asin, atan, atan2, cbrt, ceil, copysign, cos, cosh;
|
||||||
|
export erf, erfc, exp, expm1, exp2, abs, abs_sub;
|
||||||
|
export mul_add, fmax, fmin, nextafter, frexp, hypot, ldexp;
|
||||||
|
export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
|
||||||
|
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
|
||||||
|
|
||||||
|
// export when m_float == c_double
|
||||||
|
|
||||||
|
export j0, j1, jn, y0, y1, yn;
|
||||||
|
|
||||||
// PORT this must match in width according to architecture
|
// PORT this must match in width according to architecture
|
||||||
|
|
||||||
import m_float = f64;
|
import m_float = f64;
|
||||||
import m_float::*;
|
import f64::*;
|
||||||
|
|
||||||
type t = float;
|
type t = float;
|
||||||
|
|
||||||
@@ -25,7 +44,7 @@ digits - The number of significant digits
|
|||||||
exact - Whether to enforce the exact number of significant digits
|
exact - Whether to enforce the exact number of significant digits
|
||||||
*/
|
*/
|
||||||
fn to_str_common(num: float, digits: uint, exact: bool) -> str {
|
fn to_str_common(num: float, digits: uint, exact: bool) -> str {
|
||||||
if isNaN(num) { ret "NaN"; }
|
if is_NaN(num) { ret "NaN"; }
|
||||||
let (num, accum) = num < 0.0 ? (-num, "-") : (num, "");
|
let (num, accum) = num < 0.0 ? (-num, "-") : (num, "");
|
||||||
let trunc = num as uint;
|
let trunc = num as uint;
|
||||||
let frac = num - (trunc as float);
|
let frac = num - (trunc as float);
|
||||||
|
|||||||
@@ -46,16 +46,10 @@ ls - The list to fold
|
|||||||
z - The initial value
|
z - The initial value
|
||||||
f - The function to apply
|
f - The function to apply
|
||||||
*/
|
*/
|
||||||
fn foldl<copy T, copy U>(ls: list<U>, z: T, f: block(T, U) -> T) -> T {
|
fn foldl<copy T, U>(ls: list<U>, z: T, f: block(T, U) -> T) -> T {
|
||||||
let accum: T = z;
|
let accum: T = z;
|
||||||
let ls = ls;
|
iter(ls) {|elt| accum = f(accum, elt);}
|
||||||
while true {
|
accum
|
||||||
alt ls {
|
|
||||||
cons(hd, tl) { accum = f(accum, hd); ls = *tl; }
|
|
||||||
nil. { break; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret accum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -123,9 +117,10 @@ Function: len
|
|||||||
|
|
||||||
Returns the length of a list
|
Returns the length of a list
|
||||||
*/
|
*/
|
||||||
fn len<copy T>(ls: list<T>) -> uint {
|
fn len<T>(ls: list<T>) -> uint {
|
||||||
fn count<T>(&&u: uint, _t: T) -> uint { ret u + 1u; }
|
let count = 0u;
|
||||||
ret foldl(ls, 0u, bind count(_, _));
|
iter(ls) {|_e| count += 1u;}
|
||||||
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -169,16 +164,23 @@ Function: iter
|
|||||||
|
|
||||||
Iterate over a list
|
Iterate over a list
|
||||||
*/
|
*/
|
||||||
fn iter<copy T>(l: list<T>, f: block(T)) {
|
fn iter<T>(l: list<T>, f: block(T)) {
|
||||||
let cur = l;
|
alt l {
|
||||||
while cur != nil {
|
|
||||||
alt cur {
|
|
||||||
cons(hd, tl) {
|
cons(hd, tl) {
|
||||||
f(hd);
|
f(hd);
|
||||||
cur = *tl;
|
let cur = tl;
|
||||||
|
while true {
|
||||||
|
alt *cur {
|
||||||
|
cons(hd, tl) {
|
||||||
|
f(hd);
|
||||||
|
cur = tl;
|
||||||
|
}
|
||||||
|
nil. { break; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
nil. {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
S 2012-01-05 3eb3590
|
||||||
|
winnt-i386 bfa10b10e65c953f900296e7d28c89fa50257808
|
||||||
|
linux-i386 f3744aaba89ba8995b0e5f911c15822304507c70
|
||||||
|
macos-i386 64e33d698ff4dfba56e69a5191698d7f50a97e2d
|
||||||
|
linux-x86_64 80a5eb9fce7fcf6c61d46607c2d6a1669e50f96f
|
||||||
|
macos-x86_64 5cab4f241407ae5d867855aa02c869cf7d65c8b5
|
||||||
|
|
||||||
S 2011-12-22 ccb5b6f
|
S 2011-12-22 ccb5b6f
|
||||||
winnt-i386 35be60caa888246e9710bd34ccbbe8a322d3c6de
|
winnt-i386 35be60caa888246e9710bd34ccbbe8a322d3c6de
|
||||||
linux-i386 8f88a285fa86613e268503a310e32cb053c2e300
|
linux-i386 8f88a285fa86613e268503a310e32cb053c2e300
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// error-pattern:unresolved name
|
|
||||||
// a good test that we merge paths correctly in the presence of a
|
// a good test that we merge paths correctly in the presence of a
|
||||||
// variable that's used before it's declared
|
// variable that's used before it's declared
|
||||||
|
|
||||||
@@ -7,6 +6,6 @@ fn my_fail() -> ! { fail; }
|
|||||||
fn main() {
|
fn main() {
|
||||||
alt true { false { my_fail(); } true { } }
|
alt true { false { my_fail(); } true { } }
|
||||||
|
|
||||||
log(debug, x);
|
log(debug, x); //! ERROR unresolved name: x
|
||||||
let x: int;
|
let x: int;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Allow block arguments with ternary... why not, no chance of ambig.
|
// Allow block arguments with ternary... why not, no chance of ambig.
|
||||||
fn main() {
|
fn main() {
|
||||||
let v = [-1f, 1f];
|
let v = [-1f, 1f];
|
||||||
let foo = vec::any(v) { |e| float::negative(e) } ? true : false;
|
let foo = vec::any(v) { |e| float::is_negative(e) } ? true : false;
|
||||||
assert foo;
|
assert foo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,28 +8,28 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Usable at all:
|
// Usable at all:
|
||||||
let any_negative = vec::any(v) { |e| float::negative(e) };
|
let any_negative = vec::any(v) { |e| float::is_negative(e) };
|
||||||
assert any_negative;
|
assert any_negative;
|
||||||
|
|
||||||
// Higher precedence than assignments:
|
// Higher precedence than assignments:
|
||||||
any_negative = vec::any(v) { |e| float::negative(e) };
|
any_negative = vec::any(v) { |e| float::is_negative(e) };
|
||||||
assert any_negative;
|
assert any_negative;
|
||||||
|
|
||||||
// Higher precedence than unary operations:
|
// Higher precedence than unary operations:
|
||||||
let abs_v = vec::map(v) { |e| float::abs(e) };
|
let abs_v = vec::map(v) { |e| float::abs(e) };
|
||||||
assert vec::all(abs_v) { |e| float::nonnegative(e) };
|
assert vec::all(abs_v) { |e| float::is_nonnegative(e) };
|
||||||
assert !vec::any(abs_v) { |e| float::negative(e) };
|
assert !vec::any(abs_v) { |e| float::is_negative(e) };
|
||||||
|
|
||||||
// Usable in funny statement-like forms:
|
// Usable in funny statement-like forms:
|
||||||
if !vec::any(v) { |e| float::positive(e) } {
|
if !vec::any(v) { |e| float::is_positive(e) } {
|
||||||
assert false;
|
assert false;
|
||||||
}
|
}
|
||||||
alt vec::all(v) { |e| float::negative(e) } {
|
alt vec::all(v) { |e| float::is_negative(e) } {
|
||||||
true { fail "incorrect answer."; }
|
true { fail "incorrect answer."; }
|
||||||
false { }
|
false { }
|
||||||
}
|
}
|
||||||
alt 3 {
|
alt 3 {
|
||||||
_ when vec::any(v) { |e| float::negative(e) } {
|
_ when vec::any(v) { |e| float::is_negative(e) } {
|
||||||
}
|
}
|
||||||
_ {
|
_ {
|
||||||
fail "wrong answer.";
|
fail "wrong answer.";
|
||||||
@@ -46,7 +46,7 @@ fn main() {
|
|||||||
|
|
||||||
// They are not allowed as the tail of a block without parentheses:
|
// They are not allowed as the tail of a block without parentheses:
|
||||||
let w =
|
let w =
|
||||||
if true { vec::any(abs_v, { |e| float::nonnegative(e) }) }
|
if true { vec::any(abs_v, { |e| float::is_nonnegative(e) }) }
|
||||||
else { false };
|
else { false };
|
||||||
assert w;
|
assert w;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import float;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let nan = float::NaN;
|
let nan = float::NaN;
|
||||||
assert(float::isNaN(nan));
|
assert(float::is_NaN(nan));
|
||||||
|
|
||||||
let inf = float::infinity;
|
let inf = float::infinity;
|
||||||
assert(-inf == float::neg_infinity);
|
assert(-inf == float::neg_infinity);
|
||||||
@@ -61,22 +61,22 @@ fn main() {
|
|||||||
assert(!(-inf < nan));
|
assert(!(-inf < nan));
|
||||||
assert(!(-nan < nan));
|
assert(!(-nan < nan));
|
||||||
|
|
||||||
assert(float::isNaN(nan + inf));
|
assert(float::is_NaN(nan + inf));
|
||||||
assert(float::isNaN(nan + -inf));
|
assert(float::is_NaN(nan + -inf));
|
||||||
assert(float::isNaN(nan + 0.));
|
assert(float::is_NaN(nan + 0.));
|
||||||
assert(float::isNaN(nan + 1.));
|
assert(float::is_NaN(nan + 1.));
|
||||||
assert(float::isNaN(nan * 1.));
|
assert(float::is_NaN(nan * 1.));
|
||||||
assert(float::isNaN(nan / 1.));
|
assert(float::is_NaN(nan / 1.));
|
||||||
assert(float::isNaN(nan / 0.));
|
assert(float::is_NaN(nan / 0.));
|
||||||
assert(float::isNaN(0. / 0.));
|
assert(float::is_NaN(0. / 0.));
|
||||||
assert(float::isNaN(-inf + inf));
|
assert(float::is_NaN(-inf + inf));
|
||||||
assert(float::isNaN(inf - inf));
|
assert(float::is_NaN(inf - inf));
|
||||||
|
|
||||||
assert(!float::isNaN(-1.));
|
assert(!float::is_NaN(-1.));
|
||||||
assert(!float::isNaN(0.));
|
assert(!float::is_NaN(0.));
|
||||||
assert(!float::isNaN(0.1));
|
assert(!float::is_NaN(0.1));
|
||||||
assert(!float::isNaN(1.));
|
assert(!float::is_NaN(1.));
|
||||||
assert(!float::isNaN(inf));
|
assert(!float::is_NaN(inf));
|
||||||
assert(!float::isNaN(-inf));
|
assert(!float::is_NaN(-inf));
|
||||||
assert(!float::isNaN(1./-inf));
|
assert(!float::is_NaN(1./-inf));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,60 +26,60 @@ fn test_from_str() {
|
|||||||
assert ( float::from_str(" -.5 ") == -0.5 );
|
assert ( float::from_str(" -.5 ") == -0.5 );
|
||||||
assert ( float::from_str(" -5 ") == -5. );
|
assert ( float::from_str(" -5 ") == -5. );
|
||||||
|
|
||||||
assert ( float::isNaN(float::from_str("x")) );
|
assert ( float::is_NaN(float::from_str("x")) );
|
||||||
assert ( float::from_str(" ") == 0. );
|
assert ( float::from_str(" ") == 0. );
|
||||||
assert ( float::from_str(" ") == 0. );
|
assert ( float::from_str(" ") == 0. );
|
||||||
assert ( float::from_str(" 0.5") == 0.5 );
|
assert ( float::from_str(" 0.5") == 0.5 );
|
||||||
assert ( float::from_str(" 0.5 ") == 0.5 );
|
assert ( float::from_str(" 0.5 ") == 0.5 );
|
||||||
assert ( float::from_str(" .1 ") == 0.1 );
|
assert ( float::from_str(" .1 ") == 0.1 );
|
||||||
assert ( float::isNaN(float::from_str("e")) );
|
assert ( float::is_NaN(float::from_str("e")) );
|
||||||
assert ( float::isNaN(float::from_str("E")) );
|
assert ( float::is_NaN(float::from_str("E")) );
|
||||||
assert ( float::isNaN(float::from_str("E1")) );
|
assert ( float::is_NaN(float::from_str("E1")) );
|
||||||
assert ( float::isNaN(float::from_str("1e1e1")) );
|
assert ( float::is_NaN(float::from_str("1e1e1")) );
|
||||||
assert ( float::isNaN(float::from_str("1e1.1")) );
|
assert ( float::is_NaN(float::from_str("1e1.1")) );
|
||||||
assert ( float::isNaN(float::from_str("1e1-1")) );
|
assert ( float::is_NaN(float::from_str("1e1-1")) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_positive() {
|
fn test_positive() {
|
||||||
assert(float::positive(float::infinity));
|
assert(float::is_positive(float::infinity));
|
||||||
assert(float::positive(1.));
|
assert(float::is_positive(1.));
|
||||||
assert(float::positive(0.));
|
assert(float::is_positive(0.));
|
||||||
assert(!float::positive(-1.));
|
assert(!float::is_positive(-1.));
|
||||||
assert(!float::positive(float::neg_infinity));
|
assert(!float::is_positive(float::neg_infinity));
|
||||||
assert(!float::positive(1./float::neg_infinity));
|
assert(!float::is_positive(1./float::neg_infinity));
|
||||||
assert(!float::positive(float::NaN));
|
assert(!float::is_positive(float::NaN));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_negative() {
|
fn test_negative() {
|
||||||
assert(!float::negative(float::infinity));
|
assert(!float::is_negative(float::infinity));
|
||||||
assert(!float::negative(1.));
|
assert(!float::is_negative(1.));
|
||||||
assert(!float::negative(0.));
|
assert(!float::is_negative(0.));
|
||||||
assert(float::negative(-1.));
|
assert(float::is_negative(-1.));
|
||||||
assert(float::negative(float::neg_infinity));
|
assert(float::is_negative(float::neg_infinity));
|
||||||
assert(float::negative(1./float::neg_infinity));
|
assert(float::is_negative(1./float::neg_infinity));
|
||||||
assert(!float::negative(float::NaN));
|
assert(!float::is_negative(float::NaN));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nonpositive() {
|
fn test_nonpositive() {
|
||||||
assert(!float::nonpositive(float::infinity));
|
assert(!float::is_nonpositive(float::infinity));
|
||||||
assert(!float::nonpositive(1.));
|
assert(!float::is_nonpositive(1.));
|
||||||
assert(!float::nonpositive(0.));
|
assert(!float::is_nonpositive(0.));
|
||||||
assert(float::nonpositive(-1.));
|
assert(float::is_nonpositive(-1.));
|
||||||
assert(float::nonpositive(float::neg_infinity));
|
assert(float::is_nonpositive(float::neg_infinity));
|
||||||
assert(float::nonpositive(1./float::neg_infinity));
|
assert(float::is_nonpositive(1./float::neg_infinity));
|
||||||
assert(!float::nonpositive(float::NaN));
|
assert(!float::is_nonpositive(float::NaN));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nonnegative() {
|
fn test_nonnegative() {
|
||||||
assert(float::nonnegative(float::infinity));
|
assert(float::is_nonnegative(float::infinity));
|
||||||
assert(float::nonnegative(1.));
|
assert(float::is_nonnegative(1.));
|
||||||
assert(float::nonnegative(0.));
|
assert(float::is_nonnegative(0.));
|
||||||
assert(!float::nonnegative(-1.));
|
assert(!float::is_nonnegative(-1.));
|
||||||
assert(!float::nonnegative(float::neg_infinity));
|
assert(!float::is_nonnegative(float::neg_infinity));
|
||||||
assert(!float::nonnegative(1./float::neg_infinity));
|
assert(!float::is_nonnegative(1./float::neg_infinity));
|
||||||
assert(!float::nonnegative(float::NaN));
|
assert(!float::is_nonnegative(float::NaN));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user