Skip to content

Commit 15ce5d6

Browse files
committed
---
yaml --- r: 163351 b: refs/heads/snap-stage3 c: d613381 h: refs/heads/master i: 163349: 542cb22 163347: 7989942 163343: 9e68698 v: v3
1 parent 9fa2d26 commit 15ce5d6

File tree

15 files changed

+237
-167
lines changed

15 files changed

+237
-167
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 3a9305ce823df267fb1afcce76ef06ca09e407ff
4+
refs/heads/snap-stage3: d61338172fa110fcf9e5f2df0e1e83635d0fde3f
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/librustc/middle/resolve.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5807,30 +5807,16 @@ impl<'a> Resolver<'a> {
58075807
// This is a local path in the value namespace. Walk through
58085808
// scopes looking for it.
58095809

5810-
let path_name = self.path_names_to_string(path);
5811-
58125810
match self.resolve_path(expr.id, path, ValueNS, true) {
5813-
// Check if struct variant
5814-
Some((DefVariant(_, _, true), _)) => {
5815-
self.resolve_error(expr.span,
5816-
format!("`{}` is a struct variant name, but \
5817-
this expression \
5818-
uses it like a function name",
5819-
path_name).as_slice());
5820-
5821-
self.session.span_help(expr.span,
5822-
format!("Did you mean to write: \
5823-
`{} {{ /* fields */ }}`?",
5824-
path_name).as_slice());
5825-
}
58265811
Some(def) => {
58275812
// Write the result into the def map.
58285813
debug!("(resolving expr) resolved `{}`",
5829-
path_name);
5814+
self.path_names_to_string(path));
58305815

58315816
self.record_def(expr.id, def);
58325817
}
58335818
None => {
5819+
let wrong_name = self.path_names_to_string(path);
58345820
// Be helpful if the name refers to a struct
58355821
// (The pattern matching def_tys where the id is in self.structs
58365822
// matches on regular structs while excluding tuple- and enum-like
@@ -5843,12 +5829,12 @@ impl<'a> Resolver<'a> {
58435829
format!("`{}` is a structure name, but \
58445830
this expression \
58455831
uses it like a function name",
5846-
path_name).as_slice());
5832+
wrong_name).as_slice());
58475833

58485834
self.session.span_help(expr.span,
58495835
format!("Did you mean to write: \
58505836
`{} {{ /* fields */ }}`?",
5851-
path_name).as_slice());
5837+
wrong_name).as_slice());
58525838

58535839
}
58545840
_ => {
@@ -5865,7 +5851,7 @@ impl<'a> Resolver<'a> {
58655851
});
58665852

58675853
if method_scope && token::get_name(self.self_name).get()
5868-
== path_name {
5854+
== wrong_name {
58695855
self.resolve_error(
58705856
expr.span,
58715857
"`self` is not available \
@@ -5877,18 +5863,18 @@ impl<'a> Resolver<'a> {
58775863
NoSuggestion => {
58785864
// limit search to 5 to reduce the number
58795865
// of stupid suggestions
5880-
self.find_best_match_for_name(path_name.as_slice(), 5)
5866+
self.find_best_match_for_name(wrong_name.as_slice(), 5)
58815867
.map_or("".to_string(),
58825868
|x| format!("`{}`", x))
58835869
}
58845870
Field =>
5885-
format!("`self.{}`", path_name),
5871+
format!("`self.{}`", wrong_name),
58865872
Method
58875873
| TraitItem =>
5888-
format!("to call `self.{}`", path_name),
5874+
format!("to call `self.{}`", wrong_name),
58895875
TraitMethod(path_str)
58905876
| StaticMethod(path_str) =>
5891-
format!("to call `{}::{}`", path_str, path_name)
5877+
format!("to call `{}::{}`", path_str, wrong_name)
58925878
};
58935879

58945880
if msg.len() > 0 {
@@ -5898,7 +5884,7 @@ impl<'a> Resolver<'a> {
58985884
self.resolve_error(
58995885
expr.span,
59005886
format!("unresolved name `{}`{}",
5901-
path_name,
5887+
wrong_name,
59025888
msg).as_slice());
59035889
}
59045890
}

branches/snap-stage3/src/librustrt/at_exit_imp.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ use alloc::boxed::Box;
1818
use collections::vec::Vec;
1919
use core::atomic;
2020
use core::mem;
21+
use thunk::{Thunk};
2122

2223
use exclusive::Exclusive;
2324

24-
type Queue = Exclusive<Vec<proc():Send>>;
25+
type Queue = Exclusive<Vec<Thunk>>;
2526

2627
static QUEUE: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
2728
static RUNNING: atomic::AtomicBool = atomic::INIT_ATOMIC_BOOL;
@@ -34,7 +35,7 @@ pub fn init() {
3435
}
3536
}
3637

37-
pub fn push(f: proc():Send) {
38+
pub fn push(f: Thunk) {
3839
unsafe {
3940
// Note that the check against 0 for the queue pointer is not atomic at
4041
// all with respect to `run`, meaning that this could theoretically be a
@@ -59,6 +60,6 @@ pub fn run() {
5960
};
6061

6162
for to_run in cur.into_iter() {
62-
to_run();
63+
to_run.invoke(());
6364
}
6465
}

branches/snap-stage3/src/librustrt/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mod thread_local_storage;
4646
mod util;
4747
mod libunwind;
4848
mod stack_overflow;
49+
pub mod thunk;
4950

5051
pub mod args;
5152
pub mod bookkeeping;
@@ -95,8 +96,8 @@ pub fn init(argc: int, argv: *const *const u8) {
9596
///
9697
/// It is forbidden for procedures to register more `at_exit` handlers when they
9798
/// are running, and doing so will lead to a process abort.
98-
pub fn at_exit(f: proc():Send) {
99-
at_exit_imp::push(f);
99+
pub fn at_exit<F:FnOnce()+Send>(f: F) {
100+
at_exit_imp::push(thunk::Thunk::new(f));
100101
}
101102

102103
/// One-time runtime cleanup.

branches/snap-stage3/src/librustrt/task.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use core::any::Any;
2121
use core::atomic::{AtomicUint, SeqCst};
2222
use core::iter::{IteratorExt, Take};
2323
use core::kinds::marker;
24+
use core::ops::FnOnce;
2425
use core::mem;
2526
use core::ops::FnMut;
2627
use core::prelude::{Clone, Drop, Err, Iterator, None, Ok, Option, Send, Some};
@@ -34,6 +35,7 @@ use stack;
3435
use unwind;
3536
use unwind::Unwinder;
3637
use collections::str::SendStr;
38+
use thunk::Thunk;
3739

3840
/// State associated with Rust tasks.
3941
///
@@ -67,7 +69,7 @@ enum TaskState {
6769

6870
pub struct TaskOpts {
6971
/// Invoke this procedure with the result of the task when it finishes.
70-
pub on_exit: Option<proc(Result): Send>,
72+
pub on_exit: Option<Thunk<Result>>,
7173
/// A name for the task-to-be, for identification in panic messages
7274
pub name: Option<SendStr>,
7375
/// The size of the stack for the spawned task
@@ -92,7 +94,7 @@ pub enum BlockedTask {
9294

9395
/// Per-task state related to task death, killing, panic, etc.
9496
pub struct Death {
95-
pub on_exit: Option<proc(Result):Send>,
97+
pub on_exit: Option<Thunk<Result>>,
9698
marker: marker::NoCopy,
9799
}
98100

@@ -116,7 +118,13 @@ impl Task {
116118
}
117119
}
118120

119-
pub fn spawn(opts: TaskOpts, f: proc():Send) {
121+
pub fn spawn<F>(opts: TaskOpts, f: F)
122+
where F : FnOnce(), F : Send
123+
{
124+
Task::spawn_thunk(opts, Thunk::new(f))
125+
}
126+
127+
fn spawn_thunk(opts: TaskOpts, f: Thunk) {
120128
let TaskOpts { name, stack_size, on_exit } = opts;
121129

122130
let mut task = box Task::new(None, None);
@@ -138,7 +146,7 @@ impl Task {
138146
// because by the time that this function is executing we've already
139147
// consumed at least a little bit of stack (we don't know the exact byte
140148
// address at which our stack started).
141-
Thread::spawn_stack(stack, proc() {
149+
Thread::spawn_stack(stack, move|| {
142150
let something_around_the_top_of_the_stack = 1;
143151
let addr = &something_around_the_top_of_the_stack as *const int;
144152
let my_stack = addr as uint;
@@ -150,7 +158,7 @@ impl Task {
150158
task.stack_bounds = (my_stack - stack + 1024, my_stack);
151159

152160
let mut f = Some(f);
153-
drop(task.run(|| { f.take().unwrap()() }).destroy());
161+
drop(task.run(|| { f.take().unwrap().invoke(()) }).destroy());
154162
drop(token);
155163
})
156164
}
@@ -241,7 +249,7 @@ impl Task {
241249
// reconsideration to whether it's a reasonable thing to let a
242250
// task to do or not.
243251
match what_to_do {
244-
Some(f) => { f(result) }
252+
Some(f) => { f.invoke(result) }
245253
None => { drop(result) }
246254
}
247255

@@ -500,14 +508,13 @@ mod test {
500508
use super::*;
501509
use std::prelude::*;
502510
use std::task;
503-
use unwind;
504511

505512
#[test]
506513
fn unwind() {
507-
let result = task::try(proc()());
514+
let result = task::try(move|| ());
508515
rtdebug!("trying first assert");
509516
assert!(result.is_ok());
510-
let result = task::try::<()>(proc() panic!());
517+
let result = task::try(move|| -> () panic!());
511518
rtdebug!("trying second assert");
512519
assert!(result.is_err());
513520
}

0 commit comments

Comments
 (0)