Skip to content

Commit 45a2e4d

Browse files
committed
---
yaml --- r: 102118 b: refs/heads/master c: 7cc6b5e h: refs/heads/master v: v3
1 parent 02fd5a4 commit 45a2e4d

25 files changed

+309
-158
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: b48833d6db16c7d94f20ee6083dbb880979acfd4
2+
refs/heads/master: 7cc6b5e0a3a2038d66301906f76cdb778304a3bd
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/src/doc/complement-cheatsheet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Description C signature Equivalent
211211
---------------------- ---------------------------------------------- ------------------------------------------
212212
no parameters `void foo(void);` `fn foo();`
213213
return value `int foo(void);` `fn foo() -> c_int;`
214-
function parameters `void foo(int x, int y);` `fn foo(x: int, y: int);`
214+
function parameters `void foo(int x, int y);` `fn foo(x: c_int, y: c_int);`
215215
in-out pointers `void foo(const int* in_ptr, int* out_ptr);` `fn foo(in_ptr: *c_int, out_ptr: *mut c_int);`
216216
217217
Note: The Rust signatures should be wrapped in an `extern "ABI" { ... }` block.

trunk/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ type was invalid because the size was infinite!
10261026

10271027
An *owned box* (`~`) uses a dynamic memory allocation to provide the invariant
10281028
of always being the size of a pointer, regardless of the contained type. This
1029-
can be leverage to create a valid `List` definition:
1029+
can be leveraged to create a valid `List` definition:
10301030

10311031
~~~
10321032
enum List {

trunk/src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl CFGBuilder {
490490

491491
fn find_scope(&self,
492492
expr: @ast::Expr,
493-
label: Option<ast::Name>) -> LoopScope {
493+
label: Option<ast::Ident>) -> LoopScope {
494494
match label {
495495
None => {
496496
return *self.loop_scopes.last().unwrap();

trunk/src/librustc/middle/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
770770

771771
fn find_scope<'a>(&self,
772772
expr: &ast::Expr,
773-
label: Option<ast::Name>,
773+
label: Option<ast::Ident>,
774774
loop_scopes: &'a mut ~[LoopScope]) -> &'a mut LoopScope {
775775
let index = match label {
776776
None => {

trunk/src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ impl Liveness {
747747
}
748748

749749
pub fn find_loop_scope(&self,
750-
opt_label: Option<Name>,
750+
opt_label: Option<Ident>,
751751
id: NodeId,
752752
sp: Span)
753753
-> NodeId {

trunk/src/librustc/middle/resolve.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,13 +5206,13 @@ impl Resolver {
52065206
ExprLoop(_, Some(label)) => {
52075207
self.with_label_rib(|this| {
52085208
let def_like = DlDef(DefLabel(expr.id));
5209-
// plain insert (no renaming)
52105209
{
52115210
let mut label_ribs = this.label_ribs.borrow_mut();
52125211
let rib = label_ribs.get()[label_ribs.get().len() -
52135212
1];
52145213
let mut bindings = rib.bindings.borrow_mut();
5215-
bindings.get().insert(label.name, def_like);
5214+
let renamed = mtwt_resolve(label);
5215+
bindings.get().insert(renamed, def_like);
52165216
}
52175217

52185218
visit::walk_expr(this, expr, ());
@@ -5223,11 +5223,12 @@ impl Resolver {
52235223

52245224
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
52255225
let mut label_ribs = self.label_ribs.borrow_mut();
5226-
match self.search_ribs(label_ribs.get(), label, expr.span) {
5226+
let renamed = mtwt_resolve(label);
5227+
match self.search_ribs(label_ribs.get(), renamed, expr.span) {
52275228
None =>
52285229
self.resolve_error(expr.span,
52295230
format!("use of undeclared label `{}`",
5230-
token::get_name(label))),
5231+
token::get_ident(label))),
52315232
Some(DlDef(def @ DefLabel(_))) => {
52325233
// Since this def is a label, it is never read.
52335234
self.record_def(expr.id, (def, LastMod(AllPublic)))

trunk/src/librustc/middle/trans/controlflow.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use util::ppaux::Repr;
2525
use middle::trans::type_::Type;
2626

2727
use syntax::ast;
28-
use syntax::ast::Name;
28+
use syntax::ast::Ident;
2929
use syntax::ast_util;
3030
use syntax::codemap::Span;
3131
use syntax::parse::token::InternedString;
@@ -260,7 +260,7 @@ pub fn trans_loop<'a>(bcx:&'a Block<'a>,
260260

261261
pub fn trans_break_cont<'a>(bcx: &'a Block<'a>,
262262
expr_id: ast::NodeId,
263-
opt_label: Option<Name>,
263+
opt_label: Option<Ident>,
264264
exit: uint)
265265
-> &'a Block<'a> {
266266
let _icx = push_ctxt("trans_break_cont");
@@ -293,14 +293,14 @@ pub fn trans_break_cont<'a>(bcx: &'a Block<'a>,
293293

294294
pub fn trans_break<'a>(bcx: &'a Block<'a>,
295295
expr_id: ast::NodeId,
296-
label_opt: Option<Name>)
296+
label_opt: Option<Ident>)
297297
-> &'a Block<'a> {
298298
return trans_break_cont(bcx, expr_id, label_opt, cleanup::EXIT_BREAK);
299299
}
300300

301301
pub fn trans_cont<'a>(bcx: &'a Block<'a>,
302302
expr_id: ast::NodeId,
303-
label_opt: Option<Name>)
303+
label_opt: Option<Ident>)
304304
-> &'a Block<'a> {
305305
return trans_break_cont(bcx, expr_id, label_opt, cleanup::EXIT_LOOP);
306306
}

trunk/src/libstd/char.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static TAG_FOUR_B: uint = 240u;
6969
pub static MAX: char = '\U0010ffff';
7070

7171
/// Convert from `u32` to a character.
72+
#[inline]
7273
pub fn from_u32(i: u32) -> Option<char> {
7374
// catch out-of-bounds and surrogates
7475
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {

trunk/src/libstd/io/mod.rs

Lines changed: 41 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/*! Synchronous I/O
11+
// FIXME: cover these topics:
12+
// path, reader, writer, stream, raii (close not needed),
13+
// stdio, print!, println!, file access, process spawning,
14+
// error handling
1215

13-
This module defines the Rust interface for synchronous I/O.
14-
It models byte-oriented input and output with the Reader and Writer traits.
15-
Types that implement both `Reader` and `Writer` are called 'streams',
16-
and automatically implement the `Stream` trait.
17-
Implementations are provided for common I/O streams like
18-
file, TCP, UDP, Unix domain sockets.
19-
Readers and Writers may be composed to add capabilities like string
20-
parsing, encoding, and compression.
16+
17+
/*! I/O, including files, networking, timers, and processes
18+
19+
`std::io` provides Rust's basic I/O types,
20+
for reading and writing to files, TCP, UDP,
21+
and other types of sockets and pipes,
22+
manipulating the file system, spawning processes and signal handling.
2123
2224
# Examples
2325
@@ -77,9 +79,7 @@ Some examples of obvious things you might want to do
7779
let lines: ~[~str] = file.lines().collect();
7880
```
7981
80-
* Make a simple HTTP request
81-
FIXME This needs more improvement: TcpStream constructor taking &str,
82-
`write_str` and `write_line` methods.
82+
* Make a simple TCP client connection and request
8383
8484
```rust,should_fail
8585
# #[allow(unused_must_use)];
@@ -92,72 +92,35 @@ Some examples of obvious things you might want to do
9292
let response = socket.read_to_end();
9393
```
9494
95-
* Connect based on URL? Requires thinking about where the URL type lives
96-
and how to make protocol handlers extensible, e.g. the "tcp" protocol
97-
yields a `TcpStream`.
98-
FIXME this is not implemented now.
95+
* Make a simple TCP server
9996
10097
```rust
101-
// connect("tcp://localhost:8080");
98+
# fn main() { }
99+
# fn foo() {
100+
# #[allow(unused_must_use, dead_code)];
101+
use std::io::net::tcp::TcpListener;
102+
use std::io::net::ip::{Ipv4Addr, SocketAddr};
103+
use std::io::{Acceptor, Listener};
104+
105+
let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 80 };
106+
let listener = TcpListener::bind(addr);
107+
108+
// bind the listener to the specified address
109+
let mut acceptor = listener.listen();
110+
111+
// accept connections and process them
112+
# fn handle_client<T>(_: T) {}
113+
for stream in acceptor.incoming() {
114+
spawn(proc() {
115+
handle_client(stream);
116+
});
117+
}
118+
119+
// close the socket server
120+
drop(acceptor);
121+
# }
102122
```
103123
104-
# Terms
105-
106-
* Reader - An I/O source, reads bytes into a buffer
107-
* Writer - An I/O sink, writes bytes from a buffer
108-
* Stream - Typical I/O sources like files and sockets are both Readers and Writers,
109-
and are collectively referred to a `streams`.
110-
such as encoding or decoding
111-
112-
# Blocking and synchrony
113-
114-
When discussing I/O you often hear the terms 'synchronous' and
115-
'asynchronous', along with 'blocking' and 'non-blocking' compared and
116-
contrasted. A synchronous I/O interface performs each I/O operation to
117-
completion before proceeding to the next. Synchronous interfaces are
118-
usually used in imperative style as a sequence of commands. An
119-
asynchronous interface allows multiple I/O requests to be issued
120-
simultaneously, without waiting for each to complete before proceeding
121-
to the next.
122-
123-
Asynchronous interfaces are used to achieve 'non-blocking' I/O. In
124-
traditional single-threaded systems, performing a synchronous I/O
125-
operation means that the program stops all activity (it 'blocks')
126-
until the I/O is complete. Blocking is bad for performance when
127-
there are other computations that could be done.
128-
129-
Asynchronous interfaces are most often associated with the callback
130-
(continuation-passing) style popularised by node.js. Such systems rely
131-
on all computations being run inside an event loop which maintains a
132-
list of all pending I/O events; when one completes the registered
133-
callback is run and the code that made the I/O request continues.
134-
Such interfaces achieve non-blocking at the expense of being more
135-
difficult to reason about.
136-
137-
Rust's I/O interface is synchronous - easy to read - and non-blocking by default.
138-
139-
Remember that Rust tasks are 'green threads', lightweight threads that
140-
are multiplexed onto a single operating system thread. If that system
141-
thread blocks then no other task may proceed. Rust tasks are
142-
relatively cheap to create, so as long as other tasks are free to
143-
execute then non-blocking code may be written by simply creating a new
144-
task.
145-
146-
When discussing blocking in regards to Rust's I/O model, we are
147-
concerned with whether performing I/O blocks other Rust tasks from
148-
proceeding. In other words, when a task calls `read`, it must then
149-
wait (or 'sleep', or 'block') until the call to `read` is complete.
150-
During this time, other tasks may or may not be executed, depending on
151-
how `read` is implemented.
152-
153-
154-
Rust's default I/O implementation is non-blocking; by cooperating
155-
directly with the task scheduler it arranges to never block progress
156-
of *other* tasks. Under the hood, Rust uses asynchronous I/O via a
157-
per-scheduler (and hence per-thread) event loop. Synchronous I/O
158-
requests are implemented by descheduling the running task and
159-
performing an asynchronous request; the task is only resumed once the
160-
asynchronous request completes.
161124
162125
# Error Handling
163126
@@ -170,10 +133,11 @@ Rust's I/O employs a combination of techniques to reduce boilerplate
170133
while still providing feedback about errors. The basic strategy:
171134
172135
* All I/O operations return `IoResult<T>` which is equivalent to
173-
`Result<T, IoError>`. The core `Result` type is defined in the `std::result`
136+
`Result<T, IoError>`. The `Result` type is defined in the `std::result`
174137
module.
175138
* If the `Result` type goes unused, then the compiler will by default emit a
176-
warning about the unused result.
139+
warning about the unused result. This is because `Result` has the
140+
`#[must_use]` attribute.
177141
* Common traits are implemented for `IoResult`, e.g.
178142
`impl<R: Reader> Reader for IoResult<R>`, so that error values do not have
179143
to be 'unwrapped' before use.
@@ -192,7 +156,7 @@ If you wanted to handle the error though you might write:
192156
use std::io::File;
193157
194158
match File::create(&Path::new("diary.txt")).write(bytes!("Met a girl.\n")) {
195-
Ok(()) => { /* succeeded */ }
159+
Ok(()) => (), // succeeded
196160
Err(e) => println!("failed to write to my diary: {}", e),
197161
}
198162
@@ -208,55 +172,6 @@ need to inspect or unwrap the `IoResult<File>` and we simply call `write_line`
208172
on it. If `new` returned an `Err(..)` then the followup call to `write_line`
209173
will also return an error.
210174
211-
# Issues with i/o scheduler affinity, work stealing, task pinning
212-
213-
# Resource management
214-
215-
* `close` vs. RAII
216-
217-
# Paths, URLs and overloaded constructors
218-
219-
220-
221-
# Scope
222-
223-
In scope for core
224-
225-
* Url?
226-
227-
Some I/O things don't belong in core
228-
229-
- url
230-
- net - `fn connect`
231-
- http
232-
- flate
233-
234-
Out of scope
235-
236-
* Async I/O. We'll probably want it eventually
237-
238-
239-
# FIXME Questions and issues
240-
241-
* Should default constructors take `Path` or `&str`? `Path` makes simple cases verbose.
242-
Overloading would be nice.
243-
* Add overloading for Path and &str and Url &str
244-
* stdin/err/out
245-
* print, println, etc.
246-
* fsync
247-
* relationship with filesystem querying, Directory, File types etc.
248-
* Rename Reader/Writer to ByteReader/Writer, make Reader/Writer generic?
249-
* Can Port and Chan be implementations of a generic Reader<T>/Writer<T>?
250-
* Trait for things that are both readers and writers, Stream?
251-
* How to handle newline conversion
252-
* String conversion
253-
* open vs. connect for generic stream opening
254-
* Do we need `close` at all? dtors might be good enough
255-
* How does I/O relate to the Iterator trait?
256-
* std::base64 filters
257-
* Using conditions is a big unknown since we don't have much experience with them
258-
* Too many uses of OtherIoError
259-
260175
*/
261176

262177
#[allow(missing_doc)];

trunk/src/libstd/str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ static UTF8_CHAR_WIDTH: [u8, ..256] = [
10611061
];
10621062

10631063
/// Given a first byte, determine how many bytes are in this UTF-8 character
1064+
#[inline]
10641065
pub fn utf8_char_width(b: u8) -> uint {
10651066
return UTF8_CHAR_WIDTH[b] as uint;
10661067
}

trunk/src/libsyntax/ast.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ impl Eq for Ident {
5858
// if it should be non-hygienic (most things are), just compare the
5959
// 'name' fields of the idents. Or, even better, replace the idents
6060
// with Name's.
61-
fail!("not allowed to compare these idents: {:?}, {:?}.
62-
Probably related to issue \\#6993", self, other);
61+
//
62+
// On the other hand, if the comparison does need to be hygienic,
63+
// one example and its non-hygienic counterpart would be:
64+
// syntax::parse::token::mtwt_token_eq
65+
// syntax::ext::tt::macro_parser::token_name_eq
66+
fail!("not allowed to compare these idents: {:?}, {:?}. \
67+
Probably related to issue \\#6993", self, other);
6368
}
6469
}
6570
fn ne(&self, other: &Ident) -> bool {
@@ -564,8 +569,8 @@ pub enum Expr_ {
564569
ExprPath(Path),
565570

566571
ExprAddrOf(Mutability, @Expr),
567-
ExprBreak(Option<Name>),
568-
ExprAgain(Option<Name>),
572+
ExprBreak(Option<Ident>),
573+
ExprAgain(Option<Ident>),
569574
ExprRet(Option<@Expr>),
570575

571576
/// Gets the log level for the enclosing module

0 commit comments

Comments
 (0)