Skip to content

Commit 0fa7d29

Browse files
committed
---
yaml --- r: 78776 b: refs/heads/try c: a3e39b9 h: refs/heads/master v: v3
1 parent ac249ae commit 0fa7d29

28 files changed

+628
-549
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 25ed29a0edb3d48fef843a0b818ee68faf2252da
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 60fba4d7d677ec098e6a43014132fe99f7547363
5-
refs/heads/try: 8c25b7f0e8c01d3946e7e7e6912e225b30b60f89
5+
refs/heads/try: a3e39b945402475dbe0eae91833981dad4622cb7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/Makefile.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ ifdef CFG_DISABLE_OPTIMIZE
9696
$(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
9797
CFG_RUSTC_FLAGS +=
9898
else
99-
# The rtopt cfg turns off runtime sanity checks
100-
CFG_RUSTC_FLAGS += -O --cfg rtopt
99+
CFG_RUSTC_FLAGS += -O
101100
endif
102101

103102
ifdef CFG_ENABLE_DEBUG

branches/try/src/libstd/fmt/mod.rs

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@
1212
1313
# The Formatting Module
1414
15-
This module contains the runtime support for the `ifmt!` syntax extension. This
15+
This module contains the runtime support for the `format!` syntax extension. This
1616
macro is implemented in the compiler to emit calls to this module in order to
1717
format arguments at runtime into strings and streams.
1818
1919
The functions contained in this module should not normally be used in everyday
20-
use cases of `ifmt!`. The assumptions made by these functions are unsafe for all
20+
use cases of `format!`. The assumptions made by these functions are unsafe for all
2121
inputs, and the compiler performs a large amount of validation on the arguments
22-
to `ifmt!` in order to ensure safety at runtime. While it is possible to call
22+
to `format!` in order to ensure safety at runtime. While it is possible to call
2323
these functions directly, it is not recommended to do so in the general case.
2424
2525
## Usage
2626
27-
The `ifmt!` macro is intended to be familiar to those coming from C's
28-
printf/sprintf functions or Python's `str.format` function. In its current
29-
revision, the `ifmt!` macro returns a `~str` type which is the result of the
27+
The `format!` macro is intended to be familiar to those coming from C's
28+
printf/fprintf functions or Python's `str.format` function. In its current
29+
revision, the `format!` macro returns a `~str` type which is the result of the
3030
formatting. In the future it will also be able to pass in a stream to format
3131
arguments directly while performing minimal allocations.
3232
33-
Some examples of the `ifmt!` extension are:
33+
Some examples of the `format!` extension are:
3434
3535
~~~{.rust}
36-
ifmt!("Hello") // => ~"Hello"
37-
ifmt!("Hello, {:s}!", "world") // => ~"Hello, world!"
38-
ifmt!("The number is {:d}", 1) // => ~"The number is 1"
39-
ifmt!("{}", ~[3, 4]) // => ~"~[3, 4]"
40-
ifmt!("{value}", value=4) // => ~"4"
41-
ifmt!("{} {}", 1, 2) // => ~"1 2"
36+
format!("Hello") // => ~"Hello"
37+
format!("Hello, {:s}!", "world") // => ~"Hello, world!"
38+
format!("The number is {:d}", 1) // => ~"The number is 1"
39+
format!("{}", ~[3, 4]) // => ~"~[3, 4]"
40+
format!("{value}", value=4) // => ~"4"
41+
format!("{} {}", 1, 2) // => ~"1 2"
4242
~~~
4343
4444
From these, you can see that the first argument is a format string. It is
@@ -62,7 +62,7 @@ format string, although it must always be referred to with the same type.
6262
### Named parameters
6363
6464
Rust itself does not have a Python-like equivalent of named parameters to a
65-
function, but the `ifmt!` macro is a syntax extension which allows it to
65+
function, but the `format!` macro is a syntax extension which allows it to
6666
leverage named parameters. Named parameters are listed at the end of the
6767
argument list and have the syntax:
6868
@@ -146,7 +146,7 @@ helper methods.
146146
147147
## Internationalization
148148
149-
The formatting syntax supported by the `ifmt!` extension supports
149+
The formatting syntax supported by the `format!` extension supports
150150
internationalization by providing "methods" which execute various different
151151
outputs depending on the input. The syntax and methods provided are similar to
152152
other internationalization systems, so again nothing should seem alien.
@@ -164,7 +164,7 @@ to reference the string value of the argument which was selected upon. As an
164164
example:
165165
166166
~~~
167-
ifmt!("{0, select, other{#}}", "hello") // => ~"hello"
167+
format!("{0, select, other{#}}", "hello") // => ~"hello"
168168
~~~
169169
170170
This example is the equivalent of `{0:s}` essentially.
@@ -399,7 +399,44 @@ pub trait Pointer { fn fmt(&Self, &mut Formatter); }
399399
#[allow(missing_doc)]
400400
pub trait Float { fn fmt(&Self, &mut Formatter); }
401401

402-
/// The sprintf function takes a precompiled format string and a list of
402+
/// The `write` function takes an output stream, a precompiled format string,
403+
/// and a list of arguments. The arguments will be formatted according to the
404+
/// specified format string into the output stream provided.
405+
///
406+
/// See the documentation for `format` for why this function is unsafe and care
407+
/// should be taken if calling it manually.
408+
///
409+
/// Thankfully the rust compiler provides the macro `fmtf!` which will perform
410+
/// all of this validation at compile-time and provides a safe interface for
411+
/// invoking this function.
412+
///
413+
/// # Arguments
414+
///
415+
/// * output - the buffer to write output to
416+
/// * fmts - the precompiled format string to emit
417+
/// * args - the list of arguments to the format string. These are only the
418+
/// positional arguments (not named)
419+
///
420+
/// Note that this function assumes that there are enough arguments for the
421+
/// format string.
422+
pub unsafe fn write(output: &mut io::Writer,
423+
fmt: &[rt::Piece], args: &[Argument]) {
424+
let mut formatter = Formatter {
425+
flags: 0,
426+
width: None,
427+
precision: None,
428+
buf: output,
429+
align: parse::AlignUnknown,
430+
fill: ' ',
431+
args: args,
432+
curarg: args.iter(),
433+
};
434+
for piece in fmt.iter() {
435+
formatter.run(piece, None);
436+
}
437+
}
438+
439+
/// The format function takes a precompiled format string and a list of
403440
/// arguments, to return the resulting formatted string.
404441
///
405442
/// This is currently an unsafe function because the types of all arguments
@@ -409,7 +446,7 @@ pub trait Float { fn fmt(&Self, &mut Formatter); }
409446
/// for formatting the right type value. Because of this, the function is marked
410447
/// as `unsafe` if this is being called manually.
411448
///
412-
/// Thankfully the rust compiler provides the macro `ifmt!` which will perform
449+
/// Thankfully the rust compiler provides the macro `format!` which will perform
413450
/// all of this validation at compile-time and provides a safe interface for
414451
/// invoking this function.
415452
///
@@ -421,32 +458,17 @@ pub trait Float { fn fmt(&Self, &mut Formatter); }
421458
///
422459
/// Note that this function assumes that there are enough arguments for the
423460
/// format string.
424-
pub unsafe fn sprintf(fmt: &[rt::Piece], args: &[Argument]) -> ~str {
425-
let output = MemWriter::new();
426-
{
427-
let mut formatter = Formatter {
428-
flags: 0,
429-
width: None,
430-
precision: None,
431-
// FIXME(#8248): shouldn't need a transmute
432-
buf: cast::transmute(&output as &io::Writer),
433-
align: parse::AlignUnknown,
434-
fill: ' ',
435-
args: args,
436-
curarg: args.iter(),
437-
};
438-
for piece in fmt.iter() {
439-
formatter.run(piece, None);
440-
}
441-
}
461+
pub unsafe fn format(fmt: &[rt::Piece], args: &[Argument]) -> ~str {
462+
let mut output = MemWriter::new();
463+
write(&mut output as &mut io::Writer, fmt, args);
442464
return str::from_bytes_owned(output.inner());
443465
}
444466

445467
impl<'self> Formatter<'self> {
446468

447469
// First up is the collection of functions used to execute a format string
448470
// at runtime. This consumes all of the compile-time statics generated by
449-
// the ifmt! syntax extension.
471+
// the format! syntax extension.
450472

451473
fn run(&mut self, piece: &rt::Piece, cur: Option<&str>) {
452474
let setcount = |slot: &mut Option<uint>, cnt: &parse::Count| {
@@ -710,7 +732,7 @@ impl<'self> Formatter<'self> {
710732
}
711733

712734
/// This is a function which calls are emitted to by the compiler itself to
713-
/// create the Argument structures that are passed into the `sprintf` function.
735+
/// create the Argument structures that are passed into the `format` function.
714736
#[doc(hidden)]
715737
pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter),
716738
t: &'a T) -> Argument<'a> {

branches/try/src/libstd/macros.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ macro_rules! rtdebug (
2727

2828
macro_rules! rtassert (
2929
( $arg:expr ) => ( {
30-
if ::rt::util::ENFORCE_SANITY {
31-
if !$arg {
32-
rtabort!("assertion failed: %s", stringify!($arg));
33-
}
30+
if !$arg {
31+
rtabort!("assertion failed: %s", stringify!($arg));
3432
}
3533
} )
3634
)

branches/try/src/libstd/rt/comm.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<T> ChanOne<T> {
125125
unsafe {
126126

127127
// Install the payload
128-
rtassert!((*packet).payload.is_none());
128+
assert!((*packet).payload.is_none());
129129
(*packet).payload = Some(val);
130130

131131
// Atomically swap out the old state to figure out what
@@ -144,8 +144,16 @@ impl<T> ChanOne<T> {
144144
match oldstate {
145145
STATE_BOTH => {
146146
// Port is not waiting yet. Nothing to do
147+
do Local::borrow::<Scheduler, ()> |sched| {
148+
rtdebug!("non-rendezvous send");
149+
sched.metrics.non_rendezvous_sends += 1;
150+
}
147151
}
148152
STATE_ONE => {
153+
do Local::borrow::<Scheduler, ()> |sched| {
154+
rtdebug!("rendezvous send");
155+
sched.metrics.rendezvous_sends += 1;
156+
}
149157
// Port has closed. Need to clean up.
150158
let _packet: ~Packet<T> = cast::transmute(this.void_packet);
151159
recvr_active = false;
@@ -243,6 +251,7 @@ impl<T> SelectInner for PortOne<T> {
243251
STATE_BOTH => {
244252
// Data has not been sent. Now we're blocked.
245253
rtdebug!("non-rendezvous recv");
254+
sched.metrics.non_rendezvous_recvs += 1;
246255
false
247256
}
248257
STATE_ONE => {
@@ -258,6 +267,7 @@ impl<T> SelectInner for PortOne<T> {
258267
(*self.packet()).state.store(STATE_ONE, Relaxed);
259268

260269
rtdebug!("rendezvous recv");
270+
sched.metrics.rendezvous_recvs += 1;
261271

262272
// Channel is closed. Switch back and check the data.
263273
// NB: We have to drop back into the scheduler event loop here
@@ -297,7 +307,7 @@ impl<T> SelectInner for PortOne<T> {
297307
STATE_ONE => true, // Lost the race. Data available.
298308
same_ptr => {
299309
// We successfully unblocked our task pointer.
300-
rtassert!(task_as_state == same_ptr);
310+
assert!(task_as_state == same_ptr);
301311
let handle = BlockedTask::cast_from_uint(task_as_state);
302312
// Because we are already awake, the handle we
303313
// gave to this port shall already be empty.
@@ -331,8 +341,7 @@ impl<T> SelectPortInner<T> for PortOne<T> {
331341
unsafe {
332342
// See corresponding store() above in block_on for rationale.
333343
// FIXME(#8130) This can happen only in test builds.
334-
// This load is not required for correctness and may be compiled out.
335-
rtassert!((*packet).state.load(Relaxed) == STATE_ONE);
344+
assert!((*packet).state.load(Relaxed) == STATE_ONE);
336345

337346
let payload = (*packet).payload.take();
338347

@@ -378,7 +387,7 @@ impl<T> Drop for ChanOne<T> {
378387
},
379388
task_as_state => {
380389
// The port is blocked waiting for a message we will never send. Wake it.
381-
rtassert!((*this.packet()).payload.is_none());
390+
assert!((*this.packet()).payload.is_none());
382391
let recvr = BlockedTask::cast_from_uint(task_as_state);
383392
do recvr.wake().map_move |woken_task| {
384393
Scheduler::run_task(woken_task);

branches/try/src/libstd/rt/local.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ pub trait Local {
2121
fn take() -> ~Self;
2222
fn exists() -> bool;
2323
fn borrow<T>(f: &fn(&mut Self) -> T) -> T;
24-
unsafe fn unsafe_take() -> ~Self;
2524
unsafe fn unsafe_borrow() -> *mut Self;
2625
unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
2726
}
2827

2928
impl Local for Task {
30-
#[inline]
3129
fn put(value: ~Task) { unsafe { local_ptr::put(value) } }
32-
#[inline]
3330
fn take() -> ~Task { unsafe { local_ptr::take() } }
3431
fn exists() -> bool { local_ptr::exists() }
3532
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
@@ -46,11 +43,7 @@ impl Local for Task {
4643
None => { rtabort!("function failed in local_borrow") }
4744
}
4845
}
49-
#[inline]
50-
unsafe fn unsafe_take() -> ~Task { local_ptr::unsafe_take() }
51-
#[inline]
5246
unsafe fn unsafe_borrow() -> *mut Task { local_ptr::unsafe_borrow() }
53-
#[inline]
5447
unsafe fn try_unsafe_borrow() -> Option<*mut Task> {
5548
local_ptr::try_unsafe_borrow()
5649
}
@@ -64,12 +57,12 @@ impl Local for Scheduler {
6457
task.sched = Some(value.take());
6558
};
6659
}
67-
#[inline]
6860
fn take() -> ~Scheduler {
69-
unsafe {
70-
// XXX: Unsafe for speed
71-
let task = Local::unsafe_borrow::<Task>();
72-
(*task).sched.take_unwrap()
61+
do Local::borrow::<Task,~Scheduler> |task| {
62+
let sched = task.sched.take_unwrap();
63+
let task = task;
64+
task.sched = None;
65+
sched
7366
}
7467
}
7568
fn exists() -> bool {
@@ -92,7 +85,6 @@ impl Local for Scheduler {
9285
}
9386
}
9487
}
95-
unsafe fn unsafe_take() -> ~Scheduler { rtabort!("unimpl") }
9688
unsafe fn unsafe_borrow() -> *mut Scheduler {
9789
match (*Local::unsafe_borrow::<Task>()).sched {
9890
Some(~ref mut sched) => {
@@ -105,17 +97,10 @@ impl Local for Scheduler {
10597
}
10698
}
10799
unsafe fn try_unsafe_borrow() -> Option<*mut Scheduler> {
108-
match Local::try_unsafe_borrow::<Task>() {
109-
Some(task) => {
110-
match (*task).sched {
111-
Some(~ref mut sched) => {
112-
let s: *mut Scheduler = &mut *sched;
113-
Some(s)
114-
}
115-
None => None
116-
}
117-
}
118-
None => None
100+
if Local::exists::<Scheduler>() {
101+
Some(Local::unsafe_borrow())
102+
} else {
103+
None
119104
}
120105
}
121106
}
@@ -126,7 +111,6 @@ impl Local for IoFactoryObject {
126111
fn take() -> ~IoFactoryObject { rtabort!("unimpl") }
127112
fn exists() -> bool { rtabort!("unimpl") }
128113
fn borrow<T>(_f: &fn(&mut IoFactoryObject) -> T) -> T { rtabort!("unimpl") }
129-
unsafe fn unsafe_take() -> ~IoFactoryObject { rtabort!("unimpl") }
130114
unsafe fn unsafe_borrow() -> *mut IoFactoryObject {
131115
let sched = Local::unsafe_borrow::<Scheduler>();
132116
let io: *mut IoFactoryObject = (*sched).event_loop.io().unwrap();

0 commit comments

Comments
 (0)