Skip to content

Commit b4a5e1c

Browse files
yeahwhatevermarijnh
authored andcommitted
---
yaml --- r: 13777 b: refs/heads/try c: 3b9a9fc h: refs/heads/master i: 13775: 575e160 v: v3
1 parent 52f497b commit b4a5e1c

36 files changed

+455
-225
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: eaa4befd6df4a26be0776d6aab0a7925232d76a7
5+
refs/heads/try: 3b9a9fce49d4c0ad5247ca04f2d2cb89ff8c001a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ destructors. Resources might go away in the future.
13461346
Rust datatypes are not trivial to copy (the way, for example,
13471347
JavaScript values can be copied by simply taking one or two machine
13481348
words and plunking them somewhere else). Shared boxes require
1349-
reference count updates, big records, tags, or unique pointers require
1349+
reference count updates, big records, enums, or unique pointers require
13501350
an arbitrary amount of data to be copied (plus updating the reference
13511351
counts of shared boxes hanging off them).
13521352

@@ -1459,7 +1459,7 @@ alt my_rec {
14591459

14601460
The fact that arguments are conceptually passed by safe reference does
14611461
not mean all arguments are passed by pointer. Composite types like
1462-
records and tags *are* passed by pointer, but single-word values, like
1462+
records and enums *are* passed by pointer, but single-word values, like
14631463
integers and pointers, are simply passed by value. Most of the time,
14641464
the programmer does not have to worry about this, as the compiler will
14651465
simply pick the most efficient passing style. There is one exception,

branches/try/src/cargo/cargo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ fn load_link(mis: [@ast::meta_item]) -> (option::t<str>,
100100

101101
fn load_pkg(filename: str) -> option::t<pkg> {
102102
let cm = codemap::new_codemap();
103+
let handler = diagnostic::mk_handler(none);
103104
let sess = @{
104105
cm: cm,
105106
mutable next_id: 1,
106-
diagnostic: diagnostic::mk_handler(cm, none),
107+
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
107108
mutable chpos: 0u,
108109
mutable byte_pos: 0u
109110
};

branches/try/src/comp/driver/diagnostic.rs

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,83 @@ import codemap::span;
55

66
export emitter, emit;
77
export level, fatal, error, warning, note;
8-
export handler, mk_handler;
8+
export span_handler, handler, mk_span_handler, mk_handler;
9+
export codemap_span_handler, codemap_handler;
910
export ice_msg;
1011

1112
type emitter = fn@(cmsp: option<(codemap::codemap, span)>,
1213
msg: str, lvl: level);
1314

1415

15-
iface handler {
16+
iface span_handler {
1617
fn span_fatal(sp: span, msg: str) -> !;
17-
fn fatal(msg: str) -> !;
1818
fn span_err(sp: span, msg: str);
19+
fn span_warn(sp: span, msg: str);
20+
fn span_note(sp: span, msg: str);
21+
fn span_bug(sp: span, msg: str) -> !;
22+
fn span_unimpl(sp: span, msg: str) -> !;
23+
fn handler() -> handler;
24+
}
25+
26+
iface handler {
27+
fn fatal(msg: str) -> !;
1928
fn err(msg: str);
29+
fn bump_err_count();
2030
fn has_errors() -> bool;
2131
fn abort_if_errors();
22-
fn span_warn(sp: span, msg: str);
2332
fn warn(msg: str);
24-
fn span_note(sp: span, msg: str);
2533
fn note(msg: str);
26-
fn span_bug(sp: span, msg: str) -> !;
2734
fn bug(msg: str) -> !;
28-
fn span_unimpl(sp: span, msg: str) -> !;
2935
fn unimpl(msg: str) -> !;
36+
fn emit(cmsp: option<(codemap::codemap, span)>, msg: str, lvl: level);
3037
}
3138

32-
type codemap_t = @{
33-
cm: codemap::codemap,
39+
type handler_t = @{
3440
mutable err_count: uint,
35-
emit: emitter
41+
_emit: emitter
42+
};
43+
44+
type codemap_t = @{
45+
handler: handler,
46+
cm: codemap::codemap
3647
};
3748

38-
impl codemap_handler of handler for codemap_t {
49+
impl codemap_span_handler of span_handler for codemap_t {
3950
fn span_fatal(sp: span, msg: str) -> ! {
40-
self.emit(some((self.cm, sp)), msg, fatal);
51+
self.handler.emit(some((self.cm, sp)), msg, fatal);
4152
fail;
4253
}
54+
fn span_err(sp: span, msg: str) {
55+
self.handler.emit(some((self.cm, sp)), msg, error);
56+
self.handler.bump_err_count();
57+
}
58+
fn span_warn(sp: span, msg: str) {
59+
self.handler.emit(some((self.cm, sp)), msg, warning);
60+
}
61+
fn span_note(sp: span, msg: str) {
62+
self.handler.emit(some((self.cm, sp)), msg, note);
63+
}
64+
fn span_bug(sp: span, msg: str) -> ! {
65+
self.span_fatal(sp, ice_msg(msg));
66+
}
67+
fn span_unimpl(sp: span, msg: str) -> ! {
68+
self.span_bug(sp, "unimplemented " + msg);
69+
}
70+
fn handler() -> handler {
71+
self.handler
72+
}
73+
}
74+
75+
impl codemap_handler of handler for handler_t {
4376
fn fatal(msg: str) -> ! {
44-
self.emit(none, msg, fatal);
77+
self._emit(none, msg, fatal);
4578
fail;
4679
}
47-
fn span_err(sp: span, msg: str) {
48-
self.emit(some((self.cm, sp)), msg, error);
49-
self.err_count += 1u;
50-
}
5180
fn err(msg: str) {
52-
self.emit(none, msg, error);
81+
self._emit(none, msg, error);
82+
self.bump_err_count();
83+
}
84+
fn bump_err_count() {
5385
self.err_count += 1u;
5486
}
5587
fn has_errors() -> bool { self.err_count > 0u }
@@ -58,36 +90,30 @@ impl codemap_handler of handler for codemap_t {
5890
self.fatal("aborting due to previous errors");
5991
}
6092
}
61-
fn span_warn(sp: span, msg: str) {
62-
self.emit(some((self.cm, sp)), msg, warning);
63-
}
6493
fn warn(msg: str) {
65-
self.emit(none, msg, warning);
66-
}
67-
fn span_note(sp: span, msg: str) {
68-
self.emit(some((self.cm, sp)), msg, note);
94+
self._emit(none, msg, warning);
6995
}
7096
fn note(msg: str) {
71-
self.emit(none, msg, note);
72-
}
73-
fn span_bug(sp: span, msg: str) -> ! {
74-
self.span_fatal(sp, ice_msg(msg));
97+
self._emit(none, msg, note);
7598
}
7699
fn bug(msg: str) -> ! {
77100
self.fatal(ice_msg(msg));
78101
}
79-
fn span_unimpl(sp: span, msg: str) -> ! {
80-
self.span_bug(sp, "unimplemented " + msg);
81-
}
82102
fn unimpl(msg: str) -> ! { self.bug("unimplemented " + msg); }
103+
fn emit(cmsp: option<(codemap::codemap, span)>, msg: str, lvl: level) {
104+
self._emit(cmsp, msg, lvl);
105+
}
83106
}
84107

85108
fn ice_msg(msg: str) -> str {
86109
#fmt["internal compiler error %s", msg]
87110
}
88111

89-
fn mk_handler(cm: codemap::codemap,
90-
emitter: option<emitter>) -> handler {
112+
fn mk_span_handler(handler: handler, cm: codemap::codemap) -> span_handler {
113+
@{ handler: handler, cm: cm } as span_handler
114+
}
115+
116+
fn mk_handler(emitter: option<emitter>) -> handler {
91117

92118
let emit = alt emitter {
93119
some(e) { e }
@@ -101,9 +127,8 @@ fn mk_handler(cm: codemap::codemap,
101127
};
102128

103129
@{
104-
cm: cm,
105130
mutable err_count: 0u,
106-
emit: emit
131+
_emit: emit
107132
} as handler
108133
}
109134

branches/try/src/comp/driver/driver.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
299299
}
300300
ppm_expanded | ppm_normal {}
301301
}
302-
pprust::print_crate(sess.codemap, sess.diagnostic, crate, input,
302+
pprust::print_crate(sess.codemap, sess.span_diagnostic, crate, input,
303303
io::string_reader(src), io::stdout(), ann);
304304
}
305305

@@ -481,21 +481,23 @@ fn build_session(sopts: @session::options, input: str,
481481
sopts.addl_lib_search_paths);
482482
let codemap = codemap::new_codemap();
483483
let diagnostic_handler =
484-
diagnostic::mk_handler(codemap, some(demitter));
484+
diagnostic::mk_handler(some(demitter));
485+
let span_diagnostic_handler =
486+
diagnostic::mk_span_handler(diagnostic_handler, codemap);
485487
@{targ_cfg: target_cfg,
486488
opts: sopts,
487489
cstore: cstore,
488490
parse_sess: @{
489491
cm: codemap,
490492
mutable next_id: 1,
491-
diagnostic: diagnostic_handler,
493+
span_diagnostic: span_diagnostic_handler,
492494
mutable chpos: 0u,
493495
mutable byte_pos: 0u
494496
},
495497
codemap: codemap,
496498
// For a library crate, this is always none
497499
mutable main_fn: none,
498-
diagnostic: diagnostic_handler,
500+
span_diagnostic: span_diagnostic_handler,
499501
filesearch: filesearch,
500502
mutable building_library: false,
501503
working_dir: fs::dirname(input)}

branches/try/src/comp/driver/session.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,53 +60,53 @@ type session = @{targ_cfg: @config,
6060
codemap: codemap::codemap,
6161
// For a library crate, this is always none
6262
mutable main_fn: option::t<node_id>,
63-
diagnostic: diagnostic::handler,
63+
span_diagnostic: diagnostic::span_handler,
6464
filesearch: filesearch::filesearch,
6565
mutable building_library: bool,
6666
working_dir: str};
6767

6868
impl session for session {
6969
fn span_fatal(sp: span, msg: str) -> ! {
70-
self.diagnostic.span_fatal(sp, msg)
70+
self.span_diagnostic.span_fatal(sp, msg)
7171
}
7272
fn fatal(msg: str) -> ! {
73-
self.diagnostic.fatal(msg)
73+
self.span_diagnostic.handler().fatal(msg)
7474
}
7575
fn span_err(sp: span, msg: str) {
76-
self.diagnostic.span_err(sp, msg)
76+
self.span_diagnostic.span_err(sp, msg)
7777
}
7878
fn err(msg: str) {
79-
self.diagnostic.err(msg)
79+
self.span_diagnostic.handler().err(msg)
8080
}
8181
fn has_errors() -> bool {
82-
self.diagnostic.has_errors()
82+
self.span_diagnostic.handler().has_errors()
8383
}
8484
fn abort_if_errors() {
85-
self.diagnostic.abort_if_errors()
85+
self.span_diagnostic.handler().abort_if_errors()
8686
}
8787
fn span_warn(sp: span, msg: str) {
88-
self.diagnostic.span_warn(sp, msg)
88+
self.span_diagnostic.span_warn(sp, msg)
8989
}
9090
fn warn(msg: str) {
91-
self.diagnostic.warn(msg)
91+
self.span_diagnostic.handler().warn(msg)
9292
}
9393
fn span_note(sp: span, msg: str) {
94-
self.diagnostic.span_note(sp, msg)
94+
self.span_diagnostic.span_note(sp, msg)
9595
}
9696
fn note(msg: str) {
97-
self.diagnostic.note(msg)
97+
self.span_diagnostic.handler().note(msg)
9898
}
9999
fn span_bug(sp: span, msg: str) -> ! {
100-
self.diagnostic.span_bug(sp, msg)
100+
self.span_diagnostic.span_bug(sp, msg)
101101
}
102102
fn bug(msg: str) -> ! {
103-
self.diagnostic.bug(msg)
103+
self.span_diagnostic.handler().bug(msg)
104104
}
105105
fn span_unimpl(sp: span, msg: str) -> ! {
106-
self.diagnostic.span_unimpl(sp, msg)
106+
self.span_diagnostic.span_unimpl(sp, msg)
107107
}
108108
fn unimpl(msg: str) -> ! {
109-
self.diagnostic.unimpl(msg)
109+
self.span_diagnostic.handler().unimpl(msg)
110110
}
111111
fn next_node_id() -> ast::node_id {
112112
ret syntax::parse::parser::next_node_id(self.parse_sess);

branches/try/src/comp/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn parse_ident_(st: @pstate, is_last: fn@(char) -> bool) ->
3939
ast::ident {
4040
let rslt = "";
4141
while !is_last(peek(st) as char) {
42-
rslt += str::from_byte(next(st));
42+
rslt += str::unsafe_from_byte(next(st));
4343
}
4444
ret rslt;
4545
}
@@ -226,7 +226,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
226226
while peek(st) as char != ']' {
227227
let name = "";
228228
while peek(st) as char != '=' {
229-
name += str::from_byte(next(st));
229+
name += str::unsafe_from_byte(next(st));
230230
}
231231
st.pos = st.pos + 1u;
232232
fields += [{ident: name, mt: parse_mt(st, conv)}];

branches/try/src/comp/middle/trans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn sanitize(s: str) -> str {
274274
c != ' ' as u8 && c != '\t' as u8 && c != ';' as u8
275275
{
276276
let v = [c];
277-
result += str::from_bytes(v);
277+
result += str::unsafe_from_bytes(v);
278278
}
279279
}
280280
}

branches/try/src/comp/syntax/parse/lexer.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import driver::diagnostic;
1010

1111
type reader = @{
1212
cm: codemap::codemap,
13-
diagnostic: diagnostic::handler,
13+
span_diagnostic: diagnostic::span_handler,
1414
src: str,
1515
len: uint,
1616
mutable col: uint,
@@ -49,17 +49,18 @@ impl reader for reader {
4949
} else { self.curr = -1 as char; }
5050
}
5151
fn fatal(m: str) -> ! {
52-
self.diagnostic.span_fatal(
52+
self.span_diagnostic.span_fatal(
5353
ast_util::mk_sp(self.chpos, self.chpos),
5454
m)
5555
}
5656
}
5757

5858
fn new_reader(cm: codemap::codemap,
59-
diagnostic: diagnostic::handler,
59+
span_diagnostic: diagnostic::span_handler,
6060
src: str, filemap: codemap::filemap,
6161
itr: @interner::interner<str>) -> reader {
62-
let r = @{cm: cm, diagnostic: diagnostic,
62+
let r = @{cm: cm,
63+
span_diagnostic: span_diagnostic,
6364
src: src, len: str::byte_len(src),
6465
mutable col: 0u, mutable pos: 0u, mutable curr: -1 as char,
6566
mutable chpos: filemap.start_pos.ch, mutable strs: [],
@@ -667,13 +668,13 @@ fn is_lit(t: token::token) -> bool {
667668
type lit = {lit: str, pos: uint};
668669

669670
fn gather_comments_and_literals(cm: codemap::codemap,
670-
diagnostic: diagnostic::handler,
671+
span_diagnostic: diagnostic::span_handler,
671672
path: str,
672673
srdr: io::reader) ->
673674
{cmnts: [cmnt], lits: [lit]} {
674675
let src = str::unsafe_from_bytes(srdr.read_whole_stream());
675676
let itr = @interner::mk::<str>(str::hash, str::eq);
676-
let rdr = new_reader(cm, diagnostic, src,
677+
let rdr = new_reader(cm, span_diagnostic, src,
677678
codemap::new_filemap(path, 0u, 0u), itr);
678679
let comments: [cmnt] = [];
679680
let literals: [lit] = [];

0 commit comments

Comments
 (0)