Change 'iface' to 'trait' internally; parse `trait` as `iface` synonym

This commit is contained in:
Lindsey Kuper 2012-07-03 16:30:42 -07:00
parent d93f3c5d83
commit 33334f3c43
49 changed files with 453 additions and 451 deletions

View File

@ -62,7 +62,7 @@ enum ty_param_bound {
bound_copy,
bound_send,
bound_const,
bound_iface(@ty),
bound_trait(@ty),
}
#[auto_serialize]
@ -657,11 +657,11 @@ enum attr_style { attr_outer, attr_inner, }
type attribute_ = {style: attr_style, value: meta_item, is_sugared_doc: bool};
/*
iface_refs appear in both impls and in classes that implement ifaces.
resolve maps each iface_ref's id to its defining iface.
trait_refs appear in both impls and in classes that implement traits.
resolve maps each trait_ref's id to its defining trait.
*/
#[auto_serialize]
type iface_ref = {path: @path, id: node_id};
type trait_ref = {path: @path, id: node_id};
#[auto_serialize]
enum visibility { public, private }
@ -686,7 +686,7 @@ enum item_ {
item_ty(@ty, ~[ty_param], region_param),
item_enum(~[variant], ~[ty_param], region_param),
item_class(~[ty_param], /* ty params for class */
~[@iface_ref], /* ifaces this class implements */
~[@trait_ref], /* traits this class implements */
~[@class_member], /* methods, etc. */
/* (not including ctor or dtor) */
class_ctor,
@ -694,8 +694,8 @@ enum item_ {
option<class_dtor>,
region_param
),
item_iface(~[ty_param], region_param, ~[ty_method]),
item_impl(~[ty_param], region_param, option<@iface_ref> /* iface */,
item_trait(~[ty_param], region_param, ~[ty_method]),
item_impl(~[ty_param], region_param, option<@trait_ref> /* trait */,
@ty /* self */, ~[@method]),
}

View File

@ -214,11 +214,11 @@ fn map_item(i: @item, cx: ctx, v: vt) {
extend(cx, i.ident)));
}
}
item_class(tps, ifces, items, ctor, dtor, _) {
item_class(tps, traits, items, ctor, dtor, _) {
let (_, ms) = ast_util::split_class_items(items);
// Map iface refs to their parent classes. This is
// Map trait refs to their parent classes. This is
// so we can find the self_ty
do vec::iter(ifces) |p| { cx.map.insert(p.id,
do vec::iter(traits) |p| { cx.map.insert(p.id,
node_item(i, item_path)); };
let d_id = ast_util::local_def(i.id);
let p = extend(cx, i.ident);

View File

@ -530,7 +530,7 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
}
let ser_bnds = @~[
ast::bound_iface(cx.ty_path(span,
ast::bound_trait(cx.ty_path(span,
~[@"std", @"serialization",
@"serializer"],
~[]))];
@ -736,7 +736,7 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
}
let deser_bnds = @~[
ast::bound_iface(cx.ty_path(
ast::bound_trait(cx.ty_path(
span,
~[@"std", @"serialization", @"deserializer"],
~[]))];

View File

@ -142,7 +142,7 @@ fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound {
alt tpb {
bound_copy | bound_send | bound_const { tpb }
bound_iface(ty) { bound_iface(fld.fold_ty(ty)) }
bound_trait(ty) { bound_trait(fld.fold_ty(ty)) }
}
}
@ -252,7 +252,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
fold_ty_params(typms, fld),
r)
}
item_class(typms, ifaces, items, ctor, m_dtor, rp) {
item_class(typms, traits, items, ctor, m_dtor, rp) {
let ctor_body = fld.fold_block(ctor.node.body);
let ctor_decl = fold_fn_decl(ctor.node.dec, fld);
let ctor_id = fld.new_id(ctor.node.id);
@ -264,7 +264,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
with dtor}};
item_class(
/* FIXME (#2543) */ copy typms,
vec::map(ifaces, |p| fold_iface_ref(p, fld)),
vec::map(traits, |p| fold_trait_ref(p, fld)),
vec::map(items, fld.fold_class_item),
{node: {body: ctor_body,
dec: ctor_decl,
@ -274,19 +274,19 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
item_impl(tps, rp, ifce, ty, methods) {
item_impl(fold_ty_params(tps, fld),
rp,
ifce.map(|p| fold_iface_ref(p, fld)),
ifce.map(|p| fold_trait_ref(p, fld)),
fld.fold_ty(ty),
vec::map(methods, fld.fold_method))
}
item_iface(tps, rp, methods) {
item_iface(fold_ty_params(tps, fld),
item_trait(tps, rp, methods) {
item_trait(fold_ty_params(tps, fld),
rp,
/* FIXME (#2543) */ copy methods)
}
};
}
fn fold_iface_ref(&&p: @iface_ref, fld: ast_fold) -> @iface_ref {
fn fold_trait_ref(&&p: @trait_ref, fld: ast_fold) -> @trait_ref {
@{path: fld.fold_path(p.path), id: fld.new_id(p.id)}
}

View File

@ -1892,7 +1892,7 @@ class parser {
else if self.eat_keyword("const") {
push(bounds, bound_const)
}
else { push(bounds, bound_iface(self.parse_ty(false))); }
else { push(bounds, bound_trait(self.parse_ty(false))); }
}
}
ret {ident: ident, id: self.get_id(), bounds: @bounds};
@ -2008,12 +2008,12 @@ class parser {
self_id: self.get_id(), vis: pr}
}
fn parse_item_iface() -> item_info {
fn parse_item_trait() -> item_info {
let ident = self.parse_ident();
let rp = self.parse_region_param();
let tps = self.parse_ty_params();
let meths = self.parse_ty_methods();
(ident, item_iface(tps, rp, meths), none)
(ident, item_trait(tps, rp, meths), none)
}
// Parses three variants (with the region/type params always optional):
@ -2082,15 +2082,15 @@ class parser {
}
}
fn parse_iface_ref() -> @iface_ref {
fn parse_trait_ref() -> @trait_ref {
@{path: self.parse_path_with_tps(false),
id: self.get_id()}
}
fn parse_iface_ref_list() -> ~[@iface_ref] {
fn parse_trait_ref_list() -> ~[@trait_ref] {
self.parse_seq_to_before_end(
token::LBRACE, seq_sep_trailing_disallowed(token::COMMA),
|p| p.parse_iface_ref())
|p| p.parse_trait_ref())
}
fn parse_item_class() -> item_info {
@ -2098,8 +2098,8 @@ class parser {
let rp = self.parse_region_param();
let ty_params = self.parse_ty_params();
let class_path = self.ident_to_path_tys(class_name, rp, ty_params);
let ifaces : ~[@iface_ref] = if self.eat(token::COLON)
{ self.parse_iface_ref_list() }
let traits : ~[@trait_ref] = if self.eat(token::COLON)
{ self.parse_trait_ref_list() }
else { ~[] };
self.expect(token::LBRACE);
let mut ms: ~[@class_member] = ~[];
@ -2127,7 +2127,7 @@ class parser {
alt the_ctor {
some((ct_d, ct_b, ct_s)) {
(class_name,
item_class(ty_params, ifaces, ms, {
item_class(ty_params, traits, ms, {
node: {id: ctor_id,
self_id: self.get_id(),
dec: ct_d,
@ -2462,7 +2462,9 @@ class parser {
} else if self.eat_keyword("enum") {
self.parse_item_enum(vis)
} else if self.eat_keyword("iface") {
self.parse_item_iface()
self.parse_item_trait()
} else if self.eat_keyword("trait") {
self.parse_item_trait()
} else if self.eat_keyword("impl") {
self.parse_item_impl()
} else if self.eat_keyword("class") {

View File

@ -494,14 +494,14 @@ fn print_item(s: ps, &&item: @ast::item) {
bclose(s, item.span);
}
}
ast::item_class(tps, ifaces, items, ctor, m_dtor, rp) {
ast::item_class(tps, traits, items, ctor, m_dtor, rp) {
head(s, "class");
word_nbsp(s, *item.ident);
print_region_param(s, rp);
print_type_params(s, tps);
if vec::len(ifaces) != 0u {
if vec::len(traits) != 0u {
word_space(s, ":");
commasep(s, inconsistent, ifaces, |s, p|
commasep(s, inconsistent, traits, |s, p|
print_path(s, p.path, false));
}
bopen(s);
@ -579,7 +579,7 @@ fn print_item(s: ps, &&item: @ast::item) {
}
bclose(s, item.span);
}
ast::item_iface(tps, rp, methods) {
ast::item_trait(tps, rp, methods) {
head(s, "iface");
word(s.s, *item.ident);
print_region_param(s, rp);
@ -1350,7 +1350,7 @@ fn print_bounds(s: ps, bounds: @~[ast::ty_param_bound]) {
ast::bound_copy { word(s.s, "copy"); }
ast::bound_send { word(s.s, "send"); }
ast::bound_const { word(s.s, "const"); }
ast::bound_iface(t) { print_type(s, t); }
ast::bound_trait(t) { print_type(s, t); }
}
}
}

View File

@ -143,19 +143,19 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
visit_method_helper(m, e, v)
}
}
item_class(tps, ifaces, members, ctor, m_dtor, _) {
item_class(tps, traits, members, ctor, m_dtor, _) {
v.visit_ty_params(tps, e, v);
for members.each |m| {
v.visit_class_item(m, e, v);
}
for ifaces.each |p| { visit_path(p.path, e, v); }
for traits.each |p| { visit_path(p.path, e, v); }
visit_class_ctor_helper(ctor, i.ident, tps,
ast_util::local_def(i.id), e, v);
do option::iter(m_dtor) |dtor| {
visit_class_dtor_helper(dtor, tps,
ast_util::local_def(i.id), e, v)};
}
item_iface(tps, _rp, methods) {
item_trait(tps, _rp, methods) {
v.visit_ty_params(tps, e, v);
for methods.each |m| {
for m.decl.inputs.each |a| { v.visit_ty(a.ty, e, v); }
@ -260,7 +260,7 @@ fn visit_ty_params<E>(tps: ~[ty_param], e: E, v: vt<E>) {
for tps.each |tp| {
for vec::each(*tp.bounds) |bound| {
alt bound {
bound_iface(t) { v.visit_ty(t, e, v); }
bound_trait(t) { v.visit_ty(t, e, v); }
bound_copy | bound_send | bound_const { }
}
}

View File

@ -106,7 +106,7 @@ mod intrinsic {
fn visit_leave_fn(purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool;
fn visit_iface() -> bool;
fn visit_trait() -> bool;
fn visit_enter_res() -> bool;
fn visit_leave_res() -> bool;
fn visit_var() -> bool;

View File

@ -380,8 +380,8 @@ impl of tr for method_origin {
typeck::method_param(did, m, p, b) {
typeck::method_param(did.tr(xcx), m, p, b)
}
typeck::method_iface(did, m) {
typeck::method_iface(did.tr(xcx), m)
typeck::method_trait(did, m) {
typeck::method_trait(did.tr(xcx), m)
}
}
}
@ -441,8 +441,8 @@ fn encode_vtable_origin(ecx: @e::encode_ctxt,
}
}
}
typeck::vtable_iface(def_id, tys) {
ebml_w.emit_enum_variant("vtable_iface", 1u, 3u) {||
typeck::vtable_trait(def_id, tys) {
ebml_w.emit_enum_variant("vtable_trait", 1u, 3u) {||
ebml_w.emit_enum_variant_arg(0u) {||
ebml_w.emit_def_id(def_id)
}
@ -490,7 +490,7 @@ impl helpers for ebml::ebml_deserializer {
)
}
2u {
typeck::vtable_iface(
typeck::vtable_trait(
self.read_enum_variant_arg(0u) {||
self.read_def_id(xcx)
},

View File

@ -70,8 +70,8 @@ const tag_crate_dep_vers: uint = 0x2cu;
const tag_mod_impl: uint = 0x30u;
const tag_item_iface_method: uint = 0x31u;
const tag_impl_iface: uint = 0x32u;
const tag_item_trait_method: uint = 0x31u;
const tag_impl_trait: uint = 0x32u;
// discriminator value for variants
const tag_disr_val: uint = 0x34u;
@ -85,13 +85,13 @@ const tag_item_field: uint = 0x44u;
const tag_class_mut: uint = 0x45u;
const tag_region_param: uint = 0x46u;
const tag_mod_impl_iface: uint = 0x47u;
const tag_mod_impl_trait: uint = 0x47u;
/*
iface items contain tag_item_iface_method elements,
trait items contain tag_item_trait_method elements,
impl items contain tag_item_impl_method elements, and classes
have both. That's because some code treats classes like ifaces,
have both. That's because some code treats classes like traits,
and other code treats them like impls. Because classes can contain
both, tag_item_iface_method and tag_item_impl_method have to be two
both, tag_item_trait_method and tag_item_impl_method have to be two
different tags.
*/
const tag_item_impl_method: uint = 0x48u;

View File

@ -21,10 +21,10 @@ export lookup_defs;
export lookup_method_purity;
export get_enum_variants;
export get_impls_for_mod;
export get_iface_methods;
export get_trait_methods;
export each_path;
export get_type;
export get_impl_iface;
export get_impl_trait;
export get_impl_method;
export get_item_path;
export maybe_get_item_ast, found_ast, found, found_parent, not_found;
@ -133,10 +133,10 @@ fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,
}
}
fn get_iface_methods(tcx: ty::ctxt, def: ast::def_id) -> @~[ty::method] {
fn get_trait_methods(tcx: ty::ctxt, def: ast::def_id) -> @~[ty::method] {
let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_iface_methods(cdata, def.node, tcx)
decoder::get_trait_methods(cdata, def.node, tcx)
}
fn get_class_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] {
@ -171,12 +171,12 @@ fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
ret {bounds: @~[], rp: ast::rp_none, ty: ty};
}
// Given a def_id for an impl or class, return the iface it implements,
// or none if it's not for an impl or for a class that implements ifaces
fn get_impl_iface(tcx: ty::ctxt, def: ast::def_id) -> option<ty::t> {
// Given a def_id for an impl or class, return the trait it implements,
// or none if it's not for an impl or for a class that implements traits
fn get_impl_trait(tcx: ty::ctxt, def: ast::def_id) -> option<ty::t> {
let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_impl_iface(cdata, def.node, tcx)
decoder::get_impl_trait(cdata, def.node, tcx)
}
fn get_impl_method(cstore: cstore::cstore,
@ -186,8 +186,8 @@ fn get_impl_method(cstore: cstore::cstore,
decoder::get_impl_method(cdata, def.node, mname)
}
/* Because classes use the iface format rather than the impl format
for their methods (so that get_iface_methods can be reused to get
/* Because classes use the trait format rather than the impl format
for their methods (so that get_trait_methods can be reused to get
class methods), classes require a slightly different version of
get_impl_method. Sigh. */
fn get_class_method(cstore: cstore::cstore,

View File

@ -22,7 +22,7 @@ export get_symbol;
export get_enum_variants;
export get_type;
export get_type_param_count;
export get_impl_iface;
export get_impl_trait;
export get_class_method;
export get_impl_method;
export lookup_def;
@ -35,7 +35,7 @@ export get_crate_deps;
export get_crate_hash;
export get_crate_vers;
export get_impls_for_mod;
export get_iface_methods;
export get_trait_methods;
export get_crate_module_paths;
export def_like;
export dl_def;
@ -164,10 +164,10 @@ fn item_type(item_id: ast::def_id, item: ebml::doc,
} else { t }
}
fn item_impl_iface(item: ebml::doc, tcx: ty::ctxt, cdata: cmd)
fn item_impl_trait(item: ebml::doc, tcx: ty::ctxt, cdata: cmd)
-> option<ty::t> {
let mut result = none;
do ebml::tagged_docs(item, tag_impl_iface) |ity| {
do ebml::tagged_docs(item, tag_impl_trait) |ity| {
result = some(doc_type(ity, tcx, cdata));
};
result
@ -328,9 +328,9 @@ fn get_type_param_count(data: @~[u8], id: ast::node_id) -> uint {
item_ty_param_count(lookup_item(id, data))
}
fn get_impl_iface(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
fn get_impl_trait(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
-> option<ty::t> {
item_impl_iface(lookup_item(id, cdata.data), tcx, cdata)
item_impl_trait(lookup_item(id, cdata.data), tcx, cdata)
}
fn get_impl_method(cdata: cmd, id: ast::node_id,
@ -354,7 +354,7 @@ fn get_class_method(cdata: cmd, id: ast::node_id,
some(it) { it }
none { fail (#fmt("get_class_method: class id not found \
when looking up method %s", *name)) }};
do ebml::tagged_docs(cls_items, tag_item_iface_method) |mid| {
do ebml::tagged_docs(cls_items, tag_item_trait_method) |mid| {
let m_did = class_member_id(mid, cdata);
if item_name(mid) == name {
found = some(m_did);
@ -601,20 +601,20 @@ fn get_impls_for_mod(cdata: cmd,
@result
}
/* Works for both classes and ifaces */
fn get_iface_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
/* Works for both classes and traits */
fn get_trait_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
-> @~[ty::method] {
let data = cdata.data;
let item = lookup_item(id, data);
let mut result = ~[];
do ebml::tagged_docs(item, tag_item_iface_method) |mth| {
do ebml::tagged_docs(item, tag_item_trait_method) |mth| {
let bounds = item_ty_param_bounds(mth, tcx, cdata);
let name = item_name(mth);
let ty = doc_type(mth, tcx, cdata);
let fty = alt ty::get(ty).struct { ty::ty_fn(f) { f }
_ {
tcx.diag.handler().bug(
"get_iface_methods: id has non-function type");
"get_trait_methods: id has non-function type");
} };
vec::push(result, {ident: name, tps: bounds, fty: fty,
purity: alt check item_family(mth) {
@ -703,7 +703,7 @@ fn item_family_to_str(fam: char) -> str {
'n' { ret "foreign mod"; }
'v' { ret "enum"; }
'i' { ret "impl"; }
'I' { ret "iface"; }
'I' { ret "trait"; }
'C' { ret "class"; }
'g' { ret "public field"; }
'j' { ret "private field"; }

View File

@ -211,7 +211,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
}
encode_enum_variant_paths(ebml_w, variants, path, index);
}
item_iface(*) {
item_trait(*) {
do ebml_w.wr_tag(tag_paths_data_item) {
encode_name_and_def_id(ebml_w, it.ident, it.id);
}
@ -221,8 +221,8 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
}
}
fn encode_iface_ref(ebml_w: ebml::writer, ecx: @encode_ctxt, t: @iface_ref) {
ebml_w.start_tag(tag_impl_iface);
fn encode_trait_ref(ebml_w: ebml::writer, ecx: @encode_ctxt, t: @trait_ref) {
ebml_w.start_tag(tag_impl_trait);
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, t.id));
ebml_w.end_tag();
}
@ -396,7 +396,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
ebml_w.start_tag(tag_mod_impl);
alt ecx.tcx.items.find(did.node) {
some(ast_map::node_item(it@@{node: cl@item_class(*),_},_)) {
/* If did stands for an iface
/* If did stands for a trait
ref, we need to map it to its parent class */
ebml_w.wr_str(def_to_str(local_def(it.id)));
}
@ -622,7 +622,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_enum_variant_info(ecx, ebml_w, item.id, variants,
path, index, tps);
}
item_class(tps, ifaces, items, ctor, m_dtor, rp) {
item_class(tps, traits, items, ctor, m_dtor, rp) {
/* First, encode the fields and methods
These come first because we need to write them to make
the index, and the index needs to be in the item for the
@ -650,8 +650,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_name(ebml_w, item.ident);
encode_path(ebml_w, path, ast_map::path_name(item.ident));
encode_region_param(ebml_w, rp);
for ifaces.each |t| {
encode_iface_ref(ebml_w, ecx, t);
for traits.each |t| {
encode_trait_ref(ebml_w, ecx, t);
}
/* Encode the dtor */
/* Encode id for dtor */
@ -662,7 +662,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
};
/* Encode def_ids for each field and method
for methods, write all the stuff get_iface_method
for methods, write all the stuff get_trait_method
needs to know*/
let (fs,ms) = ast_util::split_class_items(items);
for fs.each |f| {
@ -677,8 +677,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
private { /* do nothing */ }
public {
/* Write the info that's needed when viewing this class
as an iface */
ebml_w.start_tag(tag_item_iface_method);
as a trait */
ebml_w.start_tag(tag_item_trait_method);
encode_family(ebml_w, purity_fn_family(m.decl.purity));
encode_name(ebml_w, m.ident);
encode_type_param_bounds(ebml_w, ecx, m.tps);
@ -713,7 +713,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
ebml_w.end_tag();
}
do option::iter(ifce) |t| {
encode_iface_ref(ebml_w, ecx, t)
encode_trait_ref(ebml_w, ecx, t)
};
encode_path(ebml_w, path, ast_map::path_name(item.ident));
ebml_w.end_tag();
@ -727,7 +727,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
vec::append(tps, m.tps));
}
}
item_iface(tps, rp, ms) {
item_trait(tps, rp, ms) {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
@ -737,8 +737,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
encode_name(ebml_w, item.ident);
let mut i = 0u;
for vec::each(*ty::iface_methods(tcx, local_def(item.id))) |mty| {
ebml_w.start_tag(tag_item_iface_method);
for vec::each(*ty::trait_methods(tcx, local_def(item.id))) |mty| {
ebml_w.start_tag(tag_item_trait_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));

View File

@ -290,7 +290,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
let def = parse_def(st, conv);
let substs = parse_substs(st, conv);
assert next(st) == ']';
ret ty::mk_iface(st.tcx, def, substs);
ret ty::mk_trait(st.tcx, def, substs);
}
'p' {
let did = parse_def(st, conv);
@ -505,7 +505,7 @@ fn parse_bounds(st: @pstate, conv: conv_did) -> @~[ty::param_bound] {
'S' { ty::bound_send }
'C' { ty::bound_copy }
'K' { ty::bound_const }
'I' { ty::bound_iface(parse_ty(st, conv)) }
'I' { ty::bound_trait(parse_ty(st, conv)) }
'.' { break; }
});
}

View File

@ -222,7 +222,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
enc_substs(w, cx, substs);
w.write_char(']');
}
ty::ty_iface(def, substs) {
ty::ty_trait(def, substs) {
w.write_str("x["/&);
w.write_str(cx.ds(def));
w.write_char('|');
@ -401,7 +401,7 @@ fn enc_bounds(w: io::writer, cx: @ctxt, bs: @~[ty::param_bound]) {
ty::bound_send { w.write_char('S'); }
ty::bound_copy { w.write_char('C'); }
ty::bound_const { w.write_char('K'); }
ty::bound_iface(tp) {
ty::bound_trait(tp) {
w.write_char('I');
enc_ty(w, cx, tp);
}

View File

@ -395,10 +395,10 @@ impl of tr for method_origin {
typeck::method_static(did.tr(xcx))
}
typeck::method_param(mp) {
typeck::method_param({iface_id:mp.iface_id.tr(xcx) with mp})
typeck::method_param({trait_id:mp.trait_id.tr(xcx) with mp})
}
typeck::method_iface(did, m) {
typeck::method_iface(did.tr(xcx), m)
typeck::method_trait(did, m) {
typeck::method_trait(did.tr(xcx), m)
}
}
}
@ -458,8 +458,8 @@ fn encode_vtable_origin(ecx: @e::encode_ctxt,
}
}
}
typeck::vtable_iface(def_id, tys) {
do ebml_w.emit_enum_variant("vtable_iface", 1u, 3u) {
typeck::vtable_trait(def_id, tys) {
do ebml_w.emit_enum_variant("vtable_trait", 1u, 3u) {
do ebml_w.emit_enum_variant_arg(0u) {
ebml_w.emit_def_id(def_id)
}
@ -507,7 +507,7 @@ impl helpers for ebml::ebml_deserializer {
)
}
2u {
typeck::vtable_iface(
typeck::vtable_trait(
do self.read_enum_variant_arg(0u) {
self.read_def_id(xcx)
},

View File

@ -265,16 +265,16 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
// and then the method bounds themselves...
ty::lookup_item_type(cx.tcx, did).bounds
}
typeck::method_param({iface_id:ifce_id,
typeck::method_param({trait_id:trt_id,
method_num:n_mth, _}) |
typeck::method_iface(ifce_id, n_mth) {
// ...iface methods bounds, in contrast, include only the
typeck::method_trait(trt_id, n_mth) {
// ...trait methods bounds, in contrast, include only the
// method bounds, so we must preprend the tps from the
// iface itself. This ought to be harmonized.
let ifce_bounds =
ty::lookup_item_type(cx.tcx, ifce_id).bounds;
let mth = ty::iface_methods(cx.tcx, ifce_id)[n_mth];
@(vec::append(*ifce_bounds, *mth.tps))
// trait itself. This ought to be harmonized.
let trt_bounds =
ty::lookup_item_type(cx.tcx, trt_id).bounds;
let mth = ty::trait_methods(cx.tcx, trt_id)[n_mth];
@(vec::append(*trt_bounds, *mth.tps))
}
}
}

View File

@ -406,7 +406,7 @@ fn maybe_insert(e: @env, id: node_id, def: option<def>) {
}
}
fn resolve_iface_ref(p: @iface_ref, sc: scopes, e: @env) {
fn resolve_trait_ref(p: @trait_ref, sc: scopes, e: @env) {
maybe_insert(e, p.id,
lookup_path_strict(*e, sc, p.path.span, p.path, ns_type));
}
@ -436,15 +436,15 @@ fn resolve_names(e: @env, c: @ast::crate) {
fn walk_item(e: @env, i: @ast::item, &&sc: scopes, v: vt<scopes>) {
visit_item_with_scope(e, i, sc, v);
alt i.node {
/* At this point, the code knows what ifaces the iface refs
/* At this point, the code knows what traits the trait refs
refer to, so it's possible to resolve them.
*/
ast::item_impl(_, _, ifce, _, _) {
ifce.iter(|p| resolve_iface_ref(p, sc, e))
ifce.iter(|p| resolve_trait_ref(p, sc, e))
}
ast::item_class(_, ifaces, _, _, _, _) {
for ifaces.each |p| {
resolve_iface_ref(p, sc, e);
ast::item_class(_, traits, _, _, _, _) {
for traits.each |p| {
resolve_trait_ref(p, sc, e);
}
}
_ {}
@ -485,7 +485,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
e.current_tp = some(current);
for vec::each(*tp.bounds) |bound| {
alt bound {
bound_iface(t) { v.visit_ty(t, sc, v); }
bound_trait(t) { v.visit_ty(t, sc, v); }
_ {}
}
}
@ -564,7 +564,7 @@ fn visit_item_with_scope(e: @env, i: @ast::item,
m.decl, m.body, m.span, m.id, msc, v);
}
}
ast::item_iface(tps, _, methods) {
ast::item_trait(tps, _, methods) {
v.visit_ty_params(tps, sc, v);
let isc = @cons(scope_method(i.id, tps), sc);
for methods.each |m| {
@ -574,14 +574,14 @@ fn visit_item_with_scope(e: @env, i: @ast::item,
v.visit_ty(m.decl.output, msc, v);
}
}
ast::item_class(tps, ifaces, members, ctor, m_dtor, _) {
ast::item_class(tps, traits, members, ctor, m_dtor, _) {
v.visit_ty_params(tps, sc, v);
let class_scope = @cons(scope_item(i), sc);
/* visit the constructor... */
let ctor_scope = @cons(scope_method(ctor.node.self_id, tps),
class_scope);
/* visit the iface refs in the class scope */
for ifaces.each |p| {
/* visit the trait refs in the class scope */
for traits.each |p| {
visit::visit_path(p.path, class_scope, v);
}
visit_fn_with_scope(e, visit::fk_ctor(i.ident, tps, ctor.node.self_id,
@ -1048,7 +1048,7 @@ fn lookup_in_scope(e: env, &&sc: scopes, sp: span, name: ident, ns: namespace,
ast::item_enum(_, tps, _) | ast::item_ty(_, tps, _) {
if ns == ns_type { ret lookup_in_ty_params(e, name, tps); }
}
ast::item_iface(tps, _, _) {
ast::item_trait(tps, _, _) {
if ns == ns_type {
if *name == "self" {
ret some(def_self(it.id));
@ -1336,7 +1336,7 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option<def> {
ret some(ast::def_foreign_mod(local_def(i.id)));
}
}
ast::item_ty(*) | item_iface(*) | item_enum(*) {
ast::item_ty(*) | item_trait(*) | item_enum(*) {
if ns == ns_type { ret some(ast::def_ty(local_def(i.id))); }
}
ast::item_class(_, _, _members, ct, _, _) {
@ -1641,7 +1641,7 @@ fn index_mod(md: ast::_mod) -> mod_index {
alt it.node {
ast::item_const(_, _) | ast::item_fn(_, _, _) | ast::item_mod(_) |
ast::item_foreign_mod(_) | ast::item_ty(_, _, _) |
ast::item_impl(*) | ast::item_iface(*) {
ast::item_impl(*) | ast::item_trait(*) {
add_to_index(index, it.ident, mie_item(it));
}
ast::item_enum(variants, _, _) {
@ -1780,7 +1780,7 @@ fn check_item(e: @env, i: @ast::item, &&x: (), v: vt<()>) {
ensure_unique(*e, i.span, ty_params, |tp| tp.ident,
"type parameter");
}
ast::item_iface(_, _, methods) {
ast::item_trait(_, _, methods) {
ensure_unique(*e, i.span, methods, |m| m.ident,
"method");
}
@ -1862,7 +1862,7 @@ fn check_block(e: @env, b: ast::blk, &&x: (), v: vt<()>) {
ast::item_const(_, _) | ast::item_fn(*) {
add_name(values, it.span, it.ident);
}
ast::item_ty(*) | ast::item_iface(*) {
ast::item_ty(*) | ast::item_trait(*) {
add_name(types, it.span, it.ident);
}
_ { }
@ -2146,7 +2146,7 @@ type method_info = {did: def_id, n_tps: uint, ident: ast::ident};
* did: the def id of the class or impl item
* ident: the name of the impl, unless it has no name (as in
"impl of X") in which case the ident
is the ident of the iface that's being implemented
is the ident of the trait that's being implemented
* methods: the item's methods
*/
type _impl = {did: def_id, ident: ast::ident, methods: ~[@method_info]};
@ -2258,7 +2258,7 @@ fn find_impls_in_item(e: env, i: @ast::item, &impls: ~[@_impl],
let n_tps = tps.len();
do vec::iter(ifces) |p| {
// The def_id, in this case, identifies the combination of
// class and iface
// class and trait
vec::push(impls, @{did: local_def(p.id),
ident: i.ident,
methods: vec::map(mthds, |m| {

View File

@ -2,7 +2,7 @@ import driver::session::session;
import metadata::csearch::{each_path, get_impls_for_mod, lookup_defs};
import metadata::cstore::find_use_stmt_cnum;
import metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
import syntax::ast::{_mod, arm, blk, bound_const, bound_copy, bound_iface};
import syntax::ast::{_mod, arm, blk, bound_const, bound_copy, bound_trait};
import syntax::ast::{bound_send, capture_clause, class_ctor, class_dtor};
import syntax::ast::{class_member, class_method, crate, crate_num, decl_item};
import syntax::ast::{def, def_arg, def_binding, def_class, def_const, def_fn};
@ -12,9 +12,9 @@ import syntax::ast::{def_upvar, def_use, def_variant, expr, expr_assign_op};
import syntax::ast::{expr_binary, expr_cast, expr_field, expr_fn};
import syntax::ast::{expr_fn_block, expr_index, expr_new, expr_path};
import syntax::ast::{expr_unary, fn_decl, foreign_item, foreign_item_fn};
import syntax::ast::{ident, iface_ref, impure_fn, instance_var, item};
import syntax::ast::{ident, trait_ref, impure_fn, instance_var, item};
import syntax::ast::{item_class, item_const, item_enum, item_fn};
import syntax::ast::{item_foreign_mod, item_iface, item_impl, item_mod};
import syntax::ast::{item_foreign_mod, item_trait, item_impl, item_mod};
import syntax::ast::{item_ty, local, local_crate, method, node_id, pat};
import syntax::ast::{pat_enum, pat_ident, path, prim_ty, stmt_decl, ty};
import syntax::ast::{ty_bool, ty_char, ty_constr, ty_f, ty_f32, ty_f64};
@ -867,7 +867,7 @@ class Resolver {
visit_item(item, new_parent, visitor);
}
item_iface(*) {
item_trait(*) {
(*name_bindings).define_type(def_ty(local_def(item.id)));
visit_item(item, new_parent, visitor);
}
@ -1233,7 +1233,7 @@ class Resolver {
fn build_reduced_graph_for_impls_in_external_module(module: @Module) {
// XXX: This is really unfortunate. decoder::each_path can produce
// false positives, since, in the crate metadata, an iface named 'bar'
// false positives, since, in the crate metadata, a trait named 'bar'
// in module 'foo' defining a method named 'baz' will result in the
// creation of a (bogus) path entry named 'foo::bar::baz', and we will
// create a module node for "bar". We can identify these fake modules
@ -2747,7 +2747,7 @@ class Resolver {
visitor);
}
item_iface(type_parameters, _, methods) {
item_trait(type_parameters, _, methods) {
// Create a new rib for the self type.
let self_type_rib = @Rib(NormalRibKind);
(*self.type_ribs).push(self_type_rib);
@ -3013,7 +3013,7 @@ class Resolver {
bound_copy | bound_send | bound_const {
// Nothing to do.
}
bound_iface(interface_type) {
bound_trait(interface_type) {
self.resolve_type(interface_type, visitor);
}
}
@ -3023,14 +3023,14 @@ class Resolver {
fn resolve_class(id: node_id,
type_parameters: @~[ty_param],
interfaces: ~[@iface_ref],
interfaces: ~[@trait_ref],
class_members: ~[@class_member],
constructor: class_ctor,
optional_destructor: option<class_dtor>,
visitor: ResolveVisitor) {
// Add a type into the def map. This is needed to prevent an ICE in
// ty::impl_iface.
// ty::impl_trait.
// If applicable, create a rib for the type parameters.
let outer_type_parameter_count = (*type_parameters).len();
@ -3055,7 +3055,7 @@ class Resolver {
// definition of the interface into the definition
// map.
#debug("(resolving class) found iface def: %?", def);
#debug("(resolving class) found trait def: %?", def);
self.record_def(interface.id, def);
@ -3122,7 +3122,7 @@ class Resolver {
fn resolve_implementation(id: node_id,
span: span,
type_parameters: ~[ty_param],
interface_reference: option<@iface_ref>,
interface_reference: option<@trait_ref>,
self_type: @ty,
methods: ~[@method],
visitor: ResolveVisitor) {

View File

@ -652,7 +652,7 @@ fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
ty::ty_fn(_) {
closure::make_fn_glue(bcx, v, t, take_ty)
}
ty::ty_iface(_, _) {
ty::ty_trait(_, _) {
let llbox = Load(bcx, GEPi(bcx, v, ~[0u, 1u]));
incr_refcnt_of_boxed(bcx, llbox);
bcx
@ -682,10 +682,10 @@ fn incr_refcnt_of_boxed(cx: block, box_ptr: ValueRef) {
fn make_visit_glue(bcx: block, v: ValueRef, t: ty::t) {
let _icx = bcx.insn_ctxt("make_visit_glue");
let mut bcx = bcx;
assert bcx.ccx().tcx.intrinsic_ifaces.contains_key(@"ty_visitor");
let (iid, ty) = bcx.ccx().tcx.intrinsic_ifaces.get(@"ty_visitor");
assert bcx.ccx().tcx.intrinsic_traits.contains_key(@"ty_visitor");
let (iid, ty) = bcx.ccx().tcx.intrinsic_traits.get(@"ty_visitor");
let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty)));
bcx = reflect::emit_calls_to_iface_visit_ty(bcx, t, v, iid);
bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, iid);
build_return(bcx);
}
@ -808,7 +808,7 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
ty::ty_fn(_) {
closure::make_fn_glue(bcx, v0, t, drop_ty)
}
ty::ty_iface(_, _) {
ty::ty_trait(_, _) {
let llbox = Load(bcx, GEPi(bcx, v0, ~[0u, 1u]));
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
}
@ -2063,7 +2063,7 @@ fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> option<ty::t> {
output: ty::mk_nil(tcx),
ret_style: ast::return_val,
constraints: ~[]})) }
ty::ty_iface(_, _) { some(ty::mk_fn(tcx, {purity: ast::impure_fn,
ty::ty_trait(_, _) { some(ty::mk_fn(tcx, {purity: ast::impure_fn,
proto: ast::proto_box,
inputs: ~[],
output: ty::mk_nil(tcx),
@ -2085,7 +2085,7 @@ fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
let mut v = ~[];
for vec::each(*bounds) |bound| {
alt bound {
ty::bound_iface(_) {
ty::bound_trait(_) {
vec::push(v, impl::vtable_id(ccx, vts[i]));
i += 1u;
}
@ -2822,7 +2822,7 @@ fn trans_cast(cx: block, e: @ast::expr, id: ast::node_id,
let ccx = cx.ccx();
let t_out = node_id_type(cx, id);
alt ty::get(t_out).struct {
ty::ty_iface(_, _) { ret impl::trans_cast(cx, e, id, dest); }
ty::ty_trait(_, _) { ret impl::trans_cast(cx, e, id, dest); }
_ {}
}
let e_res = trans_temp_expr(cx, e);
@ -4964,7 +4964,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
};
foreign::trans_foreign_mod(ccx, foreign_mod, abi);
}
ast::item_class(tps, _ifaces, items, ctor, m_dtor, _) {
ast::item_class(tps, _traits, items, ctor, m_dtor, _) {
if tps.len() == 0u {
let psubsts = {tys: ty::ty_params_to_tys(ccx.tcx, tps),
vtables: none,

View File

@ -783,7 +783,7 @@ fn T_captured_tydescs(cx: @crate_ctxt, n: uint) -> TypeRef {
ret T_struct(vec::from_elem::<TypeRef>(n, T_ptr(cx.tydesc_type)));
}
fn T_opaque_iface(cx: @crate_ctxt) -> TypeRef {
fn T_opaque_trait(cx: @crate_ctxt) -> TypeRef {
T_struct(~[T_ptr(cx.tydesc_type), T_opaque_box_ptr(cx)])
}

View File

@ -58,7 +58,7 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
{env: self_env(val, node_id_type(bcx, self.id), none)
with lval_static_fn(bcx, did, callee_id)}
}
typeck::method_param({iface_id:iid, method_num:off,
typeck::method_param({trait_id:iid, method_num:off,
param_num:p, bound_num:b}) {
alt check bcx.fcx.param_substs {
some(substs) {
@ -67,10 +67,10 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
}
}
}
typeck::method_iface(_, off) {
typeck::method_trait(_, off) {
let {bcx, val} = trans_temp_expr(bcx, self);
let fty = node_id_type(bcx, callee_id);
trans_iface_callee(bcx, val, fty, off)
trans_trait_callee(bcx, val, fty, off)
}
}
}
@ -112,14 +112,14 @@ fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id,
fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id,
base: @ast::expr, derefs: uint,
iface_id: ast::def_id, n_method: uint,
trait_id: ast::def_id, n_method: uint,
n_param: uint, n_bound: uint,
substs: param_substs) -> lval_maybe_callee {
let _icx = bcx.insn_ctxt("impl::trans_monomorphized_callee");
alt find_vtable_in_fn_ctxt(substs, n_param, n_bound) {
typeck::vtable_static(impl_did, impl_substs, sub_origins) {
let ccx = bcx.ccx();
let mname = ty::iface_methods(ccx.tcx, iface_id)[n_method].ident;
let mname = ty::trait_methods(ccx.tcx, trait_id)[n_method].ident;
let mth_id = method_with_name(bcx.ccx(), impl_did, mname);
let n_m_tps = method_ty_param_count(ccx, mth_id, impl_did);
let node_substs = node_id_type_params(bcx, callee_id);
@ -135,10 +135,10 @@ fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id,
ccx, node_id_type(bcx, callee_id))))
with lval}
}
typeck::vtable_iface(iid, tps) {
typeck::vtable_trait(iid, tps) {
let {bcx, val} = trans_temp_expr(bcx, base);
let fty = node_id_type(bcx, callee_id);
trans_iface_callee(bcx, val, fty, n_method)
trans_trait_callee(bcx, val, fty, n_method)
}
typeck::vtable_param(n_param, n_bound) {
fail "vtable_param left in monomorphized function's vtable substs";
@ -146,11 +146,11 @@ fn trans_monomorphized_callee(bcx: block, callee_id: ast::node_id,
}
}
// Method callee where the vtable comes from a boxed iface
fn trans_iface_callee(bcx: block, val: ValueRef,
// Method callee where the vtable comes from a boxed trait
fn trans_trait_callee(bcx: block, val: ValueRef,
callee_ty: ty::t, n_method: uint)
-> lval_maybe_callee {
let _icx = bcx.insn_ctxt("impl::trans_iface_callee");
let _icx = bcx.insn_ctxt("impl::trans_trait_callee");
let ccx = bcx.ccx();
let vtable = Load(bcx, PointerCast(bcx, GEPi(bcx, val, ~[0u, 0u]),
T_ptr(T_ptr(T_vtable()))));
@ -173,7 +173,7 @@ fn find_vtable_in_fn_ctxt(ps: param_substs, n_param: uint, n_bound: uint)
for vec::each(*ps.bounds) |bounds| {
if i >= n_param { break; }
for vec::each(*bounds) |bound| {
alt bound { ty::bound_iface(_) { vtable_off += 1u; } _ {} }
alt bound { ty::bound_trait(_) { vtable_off += 1u; } _ {} }
}
i += 1u;
}
@ -215,8 +215,8 @@ fn vtable_id(ccx: @crate_ctxt, origin: typeck::vtable_origin) -> mono_id {
if (*sub_vtables).len() == 0u { none }
else { some(sub_vtables) }, none)
}
typeck::vtable_iface(iface_id, substs) {
@{def: iface_id,
typeck::vtable_trait(trait_id, substs) {
@{def: trait_id,
params: vec::map(substs, |t| mono_precise(t, none))}
}
}
@ -254,11 +254,11 @@ fn make_impl_vtable(ccx: @crate_ctxt, impl_id: ast::def_id, substs: ~[ty::t],
let _icx = ccx.insn_ctxt("impl::make_impl_vtable");
let tcx = ccx.tcx;
let ifce_id = expect(ccx.sess,
ty::ty_to_def_id(option::get(ty::impl_iface(tcx,
ty::ty_to_def_id(option::get(ty::impl_trait(tcx,
impl_id))),
|| "make_impl_vtable: non-iface-type implemented");
|| "make_impl_vtable: non-trait-type implemented");
let has_tps = (*ty::lookup_item_type(ccx.tcx, impl_id).bounds).len() > 0u;
make_vtable(ccx, vec::map(*ty::iface_methods(tcx, ifce_id), |im| {
make_vtable(ccx, vec::map(*ty::trait_methods(tcx, ifce_id), |im| {
let fty = ty::subst_tps(tcx, substs, ty::mk_fn(tcx, im.fty));
if (*im.tps).len() > 0u || ty::type_has_self(fty) {
C_null(T_ptr(T_nil()))

View File

@ -121,7 +121,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
}
}
}
item_class(tps, _ifaces, items, ctor, m_dtor, _) {
item_class(tps, _traits, items, ctor, m_dtor, _) {
cx.rmap.insert(ctor.node.id, ());
do option::iter(m_dtor) |dtor| {
cx.rmap.insert(dtor.node.id, ());
@ -147,7 +147,7 @@ fn traverse_public_item(cx: ctx, item: @item) {
traverse_ty(t, cx, mk_ty_visitor());
}
item_const(*) |
item_enum(*) | item_iface(*) {}
item_enum(*) | item_trait(*) {}
}
}

View File

@ -47,7 +47,7 @@ impl methods for reflector {
let v = self.visitor_val;
let get_lval = |bcx| {
let callee =
impl::trans_iface_callee(bcx, v, mth_ty, mth_idx);
impl::trans_trait_callee(bcx, v, mth_ty, mth_idx);
#debug("calling mth ty %s, lltype %s",
ty_to_str(bcx.ccx().tcx, mth_ty),
val_str(bcx.ccx().tn, callee.val));
@ -256,7 +256,7 @@ impl methods for reflector {
}
// Miscallaneous extra types
ty::ty_iface(_, _) { self.leaf("iface") }
ty::ty_trait(_, _) { self.leaf("trait") }
ty::ty_var(_) { self.leaf("var") }
ty::ty_var_integral(_) { self.leaf("var_integral") }
ty::ty_param(n, _) { self.visit("param", ~[self.c_uint(n)]) }
@ -278,13 +278,13 @@ impl methods for reflector {
}
// Emit a sequence of calls to visit_ty::visit_foo
fn emit_calls_to_iface_visit_ty(bcx: block, t: ty::t,
fn emit_calls_to_trait_visit_ty(bcx: block, t: ty::t,
visitor_val: ValueRef,
visitor_iid: def_id) -> block {
let r = reflector({
visitor_val: visitor_val,
visitor_methods: ty::iface_methods(bcx.tcx(), visitor_iid),
visitor_methods: ty::trait_methods(bcx.tcx(), visitor_iid),
mut bcx: bcx
});

View File

@ -329,7 +329,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
add_substr(s, sub);
s
}
ty::ty_iface(_, _) { ~[shape_box_fn] }
ty::ty_trait(_, _) { ~[shape_box_fn] }
ty::ty_class(did, substs) {
// same as records, unless there's a dtor
let tps = substs.tps;

View File

@ -140,7 +140,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
T_struct(tys)
}
ty::ty_fn(_) { T_fn_pair(cx, type_of_fn_from_ty(cx, t)) }
ty::ty_iface(_, _) { T_opaque_iface(cx) }
ty::ty_trait(_, _) { T_opaque_trait(cx) }
ty::ty_type { T_ptr(cx.tydesc_type) }
ty::ty_tup(elts) {
let mut tys = ~[];

View File

@ -119,12 +119,12 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t,
alt ty::get(ty).struct {
/*
This previously included ty_box -- that was wrong
because if we cast an @T to an iface (for example) and return
because if we cast an @T to an trait (for example) and return
it, we depend on the drop glue for T (we have to write the
right tydesc into the result)
*/
ty::ty_fn(_) | ty::ty_ptr(_) | ty::ty_rptr(_, _)
| ty::ty_iface(_, _) { false }
| ty::ty_trait(_, _) { false }
ty::ty_enum(did, substs) {
if option::is_none(list::find(enums_seen, |id| id == did)) {
let seen = @cons(did, enums_seen);
@ -164,8 +164,8 @@ fn mark_for_expr(cx: ctx, e: @expr) {
expr_cast(base, _) {
let result_t = ty::node_id_to_type(cx.ccx.tcx, e.id);
alt ty::get(result_t).struct {
ty::ty_iface(*) {
// When we're casting to an iface, we need the
ty::ty_trait(*) {
// When we're casting to an trait, we need the
// tydesc for the expr that's being cast.
node_type_needs(cx, use_tydesc, base.id);
}
@ -221,7 +221,7 @@ fn mark_for_expr(cx: ctx, e: @expr) {
typeck::method_param({param_num: param, _}) {
cx.uses[param] |= use_tydesc;
}
typeck::method_iface(_, _) {}
typeck::method_trait(_, _) {}
}
}
}

View File

@ -48,7 +48,7 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
}
item_mod(m) { find_pre_post_mod(m); }
item_foreign_mod(nm) { find_pre_post_foreign_mod(nm); }
item_ty(*) | item_enum(*) | item_iface(*) { ret; }
item_ty(*) | item_enum(*) | item_trait(*) { ret; }
item_class(*) {
fail "find_pre_post_item: shouldn't be called on item_class";
}

View File

@ -69,7 +69,7 @@ export subst, subst_tps, substs_is_noop, substs_to_str, substs;
export t;
export new_ty_hash;
export enum_variants, substd_enum_variants, enum_is_univariant;
export iface_methods, store_iface_methods, impl_iface;
export trait_methods, store_trait_methods, impl_trait;
export enum_variant_with_id;
export ty_dtor;
export ty_param_bounds_and_ty;
@ -92,7 +92,7 @@ export ty_evec, mk_evec;
export ty_unboxed_vec, mk_unboxed_vec, mk_mut_unboxed_vec;
export vstore, vstore_fixed, vstore_uniq, vstore_box, vstore_slice;
export ty_nil, mk_nil, type_is_nil;
export ty_iface, mk_iface;
export ty_trait, mk_trait;
export ty_param, mk_param, ty_params_to_tys;
export ty_ptr, mk_ptr, mk_mut_ptr, mk_imm_ptr, mk_nil_ptr, type_is_unsafe_ptr;
export ty_rptr, mk_rptr;
@ -154,7 +154,7 @@ export closure_kind;
export ck_block;
export ck_box;
export ck_uniq;
export param_bound, param_bounds, bound_copy, bound_send, bound_iface;
export param_bound, param_bounds, bound_copy, bound_send, bound_trait;
export param_bounds_to_kind;
export default_arg_mode_for_ty;
export item_path;
@ -240,7 +240,7 @@ type ctxt =
node_type_substs: hashmap<node_id, ~[t]>,
items: ast_map::map,
intrinsic_ifaces: hashmap<ast::ident, (ast::def_id, t)>,
intrinsic_traits: hashmap<ast::ident, (ast::def_id, t)>,
freevars: freevars::freevar_map,
tcache: type_cache,
rcache: creader_cache,
@ -250,7 +250,7 @@ type ctxt =
kind_cache: hashmap<t, kind>,
ast_ty_to_ty_cache: hashmap<@ast::ty, ast_ty_to_ty_cache_entry>,
enum_var_cache: hashmap<def_id, @~[variant_info]>,
iface_method_cache: hashmap<def_id, @~[method]>,
trait_method_cache: hashmap<def_id, @~[method]>,
ty_param_bounds: hashmap<ast::node_id, param_bounds>,
inferred_modes: hashmap<ast::node_id, ast::mode>,
// maps the id of borrowed expr to scope of borrowed ptr
@ -366,7 +366,7 @@ enum sty {
ty_rptr(region, mt),
ty_rec(~[field]),
ty_fn(fn_ty),
ty_iface(def_id, substs),
ty_trait(def_id, substs),
ty_class(def_id, substs),
ty_tup(~[t]),
@ -426,7 +426,7 @@ enum param_bound {
bound_copy,
bound_send,
bound_const,
bound_iface(t),
bound_trait(t),
}
enum tv_vid = uint;
@ -468,7 +468,7 @@ fn param_bounds_to_kind(bounds: param_bounds) -> kind {
}
bound_send { kind = raise_kind(kind, kind_send_only()); }
bound_const { kind = raise_kind(kind, kind_const()); }
bound_iface(_) {}
bound_trait(_) {}
}
}
kind
@ -519,7 +519,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
node_types: @smallintmap::mk(),
node_type_substs: map::int_hash(),
items: amap,
intrinsic_ifaces: map::box_str_hash(),
intrinsic_traits: map::box_str_hash(),
freevars: freevars,
tcache: ast_util::new_def_hash(),
rcache: mk_rcache(),
@ -530,7 +530,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
ast_ty_to_ty_cache: map::hashmap(
ast_util::hash_ty, ast_util::eq_ty),
enum_var_cache: new_def_hash(),
iface_method_cache: new_def_hash(),
trait_method_cache: new_def_hash(),
ty_param_bounds: map::int_hash(),
inferred_modes: map::int_hash(),
borrowings: map::int_hash(),
@ -578,7 +578,7 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
ty_param(_, _) { flags |= has_params as uint; }
ty_var(_) | ty_var_integral(_) { flags |= needs_infer as uint; }
ty_self { flags |= has_self as uint; }
ty_enum(_, substs) | ty_class(_, substs) | ty_iface(_, substs) {
ty_enum(_, substs) | ty_class(_, substs) | ty_trait(_, substs) {
flags |= sflags(substs);
}
ty_box(m) | ty_uniq(m) | ty_vec(m) | ty_evec(m, _) |
@ -704,8 +704,8 @@ fn mk_tup(cx: ctxt, ts: ~[t]) -> t { mk_t(cx, ty_tup(ts)) }
fn mk_fn(cx: ctxt, fty: fn_ty) -> t { mk_t(cx, ty_fn(fty)) }
fn mk_iface(cx: ctxt, did: ast::def_id, substs: substs) -> t {
mk_t(cx, ty_iface(did, substs))
fn mk_trait(cx: ctxt, did: ast::def_id, substs: substs) -> t {
mk_t(cx, ty_trait(did, substs))
}
fn mk_class(cx: ctxt, class_id: ast::def_id, substs: substs) -> t {
@ -775,7 +775,7 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
maybe_walk_ty(tm.ty, f);
}
ty_enum(_, substs) | ty_class(_, substs) |
ty_iface(_, substs) {
ty_trait(_, substs) {
for substs.tps.each |subty| { maybe_walk_ty(subty, f); }
}
ty_rec(fields) {
@ -824,8 +824,8 @@ fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty {
ty_enum(tid, substs) {
ty_enum(tid, fold_substs(substs, fldop))
}
ty_iface(did, substs) {
ty_iface(did, fold_substs(substs, fldop))
ty_trait(did, substs) {
ty_trait(did, fold_substs(substs, fldop))
}
ty_rec(fields) {
let new_fields = do vec::map(fields) |fl| {
@ -924,8 +924,8 @@ fn fold_regions_and_ty(
ty_class(def_id, substs) {
ty::mk_class(cx, def_id, fold_substs(substs, fldr, fldt))
}
ty_iface(def_id, substs) {
ty::mk_iface(cx, def_id, fold_substs(substs, fldr, fldt))
ty_trait(def_id, substs) {
ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt))
}
sty @ ty_fn(_) {
fold_sty_to_ty(cx, sty, |t| fldfnt(t))
@ -1074,7 +1074,7 @@ fn type_is_bool(ty: t) -> bool { get(ty).struct == ty_bool }
fn type_is_structural(ty: t) -> bool {
alt get(ty).struct {
ty_rec(_) | ty_class(*) | ty_tup(_) | ty_enum(*) | ty_fn(_) |
ty_iface(*) | ty_evec(_, vstore_fixed(_))
ty_trait(*) | ty_evec(_, vstore_fixed(_))
| ty_estr(vstore_fixed(_)) { true }
_ { false }
}
@ -1497,7 +1497,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
else { kind_implicitly_copyable() }
}
}
ty_iface(_, _) { kind_implicitly_copyable() }
ty_trait(_, _) { kind_implicitly_copyable() }
ty_rptr(_, _) { kind_implicitly_copyable() }
// Unique boxes and vecs have the kind of their contained type,
@ -1669,7 +1669,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
}
}
ty_iface(_, _) {
ty_trait(_, _) {
false
}
@ -1834,7 +1834,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
ty_str | ty_box(_) | ty_uniq(_) | ty_vec(_) | ty_fn(_) |
ty_estr(vstore_uniq) | ty_estr(vstore_box) |
ty_evec(_, vstore_uniq) | ty_evec(_, vstore_box) |
ty_iface(_, _) | ty_rptr(_,_) | ty_opaque_box { result = false; }
ty_trait(_, _) | ty_rptr(_,_) | ty_opaque_box { result = false; }
// Structural types
ty_enum(did, substs) {
let variants = enum_variants(cx, did);
@ -2066,7 +2066,7 @@ fn hash_type_structure(st: sty) -> uint {
h
}
ty_uniq(mt) { hash_subty(37u, mt.ty) }
ty_iface(did, substs) {
ty_trait(did, substs) {
let mut h = hash_def(40u, did);
hash_substs(h, substs)
}
@ -2402,7 +2402,7 @@ fn ty_sort_str(cx: ctxt, t: t) -> str {
ty_rptr(_, _) { "&-ptr" }
ty_rec(_) { "record" }
ty_fn(_) { "fn" }
ty_iface(id, _) { #fmt["iface %s", item_path_str(cx, id)] }
ty_trait(id, _) { #fmt["trait %s", item_path_str(cx, id)] }
ty_class(id, _) { #fmt["class %s", item_path_str(cx, id)] }
ty_tup(_) { "tuple" }
ty_var(_) { "variable" }
@ -2513,25 +2513,25 @@ fn def_has_ty_params(def: ast::def) -> bool {
}
}
fn store_iface_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) {
cx.iface_method_cache.insert(ast_util::local_def(id), ms);
fn store_trait_methods(cx: ctxt, id: ast::node_id, ms: @~[method]) {
cx.trait_method_cache.insert(ast_util::local_def(id), ms);
}
fn iface_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
alt cx.iface_method_cache.find(id) {
fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
alt cx.trait_method_cache.find(id) {
some(ms) { ret ms; }
_ {}
}
// Local interfaces are supposed to have been added explicitly.
assert id.crate != ast::local_crate;
let result = csearch::get_iface_methods(cx, id);
cx.iface_method_cache.insert(id, result);
let result = csearch::get_trait_methods(cx, id);
cx.trait_method_cache.insert(id, result);
result
}
fn impl_iface(cx: ctxt, id: ast::def_id) -> option<t> {
fn impl_trait(cx: ctxt, id: ast::def_id) -> option<t> {
if id.crate == ast::local_crate {
#debug("(impl_iface) searching for iface impl %?", id);
#debug("(impl_trait) searching for trait impl %?", id);
alt cx.items.find(id.node) {
some(ast_map::node_item(@{node: ast::item_impl(
_, _, some(@{id: id, _}), _, _), _}, _)) {
@ -2540,13 +2540,13 @@ fn impl_iface(cx: ctxt, id: ast::def_id) -> option<t> {
some(ast_map::node_item(@{node: ast::item_class(_, _, _, _, _, _),
_},_)) {
alt cx.def_map.find(id.node) {
some(def_ty(iface_id)) {
some(def_ty(trait_id)) {
// XXX: Doesn't work cross-crate.
#debug("(impl_iface) found iface id %?", iface_id);
some(node_id_to_type(cx, iface_id.node))
#debug("(impl_trait) found trait id %?", trait_id);
some(node_id_to_type(cx, trait_id.node))
}
some(x) {
cx.sess.bug(#fmt("impl_iface: iface ref is in iface map \
cx.sess.bug(#fmt("impl_trait: trait ref is in trait map \
but is bound to %?", x));
}
none {
@ -2557,13 +2557,13 @@ fn impl_iface(cx: ctxt, id: ast::def_id) -> option<t> {
_ { none }
}
} else {
csearch::get_impl_iface(cx, id)
csearch::get_impl_trait(cx, id)
}
}
fn ty_to_def_id(ty: t) -> option<ast::def_id> {
alt get(ty).struct {
ty_iface(id, _) | ty_class(id, _) | ty_enum(id, _) {
ty_trait(id, _) | ty_class(id, _) | ty_enum(id, _) {
some(id)
}
_ { none }

View File

@ -5,7 +5,7 @@ typeck.rs, an introduction
The type checker is responsible for:
1. Determining the type of each expression
2. Resolving methods and ifaces
2. Resolving methods and traits
3. Guaranteeing that most type rules are met ("most?", you say, "why most?"
Well, dear reader, read on)
@ -81,28 +81,28 @@ enum method_origin {
// fully statically resolved method
method_static(ast::def_id),
// method invoked on a type parameter with a bounded iface
// method invoked on a type parameter with a bounded trait
method_param(method_param),
// method invoked on a boxed iface
method_iface(ast::def_id, uint),
// method invoked on a boxed trait
method_trait(ast::def_id, uint),
}
// details for a method invoked with a receiver whose type is a type parameter
// with a bounded iface.
// with a bounded trait.
#[auto_serialize]
type method_param = {
// the iface containing the method to be invoked
iface_id: ast::def_id,
// the trait containing the method to be invoked
trait_id: ast::def_id,
// index of the method to be invoked amongst the iface's methods
// index of the method to be invoked amongst the trait's methods
method_num: uint,
// index of the type parameter (from those that are in scope) that is
// the type of the receiver
param_num: uint,
// index of the bound for this type parameter which specifies the iface
// index of the bound for this type parameter which specifies the trait
bound_num: uint
};
@ -140,9 +140,9 @@ enum vtable_origin {
vtable_param(uint, uint),
/*
Dynamic vtable, comes from something known to have an interface
type. def_id refers to the iface item, tys are the substs
type. def_id refers to the trait item, tys are the substs
*/
vtable_iface(ast::def_id, ~[ty::t]),
vtable_trait(ast::def_id, ~[ty::t]),
}
type vtable_map = hashmap<ast::node_id, vtable_res>;

View File

@ -21,7 +21,7 @@
* region, or `type_rscope`, which permits the self region if the type in
* question is parameterized by a region.
*
* Unlike the `ast_conv` iface, the region scope can change as we descend
* Unlike the `ast_conv` trait, the region scope can change as we descend
* the type. This is to accommodate the fact that (a) fn types are binding
* scopes and (b) the default region may change. To understand case (a),
* consider something like:
@ -304,8 +304,8 @@ fn ast_ty_to_ty<AC: ast_conv, RS: region_scope copy>(
ty::mk_param(tcx, n, id)
}
ast::def_self(_) {
// n.b.: resolve guarantees that the self type only appears in an
// iface, which we rely upon in various places when creating
// n.b.: resolve guarantees that the self type only appears in a
// trait, which we rely upon in various places when creating
// substs
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_self(tcx)

View File

@ -30,7 +30,7 @@ can be broken down into several distinct phases:
final assignments of the various region variables if there is some
flexibility.
- vtable: find and records the impls to use for each iface bound that
- vtable: find and records the impls to use for each trait bound that
appears on a type parameter.
- writeback: writes the final types within a function body, replacing
@ -358,7 +358,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
let self_ty = ccx.to_ty(rscope::type_rscope(rp), ty);
for ms.each |m| { check_method(ccx, m, self_ty);}
}
ast::item_class(tps, ifaces, members, ctor, m_dtor, rp) {
ast::item_class(tps, traits, members, ctor, m_dtor, rp) {
let tcx = ccx.tcx;
let class_t = ty::node_id_to_type(tcx, it.id);
// typecheck the ctor
@ -1090,8 +1090,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
// Something of a hack: special rules for comparison operators that
// simply unify LHS and RHS. This helps with inference as LHS and RHS
// do not need to be "resolvable". Some tests, particularly those with
// complicated iface requirements, fail without this---I think this code
// can be removed if we improve iface resolution to be more eager when
// complicated trait requirements, fail without this---I think this code
// can be removed if we improve trait resolution to be more eager when
// possible.
ast::expr_binary(ast::eq, lhs, rhs) |
ast::expr_binary(ast::ne, lhs, rhs) |
@ -1392,7 +1392,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
alt ty::get(t_1).struct {
// This will be looked up later on
ty::ty_iface(*) {}
ty::ty_trait(*) {}
_ {
if ty::type_is_nil(t_e) {
@ -1518,7 +1518,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
}
ty::ty_class(base_id, substs) {
// This is just for fields -- the same code handles
// methods in both classes and ifaces
// methods in both classes and traits
// (1) verify that the class id actually has a field called
// field
@ -2259,9 +2259,9 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
}
"visit_ty" {
assert ccx.tcx.intrinsic_ifaces.contains_key(@"ty_visitor");
let (_, visitor_iface) = ccx.tcx.intrinsic_ifaces.get(@"ty_visitor");
(1u, ~[arg(ast::by_ref, visitor_iface)], ty::mk_nil(tcx))
assert ccx.tcx.intrinsic_traits.contains_key(@"ty_visitor");
let (_, visitor_trait) = ccx.tcx.intrinsic_traits.get(@"ty_visitor");
(1u, ~[arg(ast::by_ref, visitor_trait)], ty::mk_nil(tcx))
}
"frame_address" {
let fty = ty::mk_fn(ccx.tcx, {

View File

@ -64,8 +64,8 @@ class lookup {
ty::ty_param(n, did) {
self.add_candidates_from_param(n, did);
}
ty::ty_iface(did, substs) {
self.add_candidates_from_iface(did, substs);
ty::ty_trait(did, substs) {
self.add_candidates_from_trait(did, substs);
}
ty::ty_class(did, substs) {
self.add_candidates_from_class(did, substs);
@ -111,10 +111,10 @@ class lookup {
self.report_static_candidate(i, did);
}
method_param(p) {
self.report_param_candidate(i, p.iface_id);
self.report_param_candidate(i, p.trait_id);
}
method_iface(did, _) {
self.report_iface_candidate(i, did);
method_trait(did, _) {
self.report_trait_candidate(i, did);
}
}
}
@ -148,11 +148,11 @@ class lookup {
ty::item_path_str(self.tcx(), did)]);
}
fn report_iface_candidate(idx: uint, did: ast::def_id) {
fn report_trait_candidate(idx: uint, did: ast::def_id) {
self.tcx().sess.span_note(
self.expr.span,
#fmt["candidate #%u derives from the type of the receiver, \
which is the iface `%s`",
which is the trait `%s`",
(idx+1u),
ty::item_path_str(self.tcx(), did)]);
}
@ -161,25 +161,25 @@ class lookup {
#debug["candidates_from_param"];
let tcx = self.tcx();
let mut iface_bnd_idx = 0u; // count only iface bounds
let mut trait_bnd_idx = 0u; // count only trait bounds
let bounds = tcx.ty_param_bounds.get(did.node);
for vec::each(*bounds) |bound| {
let (iid, bound_substs) = alt bound {
ty::bound_copy | ty::bound_send | ty::bound_const {
cont; /* ok */
}
ty::bound_iface(bound_t) {
ty::bound_trait(bound_t) {
alt check ty::get(bound_t).struct {
ty::ty_iface(i, substs) { (i, substs) }
ty::ty_trait(i, substs) { (i, substs) }
}
}
};
let ifce_methods = ty::iface_methods(tcx, iid);
let ifce_methods = ty::trait_methods(tcx, iid);
alt vec::position(*ifce_methods, |m| m.ident == self.m_name) {
none {
/* check next bound */
iface_bnd_idx += 1u;
trait_bnd_idx += 1u;
}
some(pos) {
@ -187,7 +187,7 @@ class lookup {
// generic parameter itself. Note that this is the only case
// where this replacement is necessary: in all other cases, we
// are either invoking a method directly from an impl or class
// (where the self type is not permitted), or from a iface
// (where the self type is not permitted), or from a trait
// type (in which case methods that refer to self are not
// permitted).
let substs = {self_ty: some(self.self_ty)
@ -195,21 +195,21 @@ class lookup {
self.add_candidates_from_m(
substs, ifce_methods[pos],
method_param({iface_id:iid,
method_param({trait_id:iid,
method_num:pos,
param_num:n,
bound_num:iface_bnd_idx}));
bound_num:trait_bnd_idx}));
}
}
}
}
fn add_candidates_from_iface(did: ast::def_id, iface_substs: ty::substs) {
fn add_candidates_from_trait(did: ast::def_id, trait_substs: ty::substs) {
#debug["method_from_iface"];
#debug["method_from_trait"];
let ms = *ty::iface_methods(self.tcx(), did);
let ms = *ty::trait_methods(self.tcx(), did);
for ms.eachi |i, m| {
if m.ident != self.m_name { cont; }
@ -226,17 +226,17 @@ class lookup {
self.tcx().sess.span_err(
self.expr.span,
"can not call a generic method through a \
boxed iface");
boxed trait");
}
// Note: although it is illegal to invoke a method that uses self
// through a iface instance, we use a dummy subst here so that we
// through a trait instance, we use a dummy subst here so that we
// can soldier on with the compilation.
let substs = {self_ty: some(self.self_ty)
with iface_substs};
with trait_substs};
self.add_candidates_from_m(
substs, m, method_iface(did, i));
substs, m, method_trait(did, i));
}
}
@ -244,7 +244,7 @@ class lookup {
#debug["method_from_class"];
let ms = *ty::iface_methods(self.tcx(), did);
let ms = *ty::trait_methods(self.tcx(), did);
for ms.each |m| {
if m.ident != self.m_name { cont; }
@ -275,7 +275,7 @@ class lookup {
if did.crate == ast::local_crate {
alt check self.tcx().items.get(did.node) {
ast_map::node_method(m, _, _) {
// NDM iface/impl regions
// NDM trait/impl regions
let mt = ty_of_method(self.fcx.ccx, m, ast::rp_none);
ty::mk_fn(self.tcx(), {proto: ast::proto_box with mt.fty})
}

View File

@ -1,9 +1,9 @@
import check::{fn_ctxt, impl_self_ty, methods};
fn has_iface_bounds(tps: ~[ty::param_bounds]) -> bool {
fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool {
vec::any(tps, |bs| {
vec::any(*bs, |b| {
alt b { ty::bound_iface(_) { true } _ { false } }
alt b { ty::bound_trait(_) { true } _ { false } }
})
})
}
@ -16,7 +16,7 @@ fn lookup_vtables(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
for substs.tps.each |ty| {
for vec::each(*bounds[i]) |bound| {
alt bound {
ty::bound_iface(i_ty) {
ty::bound_trait(i_ty) {
let i_ty = ty::subst(tcx, substs, i_ty);
vec::push(result, lookup_vtable(fcx, isc, sp, ty, i_ty,
allow_unsafe));
@ -33,33 +33,33 @@ fn fixup_substs(fcx: @fn_ctxt, sp: span,
id: ast::def_id, substs: ty::substs) -> ty::substs {
let tcx = fcx.ccx.tcx;
// use a dummy type just to package up the substs that need fixing up
let t = ty::mk_iface(tcx, id, substs);
let t = ty::mk_trait(tcx, id, substs);
let t_f = fixup_ty(fcx, sp, t);
alt check ty::get(t_f).struct {
ty::ty_iface(_, substs_f) { substs_f }
ty::ty_trait(_, substs_f) { substs_f }
}
}
fn relate_iface_tys(fcx: @fn_ctxt, sp: span,
exp_iface_ty: ty::t, act_iface_ty: ty::t) {
demand::suptype(fcx, sp, exp_iface_ty, act_iface_ty)
fn relate_trait_tys(fcx: @fn_ctxt, sp: span,
exp_trait_ty: ty::t, act_trait_ty: ty::t) {
demand::suptype(fcx, sp, exp_trait_ty, act_trait_ty)
}
/*
Look up the vtable to use when treating an item of type <t>
as if it has type <iface_ty>
as if it has type <trait_ty>
*/
fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
ty: ty::t, iface_ty: ty::t, allow_unsafe: bool)
ty: ty::t, trait_ty: ty::t, allow_unsafe: bool)
-> vtable_origin {
#debug["lookup_vtable(ty=%s, iface_ty=%s)",
fcx.infcx.ty_to_str(ty), fcx.infcx.ty_to_str(iface_ty)];
#debug["lookup_vtable(ty=%s, trait_ty=%s)",
fcx.infcx.ty_to_str(ty), fcx.infcx.ty_to_str(trait_ty)];
let _i = indenter();
let tcx = fcx.ccx.tcx;
let (iface_id, iface_substs) = alt check ty::get(iface_ty).struct {
ty::ty_iface(did, substs) { (did, substs) }
let (trait_id, trait_substs) = alt check ty::get(trait_ty).struct {
ty::ty_trait(did, substs) { (did, substs) }
};
let ty = fixup_ty(fcx, sp, ty);
alt ty::get(ty).struct {
@ -70,13 +70,13 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
ty::bound_send | ty::bound_copy | ty::bound_const {
/* ignore */
}
ty::bound_iface(ity) {
ty::bound_trait(ity) {
alt check ty::get(ity).struct {
ty::ty_iface(idid, substs) {
if iface_id == idid {
#debug("(checking vtable) @0 relating ty to iface ty
ty::ty_trait(idid, substs) {
if trait_id == idid {
#debug("(checking vtable) @0 relating ty to trait ty
with did %?", idid);
relate_iface_tys(fcx, sp, iface_ty, ity);
relate_trait_tys(fcx, sp, trait_ty, ity);
ret vtable_param(n, n_bound);
}
}
@ -87,13 +87,13 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
}
}
ty::ty_iface(did, substs) if iface_id == did {
#debug("(checking vtable) @1 relating ty to iface ty with did %?",
ty::ty_trait(did, substs) if trait_id == did {
#debug("(checking vtable) @1 relating ty to trait ty with did %?",
did);
relate_iface_tys(fcx, sp, iface_ty, ty);
relate_trait_tys(fcx, sp, trait_ty, ty);
if !allow_unsafe {
for vec::each(*ty::iface_methods(tcx, did)) |m| {
for vec::each(*ty::trait_methods(tcx, did)) |m| {
if ty::type_has_self(ty::mk_fn(tcx, m.fty)) {
tcx.sess.span_err(
sp, "a boxed iface with self types may not be \
@ -106,7 +106,7 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
}
}
}
ret vtable_iface(did, substs.tps);
ret vtable_trait(did, substs.tps);
}
_ {
@ -116,15 +116,15 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
/* For each impl in scope... */
for vec::each(*impls) |im| {
// im = one specific impl
// find the iface that im implements (if any)
let of_ty = alt ty::impl_iface(tcx, im.did) {
// find the trait that im implements (if any)
let of_ty = alt ty::impl_trait(tcx, im.did) {
some(of_ty) { of_ty }
_ { cont; }
};
// it must have the same id as the expected one
alt ty::get(of_ty).struct {
ty::ty_iface(id, _) if id != iface_id { cont; }
ty::ty_trait(id, _) if id != trait_id { cont; }
_ { /* ok */ }
}
@ -138,19 +138,19 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
result::ok(()) { }
}
// check that desired iface type unifies
#debug("(checking vtable) @2 relating iface ty %s to \
// check that desired trait type unifies
#debug("(checking vtable) @2 relating trait ty %s to \
of_ty %s",
fcx.infcx.ty_to_str(iface_ty),
fcx.infcx.ty_to_str(trait_ty),
fcx.infcx.ty_to_str(of_ty));
let of_ty = ty::subst(tcx, substs, of_ty);
relate_iface_tys(fcx, sp, iface_ty, of_ty);
relate_trait_tys(fcx, sp, trait_ty, of_ty);
// recursively process the bounds
let iface_tps = iface_substs.tps;
let substs_f = fixup_substs(fcx, sp, iface_id, substs);
connect_iface_tps(fcx, sp, substs_f.tps,
iface_tps, im.did);
let trait_tps = trait_substs.tps;
let substs_f = fixup_substs(fcx, sp, trait_id, substs);
connect_trait_tps(fcx, sp, substs_f.tps,
trait_tps, im.did);
let subres = lookup_vtables(fcx, isc, sp,
im_bs, substs_f, false);
vec::push(found,
@ -172,7 +172,7 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
tcx.sess.span_fatal(
sp, "failed to find an implementation of interface " +
ty_to_str(tcx, iface_ty) + " for " +
ty_to_str(tcx, trait_ty) + " for " +
ty_to_str(tcx, ty));
}
@ -190,16 +190,16 @@ fn fixup_ty(fcx: @fn_ctxt, sp: span, ty: ty::t) -> ty::t {
}
}
fn connect_iface_tps(fcx: @fn_ctxt, sp: span, impl_tys: ~[ty::t],
iface_tys: ~[ty::t], impl_did: ast::def_id) {
fn connect_trait_tps(fcx: @fn_ctxt, sp: span, impl_tys: ~[ty::t],
trait_tys: ~[ty::t], impl_did: ast::def_id) {
let tcx = fcx.ccx.tcx;
let ity = option::get(ty::impl_iface(tcx, impl_did));
let iface_ty = ty::subst_tps(tcx, impl_tys, ity);
#debug("(connect iface tps) iface type is %?, impl did is %?",
ty::get(iface_ty).struct, impl_did);
alt check ty::get(iface_ty).struct {
ty::ty_iface(_, substs) {
vec::iter2(substs.tps, iface_tys,
let ity = option::get(ty::impl_trait(tcx, impl_did));
let trait_ty = ty::subst_tps(tcx, impl_tys, ity);
#debug("(connect trait tps) trait type is %?, impl did is %?",
ty::get(trait_ty).struct, impl_did);
alt check ty::get(trait_ty).struct {
ty::ty_trait(_, substs) {
vec::iter2(substs.tps, trait_tys,
|a, b| demand::suptype(fcx, sp, a, b));
}
}
@ -213,7 +213,7 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) {
some(substs) {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(ex.id));
let item_ty = ty::lookup_item_type(cx.tcx, did);
if has_iface_bounds(*item_ty.bounds) {
if has_trait_bounds(*item_ty.bounds) {
let impls = cx.impl_map.get(ex.id);
cx.vtable_map.insert(ex.id, lookup_vtables(
fcx, impls, ex.span,
@ -230,7 +230,7 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) {
alt cx.method_map.find(ex.id) {
some({origin: method_static(did), _}) {
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
if has_iface_bounds(*bounds) {
if has_trait_bounds(*bounds) {
let callee_id = alt ex.node {
ast::expr_field(_, _, _) { ex.id }
_ { ast_util::op_expr_callee_id(ex) }
@ -247,7 +247,7 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) {
ast::expr_cast(src, _) {
let target_ty = fcx.expr_ty(ex);
alt ty::get(target_ty).struct {
ty::ty_iface(*) {
ty::ty_trait(*) {
/* Casting to an interface type.
Look up all impls for the cast expr...
*/

View File

@ -34,12 +34,12 @@ fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) {
ast::item_mod(m) {
for m.items.each |intrinsic_item| {
alt intrinsic_item.node {
ast::item_iface(_, _, _) {
ast::item_trait(_, _, _) {
let def_id = { crate: ast::local_crate,
node: intrinsic_item.id };
let substs = {self_r: none, self_ty: none, tps: ~[]};
let ty = ty::mk_iface(ccx.tcx, def_id, substs);
ccx.tcx.intrinsic_ifaces.insert
let ty = ty::mk_trait(ccx.tcx, def_id, substs);
ccx.tcx.intrinsic_traits.insert
(intrinsic_item.ident, (def_id, ty));
}
_ { }
@ -128,15 +128,15 @@ fn get_enum_variant_types(ccx: @crate_ctxt,
}
}
fn ensure_iface_methods(ccx: @crate_ctxt, id: ast::node_id) {
fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) {
fn store_methods<T>(ccx: @crate_ctxt, id: ast::node_id,
stuff: ~[T], f: fn@(T) -> ty::method) {
ty::store_iface_methods(ccx.tcx, id, @vec::map(stuff, f));
ty::store_trait_methods(ccx.tcx, id, @vec::map(stuff, f));
}
let tcx = ccx.tcx;
alt check tcx.items.get(id) {
ast_map::node_item(@{node: ast::item_iface(_, rp, ms), _}, _) {
ast_map::node_item(@{node: ast::item_trait(_, rp, ms), _}, _) {
store_methods::<ast::ty_method>(ccx, id, ms, |m| {
ty_of_ty_method(ccx, m, rp)
});
@ -154,14 +154,14 @@ fn ensure_iface_methods(ccx: @crate_ctxt, id: ast::node_id) {
/**
* Checks that a method from an impl/class conforms to the signature of
* the same method as declared in the iface.
* the same method as declared in the trait.
*
* # Parameters
*
* - impl_m: the method in the impl
* - impl_tps: the type params declared on the impl itself (not the method!)
* - if_m: the method in the iface
* - if_substs: the substitutions used on the type of the iface
* - if_m: the method in the trait
* - if_substs: the substitutions used on the type of the trait
* - self_ty: the self type of the impl
*/
fn compare_impl_method(tcx: ty::ctxt, sp: span,
@ -184,10 +184,10 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span,
ret;
}
// Perform substitutions so that the iface/impl methods are expressed
// Perform substitutions so that the trait/impl methods are expressed
// in terms of the same set of type/region parameters:
// - replace iface type parameters with those from `if_substs`
// - replace method parameters on the iface with fresh, dummy parameters
// - replace trait type parameters with those from `if_substs`
// - replace method parameters on the trait with fresh, dummy parameters
// that correspond to the parameters we will find on the impl
// - replace self region with a fresh, dummy region
let dummy_self_r = ty::re_free(0, ty::br_self);
@ -223,25 +223,25 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span,
}
}
fn check_methods_against_iface(ccx: @crate_ctxt,
fn check_methods_against_trait(ccx: @crate_ctxt,
tps: ~[ast::ty_param],
rp: ast::region_param,
selfty: ty::t,
a_ifacety: @ast::iface_ref,
a_trait_ty: @ast::trait_ref,
ms: ~[converted_method]) {
let tcx = ccx.tcx;
let (did, tpt) = instantiate_iface_ref(ccx, a_ifacety, rp);
let (did, tpt) = instantiate_trait_ref(ccx, a_trait_ty, rp);
if did.crate == ast::local_crate {
ensure_iface_methods(ccx, did.node);
ensure_trait_methods(ccx, did.node);
}
for vec::each(*ty::iface_methods(tcx, did)) |if_m| {
for vec::each(*ty::trait_methods(tcx, did)) |if_m| {
alt vec::find(ms, |m| if_m.ident == m.mty.ident) {
some({mty: m, id, span}) {
if m.purity != if_m.purity {
ccx.tcx.sess.span_err(
span, #fmt["method `%s`'s purity \
not match the iface method's \
not match the trait method's \
purity", *m.ident]);
}
compare_impl_method(
@ -250,7 +250,7 @@ fn check_methods_against_iface(ccx: @crate_ctxt,
}
none {
tcx.sess.span_err(
a_ifacety.path.span,
a_trait_ty.path.span,
#fmt["missing method `%s`", *if_m.ident]);
}
} // alt
@ -314,17 +314,17 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
let cms = convert_methods(ccx, ms, rp, i_bounds, selfty);
for ifce.each |t| {
check_methods_against_iface(ccx, tps, rp, selfty, t, cms);
check_methods_against_trait(ccx, tps, rp, selfty, t, cms);
}
}
ast::item_iface(*) {
ast::item_trait(*) {
let tpt = ty_of_item(ccx, it);
#debug["item_iface(it.id=%d, tpt.ty=%s)",
#debug["item_trait(it.id=%d, tpt.ty=%s)",
it.id, ty_to_str(tcx, tpt.ty)];
write_ty_to_tcx(tcx, it.id, tpt.ty);
ensure_iface_methods(ccx, it.id);
ensure_trait_methods(ccx, it.id);
}
ast::item_class(tps, ifaces, members, ctor, m_dtor, rp) {
ast::item_class(tps, traits, members, ctor, m_dtor, rp) {
// Write the class type
let tpt = ty_of_item(ccx, it);
write_ty_to_tcx(tcx, it.id, tpt.ty);
@ -362,7 +362,7 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
rp: rp,
ty: t_dtor});
};
ensure_iface_methods(ccx, it.id);
ensure_trait_methods(ccx, it.id);
// Write the type of each of the members
let (fields, methods) = split_class_items(members);
@ -372,16 +372,16 @@ fn convert(ccx: @crate_ctxt, it: @ast::item) {
let {bounds, substs} = mk_substs(ccx, tps, rp);
let selfty = ty::mk_class(tcx, local_def(it.id), substs);
let cms = convert_methods(ccx, methods, rp, bounds, selfty);
for ifaces.each |ifce| {
check_methods_against_iface(ccx, tps, rp, selfty, ifce, cms);
for traits.each |ifce| {
check_methods_against_trait(ccx, tps, rp, selfty, ifce, cms);
// FIXME #2434---this is somewhat bogus, but it seems that
// the id of iface_ref is also the id of the impl, and so
// the id of trait_ref is also the id of the impl, and so
// we want to store the "self type" of the impl---in this
// case, the class. The reason I say this is somewhat
// bogus (and should be refactored) is that the tcache
// stores the class type for ifce.id but the node_type
// table stores the iface type. Weird. Probably just
// table stores the trait type. Weird. Probably just
// adding a "self type" table rather than overloading the
// tcache would be ok, or else adding more than one id.
tcx.tcache.insert(local_def(ifce.id), tpt);
@ -427,16 +427,16 @@ fn ty_of_ty_method(self: @crate_ctxt,
tps: ty_param_bounds(self, m.tps),
fty: ty_of_fn_decl(self, type_rscope(rp), ast::proto_bare,
m.decl, none),
// assume public, because this is only invoked on iface methods
// assume public, because this is only invoked on trait methods
purity: m.decl.purity, vis: ast::public}
}
/*
Instantiates the path for the given iface reference, assuming that
it's bound to a valid iface type. Returns the def_id for the defining
iface. Fails if the type is a type other than an iface type.
Instantiates the path for the given trait reference, assuming that
it's bound to a valid trait type. Returns the def_id for the defining
trait. Fails if the type is a type other than an trait type.
*/
fn instantiate_iface_ref(ccx: @crate_ctxt, t: @ast::iface_ref,
fn instantiate_trait_ref(ccx: @crate_ctxt, t: @ast::trait_ref,
rp: ast::region_param)
-> (ast::def_id, ty_param_substs_and_ty) {
@ -449,7 +449,7 @@ fn instantiate_iface_ref(ccx: @crate_ctxt, t: @ast::iface_ref,
ast::def_ty(t_id) {
let tpt = astconv::ast_path_to_ty(ccx, rscope, t_id, t.path, t.id);
alt ty::get(tpt.ty).struct {
ty::ty_iface(*) {
ty::ty_trait(*) {
(t_id, tpt)
}
_ { sess.span_fatal(sp, err); }
@ -520,9 +520,9 @@ fn ty_of_item(ccx: @crate_ctxt, it: @ast::item)
tcx.tcache.insert(local_def(it.id), tpt);
ret tpt;
}
ast::item_iface(tps, rp, ms) {
ast::item_trait(tps, rp, ms) {
let {bounds, substs} = mk_substs(ccx, tps, rp);
let t = ty::mk_iface(tcx, local_def(it.id), substs);
let t = ty::mk_trait(tcx, local_def(it.id), substs);
let tpt = {bounds: bounds, rp: rp, ty: t};
tcx.tcache.insert(local_def(it.id), tpt);
ret tpt;
@ -558,11 +558,11 @@ fn ty_param_bounds(ccx: @crate_ctxt,
ast::bound_send { ~[ty::bound_send] }
ast::bound_copy { ~[ty::bound_copy] }
ast::bound_const { ~[ty::bound_const] }
ast::bound_iface(t) {
ast::bound_trait(t) {
let ity = ast_ty_to_ty(ccx, empty_rscope, t);
alt ty::get(ity).struct {
ty::ty_iface(*) {
~[ty::bound_iface(ity)]
ty::ty_trait(*) {
~[ty::bound_trait(ity)]
}
_ {
ccx.tcx.sess.span_err(

View File

@ -1781,10 +1781,10 @@ fn super_tys<C:combine>(
}
}
(ty::ty_iface(a_id, a_substs), ty::ty_iface(b_id, b_substs))
(ty::ty_trait(a_id, a_substs), ty::ty_trait(b_id, b_substs))
if a_id == b_id {
do self.substs(a_substs, b_substs).chain |substs| {
ok(ty::mk_iface(tcx, a_id, substs))
ok(ty::mk_trait(tcx, a_id, substs))
}
}

View File

@ -4,7 +4,7 @@ import middle::ty::{arg, bound_region, br_anon, br_named, canon_mode};
import middle::ty::{ck_block, ck_box, ck_uniq, constr, ctxt, field, method};
import middle::ty::{mt, re_bound, re_free, re_scope, re_var, region, t};
import middle::ty::{ty_bool, ty_bot, ty_box, ty_class, ty_constr, ty_enum};
import middle::ty::{ty_estr, ty_evec, ty_float, ty_fn, ty_iface, ty_int};
import middle::ty::{ty_estr, ty_evec, ty_float, ty_fn, ty_trait, ty_int};
import middle::ty::{ty_nil, ty_opaque_box, ty_opaque_closure_ptr, ty_param};
import middle::ty::{ty_ptr, ty_rec, ty_rptr, ty_self, ty_str, ty_tup};
import middle::ty::{ty_type, ty_uniq, ty_uint, ty_var, ty_var_integral};
@ -213,7 +213,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
let base = ast_map::path_to_str(path);
parameterized(cx, base, substs.self_r, substs.tps)
}
ty_iface(did, substs) {
ty_trait(did, substs) {
let path = ty::item_path(cx, did);
let base = ast_map::path_to_str(path);
parameterized(cx, base, substs.self_r, substs.tps)

View File

@ -27,7 +27,7 @@ fn run(
fold_crate: fold_crate,
fold_item: fold_item,
fold_enum: fold_enum,
fold_iface: fold_iface,
fold_trait: fold_trait,
fold_impl: fold_impl
with *fold::default_any_fold(srv)
});
@ -181,12 +181,12 @@ fn should_extract_variant_docs() {
assert doc.cratemod().enums()[0].variants[0].desc == some("c");
}
fn fold_iface(
fn fold_trait(
fold: fold::fold<astsrv::srv>,
doc: doc::ifacedoc
) -> doc::ifacedoc {
doc: doc::traitdoc
) -> doc::traitdoc {
let srv = fold.ctxt;
let doc = fold::default_seq_fold_iface(fold, doc);
let doc = fold::default_seq_fold_trait(fold, doc);
{
methods: merge_method_attrs(srv, doc.id(), doc.methods)
@ -204,7 +204,7 @@ fn merge_method_attrs(
let attrs: ~[(str, option<str>)] = do astsrv::exec(srv) |ctxt| {
alt ctxt.ast_map.get(item_id) {
ast_map::node_item(@{
node: ast::item_iface(_, _, methods), _
node: ast::item_trait(_, _, methods), _
}, _) {
par::seqmap(methods, |method| {
(*method.ident, attr_parser::parse_desc(method.attrs))
@ -233,19 +233,19 @@ fn merge_method_attrs(
}
#[test]
fn should_extract_iface_docs() {
fn should_extract_trait_docs() {
let doc = test::mk_doc("#[doc = \"whatever\"] iface i { fn a(); }");
assert doc.cratemod().ifaces()[0].desc() == some("whatever");
assert doc.cratemod().traits()[0].desc() == some("whatever");
}
#[test]
fn should_extract_iface_method_docs() {
fn should_extract_trait_method_docs() {
let doc = test::mk_doc(
"iface i {\
#[doc = \"desc\"]\
fn f(a: bool) -> bool;\
}");
assert doc.cratemod().ifaces()[0].methods[0].desc == some("desc");
assert doc.cratemod().traits()[0].methods[0].desc == some("desc");
}

View File

@ -20,7 +20,7 @@ fn run(
) -> doc::doc {
let fold = fold::fold({
fold_item: fold_item,
fold_iface: fold_iface,
fold_trait: fold_trait,
fold_impl: fold_impl
with *fold::default_any_fold(())
});
@ -36,8 +36,8 @@ fn fold_item(fold: fold::fold<()>, doc: doc::itemdoc) -> doc::itemdoc {
}
}
fn fold_iface(fold: fold::fold<()>, doc: doc::ifacedoc) -> doc::ifacedoc {
let doc =fold::default_seq_fold_iface(fold, doc);
fn fold_trait(fold: fold::fold<()>, doc: doc::traitdoc) -> doc::traitdoc {
let doc =fold::default_seq_fold_trait(fold, doc);
{
methods: par::anymap(doc.methods, |doc| {
@ -67,9 +67,9 @@ fn should_promote_desc() {
}
#[test]
fn should_promote_iface_method_desc() {
fn should_promote_trait_method_desc() {
let doc = test::mk_doc("iface i { #[doc = \"desc\"] fn a(); }");
assert doc.cratemod().ifaces()[0].methods[0].brief == some("desc");
assert doc.cratemod().traits()[0].methods[0].brief == some("desc");
}
#[test]

View File

@ -33,7 +33,7 @@ enum itemtag {
consttag(constdoc),
fntag(fndoc),
enumtag(enumdoc),
ifacetag(ifacedoc),
traittag(traitdoc),
impltag(impldoc),
tytag(tydoc)
}
@ -81,7 +81,7 @@ type variantdoc = {
sig: option<str>
};
type ifacedoc = {
type traitdoc = {
item: itemdoc,
methods: ~[methoddoc]
};
@ -96,7 +96,7 @@ type methoddoc = {
type impldoc = {
item: itemdoc,
iface_ty: option<str>,
trait_ty: option<str>,
self_ty: option<str>,
methods: ~[methoddoc]
};
@ -187,10 +187,10 @@ impl util for moddoc {
}
}
fn ifaces() -> ~[ifacedoc] {
fn traits() -> ~[traitdoc] {
do vec::filter_map(self.items) |itemtag| {
alt itemtag {
ifacetag(ifacedoc) { some(ifacedoc) }
traittag(traitdoc) { some(traitdoc) }
_ { none }
}
}
@ -262,10 +262,10 @@ impl util for ~[page] {
}
}
fn ifaces() -> ~[ifacedoc] {
fn traits() -> ~[traitdoc] {
do vec::filter_map(self) |page| {
alt page {
itempage(ifacetag(ifacedoc)) { some(ifacedoc) }
itempage(traittag(traitdoc)) { some(traitdoc) }
_ { none }
}
}
@ -302,7 +302,7 @@ impl of item for itemtag {
doc::fntag(doc) { doc.item }
doc::consttag(doc) { doc.item }
doc::enumtag(doc) { doc.item }
doc::ifacetag(doc) { doc.item }
doc::traittag(doc) { doc.item }
doc::impltag(doc) { doc.item }
doc::tytag(doc) { doc.item }
}
@ -325,7 +325,7 @@ impl of item for enumdoc {
fn item() -> itemdoc { self.item }
}
impl of item for ifacedoc {
impl of item for traitdoc {
fn item() -> itemdoc { self.item }
}

View File

@ -83,9 +83,9 @@ fn moddoc_from_mod(
enumdoc_from_enum(itemdoc, variants)
))
}
ast::item_iface(_, _, methods) {
some(doc::ifacetag(
ifacedoc_from_iface(itemdoc, methods)
ast::item_trait(_, _, methods) {
some(doc::traittag(
traitdoc_from_trait(itemdoc, methods)
))
}
ast::item_impl(_, _, _, _, methods) {
@ -183,10 +183,10 @@ fn should_extract_enum_variants() {
assert doc.cratemod().enums()[0].variants[0].name == "v";
}
fn ifacedoc_from_iface(
fn traitdoc_from_trait(
itemdoc: doc::itemdoc,
methods: ~[ast::ty_method]
) -> doc::ifacedoc {
) -> doc::traitdoc {
{
item: itemdoc,
methods: do par::seqmap(methods) |method| {
@ -202,15 +202,15 @@ fn ifacedoc_from_iface(
}
#[test]
fn should_extract_ifaces() {
let doc = test::mk_doc("iface i { fn f(); }");
assert doc.cratemod().ifaces()[0].name() == "i";
fn should_extract_traits() {
let doc = test::mk_doc("trait i { fn f(); }");
assert doc.cratemod().traits()[0].name() == "i";
}
#[test]
fn should_extract_iface_methods() {
let doc = test::mk_doc("iface i { fn f(); }");
assert doc.cratemod().ifaces()[0].methods[0].name == "f";
fn should_extract_trait_methods() {
let doc = test::mk_doc("trait i { fn f(); }");
assert doc.cratemod().traits()[0].methods[0].name == "f";
}
fn impldoc_from_impl(
@ -219,7 +219,7 @@ fn impldoc_from_impl(
) -> doc::impldoc {
{
item: itemdoc,
iface_ty: none,
trait_ty: none,
self_ty: none,
methods: do par::seqmap(methods) |method| {
{

View File

@ -8,7 +8,7 @@ export default_seq_fold_nmod;
export default_seq_fold_fn;
export default_seq_fold_const;
export default_seq_fold_enum;
export default_seq_fold_iface;
export default_seq_fold_trait;
export default_seq_fold_impl;
export default_seq_fold_type;
export default_par_fold;
@ -28,7 +28,7 @@ type fold_nmod<T> = fn~(fold: fold<T>, doc: doc::nmoddoc) -> doc::nmoddoc;
type fold_fn<T> = fn~(fold: fold<T>, doc: doc::fndoc) -> doc::fndoc;
type fold_const<T> = fn~(fold: fold<T>, doc: doc::constdoc) -> doc::constdoc;
type fold_enum<T> = fn~(fold: fold<T>, doc: doc::enumdoc) -> doc::enumdoc;
type fold_iface<T> = fn~(fold: fold<T>, doc: doc::ifacedoc) -> doc::ifacedoc;
type fold_trait<T> = fn~(fold: fold<T>, doc: doc::traitdoc) -> doc::traitdoc;
type fold_impl<T> = fn~(fold: fold<T>, doc: doc::impldoc) -> doc::impldoc;
type fold_type<T> = fn~(fold: fold<T>, doc: doc::tydoc) -> doc::tydoc;
@ -42,7 +42,7 @@ type t<T> = {
fold_fn: fold_fn<T>,
fold_const: fold_const<T>,
fold_enum: fold_enum<T>,
fold_iface: fold_iface<T>,
fold_trait: fold_trait<T>,
fold_impl: fold_impl<T>,
fold_type: fold_type<T>
};
@ -60,7 +60,7 @@ fn mk_fold<T:copy>(
+fold_fn: fold_fn<T>,
+fold_const: fold_const<T>,
+fold_enum: fold_enum<T>,
+fold_iface: fold_iface<T>,
+fold_trait: fold_trait<T>,
+fold_impl: fold_impl<T>,
+fold_type: fold_type<T>
) -> fold<T> {
@ -74,7 +74,7 @@ fn mk_fold<T:copy>(
fold_fn: fold_fn,
fold_const: fold_const,
fold_enum: fold_enum,
fold_iface: fold_iface,
fold_trait: fold_trait,
fold_impl: fold_impl,
fold_type: fold_type
})
@ -91,7 +91,7 @@ fn default_any_fold<T:send copy>(ctxt: T) -> fold<T> {
|f, d| default_seq_fold_fn(f, d),
|f, d| default_seq_fold_const(f, d),
|f, d| default_seq_fold_enum(f, d),
|f, d| default_seq_fold_iface(f, d),
|f, d| default_seq_fold_trait(f, d),
|f, d| default_seq_fold_impl(f, d),
|f, d| default_seq_fold_type(f, d)
)
@ -108,7 +108,7 @@ fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
|f, d| default_seq_fold_fn(f, d),
|f, d| default_seq_fold_const(f, d),
|f, d| default_seq_fold_enum(f, d),
|f, d| default_seq_fold_iface(f, d),
|f, d| default_seq_fold_trait(f, d),
|f, d| default_seq_fold_impl(f, d),
|f, d| default_seq_fold_type(f, d)
)
@ -125,7 +125,7 @@ fn default_par_fold<T:send copy>(ctxt: T) -> fold<T> {
|f, d| default_seq_fold_fn(f, d),
|f, d| default_seq_fold_const(f, d),
|f, d| default_seq_fold_enum(f, d),
|f, d| default_seq_fold_iface(f, d),
|f, d| default_seq_fold_trait(f, d),
|f, d| default_seq_fold_impl(f, d),
|f, d| default_seq_fold_type(f, d)
)
@ -258,8 +258,8 @@ fn fold_itemtag<T>(fold: fold<T>, doc: doc::itemtag) -> doc::itemtag {
doc::enumtag(enumdoc) {
doc::enumtag(fold.fold_enum(fold, enumdoc))
}
doc::ifacetag(ifacedoc) {
doc::ifacetag(fold.fold_iface(fold, ifacedoc))
doc::traittag(traitdoc) {
doc::traittag(fold.fold_trait(fold, traitdoc))
}
doc::impltag(impldoc) {
doc::impltag(fold.fold_impl(fold, impldoc))
@ -300,10 +300,10 @@ fn default_seq_fold_enum<T>(
}
}
fn default_seq_fold_iface<T>(
fn default_seq_fold_trait<T>(
fold: fold<T>,
doc: doc::ifacedoc
) -> doc::ifacedoc {
doc: doc::traitdoc
) -> doc::traitdoc {
{
item: fold.fold_item(fold, doc.item)
with doc

View File

@ -198,7 +198,7 @@ fn header_kind(doc: doc::itemtag) -> str {
doc::enumtag(_) {
"Enum"
}
doc::ifacetag(_) {
doc::traittag(_) {
"Interface"
}
doc::impltag(doc) {
@ -222,9 +222,9 @@ fn header_name(doc: doc::itemtag) -> str {
doc::impltag(doc) {
assert option::is_some(doc.self_ty);
let self_ty = option::get(doc.self_ty);
alt doc.iface_ty {
some(iface_ty) {
#fmt("%s of %s for %s", doc.name(), iface_ty, self_ty)
alt doc.trait_ty {
some(trait_ty) {
#fmt("%s of %s for %s", doc.name(), trait_ty, self_ty)
}
none {
#fmt("%s for %s", doc.name(), self_ty)
@ -349,7 +349,7 @@ fn write_item_(ctxt: ctxt, doc: doc::itemtag, write_header: bool) {
doc::fntag(fndoc) { write_fn(ctxt, fndoc) }
doc::consttag(constdoc) { write_const(ctxt, constdoc) }
doc::enumtag(enumdoc) { write_enum(ctxt, enumdoc) }
doc::ifacetag(ifacedoc) { write_iface(ctxt, ifacedoc) }
doc::traittag(traitdoc) { write_trait(ctxt, traitdoc) }
doc::impltag(impldoc) { write_impl(ctxt, impldoc) }
doc::tytag(tydoc) { write_type(ctxt, tydoc) }
}
@ -639,7 +639,7 @@ fn should_write_variant_list_with_signatures() {
\n* `c(int)` - a\n\n");
}
fn write_iface(ctxt: ctxt, doc: doc::ifacedoc) {
fn write_trait(ctxt: ctxt, doc: doc::traitdoc) {
write_common(ctxt, doc.desc(), doc.sections());
write_methods(ctxt, doc.methods);
}
@ -659,27 +659,27 @@ fn write_method(ctxt: ctxt, doc: doc::methoddoc) {
}
#[test]
fn should_write_iface_header() {
fn should_write_trait_header() {
let markdown = test::render("iface i { fn a(); }");
assert str::contains(markdown, "## Interface `i`");
}
#[test]
fn should_write_iface_desc() {
fn should_write_trait_desc() {
let markdown = test::render(
"#[doc = \"desc\"] iface i { fn a(); }");
assert str::contains(markdown, "desc");
}
#[test]
fn should_write_iface_method_header() {
fn should_write_trait_method_header() {
let markdown = test::render(
"iface i { fn a(); }");
assert str::contains(markdown, "### Method `a`");
}
#[test]
fn should_write_iface_method_signature() {
fn should_write_trait_method_signature() {
let markdown = test::render(
"iface i { fn a(); }");
assert str::contains(markdown, "\n fn a()");
@ -697,7 +697,7 @@ fn should_write_impl_header() {
}
#[test]
fn should_write_impl_header_with_iface() {
fn should_write_impl_header_with_trait() {
let markdown = test::render("impl i of j for int { fn a() { } }");
assert str::contains(markdown, "## Implementation `i of j for int`");
}

View File

@ -202,9 +202,9 @@ fn should_prune_unexported_variants() {
}
#[test]
fn should_prune_unexported_ifaces_from_top_mod() {
fn should_prune_unexported_traits_from_top_mod() {
let doc = test::mk_doc("export a; mod a { } iface b { fn c(); }");
assert vec::is_empty(doc.cratemod().ifaces());
assert vec::is_empty(doc.cratemod().traits());
}
#[test]

View File

@ -374,8 +374,8 @@ fn merge_reexports(
with doc
})
}
doc::ifacetag(doc @ {item, _}) {
doc::ifacetag({
doc::traittag(doc @ {item, _}) {
doc::traittag({
item: reexport(item, name)
with doc
})

View File

@ -12,7 +12,7 @@ fn mk_pass() -> pass {
fn run(_srv: astsrv::srv, doc: doc::doc) -> doc::doc {
let fold = fold::fold({
fold_item: fold_item,
fold_iface: fold_iface,
fold_trait: fold_trait,
fold_impl: fold_impl
with *fold::default_any_fold(())
});
@ -30,8 +30,8 @@ fn fold_item(fold: fold::fold<()>, doc: doc::itemdoc) -> doc::itemdoc {
}
}
fn fold_iface(fold: fold::fold<()>, doc: doc::ifacedoc) -> doc::ifacedoc {
let doc = fold::default_seq_fold_iface(fold, doc);
fn fold_trait(fold: fold::fold<()>, doc: doc::traitdoc) -> doc::traitdoc {
let doc = fold::default_seq_fold_trait(fold, doc);
{
methods: do par::anymap(doc.methods) |method| {
@ -202,14 +202,14 @@ fn should_eliminate_desc_if_it_is_just_whitespace() {
}
#[test]
fn should_sectionalize_iface_methods() {
fn should_sectionalize_trait_methods() {
let doc = test::mk_doc(
"iface i {
#[doc = \"\
# Header\n\
Body\"]\
fn a(); }");
assert doc.cratemod().ifaces()[0].methods[0].sections.len() == 1u;
assert doc.cratemod().traits()[0].methods[0].sections.len() == 1u;
}
#[test]

View File

@ -9,7 +9,7 @@ fn mk_pass() -> pass {
doc::consttag(_) { 0 }
doc::tytag(_) { 1 }
doc::enumtag(_) { 2 }
doc::ifacetag(_) { 3 }
doc::traittag(_) { 3 }
doc::impltag(_) { 4 }
doc::fntag(_) { 5 }
doc::modtag(_) { 6 }

View File

@ -22,7 +22,7 @@ fn run(
let fold = fold::fold({
fold_item: fold_item,
fold_enum: fold_enum,
fold_iface: fold_iface,
fold_trait: fold_trait,
fold_impl: fold_impl
with *fold::default_any_fold(op)
});
@ -65,8 +65,8 @@ fn fold_enum(fold: fold::fold<op>, doc: doc::enumdoc) -> doc::enumdoc {
}
}
fn fold_iface(fold: fold::fold<op>, doc: doc::ifacedoc) -> doc::ifacedoc {
let doc = fold::default_seq_fold_iface(fold, doc);
fn fold_trait(fold: fold::fold<op>, doc: doc::traitdoc) -> doc::traitdoc {
let doc = fold::default_seq_fold_trait(fold, doc);
{
methods: apply_to_methods(fold.ctxt, doc.methods)
@ -113,31 +113,31 @@ fn should_execute_op_on_variant_desc() {
}
#[test]
fn should_execute_op_on_iface_brief() {
fn should_execute_op_on_trait_brief() {
let doc = test::mk_doc(
"#[doc = \" a \"] iface i { fn a(); }");
assert doc.cratemod().ifaces()[0].brief() == some("a");
assert doc.cratemod().traits()[0].brief() == some("a");
}
#[test]
fn should_execute_op_on_iface_desc() {
fn should_execute_op_on_trait_desc() {
let doc = test::mk_doc(
"#[doc = \" a \"] iface i { fn a(); }");
assert doc.cratemod().ifaces()[0].desc() == some("a");
assert doc.cratemod().traits()[0].desc() == some("a");
}
#[test]
fn should_execute_op_on_iface_method_brief() {
fn should_execute_op_on_trait_method_brief() {
let doc = test::mk_doc(
"iface i { #[doc = \" a \"] fn a(); }");
assert doc.cratemod().ifaces()[0].methods[0].brief == some("a");
assert doc.cratemod().traits()[0].methods[0].brief == some("a");
}
#[test]
fn should_execute_op_on_iface_method_desc() {
fn should_execute_op_on_trait_method_desc() {
let doc = test::mk_doc(
"iface i { #[doc = \" a \"] fn a(); }");
assert doc.cratemod().ifaces()[0].methods[0].desc == some("a");
assert doc.cratemod().traits()[0].methods[0].desc == some("a");
}
#[test]
@ -203,26 +203,26 @@ fn should_execute_on_item_section_bodies() {
}
#[test]
fn should_execute_on_iface_method_section_headers() {
fn should_execute_on_trait_method_section_headers() {
let doc = test::mk_doc(
"iface i {
#[doc = \"\
# Header \n\
Body\"]\
fn a(); }");
assert doc.cratemod().ifaces()[0].methods[0].sections[0].header
assert doc.cratemod().traits()[0].methods[0].sections[0].header
== "Header";
}
#[test]
fn should_execute_on_iface_method_section_bodies() {
fn should_execute_on_trait_method_section_bodies() {
let doc = test::mk_doc(
"iface i {
#[doc = \"\
# Header\n\
Body \"]\
fn a(); }");
assert doc.cratemod().ifaces()[0].methods[0].sections[0].body == "Body";
assert doc.cratemod().traits()[0].methods[0].sections[0].body == "Body";
}
#[test]

View File

@ -22,7 +22,7 @@ fn run(
fold_fn: fold_fn,
fold_const: fold_const,
fold_enum: fold_enum,
fold_iface: fold_iface,
fold_trait: fold_trait,
fold_impl: fold_impl,
fold_type: fold_type
with *fold::default_any_fold(srv)
@ -137,10 +137,10 @@ fn should_add_variant_sigs() {
assert doc.cratemod().enums()[0].variants[0].sig == some("b(int)");
}
fn fold_iface(
fn fold_trait(
fold: fold::fold<astsrv::srv>,
doc: doc::ifacedoc
) -> doc::ifacedoc {
doc: doc::traitdoc
) -> doc::traitdoc {
{
methods: merge_methods(fold.ctxt, doc.id(), doc.methods)
with doc
@ -168,7 +168,7 @@ fn get_method_sig(
do astsrv::exec(srv) |ctxt| {
alt check ctxt.ast_map.get(item_id) {
ast_map::node_item(@{
node: ast::item_iface(_, _, methods), _
node: ast::item_trait(_, _, methods), _
}, _) {
alt check vec::find(methods, |method| {
*method.ident == method_name
@ -202,9 +202,9 @@ fn get_method_sig(
}
#[test]
fn should_add_iface_method_sigs() {
fn should_add_trait_method_sigs() {
let doc = test::mk_doc("iface i { fn a<T>() -> int; }");
assert doc.cratemod().ifaces()[0].methods[0].sig
assert doc.cratemod().traits()[0].methods[0].sig
== some("fn a<T>() -> int");
}
@ -215,22 +215,22 @@ fn fold_impl(
let srv = fold.ctxt;
let (iface_ty, self_ty) = do astsrv::exec(srv) |ctxt| {
let (trait_ty, self_ty) = do astsrv::exec(srv) |ctxt| {
alt ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
node: ast::item_impl(_, _, iface_ty, self_ty, _), _
node: ast::item_impl(_, _, trait_ty, self_ty, _), _
}, _) {
let iface_ty = option::map(iface_ty, |p| {
let trait_ty = option::map(trait_ty, |p| {
pprust::path_to_str(p.path)
});
(iface_ty, some(pprust::ty_to_str(self_ty)))
(trait_ty, some(pprust::ty_to_str(self_ty)))
}
_ { fail "expected impl" }
}
};
{
iface_ty: iface_ty,
trait_ty: trait_ty,
self_ty: self_ty,
methods: merge_methods(fold.ctxt, doc.id(), doc.methods)
with doc
@ -238,15 +238,15 @@ fn fold_impl(
}
#[test]
fn should_add_impl_iface_ty() {
fn should_add_impl_trait_ty() {
let doc = test::mk_doc("impl i of j for int { fn a<T>() { } }");
assert doc.cratemod().impls()[0].iface_ty == some("j");
assert doc.cratemod().impls()[0].trait_ty == some("j");
}
#[test]
fn should_not_add_impl_iface_ty_if_none() {
fn should_not_add_impl_trait_ty_if_none() {
let doc = test::mk_doc("impl i for int { fn a() { } }");
assert doc.cratemod().impls()[0].iface_ty == none;
assert doc.cratemod().impls()[0].trait_ty == none;
}
#[test]