Skip to content

Commit 0d6f51b

Browse files
committed
---
yaml --- r: 77183 b: refs/heads/snap-stage3 c: f7f1d89 h: refs/heads/master i: 77181: 1e1ecea 77179: 783bb76 77175: 6f395dd 77167: e46c089 77151: d3b3208 77119: b333657 77055: e0f463a v: v3
1 parent ba46438 commit 0d6f51b

29 files changed

+671
-751
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: f1132496dddbdd88f321a7919eec3d65136b3f75
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a3e39b945402475dbe0eae91833981dad4622cb7
4+
refs/heads/snap-stage3: f7f1d896497b10cb56389730e784aff6e513b0e8
55
refs/heads/try: ebfe63cd1c0b5d23f7ea60c69b4fde2e30cfd42a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/Makefile.in

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

102103
ifdef CFG_ENABLE_DEBUG

branches/snap-stage3/src/libstd/fmt/mod.rs

Lines changed: 38 additions & 60 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 `format!` syntax extension. This
15+
This module contains the runtime support for the `ifmt!` 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 `format!`. The assumptions made by these functions are unsafe for all
20+
use cases of `ifmt!`. 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 `format!` in order to ensure safety at runtime. While it is possible to call
22+
to `ifmt!` 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 `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
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
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 `format!` extension are:
33+
Some examples of the `ifmt!` extension are:
3434
3535
~~~{.rust}
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"
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"
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 `format!` macro is a syntax extension which allows it to
65+
function, but the `ifmt!` 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 `format!` extension supports
149+
The formatting syntax supported by the `ifmt!` 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-
format!("{0, select, other{#}}", "hello") // => ~"hello"
167+
ifmt!("{0, select, other{#}}", "hello") // => ~"hello"
168168
~~~
169169
170170
This example is the equivalent of `{0:s}` essentially.
@@ -399,44 +399,7 @@ pub trait Pointer { fn fmt(&Self, &mut Formatter); }
399399
#[allow(missing_doc)]
400400
pub trait Float { fn fmt(&Self, &mut Formatter); }
401401

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
402+
/// The sprintf function takes a precompiled format string and a list of
440403
/// arguments, to return the resulting formatted string.
441404
///
442405
/// This is currently an unsafe function because the types of all arguments
@@ -446,7 +409,7 @@ pub unsafe fn write(output: &mut io::Writer,
446409
/// for formatting the right type value. Because of this, the function is marked
447410
/// as `unsafe` if this is being called manually.
448411
///
449-
/// Thankfully the rust compiler provides the macro `format!` which will perform
412+
/// Thankfully the rust compiler provides the macro `ifmt!` which will perform
450413
/// all of this validation at compile-time and provides a safe interface for
451414
/// invoking this function.
452415
///
@@ -458,17 +421,32 @@ pub unsafe fn write(output: &mut io::Writer,
458421
///
459422
/// Note that this function assumes that there are enough arguments for the
460423
/// format string.
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);
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+
}
464442
return str::from_bytes_owned(output.inner());
465443
}
466444

467445
impl<'self> Formatter<'self> {
468446

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

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

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

branches/snap-stage3/src/libstd/macros.rs

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

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

branches/snap-stage3/src/libstd/rt/comm.rs

Lines changed: 5 additions & 14 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-
assert!((*packet).payload.is_none());
128+
rtassert!((*packet).payload.is_none());
129129
(*packet).payload = Some(val);
130130

131131
// Atomically swap out the old state to figure out what
@@ -144,16 +144,8 @@ 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-
}
151147
}
152148
STATE_ONE => {
153-
do Local::borrow::<Scheduler, ()> |sched| {
154-
rtdebug!("rendezvous send");
155-
sched.metrics.rendezvous_sends += 1;
156-
}
157149
// Port has closed. Need to clean up.
158150
let _packet: ~Packet<T> = cast::transmute(this.void_packet);
159151
recvr_active = false;
@@ -251,7 +243,6 @@ impl<T> SelectInner for PortOne<T> {
251243
STATE_BOTH => {
252244
// Data has not been sent. Now we're blocked.
253245
rtdebug!("non-rendezvous recv");
254-
sched.metrics.non_rendezvous_recvs += 1;
255246
false
256247
}
257248
STATE_ONE => {
@@ -267,7 +258,6 @@ impl<T> SelectInner for PortOne<T> {
267258
(*self.packet()).state.store(STATE_ONE, Relaxed);
268259

269260
rtdebug!("rendezvous recv");
270-
sched.metrics.rendezvous_recvs += 1;
271261

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

346337
let payload = (*packet).payload.take();
347338

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

0 commit comments

Comments
 (0)