Skip to content

Commit 9371276

Browse files
committed
---
yaml --- r: 149690 b: refs/heads/try2 c: 997ff7a h: refs/heads/master v: v3
1 parent a562f02 commit 9371276

File tree

19 files changed

+127
-104
lines changed

19 files changed

+127
-104
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: c81b3fb21a560f9eaacc06ceeabcd5b4339e54d0
8+
refs/heads/try2: 997ff7abd4f3b803575a7bfa4af3fb05569b1f75
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/etc/vim/syntax/rust.vim

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,11 @@ syn region rustGenericLifetimeCandidate display start=/\%(<\|,\s*\)\@<='/ end=/[
163163
syn match rustLifetime display "\'\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"
164164
syn match rustCharacter /'\([^'\\]\|\\\(.\|x\x\{2}\|u\x\{4}\|U\x\{8}\)\)'/ contains=rustSpecial,rustSpecialError
165165

166-
syn region rustCommentLine start="//" end="$" contains=rustTodo,@Spell
167-
syn region rustCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell
168-
syn region rustCommentBlock matchgroup=rustCommentBlock start="/\*\%(!\|\*[*/]\@!\)\@!" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell
169-
syn region rustCommentBlockDoc matchgroup=rustCommentBlockDoc start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell
170-
syn region rustCommentBlockNest matchgroup=rustCommentBlock start="/\*" end="\*/" contains=rustTodo,rustCommentBlockNest,@Spell contained transparent
171-
syn region rustCommentBlockDocNest matchgroup=rustCommentBlockDoc start="/\*" end="\*/" contains=rustTodo,rustCommentBlockDocNest,@Spell contained transparent
166+
syn cluster rustComment contains=rustCommentLine,rustCommentLineDoc,rustCommentBlock,rustCommentBlockDoc
167+
syn region rustCommentLine start="//" end="$" contains=rustTodo,@Spell
168+
syn region rustCommentLineDoc start="//\%(//\@!\|!\)" end="$" contains=rustTodo,@Spell
169+
syn region rustCommentBlock matchgroup=rustCommentBlock start="/\*\%(!\|\*[*/]\@!\)\@!" end="\*/" contains=rustTodo,@rustComment,@Spell keepend extend
170+
syn region rustCommentBlockDoc matchgroup=rustCommentBlockDoc start="/\*\%(!\|\*[*/]\@!\)" end="\*/" contains=rustTodo,@rustComment,@Spell keepend extend
172171
" FIXME: this is a really ugly and not fully correct implementation. Most
173172
" importantly, a case like ``/* */*`` should have the final ``*`` not being in
174173
" a comment, but in practice at present it leaves comments open two levels

branches/try2/src/librustc/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ pub fn run_compiler(args: &[~str]) {
297297
match input {
298298
d::FileInput(ref ifile) => {
299299
let mut stdout = io::stdout();
300-
d::list_metadata(sess, &(*ifile), &mut stdout).unwrap();
300+
d::list_metadata(sess, &(*ifile),
301+
&mut stdout as &mut io::Writer).unwrap();
301302
}
302303
d::StrInput(_) => {
303304
d::early_error("can not list metadata for stdin");

branches/try2/src/librustc/metadata/decoder.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,12 +1145,26 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
11451145
Ok(())
11461146
}
11471147

1148+
pub fn maybe_get_crate_hash(data: &[u8]) -> Option<Svh> {
1149+
let cratedoc = reader::Doc(data);
1150+
reader::maybe_get_doc(cratedoc, tag_crate_hash).map(|doc| {
1151+
Svh::new(doc.as_str_slice())
1152+
})
1153+
}
1154+
11481155
pub fn get_crate_hash(data: &[u8]) -> Svh {
11491156
let cratedoc = reader::Doc(data);
11501157
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
11511158
Svh::new(hashdoc.as_str_slice())
11521159
}
11531160

1161+
pub fn maybe_get_crate_id(data: &[u8]) -> Option<CrateId> {
1162+
let cratedoc = reader::Doc(data);
1163+
reader::maybe_get_doc(cratedoc, tag_crate_crateid).map(|doc| {
1164+
from_str(doc.as_str_slice()).unwrap()
1165+
})
1166+
}
1167+
11541168
pub fn get_crate_id(data: &[u8]) -> CrateId {
11551169
let cratedoc = reader::Doc(data);
11561170
let hashdoc = reader::get_doc(cratedoc, tag_crate_crateid);

branches/try2/src/librustc/metadata/loader.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,17 @@ impl<'a> Context<'a> {
318318
}
319319

320320
fn crate_matches(&mut self, crate_data: &[u8]) -> bool {
321-
let other_id = decoder::get_crate_id(crate_data);
322-
if !self.crate_id.matches(&other_id) { return false }
321+
match decoder::maybe_get_crate_id(crate_data) {
322+
Some(ref id) if self.crate_id.matches(id) => {}
323+
_ => return false
324+
}
325+
let hash = match decoder::maybe_get_crate_hash(crate_data) {
326+
Some(hash) => hash, None => return false
327+
};
323328
match self.hash {
324329
None => true,
325-
Some(hash) => {
326-
if *hash != decoder::get_crate_hash(crate_data) {
330+
Some(myhash) => {
331+
if *myhash != hash {
327332
self.rejected_via_hash = true;
328333
false
329334
} else {

branches/try2/src/librustc/middle/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ impl<'a> DynamicFailureHandler<'a> {
11881188

11891189
let fcx = self.bcx.fcx;
11901190
let fail_cx = fcx.new_block(false, "case_fallthrough", None);
1191-
controlflow::trans_fail(fail_cx, self.sp, self.msg.clone());
1191+
controlflow::trans_fail(fail_cx, Some(self.sp), self.msg.clone());
11921192
self.finished.set(Some(fail_cx.llbb));
11931193
fail_cx.llbb
11941194
}

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ pub fn fail_if_zero<'a>(
864864
}
865865
};
866866
with_cond(cx, is_zero, |bcx| {
867-
controlflow::trans_fail(bcx, span, InternedString::new(text))
867+
controlflow::trans_fail(bcx, Some(span), InternedString::new(text))
868868
})
869869
}
870870

branches/try2/src/librustc/middle/trans/controlflow.rs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use middle::trans::debuginfo;
1818
use middle::trans::cleanup;
1919
use middle::trans::cleanup::CleanupMethods;
2020
use middle::trans::expr;
21+
use middle::ty;
22+
use util::ppaux;
2123
use util::ppaux::Repr;
2224

2325
use middle::trans::type_::Type;
@@ -325,23 +327,67 @@ pub fn trans_ret<'a>(bcx: &'a Block<'a>,
325327
return bcx;
326328
}
327329

330+
pub fn trans_fail_expr<'a>(
331+
bcx: &'a Block<'a>,
332+
sp_opt: Option<Span>,
333+
fail_expr: Option<@ast::Expr>)
334+
-> &'a Block<'a> {
335+
let _icx = push_ctxt("trans_fail_expr");
336+
let mut bcx = bcx;
337+
match fail_expr {
338+
Some(arg_expr) => {
339+
let ccx = bcx.ccx();
340+
let tcx = ccx.tcx;
341+
let arg_datum =
342+
unpack_datum!(bcx, expr::trans_to_lvalue(bcx, arg_expr, "fail"));
343+
344+
if ty::type_is_str(arg_datum.ty) {
345+
let (lldata, _) = arg_datum.get_vec_base_and_len(bcx);
346+
return trans_fail_value(bcx, sp_opt, lldata);
347+
} else if bcx.unreachable.get() || ty::type_is_bot(arg_datum.ty) {
348+
return bcx;
349+
} else {
350+
bcx.sess().span_bug(
351+
arg_expr.span, ~"fail called with unsupported type " +
352+
ppaux::ty_to_str(tcx, arg_datum.ty));
353+
}
354+
}
355+
_ => trans_fail(bcx, sp_opt, InternedString::new("explicit failure"))
356+
}
357+
}
358+
328359
pub fn trans_fail<'a>(
329360
bcx: &'a Block<'a>,
330-
sp: Span,
361+
sp_opt: Option<Span>,
331362
fail_str: InternedString)
332363
-> &'a Block<'a> {
364+
let _icx = push_ctxt("trans_fail");
333365
let V_fail_str = C_cstr(bcx.ccx(), fail_str);
366+
return trans_fail_value(bcx, sp_opt, V_fail_str);
367+
}
368+
369+
fn trans_fail_value<'a>(
370+
bcx: &'a Block<'a>,
371+
sp_opt: Option<Span>,
372+
V_fail_str: ValueRef)
373+
-> &'a Block<'a> {
334374
let _icx = push_ctxt("trans_fail_value");
335375
let ccx = bcx.ccx();
336-
let sess = bcx.sess();
337-
let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo);
338-
let V_filename = C_cstr(bcx.ccx(),
339-
token::intern_and_get_ident(loc.file.name));
340-
let V_line = loc.line as int;
376+
let (V_filename, V_line) = match sp_opt {
377+
Some(sp) => {
378+
let sess = bcx.sess();
379+
let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo);
380+
(C_cstr(bcx.ccx(), token::intern_and_get_ident(loc.file.name)),
381+
loc.line as int)
382+
}
383+
None => {
384+
(C_cstr(bcx.ccx(), InternedString::new("<runtime>")), 0)
385+
}
386+
};
341387
let V_str = PointerCast(bcx, V_fail_str, Type::i8p());
342388
let V_filename = PointerCast(bcx, V_filename, Type::i8p());
343389
let args = ~[V_str, V_filename, C_int(ccx, V_line)];
344-
let did = langcall(bcx, Some(sp), "", FailFnLangItem);
390+
let did = langcall(bcx, sp_opt, "", FailFnLangItem);
345391
let bcx = callee::trans_lang_call(bcx, did, args, Some(expr::Ignore)).bcx;
346392
Unreachable(bcx);
347393
return bcx;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ uniform_fn_call_workaround! {
654654
/// use std::fmt;
655655
/// use std::io;
656656
///
657-
/// let mut w = io::stdout();
658-
/// format_args!(|args| { fmt::write(&mut w, args); }, "Hello, {}!", "world");
657+
/// let w = &mut io::stdout() as &mut io::Writer;
658+
/// format_args!(|args| { fmt::write(w, args); }, "Hello, {}!", "world");
659659
/// ```
660660
pub fn write(output: &mut io::Writer, args: &Arguments) -> Result {
661661
unsafe { write_unsafe(output, args.fmt, args.args) }

branches/try2/src/libstd/io/buffered.rs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use cmp;
1414
use container::Container;
1515
use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult};
1616
use iter::ExactSize;
17-
use ops::Drop;
18-
use option::{Some, None, Option};
17+
use option::{Some, None};
1918
use result::{Ok, Err};
2019
use vec::{OwnedVector, ImmutableVector, MutableVector};
2120
use vec;
@@ -116,7 +115,7 @@ impl<R: Reader> Reader for BufferedReader<R> {
116115

117116
/// Wraps a Writer and buffers output to it
118117
///
119-
/// This writer will be flushed when it is dropped.
118+
/// Note that `BufferedWriter` will NOT flush its buffer when dropped.
120119
///
121120
/// # Example
122121
///
@@ -131,7 +130,7 @@ impl<R: Reader> Reader for BufferedReader<R> {
131130
/// writer.flush();
132131
/// ```
133132
pub struct BufferedWriter<W> {
134-
priv inner: Option<W>,
133+
priv inner: W,
135134
priv buf: ~[u8],
136135
priv pos: uint
137136
}
@@ -143,7 +142,7 @@ impl<W: Writer> BufferedWriter<W> {
143142
let mut buf = vec::with_capacity(cap);
144143
unsafe { buf.set_len(cap); }
145144
BufferedWriter {
146-
inner: Some(inner),
145+
inner: inner,
147146
buf: buf,
148147
pos: 0
149148
}
@@ -156,7 +155,7 @@ impl<W: Writer> BufferedWriter<W> {
156155

157156
fn flush_buf(&mut self) -> IoResult<()> {
158157
if self.pos != 0 {
159-
let ret = self.inner.get_mut_ref().write(self.buf.slice_to(self.pos));
158+
let ret = self.inner.write(self.buf.slice_to(self.pos));
160159
self.pos = 0;
161160
ret
162161
} else {
@@ -168,15 +167,15 @@ impl<W: Writer> BufferedWriter<W> {
168167
///
169168
/// This type does not expose the ability to get a mutable reference to the
170169
/// underlying reader because that could possibly corrupt the buffer.
171-
pub fn get_ref<'a>(&'a self) -> &'a W { self.inner.get_ref() }
170+
pub fn get_ref<'a>(&'a self) -> &'a W { &self.inner }
172171

173172
/// Unwraps this buffer, returning the underlying writer.
174173
///
175174
/// The buffer is flushed before returning the writer.
176175
pub fn unwrap(mut self) -> W {
177-
// FIXME(#12628): is failing the right thing to do if flushing fails?
176+
// FIXME: is failing the right thing to do if flushing fails?
178177
self.flush_buf().unwrap();
179-
self.inner.take_unwrap()
178+
self.inner
180179
}
181180
}
182181

@@ -187,7 +186,7 @@ impl<W: Writer> Writer for BufferedWriter<W> {
187186
}
188187

189188
if buf.len() > self.buf.len() {
190-
self.inner.get_mut_ref().write(buf)
189+
self.inner.write(buf)
191190
} else {
192191
let dst = self.buf.mut_slice_from(self.pos);
193192
vec::bytes::copy_memory(dst, buf);
@@ -197,24 +196,14 @@ impl<W: Writer> Writer for BufferedWriter<W> {
197196
}
198197

199198
fn flush(&mut self) -> IoResult<()> {
200-
self.flush_buf().and_then(|()| self.inner.get_mut_ref().flush())
201-
}
202-
}
203-
204-
#[unsafe_destructor]
205-
impl<W: Writer> Drop for BufferedWriter<W> {
206-
fn drop(&mut self) {
207-
if self.inner.is_some() {
208-
// FIXME(#12628): should this error be ignored?
209-
let _ = self.flush_buf();
210-
}
199+
self.flush_buf().and_then(|()| self.inner.flush())
211200
}
212201
}
213202

214203
/// Wraps a Writer and buffers output to it, flushing whenever a newline (`0x0a`,
215204
/// `'\n'`) is detected.
216205
///
217-
/// This writer will be flushed when it is dropped.
206+
/// Note that this structure does NOT flush the output when dropped.
218207
pub struct LineBufferedWriter<W> {
219208
priv inner: BufferedWriter<W>,
220209
}
@@ -267,13 +256,13 @@ impl<W> InternalBufferedWriter<W> {
267256

268257
impl<W: Reader> Reader for InternalBufferedWriter<W> {
269258
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
270-
self.get_mut_ref().inner.get_mut_ref().read(buf)
259+
self.get_mut_ref().inner.read(buf)
271260
}
272261
}
273262

274-
/// Wraps a Stream and buffers input and output to and from it.
263+
/// Wraps a Stream and buffers input and output to and from it
275264
///
276-
/// The output half will be flushed when this stream is dropped.
265+
/// Note that `BufferedStream` will NOT flush its output buffer when dropped.
277266
///
278267
/// # Example
279268
///

branches/try2/src/libstd/io/stdio.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T {
9090
/// buffered access is not desired, the `stdin_raw` function is provided to
9191
/// provided unbuffered access to stdin.
9292
///
93-
/// Care should be taken when creating multiple handles to the stdin of a
94-
/// process. Beause this is a buffered reader by default, it's possible for
95-
/// pending input to be unconsumed in one reader and unavailable to other
96-
/// readers. It is recommended that only one handle at a time is created for the
97-
/// stdin of a process.
98-
///
9993
/// See `stdout()` for more notes about this function.
10094
pub fn stdin() -> BufferedReader<StdReader> {
10195
BufferedReader::new(stdin_raw())
@@ -110,38 +104,20 @@ pub fn stdin_raw() -> StdReader {
110104
src(libc::STDIN_FILENO, true, |src| StdReader { inner: src })
111105
}
112106

113-
/// Creates a line-buffered handle to the stdout of the current process.
107+
/// Creates a new non-blocking handle to the stdout of the current process.
114108
///
115109
/// Note that this is a fairly expensive operation in that at least one memory
116110
/// allocation is performed. Additionally, this must be called from a runtime
117111
/// task context because the stream returned will be a non-blocking object using
118112
/// the local scheduler to perform the I/O.
119-
///
120-
/// Care should be taken when creating multiple handles to an output stream for
121-
/// a single process. While usage is still safe, the output may be surprising if
122-
/// no synchronization is performed to ensure a sane output.
123-
pub fn stdout() -> LineBufferedWriter<StdWriter> {
124-
LineBufferedWriter::new(stdout_raw())
125-
}
126-
127-
/// Creates an unbuffered handle to the stdout of the current process
128-
///
129-
/// See notes in `stdout()` for more information.
130-
pub fn stdout_raw() -> StdWriter {
113+
pub fn stdout() -> StdWriter {
131114
src(libc::STDOUT_FILENO, false, |src| StdWriter { inner: src })
132115
}
133116

134-
/// Creates a line-buffered handle to the stderr of the current process.
117+
/// Creates a new non-blocking handle to the stderr of the current process.
135118
///
136119
/// See `stdout()` for notes about this function.
137-
pub fn stderr() -> LineBufferedWriter<StdWriter> {
138-
LineBufferedWriter::new(stderr_raw())
139-
}
140-
141-
/// Creates an unbuffered handle to the stderr of the current process
142-
///
143-
/// See notes in `stdout()` for more information.
144-
pub fn stderr_raw() -> StdWriter {
120+
pub fn stderr() -> StdWriter {
145121
src(libc::STDERR_FILENO, false, |src| StdWriter { inner: src })
146122
}
147123

@@ -206,7 +182,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()> ) {
206182
Local::put(task);
207183

208184
if my_stdout.is_none() {
209-
my_stdout = Some(~stdout() as ~Writer);
185+
my_stdout = Some(~LineBufferedWriter::new(stdout()) as ~Writer);
210186
}
211187
let ret = f(*my_stdout.get_mut_ref());
212188

branches/try2/src/libstd/logging.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ pub fn log(level: u32, args: &fmt::Arguments) {
166166
};
167167

168168
if logger.is_none() {
169-
logger = Some(~DefaultLogger { handle: io::stderr(), } as ~Logger);
169+
logger = Some(~DefaultLogger {
170+
handle: LineBufferedWriter::new(io::stderr()),
171+
} as ~Logger);
170172
}
171173
logger.get_mut_ref().log(level, args);
172174

0 commit comments

Comments
 (0)