Skip to content

Commit 51f3872

Browse files
committed
---
yaml --- r: 145389 b: refs/heads/try2 c: 68ea9ae h: refs/heads/master i: 145387: 5df32c2 v: v3
1 parent 804b164 commit 51f3872

File tree

16 files changed

+91
-113
lines changed

16 files changed

+91
-113
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: 9a4de3f3058ddb2cd43863c7c2723cec3d0fc30a
8+
refs/heads/try2: 68ea9aed96b6b8147b6c37b844c85cb7ae2867f4
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/c_vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
* still held if needed.
3737
*/
3838

39-
use std::cast;
4039
use std::ptr;
4140
use std::routine::Runnable;
4241
use std::util;
@@ -57,9 +56,10 @@ struct DtorRes {
5756
#[unsafe_destructor]
5857
impl Drop for DtorRes {
5958
fn drop(&mut self) {
60-
match self.dtor {
61-
option::None => (),
62-
option::Some(f) => f()
59+
let dtor = util::replace(&mut self.dtor, None);
60+
match dtor {
61+
None => (),
62+
Some(f) => f.run()
6363
}
6464
}
6565
}

branches/try2/src/libextra/rl.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ pub mod rustrt {
3030

3131
macro_rules! locked {
3232
($expr:expr) => {
33-
unsafe {
34-
// FIXME #9105: can't use a static mutex in pure Rust yet.
35-
rustrt::rust_take_linenoise_lock();
36-
let x = $expr;
37-
rustrt::rust_drop_linenoise_lock();
38-
x
39-
}
33+
// FIXME #9105: can't use a static mutex in pure Rust yet.
34+
rustrt::rust_take_linenoise_lock();
35+
let x = $expr;
36+
rustrt::rust_drop_linenoise_lock();
37+
x
4038
}
4139
}
4240

@@ -88,35 +86,36 @@ pub fn read(prompt: &str) -> Option<~str> {
8886
}
8987
}
9088

91-
pub type CompletionCb = @fn(~str, @fn(~str));
89+
/// The callback used to perform completions.
90+
pub trait CompletionCb {
91+
/// Performs a completion.
92+
fn complete(&self, line: ~str, suggestion: &fn(~str));
93+
}
9294

93-
local_data_key!(complete_key: CompletionCb)
95+
local_data_key!(complete_key: @CompletionCb)
9496

9597
/// Bind to the main completion callback in the current task.
9698
///
9799
/// The completion callback should not call any `extra::rl` functions
98100
/// other than the closure that it receives as its second
99101
/// argument. Calling such a function will deadlock on the mutex used
100102
/// to ensure that the calls are thread-safe.
101-
pub fn complete(cb: CompletionCb) {
103+
pub unsafe fn complete(cb: @CompletionCb) {
102104
local_data::set(complete_key, cb);
103105

104-
extern fn callback(c_line: *c_char, completions: *()) {
106+
extern fn callback(line: *c_char, completions: *()) {
105107
do local_data::get(complete_key) |opt_cb| {
106108
// only fetch completions if a completion handler has been
107109
// registered in the current task.
108110
match opt_cb {
109-
None => {},
111+
None => {}
110112
Some(cb) => {
111-
let line = unsafe { str::raw::from_c_str(c_line) };
112-
do (*cb)(line) |suggestion| {
113-
do suggestion.with_c_str |buf| {
114-
// This isn't locked, because `callback` gets
115-
// called inside `rustrt::linenoise`, which
116-
// *is* already inside the mutex, so
117-
// re-locking would be a deadlock.
118-
unsafe {
119-
rustrt::linenoiseAddCompletion(completions, buf);
113+
unsafe {
114+
do cb.complete(str::raw::from_c_str(line))
115+
|suggestion| {
116+
do suggestion.with_c_str |buf| {
117+
rustrt::linenoiseAddCompletion(completions,
118+
buf);
120119
}
121120
}
122121
}

branches/try2/src/libextra/test.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,6 @@ pub fn filter_tests(
807807
}
808808
}
809809

810-
struct TestFuture {
811-
test: TestDesc,
812-
wait: @fn() -> TestResult,
813-
}
814-
815810
pub fn run_test(force_ignore: bool,
816811
test: TestDescAndFn,
817812
monitor_ch: SharedChan<MonitorMsg>) {

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,25 @@ fn with_appropriate_checker(cx: Context, id: NodeId,
218218

219219
let fty = ty::node_id_to_type(cx.tcx, id);
220220
match ty::get(fty).sty {
221-
ty::ty_closure(ty::ClosureTy {sigil: OwnedSigil, bounds: bounds, _}) => {
221+
ty::ty_closure(ty::ClosureTy {
222+
sigil: OwnedSigil,
223+
bounds: bounds,
224+
_
225+
}) => {
222226
b(|cx, fv| check_for_uniq(cx, fv, bounds))
223227
}
224-
ty::ty_closure(ty::ClosureTy {sigil: ManagedSigil, bounds: bounds, _}) => {
225-
b(|cx, fv| check_for_box(cx, fv, bounds))
228+
ty::ty_closure(ty::ClosureTy {
229+
sigil: ManagedSigil,
230+
_
231+
}) => {
232+
// can't happen
226233
}
227-
ty::ty_closure(ty::ClosureTy {sigil: BorrowedSigil, bounds: bounds,
228-
region: region, _}) => {
234+
ty::ty_closure(ty::ClosureTy {
235+
sigil: BorrowedSigil,
236+
bounds: bounds,
237+
region: region,
238+
_
239+
}) => {
229240
b(|cx, fv| check_for_block(cx, fv, bounds, region))
230241
}
231242
ty::ty_bare_fn(_) => {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
187187
Some(deref_ptr(gc_ptr(m)))
188188
}
189189

190-
ty::ty_estr(ty::vstore_box) |
191-
ty::ty_closure(ty::ClosureTy {sigil: ast::ManagedSigil, _}) => {
190+
ty::ty_estr(ty::vstore_box) => {
192191
Some(deref_ptr(gc_ptr(ast::MutImmutable)))
193192
}
194193

@@ -515,7 +514,8 @@ impl mem_categorization_ctxt {
515514
(ast::BorrowedSigil, ast::Once) => true,
516515
// Heap closures always capture by copy/move, and can
517516
// move out iff they are once.
518-
(ast::OwnedSigil, _) | (ast::ManagedSigil, _) => false,
517+
(ast::OwnedSigil, _) |
518+
(ast::ManagedSigil, _) => false,
519519

520520
};
521521
if var_is_refd {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ fn stack_check_fn<'a>(v: StackCheckVisitor,
116116
visit::fk_anon(*) | visit::fk_fn_block => {
117117
match ty::get(ty::node_id_to_type(in_cx.tcx, id)).sty {
118118
ty::ty_bare_fn(*) |
119-
ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, _}) |
120-
ty::ty_closure(ty::ClosureTy {sigil: ast::ManagedSigil, _}) => {
119+
ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, _}) => {
121120
false
122121
}
123122
_ => {

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

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub fn allocate_cbox(bcx: @mut Block, sigil: ast::Sigil, cdata_ty: ty::t)
172172
// Allocate and initialize the box:
173173
match sigil {
174174
ast::ManagedSigil => {
175-
malloc_raw(bcx, cdata_ty, heap_managed)
175+
tcx.sess.bug("trying to trans allocation of @fn")
176176
}
177177
ast::OwnedSigil => {
178178
malloc_raw(bcx, cdata_ty, heap_for_unique_closure(bcx, cdata_ty))
@@ -197,7 +197,8 @@ pub struct ClosureResult {
197197
// Otherwise, it is stack allocated and copies pointers to the upvars.
198198
pub fn store_environment(bcx: @mut Block,
199199
bound_values: ~[EnvValue],
200-
sigil: ast::Sigil) -> ClosureResult {
200+
sigil: ast::Sigil)
201+
-> ClosureResult {
201202
let _icx = push_ctxt("closure::store_environment");
202203
let ccx = bcx.ccx();
203204
let tcx = ccx.tcx;
@@ -444,27 +445,6 @@ pub fn make_closure_glue(
444445
}
445446
}
446447

447-
pub fn make_opaque_cbox_take_glue(
448-
bcx: @mut Block,
449-
sigil: ast::Sigil,
450-
cboxptr: ValueRef) // ptr to ptr to the opaque closure
451-
-> @mut Block {
452-
// Easy cases:
453-
let _icx = push_ctxt("closure::make_opaque_cbox_take_glue");
454-
match sigil {
455-
ast::BorrowedSigil => {
456-
return bcx;
457-
}
458-
ast::ManagedSigil => {
459-
glue::incr_refcnt_of_boxed(bcx, Load(bcx, cboxptr));
460-
return bcx;
461-
}
462-
ast::OwnedSigil => {
463-
fail!("unique closures are not copyable")
464-
}
465-
}
466-
}
467-
468448
pub fn make_opaque_cbox_drop_glue(
469449
bcx: @mut Block,
470450
sigil: ast::Sigil,
@@ -474,9 +454,7 @@ pub fn make_opaque_cbox_drop_glue(
474454
match sigil {
475455
ast::BorrowedSigil => bcx,
476456
ast::ManagedSigil => {
477-
glue::decr_refcnt_maybe_free(
478-
bcx, Load(bcx, cboxptr), Some(cboxptr),
479-
ty::mk_opaque_closure_ptr(bcx.tcx(), sigil))
457+
bcx.tcx().sess.bug("trying to trans drop glue of @fn")
480458
}
481459
ast::OwnedSigil => {
482460
glue::free_ty(
@@ -516,12 +494,8 @@ pub fn make_opaque_cbox_free_glue(
516494
abi::tydesc_field_drop_glue, None);
517495

518496
// Free the ty descr (if necc) and the box itself
519-
match sigil {
520-
ast::ManagedSigil => glue::trans_free(bcx, cbox),
521-
ast::OwnedSigil => glue::trans_exchange_free(bcx, cbox),
522-
ast::BorrowedSigil => {
523-
bcx.sess().bug("impossible")
524-
}
525-
}
497+
glue::trans_exchange_free(bcx, cbox);
498+
499+
bcx
526500
}
527501
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,7 @@ pub fn make_take_glue(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block {
581581
| ty::ty_estr(ty::vstore_slice(_)) => {
582582
bcx
583583
}
584-
ty::ty_closure(ty::ClosureTy { sigil: ast::BorrowedSigil, _ }) |
585-
ty::ty_closure(ty::ClosureTy { sigil: ast::ManagedSigil, _ }) => {
586-
closure::make_closure_glue(bcx, v, t, take_ty)
587-
}
588-
ty::ty_closure(ty::ClosureTy { sigil: ast::OwnedSigil, _ }) => bcx,
584+
ty::ty_closure(_) => bcx,
589585
ty::ty_trait(_, _, ty::BoxTraitStore, _, _) => {
590586
let llbox = Load(bcx, GEPi(bcx, v, [0u, abi::trt_field_box]));
591587
incr_refcnt_of_boxed(bcx, llbox);
@@ -606,9 +602,7 @@ pub fn make_take_glue(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block {
606602
None);
607603
bcx
608604
}
609-
ty::ty_opaque_closure_ptr(ck) => {
610-
closure::make_opaque_cbox_take_glue(bcx, ck, v)
611-
}
605+
ty::ty_opaque_closure_ptr(_) => bcx,
612606
ty::ty_struct(did, _) => {
613607
let tcx = bcx.tcx();
614608
let bcx = iter_structural_ty(bcx, v, t, take_ty);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,12 +2308,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
23082308
ast::Many => TC_NONE
23092309
};
23102310
// Prevent noncopyable types captured in the environment from being copied.
2311-
let ct = if cty.sigil == ast::ManagedSigil {
2312-
TC_NONE
2313-
} else {
2314-
TC_NONCOPY_TRAIT
2315-
};
2316-
st + rt + ot + ct
2311+
st + rt + ot + TC_NONCOPY_TRAIT
23172312
}
23182313

23192314
fn trait_contents(store: TraitStore, mutbl: ast::Mutability,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope + Clone + 'static>(
400400
bf.abis, &bf.lifetimes, &bf.decl))
401401
}
402402
ast::ty_closure(ref f) => {
403+
if f.sigil == ast::ManagedSigil {
404+
tcx.sess.span_err(ast_ty.span,
405+
"managed closures are not supported");
406+
}
407+
403408
let bounds = conv_builtin_bounds(this.tcx(), &f.bounds, match f.sigil {
404409
// Use corresponding trait store to figure out default bounds
405410
// if none were specified.

branches/try2/src/librustpkg/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ struct ViewItemVisitor<'self> {
403403
sess: session::Session,
404404
exec: &'self mut workcache::Exec,
405405
c: &'self ast::Crate,
406-
save: @fn(Path),
406+
save: &'self fn(Path),
407407
}
408408

409409
impl<'self> Visitor<()> for ViewItemVisitor<'self> {
@@ -508,7 +508,7 @@ pub fn find_and_install_dependencies(context: &BuildContext,
508508
sess: session::Session,
509509
exec: &mut workcache::Exec,
510510
c: &ast::Crate,
511-
save: @fn(Path)) {
511+
save: &fn(Path)) {
512512
debug!("In find_and_install_dependencies...");
513513
let mut visitor = ViewItemVisitor {
514514
context: context,

branches/try2/src/libstd/io.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,31 +1846,38 @@ pub mod fsync {
18461846
pub struct Arg<t> {
18471847
val: t,
18481848
opt_level: Option<Level>,
1849-
fsync_fn: @fn(f: &t, Level) -> int,
1849+
fsync_fn: extern "Rust" fn(f: &t, Level) -> int,
18501850
}
18511851

18521852
// fsync file after executing blk
18531853
// FIXME (#2004) find better way to create resources within lifetime of
18541854
// outer res
1855-
pub fn FILE_res_sync(file: &FILERes, opt_level: Option<Level>,
1855+
pub fn FILE_res_sync(file: &FILERes,
1856+
opt_level: Option<Level>,
18561857
blk: &fn(v: Res<*libc::FILE>)) {
18571858
blk(Res::new(Arg {
1858-
val: file.f, opt_level: opt_level,
1859-
fsync_fn: |file, l| fsync_fd(fileno(*file), l)
1859+
val: file.f,
1860+
opt_level: opt_level,
1861+
fsync_fn: fsync_FILE,
18601862
}));
18611863

18621864
fn fileno(stream: *libc::FILE) -> libc::c_int {
18631865
#[fixed_stack_segment]; #[inline(never)];
18641866
unsafe { libc::fileno(stream) }
18651867
}
1868+
1869+
fn fsync_FILE(stream: &*libc::FILE, level: Level) -> int {
1870+
fsync_fd(fileno(*stream), level)
1871+
}
18661872
}
18671873

18681874
// fsync fd after executing blk
18691875
pub fn fd_res_sync(fd: &FdRes, opt_level: Option<Level>,
18701876
blk: &fn(v: Res<fd_t>)) {
18711877
blk(Res::new(Arg {
1872-
val: fd.fd, opt_level: opt_level,
1873-
fsync_fn: |fd, l| fsync_fd(*fd, l)
1878+
val: fd.fd,
1879+
opt_level: opt_level,
1880+
fsync_fn: fsync_fd_helper,
18741881
}));
18751882
}
18761883

@@ -1880,17 +1887,26 @@ pub mod fsync {
18801887
os::fsync_fd(fd, level) as int
18811888
}
18821889

1890+
fn fsync_fd_helper(fd_ptr: &libc::c_int, level: Level) -> int {
1891+
fsync_fd(*fd_ptr, level)
1892+
}
1893+
18831894
// Type of objects that may want to fsync
18841895
pub trait FSyncable { fn fsync(&self, l: Level) -> int; }
18851896

18861897
// Call o.fsync after executing blk
18871898
pub fn obj_sync(o: @FSyncable, opt_level: Option<Level>,
18881899
blk: &fn(v: Res<@FSyncable>)) {
18891900
blk(Res::new(Arg {
1890-
val: o, opt_level: opt_level,
1891-
fsync_fn: |o, l| (*o).fsync(l)
1901+
val: o,
1902+
opt_level: opt_level,
1903+
fsync_fn: obj_fsync_fn,
18921904
}));
18931905
}
1906+
1907+
fn obj_fsync_fn(o: &@FSyncable, level: Level) -> int {
1908+
(*o).fsync(level)
1909+
}
18941910
}
18951911

18961912
#[cfg(test)]

0 commit comments

Comments
 (0)