Skip to content

Commit dc00ff2

Browse files
committed
librustc: Make || lambdas not infer to procs
1 parent 17bf45d commit dc00ff2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+153
-139
lines changed

doc/tutorial-tasks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn print_message() { println("I am running in a different task!"); }
7676
spawn(print_message);
7777
7878
// Print something more profound in a different task using a lambda expression
79-
spawn( || println("I am also running in a different task!") );
79+
spawn(proc() println("I am also running in a different task!") );
8080
8181
// The canonical way to spawn is using `do` notation
8282
do spawn {
@@ -278,7 +278,7 @@ fn fib(n: u64) -> u64 {
278278
12586269025
279279
}
280280
281-
let mut delayed_fib = extra::future::Future::spawn (|| fib(50) );
281+
let mut delayed_fib = extra::future::Future::spawn(proc() fib(50));
282282
make_a_sandwich();
283283
println!("fib(50) = {:?}", delayed_fib.get())
284284
~~~

src/compiletest/compiletest.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,15 @@ pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn {
333333
let config = Cell::new((*config).clone());
334334
// FIXME (#9639): This needs to handle non-utf8 paths
335335
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
336-
test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) })
336+
test::DynTestFn(proc() { runtest::run(config.take(), testfile.take()) })
337337
}
338338

339339
pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
340340
use std::cell::Cell;
341341
let config = Cell::new((*config).clone());
342342
// FIXME (#9639): This needs to handle non-utf8 paths
343343
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
344-
test::DynMetricFn(|mm| { runtest::run_metrics(config.take(), testfile.take(), mm) })
344+
test::DynMetricFn(proc(mm) {
345+
runtest::run_metrics(config.take(), testfile.take(), mm)
346+
})
345347
}

src/libextra/future.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ mod test {
179179
180180
#[test]
181181
fn test_from_fn() {
182-
let mut f = Future::from_fn(|| ~"brail");
182+
let mut f = Future::from_fn(proc() ~"brail");
183183
assert_eq!(f.get(), ~"brail");
184184
}
185185
@@ -203,20 +203,20 @@ mod test {
203203
204204
#[test]
205205
fn test_spawn() {
206-
let mut f = Future::spawn(|| ~"bale");
206+
let mut f = Future::spawn(proc() ~"bale");
207207
assert_eq!(f.get(), ~"bale");
208208
}
209209
210210
#[test]
211211
fn test_spawn_with() {
212-
let mut f = Future::spawn_with(~"gale", |s| { s });
212+
let mut f = Future::spawn_with(~"gale", proc(s) { s });
213213
assert_eq!(f.get(), ~"gale");
214214
}
215215
216216
#[test]
217217
#[should_fail]
218218
fn test_futurefail() {
219-
let mut f = Future::spawn(|| fail!());
219+
let mut f = Future::spawn(proc() fail!());
220220
let _x: ~str = f.get();
221221
}
222222

src/libextra/task_pool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<T> TaskPool<T> {
5757
let (port, chan) = comm::stream::<Msg<T>>();
5858
let init_fn = init_fn_factory();
5959

60-
let task_body: proc() = || {
60+
let task_body: proc() = proc() {
6161
let local_data = init_fn(i);
6262
loop {
6363
match port.recv() {
@@ -98,11 +98,11 @@ impl<T> TaskPool<T> {
9898
#[test]
9999
fn test_task_pool() {
100100
let f: || -> proc(uint) -> uint = || {
101-
let g: proc(uint) -> uint = |i| i;
101+
let g: proc(uint) -> uint = proc(i) i;
102102
g
103103
};
104104
let mut pool = TaskPool::new(4, Some(SingleThreaded), f);
105105
8.times(|| {
106-
pool.execute(|i| println!("Hello from thread {}!", *i));
106+
pool.execute(proc(i) println!("Hello from thread {}!", *i));
107107
})
108108
}

src/libextra/test.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ pub fn run_test(force_ignore: bool,
905905
return;
906906
}
907907
DynTestFn(f) => run_test_inner(desc, monitor_ch, f),
908-
StaticTestFn(f) => run_test_inner(desc, monitor_ch, || f())
908+
StaticTestFn(f) => run_test_inner(desc, monitor_ch, proc() f())
909909
}
910910
}
911911

@@ -1202,7 +1202,7 @@ mod tests {
12021202
ignore: true,
12031203
should_fail: false
12041204
},
1205-
testfn: DynTestFn(|| f()),
1205+
testfn: DynTestFn(proc() f()),
12061206
};
12071207
let (p, ch) = stream();
12081208
let ch = SharedChan::new(ch);
@@ -1220,7 +1220,7 @@ mod tests {
12201220
ignore: true,
12211221
should_fail: false
12221222
},
1223-
testfn: DynTestFn(|| f()),
1223+
testfn: DynTestFn(proc() f()),
12241224
};
12251225
let (p, ch) = stream();
12261226
let ch = SharedChan::new(ch);
@@ -1238,7 +1238,7 @@ mod tests {
12381238
ignore: false,
12391239
should_fail: true
12401240
},
1241-
testfn: DynTestFn(|| f()),
1241+
testfn: DynTestFn(proc() f()),
12421242
};
12431243
let (p, ch) = stream();
12441244
let ch = SharedChan::new(ch);
@@ -1256,7 +1256,7 @@ mod tests {
12561256
ignore: false,
12571257
should_fail: true
12581258
},
1259-
testfn: DynTestFn(|| f()),
1259+
testfn: DynTestFn(proc() f()),
12601260
};
12611261
let (p, ch) = stream();
12621262
let ch = SharedChan::new(ch);
@@ -1311,15 +1311,15 @@ mod tests {
13111311
ignore: true,
13121312
should_fail: false,
13131313
},
1314-
testfn: DynTestFn(|| {}),
1314+
testfn: DynTestFn(proc() {}),
13151315
},
13161316
TestDescAndFn {
13171317
desc: TestDesc {
13181318
name: StaticTestName("2"),
13191319
ignore: false,
13201320
should_fail: false
13211321
},
1322-
testfn: DynTestFn(|| {}),
1322+
testfn: DynTestFn(proc() {}),
13231323
},
13241324
];
13251325
let filtered = filter_tests(&opts, tests);

src/librustc/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) {
346346
task_builder.opts.stack_size = Some(STACK_SIZE);
347347
}
348348

349-
match task_builder.try(|| {
349+
match task_builder.try(proc() {
350350
let ch = ch_capture.clone();
351351
// The 'diagnostics emitter'. Every error, warning, etc. should
352352
// go through this function.
@@ -404,6 +404,6 @@ pub fn main() {
404404

405405
pub fn main_args(args: &[~str]) -> int {
406406
let owned_args = args.to_owned();
407-
monitor(|demitter| run_compiler(owned_args, demitter));
407+
monitor(proc(demitter) run_compiler(owned_args, demitter));
408408
0
409409
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,8 +2905,13 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
29052905
_match::check_match(fcx, expr, discrim, *arms);
29062906
}
29072907
ast::ExprFnBlock(ref decl, ref body) => {
2908-
check_expr_fn(fcx, expr, None,
2909-
decl, body, Vanilla, expected);
2908+
check_expr_fn(fcx,
2909+
expr,
2910+
Some(ast::BorrowedSigil),
2911+
decl,
2912+
body,
2913+
Vanilla,
2914+
expected);
29102915
}
29112916
ast::ExprProc(ref decl, ref body) => {
29122917
check_expr_fn(fcx,

src/librustdoc/html/render.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,9 @@ impl Context {
711711
let mut task = task::task();
712712
task.unlinked(); // we kill things manually
713713
task.name(format!("worker{}", i));
714-
task.spawn_with(cache.clone(),
715-
|cache| worker(cache, &port, &chan, &prog_chan));
714+
task.spawn_with(cache.clone(), proc(cache) {
715+
worker(cache, &port, &chan, &prog_chan)
716+
});
716717

717718
fn worker(cache: RWArc<Cache>,
718719
port: &SharedPort<Work>,

src/librustpkg/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl CtxMethods for BuildContext {
474474
let psp = package_script_path.clone();
475475
let ws = workspace.clone();
476476
let pid = pkgid.clone();
477-
prep.exec(|exec| {
477+
prep.exec(proc(exec) {
478478
let mut pscript = PkgScript::parse(subsysroot.clone(),
479479
psp.clone(),
480480
&ws,
@@ -636,7 +636,7 @@ impl CtxMethods for BuildContext {
636636
let sub_target_ex = target_exec.clone();
637637
let sub_target_lib = target_lib.clone();
638638
let sub_build_inputs = build_inputs.to_owned();
639-
prep.exec(|exe_thing| {
639+
prep.exec(proc(exe_thing) {
640640
let mut outputs = ~[];
641641
// Declare all the *inputs* to the declared input too, as inputs
642642
for executable in subex.iter() {

src/librustpkg/package_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl PkgSrc {
412412
let sub_deps = deps.clone();
413413
let inputs = inputs_to_discover.map(|&(ref k, ref p)|
414414
(k.clone(), p.as_str().unwrap().to_owned()));
415-
prep.exec(|exec| {
415+
prep.exec(proc(exec) {
416416
for &(ref kind, ref p) in inputs.iter() {
417417
let pth = Path::new(p.clone());
418418
exec.discover_input(*kind, *p, if *kind == ~"file" {

src/librustuv/net.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ mod test {
10991099
let handle2 = Cell::new(sched2.make_handle());
11001100
let tasksFriendHandle = Cell::new(sched2.make_handle());
11011101
1102-
let on_exit: proc(UnwindResult) = |exit_status| {
1102+
let on_exit: proc(UnwindResult) = proc(exit_status) {
11031103
handle1.take().send(Shutdown);
11041104
handle2.take().send(Shutdown);
11051105
assert!(exit_status.is_success());
@@ -1113,7 +1113,7 @@ mod test {
11131113
})
11141114
}
11151115
1116-
let test_function: proc() = || {
1116+
let test_function: proc() = proc() {
11171117
let io = unsafe { local_io() };
11181118
let addr = next_test_ip4();
11191119
let maybe_socket = io.udp_bind(addr);

src/libstd/io/net/unix.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,29 +214,29 @@ mod tests {
214214

215215
#[test]
216216
fn smoke() {
217-
smalltest(|mut server| {
217+
smalltest(proc(mut server) {
218218
let mut buf = [0];
219219
server.read(buf);
220220
assert!(buf[0] == 99);
221-
}, |mut client| {
221+
}, proc(mut client) {
222222
client.write([99]);
223223
})
224224
}
225225

226226
#[test]
227227
fn read_eof() {
228-
smalltest(|mut server| {
228+
smalltest(proc(mut server) {
229229
let mut buf = [0];
230230
assert!(server.read(buf).is_none());
231231
assert!(server.read(buf).is_none());
232-
}, |_client| {
232+
}, proc(_client) {
233233
// drop the client
234234
})
235235
}
236236

237237
#[test]
238238
fn write_begone() {
239-
smalltest(|mut server| {
239+
smalltest(proc(mut server) {
240240
let buf = [0];
241241
let mut stop = false;
242242
while !stop{
@@ -248,7 +248,7 @@ mod tests {
248248
server.write(buf);
249249
})
250250
}
251-
}, |_client| {
251+
}, proc(_client) {
252252
// drop the client
253253
})
254254
}

src/libstd/rt/kill.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,11 @@ impl KillHandle {
480480
// Couldn't unwrap; children still alive. Reparent entire handle as
481481
// our own tombstone, to be unwrapped later.
482482
UnsafeArcSelf(this) => {
483-
let this = Cell::new(this); // :(
483+
let this = Cell::new(this);
484484
add_lazy_tombstone(parent, |other_tombstones| {
485-
let this = Cell::new(this.take()); // :(
486-
let others = Cell::new(other_tombstones); // :(
487-
|| {
485+
let this = Cell::new(this.take());
486+
let others = Cell::new(other_tombstones);
487+
proc() {
488488
// Prefer to check tombstones that were there first,
489489
// being "more fair" at the expense of tail-recursion.
490490
others.take().map_default(true, |f| f()) && {
@@ -505,11 +505,11 @@ impl KillHandle {
505505
// don't want to wait on now. Give them to our parent.
506506
UnsafeArcT(KillHandleInner { any_child_failed: false,
507507
child_tombstones: Some(f), _ }) => {
508-
let f = Cell::new(f); // :(
508+
let f = Cell::new(f);
509509
add_lazy_tombstone(parent, |other_tombstones| {
510-
let f = Cell::new(f.take()); // :(
511-
let others = Cell::new(other_tombstones); // :(
512-
|| {
510+
let f = Cell::new(f.take());
511+
let others = Cell::new(other_tombstones);
512+
proc() {
513513
// Prefer fairness to tail-recursion, as in above case.
514514
others.take().map_default(true, |f| f()) &&
515515
f.take()()

src/libstd/rt/local.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mod test {
134134
do run_in_bare_thread {
135135
local_ptr::init_tls_key();
136136
let mut sched = ~new_test_uv_sched();
137-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
137+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
138138
Local::put(task);
139139
let task: ~Task = Local::take();
140140
cleanup_task(task);
@@ -146,11 +146,11 @@ mod test {
146146
do run_in_bare_thread {
147147
local_ptr::init_tls_key();
148148
let mut sched = ~new_test_uv_sched();
149-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
149+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
150150
Local::put(task);
151151
let task: ~Task = Local::take();
152152
cleanup_task(task);
153-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
153+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
154154
Local::put(task);
155155
let task: ~Task = Local::take();
156156
cleanup_task(task);
@@ -163,7 +163,7 @@ mod test {
163163
do run_in_bare_thread {
164164
local_ptr::init_tls_key();
165165
let mut sched = ~new_test_uv_sched();
166-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
166+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
167167
Local::put(task);
168168

169169
unsafe {
@@ -179,7 +179,7 @@ mod test {
179179
do run_in_bare_thread {
180180
local_ptr::init_tls_key();
181181
let mut sched = ~new_test_uv_sched();
182-
let task = ~Task::new_root(&mut sched.stack_pool, None, || {});
182+
let task = ~Task::new_root(&mut sched.stack_pool, None, proc(){});
183183
Local::put(task);
184184

185185
let res = Local::borrow(|_task: &mut Task| {

src/libstd/rt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ fn run_(main: proc(), use_main_sched: bool) -> int {
340340

341341
// When the main task exits, after all the tasks in the main
342342
// task tree, shut down the schedulers and set the exit code.
343-
let handles = Cell::new(handles);
344-
let on_exit: proc(UnwindResult) = |exit_success| {
343+
let handles = handles;
344+
let on_exit: proc(UnwindResult) = proc(exit_success) {
345345
unsafe {
346346
assert!(!(*exited_already.get()).swap(true, SeqCst),
347347
"the runtime already exited");
348348
}
349349

350-
let mut handles = handles.take();
350+
let mut handles = handles;
351351
for handle in handles.mut_iter() {
352352
handle.send(Shutdown);
353353
}

0 commit comments

Comments
 (0)