Skip to content

Commit 32adc0e

Browse files
committed
auto merge of #7382 : msullivan/rust/cleanup, r=bblum
2 parents 23fb227 + 663f298 commit 32adc0e

File tree

9 files changed

+48
-111
lines changed

9 files changed

+48
-111
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ use syntax::ast;
2424
use syntax::ast_map;
2525
use syntax::diagnostic::expect;
2626

27-
pub struct ProvidedTraitMethodInfo {
28-
ty: ty::Method,
29-
def_id: ast::def_id
30-
}
31-
3227
pub struct StaticMethodInfo {
3328
ident: ast::ident,
3429
def_id: ast::def_id,
@@ -134,7 +129,7 @@ pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,
134129

135130
pub fn get_provided_trait_methods(tcx: ty::ctxt,
136131
def: ast::def_id)
137-
-> ~[ProvidedTraitMethodInfo] {
132+
-> ~[@ty::Method] {
138133
let cstore = tcx.cstore;
139134
let cdata = cstore::get_crate_data(cstore, def.crate);
140135
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)

src/librustc/metadata/decoder.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::prelude::*;
1414

1515
use metadata::cstore::crate_metadata;
1616
use metadata::common::*;
17-
use metadata::csearch::{ProvidedTraitMethodInfo, StaticMethodInfo};
17+
use metadata::csearch::StaticMethodInfo;
1818
use metadata::csearch;
1919
use metadata::cstore;
2020
use metadata::decoder;
@@ -752,7 +752,7 @@ pub fn get_trait_method_def_ids(cdata: cmd,
752752

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

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

766-
let ty_method = get_method(intr, cdata, did.node, tcx);
767-
let provided_trait_method_info = ProvidedTraitMethodInfo {
768-
ty: ty_method,
769-
def_id: did
770-
};
771-
772-
vec::push(&mut result, provided_trait_method_info);
766+
vec::push(&mut result,
767+
@get_method(intr, cdata, did.node, tcx));
773768
}
774769

775770
return result;

src/librustc/middle/trans/base.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,21 +1683,20 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
16831683

16841684
match fcx.llself {
16851685
Some(slf) => {
1686-
// We really should do this regardless of whether self is owned, but
1687-
// it doesn't work right with default method impls yet. (FIXME: #2794)
1688-
if slf.is_owned {
1689-
let self_val = if datum::appropriate_mode(slf.t).is_by_value() {
1690-
let tmp = BitCast(bcx, slf.v, type_of(bcx.ccx(), slf.t));
1691-
let alloc = alloc_ty(bcx, slf.t);
1692-
Store(bcx, tmp, alloc);
1693-
alloc
1694-
} else {
1695-
PointerCast(bcx, slf.v, type_of(bcx.ccx(), slf.t).ptr_to())
1696-
};
1697-
1698-
fcx.llself = Some(ValSelfData {v: self_val, ..slf});
1699-
add_clean(bcx, self_val, slf.t);
1700-
}
1686+
let self_val = if slf.is_owned
1687+
&& datum::appropriate_mode(slf.t).is_by_value() {
1688+
let tmp = BitCast(bcx, slf.v, type_of(bcx.ccx(), slf.t));
1689+
let alloc = alloc_ty(bcx, slf.t);
1690+
Store(bcx, tmp, alloc);
1691+
alloc
1692+
} else {
1693+
PointerCast(bcx, slf.v, type_of(bcx.ccx(), slf.t).ptr_to())
1694+
};
1695+
1696+
fcx.llself = Some(ValSelfData {v: self_val, ..slf});
1697+
if slf.is_owned {
1698+
add_clean(bcx, self_val, slf.t);
1699+
}
17011700
}
17021701
_ => {}
17031702
}
@@ -2110,7 +2109,7 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
21102109
}
21112110
ast::item_impl(ref generics, _, _, ref ms) => {
21122111
meth::trans_impl(ccx, /*bad*/copy *path, item.ident, *ms,
2113-
generics, None, item.id);
2112+
generics, item.id);
21142113
}
21152114
ast::item_mod(ref m) => {
21162115
trans_mod(ccx, m);

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,8 @@ pub fn trans_local_var(bcx: block, def: ast::def) -> Datum {
10511051
debug!("def_self() reference, self_info.t=%s",
10521052
self_info.t.repr(bcx.tcx()));
10531053

1054-
// This cast should not be necessary. We should cast self *once*,
1055-
// but right now this conflicts with default methods.
1056-
let real_self_ty = monomorphize_type(bcx, self_info.t);
1057-
let llselfty = type_of::type_of(bcx.ccx(), real_self_ty).ptr_to();
1058-
1059-
let casted_val = PointerCast(bcx, self_info.v, llselfty);
10601054
Datum {
1061-
val: casted_val,
1055+
val: self_info.v,
10621056
ty: self_info.t,
10631057
mode: ByRef(ZeroMem)
10641058
}

src/librustc/middle/trans/meth.rs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ pub fn trans_impl(ccx: @mut CrateContext,
4949
name: ast::ident,
5050
methods: &[@ast::method],
5151
generics: &ast::Generics,
52-
self_ty: Option<ty::t>,
5352
id: ast::node_id) {
5453
let _icx = push_ctxt("impl::trans_impl");
5554
let tcx = ccx.tcx;
5655

57-
debug!("trans_impl(path=%s, name=%s, self_ty=%s, id=%?)",
58-
path.repr(tcx), name.repr(tcx), self_ty.repr(tcx), id);
56+
debug!("trans_impl(path=%s, name=%s, id=%?)",
57+
path.repr(tcx), name.repr(tcx), id);
5958

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

68-
let param_substs_opt;
69-
match self_ty {
70-
None => param_substs_opt = None,
71-
Some(self_ty) => {
72-
param_substs_opt = Some(@param_substs {
73-
tys: ~[],
74-
vtables: None,
75-
type_param_defs: @~[],
76-
self_ty: Some(self_ty)
77-
});
78-
}
79-
}
80-
8167
trans_method(ccx,
8268
path,
8369
*method,
84-
param_substs_opt,
85-
self_ty,
70+
None,
8671
llfn,
8772
ast_util::local_def(id));
8873
}
@@ -98,17 +83,13 @@ Translates a (possibly monomorphized) method body.
9883
- `method`: the AST node for the method
9984
- `param_substs`: if this is a generic method, the current values for
10085
type parameters and so forth, else none
101-
- `base_self_ty`: optionally, the explicit self type for this method. This
102-
will be none if this is not a default method and must always be present
103-
if this is a default method.
10486
- `llfn`: the LLVM ValueRef for the method
10587
- `impl_id`: the node ID of the impl this method is inside
10688
*/
10789
pub fn trans_method(ccx: @mut CrateContext,
10890
path: path,
10991
method: &ast::method,
11092
param_substs: Option<@param_substs>,
111-
base_self_ty: Option<ty::t>,
11293
llfn: ValueRef,
11394
impl_id: ast::def_id) {
11495
// figure out how self is being passed
@@ -119,18 +100,14 @@ pub fn trans_method(ccx: @mut CrateContext,
119100
_ => {
120101
// determine the (monomorphized) type that `self` maps to for
121102
// this method
122-
let self_ty = match base_self_ty {
123-
None => ty::node_id_to_type(ccx.tcx, method.self_id),
124-
Some(provided_self_ty) => provided_self_ty,
125-
};
103+
let self_ty = ty::node_id_to_type(ccx.tcx, method.self_id);
126104
let self_ty = match param_substs {
127105
None => self_ty,
128-
Some(@param_substs {tys: ref tys, _}) => {
129-
ty::subst_tps(ccx.tcx, *tys, None, self_ty)
106+
Some(@param_substs {tys: ref tys, self_ty: ref self_sub, _}) => {
107+
ty::subst_tps(ccx.tcx, *tys, *self_sub, self_ty)
130108
}
131109
};
132-
debug!("calling trans_fn with base_self_ty %s, self_ty %s",
133-
base_self_ty.repr(ccx.tcx),
110+
debug!("calling trans_fn with self_ty %s",
134111
self_ty.repr(ccx.tcx));
135112
match method.explicit_self.node {
136113
ast::sty_value => {

src/librustc/middle/trans/monomorphize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
233233
Some(override_impl_did) => impl_did = override_impl_did
234234
}
235235

236-
meth::trans_method(ccx, pt, mth, psubsts, None, d, impl_did);
236+
meth::trans_method(ccx, pt, mth, psubsts, d, impl_did);
237237
d
238238
}
239239
ast_map::node_trait_method(@ast::provided(mth), _, pt) => {
240240
let d = mk_lldecl();
241241
set_inline_hint_if_appr(/*bad*/copy mth.attrs, d);
242242
debug!("monomorphic_fn impl_did_opt is %?", impl_did_opt);
243-
meth::trans_method(ccx, /*bad*/copy *pt, mth, psubsts, None, d,
243+
meth::trans_method(ccx, /*bad*/copy *pt, mth, psubsts, d,
244244
impl_did_opt.get());
245245
d
246246
}

src/librustc/middle/ty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,21 +3649,21 @@ pub fn def_has_ty_params(def: ast::def) -> bool {
36493649
}
36503650
}
36513651

3652-
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[ast::ident] {
3652+
pub fn provided_trait_methods(cx: ctxt, id: ast::def_id) -> ~[@Method] {
36533653
if is_local(id) {
36543654
match cx.items.find(&id.node) {
36553655
Some(&ast_map::node_item(@ast::item {
36563656
node: item_trait(_, _, ref ms),
36573657
_
36583658
}, _)) =>
36593659
match ast_util::split_trait_methods(*ms) {
3660-
(_, p) => p.map(|method| method.ident)
3660+
(_, p) => p.map(|m| method(cx, ast_util::local_def(m.id)))
36613661
},
36623662
_ => cx.sess.bug(fmt!("provided_trait_methods: %? is not a trait",
36633663
id))
36643664
}
36653665
} else {
3666-
csearch::get_provided_trait_methods(cx, id).map(|ifo| ifo.ty.ident)
3666+
csearch::get_provided_trait_methods(cx, id)
36673667
}
36683668
}
36693669

src/librustc/middle/typeck/coherence.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ impl CoherenceChecker {
333333

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

336-
for self.each_provided_trait_method(trait_ref.def_id) |trait_method| {
336+
let provided = ty::provided_trait_methods(tcx, trait_ref.def_id);
337+
for provided.iter().advance |trait_method| {
337338
// Synthesize an ID.
338339
let new_id = parse::next_node_id(tcx.sess.parse_sess);
339340
let new_did = local_def(new_id);
@@ -347,7 +348,7 @@ impl CoherenceChecker {
347348
impl_id,
348349
trait_ref,
349350
new_did,
350-
trait_method);
351+
*trait_method);
351352

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

@@ -526,29 +527,6 @@ impl CoherenceChecker {
526527
}
527528
}
528529

529-
pub fn each_provided_trait_method(&self,
530-
trait_did: ast::def_id,
531-
f: &fn(x: @ty::Method) -> bool)
532-
-> bool {
533-
// Make a list of all the names of the provided methods.
534-
// XXX: This is horrible.
535-
let mut provided_method_idents = HashSet::new();
536-
let tcx = self.crate_context.tcx;
537-
let r = ty::provided_trait_methods(tcx, trait_did);
538-
for r.iter().advance |ident| {
539-
provided_method_idents.insert(*ident);
540-
}
541-
542-
for ty::trait_methods(tcx, trait_did).iter().advance |&method| {
543-
if provided_method_idents.contains(&method.ident) {
544-
if !f(method) {
545-
return false;
546-
}
547-
}
548-
}
549-
return true;
550-
}
551-
552530
pub fn polytypes_unify(&self,
553531
polytype_a: ty_param_bounds_and_ty,
554532
polytype_b: ty_param_bounds_and_ty)
@@ -729,9 +707,9 @@ impl CoherenceChecker {
729707
}
730708
// Default methods
731709
let r = ty::provided_trait_methods(tcx, trait_did);
732-
for r.iter().advance |ident| {
733-
debug!("inserting provided method %s", ident.repr(tcx));
734-
provided_names.insert(*ident);
710+
for r.iter().advance |method| {
711+
debug!("inserting provided method %s", method.ident.repr(tcx));
712+
provided_names.insert(method.ident);
735713
}
736714

737715
let r = ty::trait_methods(tcx, trait_did);

src/librustpkg/tests.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ fn output_file_name(workspace: &Path, short_name: &str) -> Path {
268268
workspace.push(fmt!("%s%s", short_name, os::EXE_SUFFIX))
269269
}
270270

271-
fn touch_source_file(workspace: &Path, short_name: &str) {
271+
fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
272272
use conditions::bad_path::cond;
273-
let pkg_src_dir = workspace.push("src").push(short_name);
274-
let contents = os::list_dir(&pkg_src_dir);
273+
let pkg_src_dir = workspace.push("src").push(pkgid.to_str());
274+
let contents = os::list_dir_path(&pkg_src_dir);
275275
for contents.iter().advance |p| {
276-
if Path(copy *p).filetype() == Some(~".rs") {
276+
if p.filetype() == Some(~".rs") {
277277
// should be able to do this w/o a process
278278
if run::process_output("touch", [p.to_str()]).status != 0 {
279279
let _ = cond.raise((copy pkg_src_dir, ~"Bad path"));
@@ -287,20 +287,19 @@ fn touch_source_file(workspace: &Path, short_name: &str) {
287287
fn frob_source_file(workspace: &Path, pkgid: &PkgId) {
288288
use conditions::bad_path::cond;
289289
let pkg_src_dir = workspace.push("src").push(pkgid.to_str());
290-
let contents = os::list_dir(&pkg_src_dir);
290+
let contents = os::list_dir_path(&pkg_src_dir);
291291
let mut maybe_p = None;
292292
for contents.iter().advance |p| {
293-
if Path(copy *p).filetype() == Some(~".rs") {
293+
if p.filetype() == Some(~".rs") {
294294
maybe_p = Some(p);
295295
break;
296296
}
297297
}
298298
match maybe_p {
299299
Some(p) => {
300-
let p = Path(copy *p);
301-
let w = io::buffered_file_writer(&p);
300+
let w = io::file_writer(*p, &[io::Append]);
302301
match w {
303-
Err(s) => { let _ = cond.raise((p, fmt!("Bad path: %s", s))); }
302+
Err(s) => { let _ = cond.raise((copy **p, fmt!("Bad path: %s", s))); }
304303
Ok(w) => w.write_line("")
305304
}
306305
}
@@ -615,7 +614,7 @@ fn do_rebuild_dep_dates_change() {
615614
let workspace = create_local_package_with_dep(&p_id, &dep_id);
616615
command_line_test([~"build", ~"foo"], &workspace);
617616
let bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar"));
618-
touch_source_file(&workspace, "bar");
617+
touch_source_file(&workspace, &dep_id);
619618
command_line_test([~"build", ~"foo"], &workspace);
620619
let new_bar_date = datestamp(&lib_output_file_name(&workspace, "build", "bar"));
621620
assert!(new_bar_date > bar_date);

0 commit comments

Comments
 (0)