Skip to content

Commit 3360991

Browse files
committed
---
yaml --- r: 144267 b: refs/heads/try2 c: a901b16 h: refs/heads/master i: 144265: 497ddd8 144263: d6da62f v: v3
1 parent d4c09c9 commit 3360991

File tree

13 files changed

+254
-107
lines changed

13 files changed

+254
-107
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 23bfa600a0f91f1ea62ea3f3783c358a7cb7da45
8+
refs/heads/try2: a901b166901601c6b132c2036882ad9754722f1c
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ impl Liveness {
16171617

16181618
pub fn should_warn(&self, var: Variable) -> Option<@str> {
16191619
let name = self.ir.variable_name(var);
1620-
if name.len() == 0 || name[0] == ('_' as u8) { None } else { Some(name) }
1620+
if name[0] == ('_' as u8) { None } else { Some(name) }
16211621
}
16221622

16231623
pub fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) {

branches/try2/src/librustc/middle/trans/meth.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -577,23 +577,20 @@ fn emit_vtable_methods(bcx: @mut Block,
577577

578578
let trait_method_def_ids = ty::trait_method_def_ids(tcx, trt_id);
579579
do trait_method_def_ids.map |method_def_id| {
580-
let ident = ty::method(tcx, *method_def_id).ident;
581-
// The substitutions we have are on the impl, so we grab
582-
// the method type from the impl to substitute into.
583-
let m_id = method_with_name(ccx, impl_id, ident);
584-
let m = ty::method(tcx, m_id);
585-
debug!("(making impl vtable) emitting method %s at subst %s",
586-
m.repr(tcx),
587-
substs.repr(tcx));
580+
let im = ty::method(tcx, *method_def_id);
588581
let fty = ty::subst_tps(tcx,
589582
substs,
590583
None,
591-
ty::mk_bare_fn(tcx, m.fty.clone()));
592-
if m.generics.has_type_params() || ty::type_has_self(fty) {
584+
ty::mk_bare_fn(tcx, im.fty.clone()));
585+
if im.generics.has_type_params() || ty::type_has_self(fty) {
593586
debug!("(making impl vtable) method has self or type params: %s",
594-
tcx.sess.str_of(ident));
587+
tcx.sess.str_of(im.ident));
595588
C_null(Type::nil().ptr_to())
596589
} else {
590+
debug!("(making impl vtable) adding method to vtable: %s",
591+
tcx.sess.str_of(im.ident));
592+
let m_id = method_with_name(ccx, impl_id, im.ident);
593+
597594
trans_fn_ref_with_vtables(bcx, m_id, 0,
598595
substs, Some(vtables)).llfn
599596
}

branches/try2/src/librustc/middle/typeck/check/method.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -938,18 +938,9 @@ impl<'self> LookupContext<'self> {
938938

939939
// static methods should never have gotten this far:
940940
assert!(candidate.method_ty.explicit_self != sty_static);
941-
942-
let transformed_self_ty = match candidate.origin {
943-
method_object(*) => {
944-
// For annoying reasons, we've already handled the
945-
// substitution for object calls.
946-
candidate.method_ty.transformed_self_ty.unwrap()
947-
}
948-
_ => {
949-
ty::subst(tcx, &candidate.rcvr_substs,
950-
candidate.method_ty.transformed_self_ty.unwrap())
951-
}
952-
};
941+
let transformed_self_ty =
942+
ty::subst(tcx, &candidate.rcvr_substs,
943+
candidate.method_ty.transformed_self_ty.unwrap());
953944

954945
// Determine the values for the type parameters of the method.
955946
// If they were not explicitly supplied, just construct fresh

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,6 +3092,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt,
30923092
sp: span,
30933093
defn: ast::def)
30943094
-> ty_param_bounds_and_ty {
3095+
30953096
match defn {
30963097
ast::def_arg(nid, _) | ast::def_local(nid, _) | ast::def_self(nid, _) |
30973098
ast::def_binding(nid, _) => {
@@ -3148,8 +3149,7 @@ pub fn instantiate_path(fcx: @mut FnCtxt,
31483149
let ty_param_count = tpt.generics.type_param_defs.len();
31493150
let ty_substs_len = pth.types.len();
31503151

3151-
debug!("tpt=%s ty_param_count=%? ty_substs_len=%?",
3152-
tpt.repr(fcx.tcx()),
3152+
debug!("ty_param_count=%? ty_substs_len=%?",
31533153
ty_param_count,
31543154
ty_substs_len);
31553155

branches/try2/src/librustc/middle/typeck/collect.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,9 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
346346
let substd_type_param_defs = m.generics.type_param_defs.subst(tcx, &substs);
347347
new_type_param_defs.push_all(*substd_type_param_defs);
348348

349-
debug!("static method %s type_param_defs=%s ty=%s, substs=%s",
349+
debug!("static method %s type_param_defs=%s substs=%s",
350350
m.def_id.repr(tcx),
351351
new_type_param_defs.repr(tcx),
352-
ty.repr(tcx),
353352
substs.repr(tcx));
354353

355354
tcx.tcache.insert(m.def_id,
@@ -894,8 +893,8 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
894893
}
895894
ast::item_trait(ref generics, _, ref trait_methods) => {
896895
let _trait_def = trait_def_of_item(ccx, it);
896+
ensure_trait_methods(ccx, it.id);
897897

898-
// Run convert_methods on the provided methods.
899898
let (_, provided_methods) =
900899
split_trait_methods(*trait_methods);
901900
let untransformed_rcvr_ty = ty::mk_self(tcx, local_def(it.id));
@@ -905,11 +904,6 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
905904
untransformed_rcvr_ty,
906905
&ty_generics, generics,
907906
it.vis);
908-
909-
// We need to do this *after* converting methods, since
910-
// convert_methods produces a tcache entry that is wrong for
911-
// static trait methods. This is somewhat unfortunate.
912-
ensure_trait_methods(ccx, it.id);
913907
}
914908
ast::item_struct(struct_def, ref generics) => {
915909
ensure_no_ty_param_bounds(ccx, it.span, generics, "structure");

branches/try2/src/librustpkg/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ fn rustpkg_local_pkg() {
678678
}
679679
680680
#[test]
681-
#[ignore (reason = "test makes bogus assumptions about build directory layout: issue #8690")]
682681
fn package_script_with_default_build() {
683682
let dir = create_local_package(&PkgId::new("fancy-lib"));
684683
debug!("dir = %s", dir.to_str());

branches/try2/src/libstd/rt/uv/file.rs

Lines changed: 160 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,87 @@
1111
use prelude::*;
1212
use ptr::null;
1313
use libc::c_void;
14-
use rt::uv::{Request, NativeHandle, Loop, FsCallback};
14+
use rt::uv::{Request, NativeHandle, Loop, FsCallback,
15+
status_to_maybe_uv_error_with_loop};
1516
use rt::uv::uvll;
1617
use rt::uv::uvll::*;
18+
use path::Path;
19+
use cast::transmute;
20+
use libc::{c_int};
1721

1822
pub struct FsRequest(*uvll::uv_fs_t);
1923
impl Request for FsRequest;
2024

25+
#[allow(non_camel_case_types)]
26+
pub enum UvFileFlag {
27+
O_RDONLY,
28+
O_WRONLY,
29+
O_RDWR,
30+
O_CREAT,
31+
O_TRUNC
32+
}
33+
pub fn map_flag(v: UvFileFlag) -> int {
34+
unsafe {
35+
match v {
36+
O_RDONLY => uvll::get_O_RDONLY() as int,
37+
O_WRONLY => uvll::get_O_WRONLY() as int,
38+
O_RDWR => uvll::get_O_RDWR() as int,
39+
O_CREAT => uvll::get_O_CREAT() as int,
40+
O_TRUNC => uvll::get_O_TRUNC() as int
41+
}
42+
}
43+
}
44+
45+
pub struct RequestData {
46+
complete_cb: Option<FsCallback>
47+
}
48+
2149
impl FsRequest {
22-
fn new() -> FsRequest {
50+
pub fn new(cb: Option<FsCallback>) -> FsRequest {
2351
let fs_req = unsafe { malloc_req(UV_FS) };
2452
assert!(fs_req.is_not_null());
25-
let fs_req = fs_req as *uvll::uv_write_t;
26-
unsafe { uvll::set_data_for_req(fs_req, null::<()>()); }
27-
NativeHandle::from_native_handle(fs_req)
53+
let fs_req: FsRequest = NativeHandle::from_native_handle(fs_req);
54+
fs_req.install_req_data(cb);
55+
fs_req
56+
}
57+
58+
pub fn install_req_data(&self, cb: Option<FsCallback>) {
59+
let fs_req = (self.native_handle()) as *uvll::uv_write_t;
60+
let data = ~RequestData {
61+
complete_cb: cb
62+
};
63+
unsafe {
64+
let data = transmute::<~RequestData, *c_void>(data);
65+
uvll::set_data_for_req(fs_req, data);
66+
}
2867
}
2968

30-
fn delete(self) {
31-
unsafe { free_req(self.native_handle() as *c_void) }
69+
fn get_req_data<'r>(&'r mut self) -> &'r mut RequestData {
70+
unsafe {
71+
let data = uvll::get_data_for_req((self.native_handle()));
72+
let data = transmute::<&*c_void, &mut ~RequestData>(&data);
73+
return &mut **data;
74+
}
3275
}
3376

34-
fn open(&mut self, _loop_: &Loop, _cb: FsCallback) {
77+
pub fn get_result(&mut self) -> c_int {
78+
unsafe {
79+
uvll::get_result_from_fs_req(self.native_handle())
80+
}
3581
}
3682

37-
fn close(&mut self, _loop_: &Loop, _cb: FsCallback) {
83+
pub fn get_loop(&self) -> Loop {
84+
unsafe { Loop{handle:uvll::get_loop_from_fs_req(self.native_handle())} }
85+
}
86+
87+
fn cleanup_and_delete(self) {
88+
unsafe {
89+
uvll::fs_req_cleanup(self.native_handle());
90+
let data = uvll::get_data_for_uv_handle(self.native_handle());
91+
let _data = transmute::<*c_void, ~RequestData>(data);
92+
uvll::set_data_for_uv_handle(self.native_handle(), null::<()>());
93+
free_req(self.native_handle() as *c_void)
94+
}
3895
}
3996
}
4097

@@ -46,3 +103,97 @@ impl NativeHandle<*uvll::uv_fs_t> for FsRequest {
46103
match self { &FsRequest(ptr) => ptr }
47104
}
48105
}
106+
107+
pub struct FileDescriptor(c_int);
108+
impl FileDescriptor {
109+
fn new(fd: c_int) -> FileDescriptor {
110+
FileDescriptor(fd)
111+
}
112+
113+
pub fn from_open_req(req: &mut FsRequest) -> FileDescriptor {
114+
FileDescriptor::new(req.get_result())
115+
}
116+
117+
pub fn open(loop_: Loop, path: Path, flags: int, mode: int,
118+
cb: FsCallback) -> int {
119+
let req = FsRequest::new(Some(cb));
120+
path.to_str().to_c_str().with_ref(|p| unsafe {
121+
uvll::fs_open(loop_.native_handle(),
122+
req.native_handle(), p, flags, mode, complete_cb) as int
123+
})
124+
125+
}
126+
127+
fn close(self, loop_: Loop, cb: FsCallback) -> int {
128+
let req = FsRequest::new(Some(cb));
129+
unsafe {
130+
uvll::fs_close(loop_.native_handle(), req.native_handle(),
131+
self.native_handle(), complete_cb) as int
132+
}
133+
}
134+
}
135+
extern fn complete_cb(req: *uv_fs_t) {
136+
let mut req: FsRequest = NativeHandle::from_native_handle(req);
137+
let loop_ = req.get_loop();
138+
// pull the user cb out of the req data
139+
let cb = {
140+
let data = req.get_req_data();
141+
assert!(data.complete_cb.is_some());
142+
// option dance, option dance. oooooh yeah.
143+
data.complete_cb.take_unwrap()
144+
};
145+
// in uv_fs_open calls, the result will be the fd in the
146+
// case of success, otherwise it's -1 indicating an error
147+
let result = req.get_result();
148+
let status = status_to_maybe_uv_error_with_loop(
149+
loop_.native_handle(), result);
150+
// we have a req and status, call the user cb..
151+
// only giving the user a ref to the FsRequest, as we
152+
// have to clean it up, afterwards (and they aren't really
153+
// reusable, anyways
154+
cb(&mut req, status);
155+
// clean up the req (and its data!) after calling the user cb
156+
req.cleanup_and_delete();
157+
}
158+
159+
impl NativeHandle<c_int> for FileDescriptor {
160+
fn from_native_handle(handle: c_int) -> FileDescriptor {
161+
FileDescriptor(handle)
162+
}
163+
fn native_handle(&self) -> c_int {
164+
match self { &FileDescriptor(ptr) => ptr }
165+
}
166+
}
167+
168+
mod test {
169+
use super::*;
170+
//use rt::test::*;
171+
use unstable::run_in_bare_thread;
172+
use path::Path;
173+
use rt::uv::Loop;
174+
175+
// this is equiv to touch, i guess?
176+
fn file_test_touch_impl() {
177+
debug!("hello?")
178+
do run_in_bare_thread {
179+
debug!("In bare thread")
180+
let loop_ = Loop::new();
181+
let flags = map_flag(O_RDWR) |
182+
map_flag(O_CREAT) | map_flag(O_TRUNC);
183+
do FileDescriptor::open(loop_, Path("./foo.txt"), flags, 0644)
184+
|req, uverr| {
185+
let loop_ = req.get_loop();
186+
assert!(uverr.is_none());
187+
let fd = FileDescriptor::from_open_req(req);
188+
do fd.close(loop_) |_, uverr| {
189+
assert!(uverr.is_none());
190+
};
191+
};
192+
}
193+
}
194+
195+
#[test]
196+
fn file_test_touch() {
197+
file_test_touch_impl();
198+
}
199+
}

branches/try2/src/libstd/rt/uv/mod.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use rt::io::IoError;
5353

5454
//#[cfg(test)] use unstable::run_in_bare_thread;
5555

56-
pub use self::file::FsRequest;
56+
pub use self::file::{FsRequest};
5757
pub use self::net::{StreamWatcher, TcpWatcher, UdpWatcher};
5858
pub use self::idle::IdleWatcher;
5959
pub use self::timer::TimerWatcher;
@@ -125,7 +125,7 @@ pub type ReadCallback = ~fn(StreamWatcher, int, Buf, Option<UvError>);
125125
pub type NullCallback = ~fn();
126126
pub type IdleCallback = ~fn(IdleWatcher, Option<UvError>);
127127
pub type ConnectionCallback = ~fn(StreamWatcher, Option<UvError>);
128-
pub type FsCallback = ~fn(FsRequest, Option<UvError>);
128+
pub type FsCallback = ~fn(&mut FsRequest, Option<UvError>);
129129
pub type TimerCallback = ~fn(TimerWatcher, Option<UvError>);
130130
pub type AsyncCallback = ~fn(AsyncWatcher, Option<UvError>);
131131
pub type UdpReceiveCallback = ~fn(UdpWatcher, int, Buf, SocketAddr, uint, Option<UvError>);
@@ -281,6 +281,20 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
281281
}
282282
}
283283
284+
/// Given a uv handle, convert a callback status to a UvError
285+
pub fn status_to_maybe_uv_error_with_loop(
286+
loop_: *uvll::uv_loop_t,
287+
status: c_int) -> Option<UvError> {
288+
if status != -1 {
289+
None
290+
} else {
291+
unsafe {
292+
rtdebug!("loop: %x", loop_ as uint);
293+
let err = uvll::last_error(loop_);
294+
Some(UvError(err))
295+
}
296+
}
297+
}
284298
/// Given a uv handle, convert a callback status to a UvError
285299
pub fn status_to_maybe_uv_error<T, U: Watcher + NativeHandle<*T>>(handle: U,
286300
status: c_int) -> Option<UvError> {
@@ -290,9 +304,7 @@ pub fn status_to_maybe_uv_error<T, U: Watcher + NativeHandle<*T>>(handle: U,
290304
unsafe {
291305
rtdebug!("handle: %x", handle.native_handle() as uint);
292306
let loop_ = uvll::get_loop_for_uv_handle(handle.native_handle());
293-
rtdebug!("loop: %x", loop_ as uint);
294-
let err = uvll::last_error(loop_);
295-
Some(UvError(err))
307+
status_to_maybe_uv_error_with_loop(loop_, status)
296308
}
297309
}
298310
}

0 commit comments

Comments
 (0)