Skip to content

Commit 0726df0

Browse files
committed
---
yaml --- r: 144375 b: refs/heads/try2 c: 39207a3 h: refs/heads/master i: 144373: 722a54e 144371: 12305b8 144367: 8d1ef1b v: v3
1 parent ce8c8c1 commit 0726df0

File tree

20 files changed

+381
-396
lines changed

20 files changed

+381
-396
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: f7f1d896497b10cb56389730e784aff6e513b0e8
8+
refs/heads/try2: 39207a358bdbaf3d4ba921c2b7cce786cf2c7cef
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/src/libstd/fmt/mod.rs

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,43 @@ pub trait Pointer { fn fmt(&Self, &mut Formatter); }
399399
#[allow(missing_doc)]
400400
pub trait Float { fn fmt(&Self, &mut Formatter); }
401401

402+
/// The fprintf 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 `sprintf` 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 fprintf(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+
402439
/// The sprintf function takes a precompiled format string and a list of
403440
/// arguments, to return the resulting formatted string.
404441
///
@@ -422,23 +459,8 @@ pub trait Float { fn fmt(&Self, &mut Formatter); }
422459
/// Note that this function assumes that there are enough arguments for the
423460
/// format string.
424461
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-
}
462+
let mut output = MemWriter::new();
463+
fprintf(&mut output as &mut io::Writer, fmt, args);
442464
return str::from_bytes_owned(output.inner());
443465
}
444466

branches/try2/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/try2/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);

0 commit comments

Comments
 (0)