Skip to content

Commit a2e2e78

Browse files
committed
Merge remote branch 'origin/master' into HEAD
Conflicts: src/comp/middle/trans.rs
2 parents fbbc1a7 + 41b7af9 commit a2e2e78

27 files changed

+3363
-124
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ config.mk
5555
src/.DS_Store
5656
/stage0/
5757
/dl/
58+
/stage1/
59+
*.bz2

src/comp/driver/rustc.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import middle::trans;
99
import middle::resolve;
1010
import middle::ty;
1111
import middle::typeck;
12-
import middle::typestate_check;
12+
import middle::tstate::ck;
1313
import back::link;
1414
import lib::llvm;
1515
import util::common;
@@ -105,7 +105,8 @@ fn compile_input(session::session sess,
105105

106106
if (sess.get_opts().run_typestate) {
107107
crate = time(time_passes, "typestate checking",
108-
bind typestate_check::check_crate(crate, def_map));
108+
bind middle::tstate::ck::check_crate(node_type_table,
109+
ty_cx, crate));
109110
}
110111

111112
auto llmod = time[llvm::ModuleRef](time_passes, "translation",
@@ -165,26 +166,31 @@ options:
165166
}
166167

167168
fn get_os(str triple) -> session::os {
168-
if (_str::find(triple, "win32") > 0 ||
169-
_str::find(triple, "mingw32") > 0 ) {
169+
if (_str::find(triple, "win32") >= 0 ||
170+
_str::find(triple, "mingw32") >= 0 ) {
170171
ret session::os_win32;
171-
} else if (_str::find(triple, "darwin") > 0) { ret session::os_macos; }
172-
else if (_str::find(triple, "linux") > 0) { ret session::os_linux; }
172+
} else if (_str::find(triple, "darwin") >= 0) { ret session::os_macos; }
173+
else if (_str::find(triple, "linux") >= 0) { ret session::os_linux; }
174+
else { log_err "Unknown operating system!"; fail; }
173175
}
174176

175177
fn get_arch(str triple) -> session::arch {
176-
if (_str::find(triple, "i386") > 0 ||
177-
_str::find(triple, "i486") > 0 ||
178-
_str::find(triple, "i586") > 0 ||
179-
_str::find(triple, "i686") > 0 ||
180-
_str::find(triple, "i786") > 0 ) {
178+
if (_str::find(triple, "i386") >= 0 ||
179+
_str::find(triple, "i486") >= 0 ||
180+
_str::find(triple, "i586") >= 0 ||
181+
_str::find(triple, "i686") >= 0 ||
182+
_str::find(triple, "i786") >= 0 ) {
181183
ret session::arch_x86;
182-
} else if (_str::find(triple, "x86_64") > 0) {
184+
} else if (_str::find(triple, "x86_64") >= 0) {
183185
ret session::arch_x64;
184-
} else if (_str::find(triple, "arm") > 0 ||
185-
_str::find(triple, "xscale") > 0 ) {
186+
} else if (_str::find(triple, "arm") >= 0 ||
187+
_str::find(triple, "xscale") >= 0 ) {
186188
ret session::arch_arm;
187189
}
190+
else {
191+
log_err ("Unknown architecture! " + triple);
192+
fail;
193+
}
188194
}
189195

190196
fn get_default_sysroot(str binary) -> str {

src/comp/front/ast.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import std::map::hashmap;
32
import std::option;
43
import std::_str;
@@ -7,7 +6,7 @@ import util::common::span;
76
import util::common::spanned;
87
import util::common::ty_mach;
98
import util::common::filename;
10-
import util::typestate_ann::ts_ann;
9+
import middle::tstate::ann::ts_ann;
1110

1211
type ident = str;
1312

@@ -323,6 +322,12 @@ type ty_method = rec(proto proto, ident ident,
323322
type ty = spanned[ty_];
324323
tag ty_ {
325324
ty_nil;
325+
ty_bot; /* return type of ! functions and type of
326+
ret/fail/break/cont. there is no syntax
327+
for this type. */
328+
/* bot represents the value of functions that don't return a value
329+
locally to their context. in contrast, things like log that do
330+
return, but don't return a meaningful value, have result type nil. */
326331
ty_bool;
327332
ty_int;
328333
ty_uint;
@@ -354,12 +359,19 @@ type constr = spanned[constr_];
354359
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
355360
type fn_decl = rec(vec[arg] inputs,
356361
@ty output,
357-
purity purity);
362+
purity purity,
363+
controlflow cf);
358364
tag purity {
359365
pure_fn; // declared with "pred"
360366
impure_fn; // declared with "fn"
361367
}
362368

369+
tag controlflow {
370+
noreturn; // functions with return type _|_ that always
371+
// raise an error or exit (i.e. never return to the caller)
372+
return; // everything else
373+
}
374+
363375
type _fn = rec(fn_decl decl,
364376
proto proto,
365377
block body);

src/comp/front/parser.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ tag file_type {
2323
SOURCE_FILE;
2424
}
2525

26+
tag ty_or_bang {
27+
a_ty(@ast::ty);
28+
a_bang;
29+
}
30+
2631
state type parser =
2732
state obj {
2833
fn peek() -> token::token;
@@ -448,6 +453,13 @@ fn parse_ty_constrs(@ast::ty t, parser p) -> @ast::ty {
448453
ret t;
449454
}
450455

456+
fn parse_ty_or_bang(parser p) -> ty_or_bang {
457+
alt (p.peek()) {
458+
case (token::NOT) { p.bump(); ret a_bang; }
459+
case (_) { ret a_ty(parse_ty(p)); }
460+
}
461+
}
462+
451463
fn parse_ty(parser p) -> @ast::ty {
452464
auto lo = p.get_lo_pos();
453465
auto hi = lo;
@@ -1713,20 +1725,31 @@ fn parse_fn_decl(parser p, ast::purity purity) -> ast::fn_decl {
17131725
some(token::COMMA),
17141726
pf, p);
17151727

1716-
let @ast::ty output;
1728+
let ty_or_bang res;
17171729

17181730
// FIXME: dropping constrs on the floor at the moment.
17191731
// pick them up when they're used by typestate pass.
17201732
parse_constrs(p);
17211733

17221734
if (p.peek() == token::RARROW) {
17231735
p.bump();
1724-
output = parse_ty(p);
1736+
res = parse_ty_or_bang(p);
17251737
} else {
1726-
output = @spanned(inputs.span.lo, inputs.span.hi, ast::ty_nil);
1738+
res = a_ty(@spanned(inputs.span.lo, inputs.span.hi, ast::ty_nil));
1739+
}
1740+
1741+
alt (res) {
1742+
case (a_ty(?t)) {
1743+
ret rec(inputs=inputs.node, output=t,
1744+
purity=purity, cf=ast::return);
1745+
}
1746+
case (a_bang) {
1747+
ret rec(inputs=inputs.node,
1748+
output=@spanned(p.get_lo_pos(),
1749+
p.get_hi_pos(), ast::ty_bot),
1750+
purity=purity, cf=ast::noreturn);
1751+
}
17271752
}
1728-
// FIXME
1729-
ret rec(inputs=inputs.node, output=output, purity=purity);
17301753
}
17311754

17321755
fn parse_fn(parser p, ast::proto proto, ast::purity purity) -> ast::_fn {
@@ -1778,11 +1801,12 @@ fn parse_dtor(parser p) -> @ast::method {
17781801
let vec[ast::arg] inputs = [];
17791802
let @ast::ty output = @spanned(lo, lo, ast::ty_nil);
17801803
let ast::fn_decl d = rec(inputs=inputs,
1781-
output=output,
1782-
purity=ast::impure_fn);
1804+
output=output,
1805+
purity=ast::impure_fn,
1806+
cf=ast::return);
17831807
let ast::_fn f = rec(decl = d,
1784-
proto = ast::proto_fn,
1785-
body = b);
1808+
proto = ast::proto_fn,
1809+
body = b);
17861810
let ast::method_ m = rec(ident="drop",
17871811
meth=f,
17881812
id=p.next_def_id(),

src/comp/middle/fold.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import util::common::new_str_hash;
77
import util::common::spanned;
88
import util::common::span;
99
import util::common::ty_mach;
10-
import util::typestate_ann::ts_ann;
10+
import middle::tstate::ann::ts_ann;
1111

1212
import front::ast;
1313
import front::ast::fn_decl;
1414
import front::ast::ident;
1515
import front::ast::path;
1616
import front::ast::mutability;
17+
import front::ast::controlflow;
1718
import front::ast::ty;
1819
import front::ast::expr;
1920
import front::ast::stmt;
@@ -44,6 +45,7 @@ type ast_fold[ENV] =
4445

4546
// Type folds.
4647
(fn(&ENV e, &span sp) -> @ty) fold_ty_nil,
48+
(fn(&ENV e, &span sp) -> @ty) fold_ty_bot,
4749
(fn(&ENV e, &span sp) -> @ty) fold_ty_bool,
4850
(fn(&ENV e, &span sp) -> @ty) fold_ty_int,
4951
(fn(&ENV e, &span sp) -> @ty) fold_ty_uint,
@@ -314,7 +316,7 @@ type ast_fold[ENV] =
314316
(fn(&ENV e,
315317
&vec[arg] inputs,
316318
&@ty output,
317-
&purity p) -> ast::fn_decl) fold_fn_decl,
319+
&purity p, &controlflow c) -> ast::fn_decl) fold_fn_decl,
318320

319321
(fn(&ENV e, &ast::_mod m) -> ast::_mod) fold_mod,
320322

@@ -375,6 +377,7 @@ fn fold_ty[ENV](&ENV env, &ast_fold[ENV] fld, &@ty t) -> @ty {
375377

376378
alt (t.node) {
377379
case (ast::ty_nil) { ret fld.fold_ty_nil(env_, t.span); }
380+
case (ast::ty_bot) { ret fld.fold_ty_bot(env_, t.span); }
378381
case (ast::ty_bool) { ret fld.fold_ty_bool(env_, t.span); }
379382
case (ast::ty_int) { ret fld.fold_ty_int(env_, t.span); }
380383
case (ast::ty_uint) { ret fld.fold_ty_uint(env_, t.span); }
@@ -926,7 +929,7 @@ fn fold_fn_decl[ENV](&ENV env, &ast_fold[ENV] fld,
926929
inputs += [fold_arg(env, fld, a)];
927930
}
928931
auto output = fold_ty[ENV](env, fld, decl.output);
929-
ret fld.fold_fn_decl(env, inputs, output, decl.purity);
932+
ret fld.fold_fn_decl(env, inputs, output, decl.purity, decl.cf);
930933
}
931934

932935
fn fold_fn[ENV](&ENV env, &ast_fold[ENV] fld, &ast::_fn f) -> ast::_fn {
@@ -1202,6 +1205,10 @@ fn identity_fold_ty_nil[ENV](&ENV env, &span sp) -> @ty {
12021205
ret @respan(sp, ast::ty_nil);
12031206
}
12041207

1208+
fn identity_fold_ty_bot[ENV](&ENV env, &span sp) -> @ty {
1209+
ret @respan(sp, ast::ty_bot);
1210+
}
1211+
12051212
fn identity_fold_ty_bool[ENV](&ENV env, &span sp) -> @ty {
12061213
ret @respan(sp, ast::ty_bool);
12071214
}
@@ -1622,8 +1629,8 @@ fn identity_fold_block[ENV](&ENV e, &span sp, &ast::block_ blk) -> block {
16221629
fn identity_fold_fn_decl[ENV](&ENV e,
16231630
&vec[arg] inputs,
16241631
&@ty output,
1625-
&purity p) -> ast::fn_decl {
1626-
ret rec(inputs=inputs, output=output, purity=p);
1632+
&purity p, &controlflow c) -> ast::fn_decl {
1633+
ret rec(inputs=inputs, output=output, purity=p, cf=c);
16271634
}
16281635

16291636
fn identity_fold_fn[ENV](&ENV e,
@@ -1722,6 +1729,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
17221729
fold_path = bind identity_fold_path[ENV](_,_,_),
17231730

17241731
fold_ty_nil = bind identity_fold_ty_nil[ENV](_,_),
1732+
fold_ty_bot = bind identity_fold_ty_bot[ENV](_,_),
17251733
fold_ty_bool = bind identity_fold_ty_bool[ENV](_,_),
17261734
fold_ty_int = bind identity_fold_ty_int[ENV](_,_),
17271735
fold_ty_uint = bind identity_fold_ty_uint[ENV](_,_),
@@ -1821,7 +1829,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
18211829
fold_ann = bind identity_fold_ann[ENV](_,_),
18221830

18231831
fold_fn = bind identity_fold_fn[ENV](_,_,_,_),
1824-
fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_),
1832+
fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_,_),
18251833
fold_mod = bind identity_fold_mod[ENV](_,_),
18261834
fold_native_mod = bind identity_fold_native_mod[ENV](_,_),
18271835
fold_crate = bind identity_fold_crate[ENV](_,_,_,_),

src/comp/middle/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ mod Encode {
228228
w.write_str(common::uistr(id));
229229
}
230230
case (ty::ty_type) {w.write_char('Y');}
231+
case (ty::ty_task) {w.write_char('a');}
231232

232233
// These two don't appear in crate metadata, but are here because
233234
// `hash_ty()` uses this function.

src/comp/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import util::common::new_int_hash;
1010
import util::common::new_uint_hash;
1111
import util::common::new_str_hash;
1212
import util::common::span;
13-
import util::typestate_ann::ts_ann;
13+
import middle::tstate::ann::ts_ann;
1414
import std::map::hashmap;
1515
import std::list::list;
1616
import std::list::nil;

0 commit comments

Comments
 (0)