Skip to content

A handful of cleanups and minor bug fixes #7382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ use syntax::ast;
use syntax::ast_map;
use syntax::diagnostic::expect;

pub struct ProvidedTraitMethodInfo {
ty: ty::Method,
def_id: ast::def_id
}

pub struct StaticMethodInfo {
ident: ast::ident,
def_id: ast::def_id,
Expand Down Expand Up @@ -134,7 +129,7 @@ pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,

pub fn get_provided_trait_methods(tcx: ty::ctxt,
def: ast::def_id)
-> ~[ProvidedTraitMethodInfo] {
-> ~[@ty::Method] {
let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)
Expand Down
13 changes: 4 additions & 9 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::prelude::*;

use metadata::cstore::crate_metadata;
use metadata::common::*;
use metadata::csearch::{ProvidedTraitMethodInfo, StaticMethodInfo};
use metadata::csearch::StaticMethodInfo;
use metadata::csearch;
use metadata::cstore;
use metadata::decoder;
Expand Down Expand Up @@ -752,7 +752,7 @@ pub fn get_trait_method_def_ids(cdata: cmd,

pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
id: ast::node_id, tcx: ty::ctxt) ->
~[ProvidedTraitMethodInfo] {
~[@ty::Method] {
let data = cdata.data;
let item = lookup_item(id, data);
let mut result = ~[];
Expand All @@ -763,13 +763,8 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,

if item_method_sort(mth) != 'p' { loop; }

let ty_method = get_method(intr, cdata, did.node, tcx);
let provided_trait_method_info = ProvidedTraitMethodInfo {
ty: ty_method,
def_id: did
};

vec::push(&mut result, provided_trait_method_info);
vec::push(&mut result,
@get_method(intr, cdata, did.node, tcx));
}

return result;
Expand Down
31 changes: 15 additions & 16 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,21 +1683,20 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,

match fcx.llself {
Some(slf) => {
// We really should do this regardless of whether self is owned, but
// it doesn't work right with default method impls yet. (FIXME: #2794)
if slf.is_owned {
let self_val = if datum::appropriate_mode(slf.t).is_by_value() {
let tmp = BitCast(bcx, slf.v, type_of(bcx.ccx(), slf.t));
let alloc = alloc_ty(bcx, slf.t);
Store(bcx, tmp, alloc);
alloc
} else {
PointerCast(bcx, slf.v, type_of(bcx.ccx(), slf.t).ptr_to())
};

fcx.llself = Some(ValSelfData {v: self_val, ..slf});
add_clean(bcx, self_val, slf.t);
}
let self_val = if slf.is_owned
&& datum::appropriate_mode(slf.t).is_by_value() {
let tmp = BitCast(bcx, slf.v, type_of(bcx.ccx(), slf.t));
let alloc = alloc_ty(bcx, slf.t);
Store(bcx, tmp, alloc);
alloc
} else {
PointerCast(bcx, slf.v, type_of(bcx.ccx(), slf.t).ptr_to())
};

fcx.llself = Some(ValSelfData {v: self_val, ..slf});
if slf.is_owned {
add_clean(bcx, self_val, slf.t);
}
}
_ => {}
}
Expand Down Expand Up @@ -2110,7 +2109,7 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
}
ast::item_impl(ref generics, _, _, ref ms) => {
meth::trans_impl(ccx, /*bad*/copy *path, item.ident, *ms,
generics, None, item.id);
generics, item.id);
}
ast::item_mod(ref m) => {
trans_mod(ccx, m);
Expand Down
8 changes: 1 addition & 7 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,14 +1051,8 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
debug!("def_self() reference, self_info.t=%s",
self_info.t.repr(bcx.tcx()));

// This cast should not be necessary. We should cast self *once*,
// but right now this conflicts with default methods.
let real_self_ty = monomorphize_type(bcx, self_info.t);
let llselfty = type_of::type_of(bcx.ccx(), real_self_ty).ptr_to();

let casted_val = PointerCast(bcx, self_info.v, llselfty);
Datum {
val: casted_val,
val: self_info.v,
ty: self_info.t,
mode: ByRef(ZeroMem)
}
Expand Down
37 changes: 7 additions & 30 deletions src/librustc/middle/trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ pub fn trans_impl(ccx: @mut CrateContext,
name: ast::ident,
methods: &[@ast::method],
generics: &ast::Generics,
self_ty: Option<ty::t>,
id: ast::node_id) {
let _icx = push_ctxt("impl::trans_impl");
let tcx = ccx.tcx;

debug!("trans_impl(path=%s, name=%s, self_ty=%s, id=%?)",
path.repr(tcx), name.repr(tcx), self_ty.repr(tcx), id);
debug!("trans_impl(path=%s, name=%s, id=%?)",
path.repr(tcx), name.repr(tcx), id);

if !generics.ty_params.is_empty() { return; }
let sub_path = vec::append_one(path, path_name(name));
Expand All @@ -65,24 +64,10 @@ pub fn trans_impl(ccx: @mut CrateContext,
let path = vec::append_one(/*bad*/copy sub_path,
path_name(method.ident));

let param_substs_opt;
match self_ty {
None => param_substs_opt = None,
Some(self_ty) => {
param_substs_opt = Some(@param_substs {
tys: ~[],
vtables: None,
type_param_defs: @~[],
self_ty: Some(self_ty)
});
}
}

trans_method(ccx,
path,
*method,
param_substs_opt,
self_ty,
None,
llfn,
ast_util::local_def(id));
}
Expand All @@ -98,17 +83,13 @@ Translates a (possibly monomorphized) method body.
- `method`: the AST node for the method
- `param_substs`: if this is a generic method, the current values for
type parameters and so forth, else none
- `base_self_ty`: optionally, the explicit self type for this method. This
will be none if this is not a default method and must always be present
if this is a default method.
- `llfn`: the LLVM ValueRef for the method
- `impl_id`: the node ID of the impl this method is inside
*/
pub fn trans_method(ccx: @mut CrateContext,
path: path,
method: &ast::method,
param_substs: Option<@param_substs>,
base_self_ty: Option<ty::t>,
llfn: ValueRef,
impl_id: ast::def_id) {
// figure out how self is being passed
Expand All @@ -119,18 +100,14 @@ pub fn trans_method(ccx: @mut CrateContext,
_ => {
// determine the (monomorphized) type that `self` maps to for
// this method
let self_ty = match base_self_ty {
None => ty::node_id_to_type(ccx.tcx, method.self_id),
Some(provided_self_ty) => provided_self_ty,
};
let self_ty = ty::node_id_to_type(ccx.tcx, method.self_id);
let self_ty = match param_substs {
None => self_ty,
Some(@param_substs {tys: ref tys, _}) => {
ty::subst_tps(ccx.tcx, *tys, None, self_ty)
Some(@param_substs {tys: ref tys, self_ty: ref self_sub, _}) => {
ty::subst_tps(ccx.tcx, *tys, *self_sub, self_ty)
}
};
debug!("calling trans_fn with base_self_ty %s, self_ty %s",
base_self_ty.repr(ccx.tcx),
debug!("calling trans_fn with self_ty %s",
self_ty.repr(ccx.tcx));
match method.explicit_self.node {
ast::sty_value => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
Some(override_impl_did) => impl_did = override_impl_did
}

meth::trans_method(ccx, pt, mth, psubsts, None, d, impl_did);
meth::trans_method(ccx, pt, mth, psubsts, d, impl_did);
d
}
ast_map::node_trait_method(@ast::provided(mth), _, pt) => {
let d = mk_lldecl();
set_inline_hint_if_appr(/*bad*/copy mth.attrs, d);
debug!("monomorphic_fn impl_did_opt is %?", impl_did_opt);
meth::trans_method(ccx, /*bad*/copy *pt, mth, psubsts, None, d,
meth::trans_method(ccx, /*bad*/copy *pt, mth, psubsts, d,
impl_did_opt.get());
d
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3649,21 +3649,21 @@ pub fn def_has_ty_params(def: ast::def) -> bool {
}
}

pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] {
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[@Method] {
if is_local(id) {
match cx.items.find(&id.node) {
Some(&ast_map::node_item(@ast::item {
node: item_trait(_, _, ref ms),
_
}, _)) =>
match ast_util::split_trait_methods(*ms) {
(_, p) => p.map(|method| method.ident)
(_, p) => p.map(|m| method(cx, ast_util::local_def(m.id)))
},
_ => cx.sess.bug(fmt!("provided_trait_methods: %? is not a trait",
id))
}
} else {
csearch::get_provided_trait_methods(cx, id).map(|ifo| ifo.ty.ident)
csearch::get_provided_trait_methods(cx, id)
}
}

Expand Down
34 changes: 6 additions & 28 deletions src/librustc/middle/typeck/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ impl CoherenceChecker {

let impl_poly_type = ty::lookup_item_type(tcx, impl_id);

for self.each_provided_trait_method(trait_ref.def_id) |trait_method| {
let provided = ty::provided_trait_methods(tcx, trait_ref.def_id);
for provided.iter().advance |trait_method| {
// Synthesize an ID.
let new_id = parse::next_node_id(tcx.sess.parse_sess);
let new_did = local_def(new_id);
Expand All @@ -347,7 +348,7 @@ impl CoherenceChecker {
impl_id,
trait_ref,
new_did,
trait_method);
*trait_method);

debug!("new_method_ty=%s", new_method_ty.repr(tcx));

Expand Down Expand Up @@ -526,29 +527,6 @@ impl CoherenceChecker {
}
}

pub fn each_provided_trait_method(&self,
trait_did: ast::def_id,
f: &fn(x: @ty::Method) -> bool)
-> bool {
// Make a list of all the names of the provided methods.
// XXX: This is horrible.
let mut provided_method_idents = HashSet::new();
let tcx = self.crate_context.tcx;
let r = ty::provided_trait_methods(tcx, trait_did);
for r.iter().advance |ident| {
provided_method_idents.insert(*ident);
}

for ty::trait_methods(tcx, trait_did).iter().advance |&method| {
if provided_method_idents.contains(&method.ident) {
if !f(method) {
return false;
}
}
}
return true;
}

pub fn polytypes_unify(&self,
polytype_a: ty_param_bounds_and_ty,
polytype_b: ty_param_bounds_and_ty)
Expand Down Expand Up @@ -729,9 +707,9 @@ impl CoherenceChecker {
}
// Default methods
let r = ty::provided_trait_methods(tcx, trait_did);
for r.iter().advance |ident| {
debug!("inserting provided method %s", ident.repr(tcx));
provided_names.insert(*ident);
for r.iter().advance |method| {
debug!("inserting provided method %s", method.ident.repr(tcx));
provided_names.insert(method.ident);
}

let r = ty::trait_methods(tcx, trait_did);
Expand Down
19 changes: 9 additions & 10 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ fn output_file_name(workspace: &Path, short_name: &str) -> Path {
workspace.push(fmt!("%s%s", short_name, os::EXE_SUFFIX))
}

fn touch_source_file(workspace: &Path, short_name: &str) {
fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
use conditions::bad_path::cond;
let pkg_src_dir = workspace.push("src").push(short_name);
let contents = os::list_dir(&pkg_src_dir);
let pkg_src_dir = workspace.push("src").push(pkgid.to_str());
let contents = os::list_dir_path(&pkg_src_dir);
for contents.iter().advance |p| {
if Path(copy *p).filetype() == Some(~".rs") {
if p.filetype() == Some(~".rs") {
// should be able to do this w/o a process
if run::process_output("touch", [p.to_str()]).status != 0 {
let _ = cond.raise((copy pkg_src_dir, ~"Bad path"));
Expand All @@ -287,20 +287,19 @@ fn touch_source_file(workspace: &Path, short_name: &str) {
fn frob_source_file(workspace: &Path, pkgid: &PkgId) {
use conditions::bad_path::cond;
let pkg_src_dir = workspace.push("src").push(pkgid.to_str());
let contents = os::list_dir(&pkg_src_dir);
let contents = os::list_dir_path(&pkg_src_dir);
let mut maybe_p = None;
for contents.iter().advance |p| {
if Path(copy *p).filetype() == Some(~".rs") {
if p.filetype() == Some(~".rs") {
maybe_p = Some(p);
break;
}
}
match maybe_p {
Some(p) => {
let p = Path(copy *p);
let w = io::buffered_file_writer(&p);
let w = io::file_writer(*p, &[io::Append]);
match w {
Err(s) => { let _ = cond.raise((p, fmt!("Bad path: %s", s))); }
Err(s) => { let _ = cond.raise((copy **p, fmt!("Bad path: %s", s))); }
Ok(w) => w.write_line("")
}
}
Expand Down Expand Up @@ -615,7 +614,7 @@ fn do_rebuild_dep_dates_change() {
let workspace = create_local_package_with_dep(&p_id, &dep_id);
command_line_test([~"build", ~"foo"], &workspace);
let bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar"));
touch_source_file(&workspace, "bar");
touch_source_file(&workspace, &dep_id);
command_line_test([~"build", ~"foo"], &workspace);
let new_bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar"));
assert!(new_bar_date > bar_date);
Expand Down