Skip to content

Commit

Permalink
auto merge of #5676 : nikomatsakis/rust/issue-4183-trait_ref, r=nikom…
Browse files Browse the repository at this point in the history
…atsakis

These are a number of incremental steps towards #4183 and #4646.
  • Loading branch information
bors committed Apr 6, 2013
2 parents babe506 + 13801f6 commit 08e2cf8
Show file tree
Hide file tree
Showing 60 changed files with 1,895 additions and 1,422 deletions.
2 changes: 1 addition & 1 deletion src/libcore/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ pub mod funcs {
use libc::types::common::posix88::{DIR, dirent_t};
use libc::types::os::arch::c95::{c_char, c_int, c_long};

// NOTE: On OS X opendir and readdir have two versions,
// NB: On OS X opendir and readdir have two versions,
// one for 32-bit kernelspace and one for 64.
// We should be linking to the 64-bit ones, called
// opendir$INODE64, etc. but for some reason rustc
Expand Down
28 changes: 27 additions & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ use ops::Add;
use kinds::Copy;
use util;
use num::Zero;
use iter::{BaseIter, MutableIter};
use iter::{BaseIter, MutableIter, ExtendedIter};
use iter;

#[cfg(test)] use ptr;
#[cfg(test)] use str;
Expand Down Expand Up @@ -118,6 +119,31 @@ impl<T> MutableIter<T> for Option<T> {
}
}

impl<A> ExtendedIter<A> for Option<A> {
pub fn eachi(&self, blk: &fn(uint, v: &A) -> bool) {
iter::eachi(self, blk)
}
pub fn all(&self, blk: &fn(&A) -> bool) -> bool {
iter::all(self, blk)
}
pub fn any(&self, blk: &fn(&A) -> bool) -> bool {
iter::any(self, blk)
}
pub fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B {
iter::foldl(self, b0, blk)
}
pub fn position(&self, f: &fn(&A) -> bool) -> Option<uint> {
iter::position(self, f)
}
fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] {
iter::map_to_vec(self, op)
}
fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB)
-> ~[B] {
iter::flat_map_to_vec(self, op)
}
}

pub impl<T> Option<T> {
/// Returns true if the option equals `none`
fn is_none(&const self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
}

fn visit_trait(&self) -> bool {
self.align_to::<TyVisitor>();
self.align_to::<@TyVisitor>();
if ! self.inner.visit_trait() { return false; }
self.bump_past::<TyVisitor>();
self.bump_past::<@TyVisitor>();
true
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub fn start_program(prog: &str, args: &[~str]) -> @Program {
@ProgRes(repr) as @Program
}

fn read_all(rd: io::Reader) -> ~str {
fn read_all(rd: @io::Reader) -> ~str {
let buf = io::with_bytes_writer(|wr| {
let mut bytes = [0, ..4096];
while !rd.eof() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub fn compile_rest(sess: Session, cfg: ast::crate_cfg,

};

// NOTE: Android hack
// NB: Android hack
if sess.targ_cfg.arch == abi::Arm &&
(sess.opts.output_type == link::output_type_object ||
sess.opts.output_type == link::output_type_exe) {
Expand Down
9 changes: 8 additions & 1 deletion src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ pub static tag_crate_dep_vers: uint = 0x2cu;
pub static tag_mod_impl: uint = 0x30u;

pub static tag_item_trait_method: uint = 0x31u;
pub static tag_impl_trait: uint = 0x32u;

pub static tag_item_trait_ref: uint = 0x32u;
pub static tag_item_super_trait_ref: uint = 0x33u;

// discriminator value for variants
pub static tag_disr_val: uint = 0x34u;
Expand Down Expand Up @@ -102,6 +104,7 @@ pub static tag_item_dtor: uint = 0x49u;
pub static tag_item_trait_method_self_ty: uint = 0x4b;
pub static tag_item_trait_method_self_ty_region: uint = 0x4c;


// Reexports are found within module tags. Each reexport contains def_ids
// and names.
pub static tag_items_data_item_reexport: uint = 0x4d;
Expand Down Expand Up @@ -159,6 +162,10 @@ pub static tag_items_data_item_visibility: uint = 0x78;
pub static tag_link_args: uint = 0x79;
pub static tag_link_args_arg: uint = 0x7a;

pub static tag_item_method_tps: uint = 0x7b;
pub static tag_item_method_fty: uint = 0x7c;
pub static tag_item_method_transformed_self_ty: uint = 0x7d;

pub struct LinkMeta {
name: @str,
vers: @str,
Expand Down
44 changes: 28 additions & 16 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,24 @@ pub fn get_impls_for_mod(cstore: @mut cstore::CStore, def: ast::def_id,
}
}

pub fn get_trait_methods(tcx: ty::ctxt,
def: ast::def_id)
-> @~[ty::method] {
let cstore = tcx.cstore;
pub fn get_method(tcx: ty::ctxt,
def: ast::def_id) -> ty::method
{
let cdata = cstore::get_crate_data(tcx.cstore, def.crate);
decoder::get_method(tcx.cstore.intr, cdata, def.node, tcx)
}

pub fn get_method_name_and_self_ty(cstore: @mut cstore::CStore,
def: ast::def_id) -> (ast::ident, ast::self_ty_)
{
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_method_name_and_self_ty(cstore.intr, cdata, def.node)
}

pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,
def: ast::def_id) -> ~[ast::def_id] {
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_trait_methods(cstore.intr, cdata, def.node, tcx)
decoder::get_trait_method_def_ids(cdata, def.node)
}

pub fn get_provided_trait_methods(tcx: ty::ctxt,
Expand All @@ -127,19 +139,12 @@ pub fn get_provided_trait_methods(tcx: ty::ctxt,
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)
}

pub fn get_supertraits(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::t] {
pub fn get_supertraits(tcx: ty::ctxt, def: ast::def_id) -> ~[@ty::TraitRef] {
let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_supertraits(cdata, def.node, tcx)
}

pub fn get_method_names_if_trait(cstore: @mut cstore::CStore,
def: ast::def_id)
-> Option<~[(ast::ident, ast::self_ty_)]> {
let cdata = cstore::get_crate_data(cstore, def.crate);
return decoder::get_method_names_if_trait(cstore.intr, cdata, def.node);
}

pub fn get_type_name_if_impl(cstore: @mut cstore::CStore, def: ast::def_id)
-> Option<ast::ident> {
let cdata = cstore::get_crate_data(cstore, def.crate);
Expand Down Expand Up @@ -175,6 +180,12 @@ pub fn get_type(tcx: ty::ctxt,
decoder::get_type(cdata, def.node, tcx)
}

pub fn get_trait_def(tcx: ty::ctxt, def: ast::def_id) -> ty::TraitDef {
let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_trait_def(cdata, def.node, tcx)
}

pub fn get_region_param(cstore: @mut metadata::cstore::CStore,
def: ast::def_id) -> Option<ty::region_variance> {
let cdata = cstore::get_crate_data(cstore, def.crate);
Expand All @@ -199,16 +210,17 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
debug!("got field data %?", the_field);
let ty = decoder::item_type(def, the_field, tcx, cdata);
ty::ty_param_bounds_and_ty {
bounds: @~[],
region_param: None,
generics: ty::Generics {bounds: @~[],
region_param: None},
ty: ty
}
}

// Given a def_id for an impl or class, return the traits it implements,
// or the empty vector if it's not for an impl or for a class that implements
// traits
pub fn get_impl_traits(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::t] {
pub fn get_impl_traits(tcx: ty::ctxt,
def: ast::def_id) -> ~[@ty::TraitRef] {
let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_impl_traits(cdata, def.node, tcx)
Expand Down
Loading

0 comments on commit 08e2cf8

Please sign in to comment.