Skip to content

Commit 2a894ca

Browse files
committed
Merge branch 'master' of github.com:graydon/rust
2 parents d9da439 + 25320da commit 2a894ca

File tree

17 files changed

+443
-137
lines changed

17 files changed

+443
-137
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ config.mk
5252
/test/
5353
/build/
5454
src/.DS_Store
55+
/stage0/

src/comp/front/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ tag mode {
215215
216216
type stmt = spanned[stmt_];
217217
tag stmt_ {
218-
stmt_decl(@decl);
219-
stmt_expr(@expr);
218+
stmt_decl(@decl, option.t[@ts_ann]);
219+
stmt_expr(@expr, option.t[@ts_ann]);
220220
// These only exist in crate-level blocks.
221221
stmt_crate_directive(@crate_directive);
222222
}
@@ -495,7 +495,7 @@ fn index_native_view_item(native_mod_index index, @view_item it) {
495495
496496
fn index_stmt(block_index index, @stmt s) {
497497
alt (s.node) {
498-
case (ast.stmt_decl(?d)) {
498+
case (ast.stmt_decl(?d,_)) {
499499
alt (d.node) {
500500
case (ast.decl_local(?loc)) {
501501
index.insert(loc.ident, ast.bie_local(loc));

src/comp/front/parser.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import util.common;
1111
import util.common.filename;
1212
import util.common.span;
1313
import util.common.new_str_hash;
14+
import util.typestate_ann.ts_ann;
1415

1516
tag restriction {
1617
UNRESTRICTED;
@@ -1555,13 +1556,13 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt {
15551556
case (token.LET) {
15561557
auto decl = parse_let(p);
15571558
auto hi = p.get_span();
1558-
ret @spanned(lo, hi, ast.stmt_decl(decl));
1559+
ret @spanned(lo, hi, ast.stmt_decl(decl, none[@ts_ann]));
15591560
}
15601561

15611562
case (token.AUTO) {
15621563
auto decl = parse_auto(p);
15631564
auto hi = p.get_span();
1564-
ret @spanned(lo, hi, ast.stmt_decl(decl));
1565+
ret @spanned(lo, hi, ast.stmt_decl(decl, none[@ts_ann]));
15651566
}
15661567

15671568
case (_) {
@@ -1570,13 +1571,13 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt {
15701571
auto i = parse_item(p);
15711572
auto hi = i.span;
15721573
auto decl = @spanned(lo, hi, ast.decl_item(i));
1573-
ret @spanned(lo, hi, ast.stmt_decl(decl));
1574+
ret @spanned(lo, hi, ast.stmt_decl(decl, none[@ts_ann]));
15741575

15751576
} else {
15761577
// Remainder are line-expr stmts.
15771578
auto e = parse_expr(p);
15781579
auto hi = p.get_span();
1579-
ret @spanned(lo, hi, ast.stmt_expr(e));
1580+
ret @spanned(lo, hi, ast.stmt_expr(e, none[@ts_ann]));
15801581
}
15811582
}
15821583
}
@@ -1613,21 +1614,21 @@ fn index_arm(@ast.pat pat) -> hashmap[ast.ident,ast.def_id] {
16131614

16141615
fn stmt_to_expr(@ast.stmt stmt) -> option.t[@ast.expr] {
16151616
alt (stmt.node) {
1616-
case (ast.stmt_expr(?e)) { ret some[@ast.expr](e); }
1617+
case (ast.stmt_expr(?e,_)) { ret some[@ast.expr](e); }
16171618
case (_) { /* fall through */ }
16181619
}
16191620
ret none[@ast.expr];
16201621
}
16211622

16221623
fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
16231624
alt (stmt.node) {
1624-
case (ast.stmt_decl(?d)) {
1625+
case (ast.stmt_decl(?d,_)) {
16251626
alt (d.node) {
16261627
case (ast.decl_local(_)) { ret true; }
16271628
case (ast.decl_item(_)) { ret false; }
16281629
}
16291630
}
1630-
case (ast.stmt_expr(?e)) {
1631+
case (ast.stmt_expr(?e,_)) {
16311632
alt (e.node) {
16321633
case (ast.expr_vec(_,_,_)) { ret true; }
16331634
case (ast.expr_tup(_,_)) { ret true; }

src/comp/lib/llvm.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,40 @@ native mod llvm = llvm_lib {
741741
/** Adds a verification pass. */
742742
fn LLVMAddVerifierPass(PassManagerRef PM);
743743

744+
fn LLVMAddGlobalOptimizerPass(PassManagerRef PM);
745+
fn LLVMAddIPSCCPPass(PassManagerRef PM);
746+
fn LLVMAddDeadArgEliminationPass(PassManagerRef PM);
747+
fn LLVMAddInstructionCombiningPass(PassManagerRef PM);
748+
fn LLVMAddCFGSimplificationPass(PassManagerRef PM);
749+
fn LLVMAddFunctionInliningPass(PassManagerRef PM);
750+
fn LLVMAddFunctionAttrsPass(PassManagerRef PM);
751+
fn LLVMAddScalarReplAggregatesPass(PassManagerRef PM);
752+
// fn LLVMAddScalarReplAggregatesPassSSA(PassManagerRef PM);
753+
fn LLVMAddJumpThreadingPass(PassManagerRef PM);
754+
fn LLVMAddConstantPropagationPass(PassManagerRef PM);
755+
fn LLVMAddReassociatePass(PassManagerRef PM);
756+
fn LLVMAddLoopRotatePass(PassManagerRef PM);
757+
fn LLVMAddLICMPass(PassManagerRef PM);
758+
fn LLVMAddLoopUnswitchPass(PassManagerRef PM);
759+
fn LLVMAddLoopDeletionPass(PassManagerRef PM);
760+
fn LLVMAddLoopUnrollPass(PassManagerRef PM);
761+
fn LLVMAddGVNPass(PassManagerRef PM);
762+
fn LLVMAddMemCpyOptPass(PassManagerRef PM);
763+
fn LLVMAddSCCPPass(PassManagerRef PM);
764+
fn LLVMAddDeadStoreEliminationPass(PassManagerRef PM);
765+
fn LLVMAddStripDeadPrototypesPass(PassManagerRef PM);
766+
fn LLVMAddDeadTypeEliminationPass(PassManagerRef PM);
767+
fn LLVMAddConstantMergePass(PassManagerRef PM);
768+
fn LLVMAddArgumentPromotionPass(PassManagerRef PM);
769+
fn LLVMAddTailCallEliminationPass(PassManagerRef PM);
770+
fn LLVMAddIndVarSimplifyPass(PassManagerRef PM);
771+
fn LLVMAddAggressiveDCEPass(PassManagerRef PM);
772+
fn LLVMAddGlobalDCEPass(PassManagerRef PM);
773+
// fn LLVMAddCorrelatedValuePropagationPass(PassManagerRef PM);
774+
fn LLVMAddPruneEHPass(PassManagerRef PM);
775+
fn LLVMAddSimplifyLibCallsPass(PassManagerRef PM);
776+
// fn LLVMAddLoopIdiomPass(PassManagerRef PM);
777+
744778
/** Destroys a memory buffer. */
745779
fn LLVMDisposeMemoryBuffer(MemoryBufferRef MemBuf);
746780

src/comp/middle/fold.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ 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;
1011

1112
import front.ast;
1213
import front.ast.fn_decl;
@@ -232,10 +233,12 @@ type ast_fold[ENV] =
232233

233234
// Stmt folds.
234235
(fn(&ENV e, &span sp,
235-
@decl decl) -> @stmt) fold_stmt_decl,
236+
@decl decl, option.t[@ts_ann] a)
237+
-> @stmt) fold_stmt_decl,
236238

237239
(fn(&ENV e, &span sp,
238-
@expr e) -> @stmt) fold_stmt_expr,
240+
@expr e, option.t[@ts_ann] a)
241+
-> @stmt) fold_stmt_expr,
239242

240243
// Item folds.
241244
(fn(&ENV e, &span sp, ident ident,
@@ -788,14 +791,14 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt {
788791
}
789792

790793
alt (s.node) {
791-
case (ast.stmt_decl(?d)) {
794+
case (ast.stmt_decl(?d, ?a)) {
792795
auto dd = fold_decl(env_, fld, d);
793-
ret fld.fold_stmt_decl(env_, s.span, dd);
796+
ret fld.fold_stmt_decl(env_, s.span, dd, a);
794797
}
795798

796-
case (ast.stmt_expr(?e)) {
799+
case (ast.stmt_expr(?e, ?a)) {
797800
auto ee = fold_expr(env_, fld, e);
798-
ret fld.fold_stmt_expr(env_, s.span, ee);
801+
ret fld.fold_stmt_expr(env_, s.span, ee, a);
799802
}
800803
}
801804
fail;
@@ -1386,12 +1389,14 @@ fn identity_fold_pat_tag[ENV](&ENV e, &span sp, path p, vec[@pat] args,
13861389

13871390
// Stmt identities.
13881391

1389-
fn identity_fold_stmt_decl[ENV](&ENV env, &span sp, @decl d) -> @stmt {
1390-
ret @respan(sp, ast.stmt_decl(d));
1392+
fn identity_fold_stmt_decl[ENV](&ENV env, &span sp, @decl d,
1393+
option.t[@ts_ann] a) -> @stmt {
1394+
ret @respan(sp, ast.stmt_decl(d, a));
13911395
}
13921396

1393-
fn identity_fold_stmt_expr[ENV](&ENV e, &span sp, @expr x) -> @stmt {
1394-
ret @respan(sp, ast.stmt_expr(x));
1397+
fn identity_fold_stmt_expr[ENV](&ENV e, &span sp, @expr x,
1398+
option.t[@ts_ann] a) -> @stmt {
1399+
ret @respan(sp, ast.stmt_expr(x, a));
13951400
}
13961401

13971402

@@ -1642,8 +1647,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
16421647
fold_pat_bind = bind identity_fold_pat_bind[ENV](_,_,_,_,_),
16431648
fold_pat_tag = bind identity_fold_pat_tag[ENV](_,_,_,_,_,_),
16441649

1645-
fold_stmt_decl = bind identity_fold_stmt_decl[ENV](_,_,_),
1646-
fold_stmt_expr = bind identity_fold_stmt_expr[ENV](_,_,_),
1650+
fold_stmt_decl = bind identity_fold_stmt_decl[ENV](_,_,_,_),
1651+
fold_stmt_expr = bind identity_fold_stmt_expr[ENV](_,_,_,_),
16471652

16481653
fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_),
16491654
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_),

src/comp/middle/resolve.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import front.creader;
66
import driver.session;
77
import util.common.new_def_hash;
88
import util.common.span;
9+
import util.typestate_ann.ts_ann;
910
import std.map.hashmap;
1011
import std.list.list;
1112
import std.list.nil;
@@ -348,7 +349,7 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns)
348349

349350
fn found_decl_stmt(@ast.stmt s, namespace ns) -> def_wrap {
350351
alt (s.node) {
351-
case (ast.stmt_decl(?d)) {
352+
case (ast.stmt_decl(?d,_)) {
352353
alt (d.node) {
353354
case (ast.decl_local(?loc)) {
354355
auto t = ast.def_local(loc.id);

src/comp/middle/trans.rs

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5208,11 +5208,11 @@ fn init_local(@block_ctxt cx, @ast.local local) -> result {
52085208
fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
52095209
auto bcx = cx;
52105210
alt (s.node) {
5211-
case (ast.stmt_expr(?e)) {
5211+
case (ast.stmt_expr(?e,_)) {
52125212
bcx = trans_expr(cx, e).bcx;
52135213
}
52145214

5215-
case (ast.stmt_decl(?d)) {
5215+
case (ast.stmt_decl(?d,_)) {
52165216
alt (d.node) {
52175217
case (ast.decl_local(?local)) {
52185218
bcx = init_local(bcx, local).bcx;
@@ -5302,7 +5302,7 @@ iter block_locals(&ast.block b) -> @ast.local {
53025302
// use the index here.
53035303
for (@ast.stmt s in b.node.stmts) {
53045304
alt (s.node) {
5305-
case (ast.stmt_decl(?d)) {
5305+
case (ast.stmt_decl(?d,_)) {
53065306
alt (d.node) {
53075307
case (ast.decl_local(?local)) {
53085308
put local;
@@ -6599,12 +6599,71 @@ fn trap(@block_ctxt bcx) {
65996599
bcx.build.Call(bcx.fcx.ccx.intrinsics.get("llvm.trap"), v);
66006600
}
66016601

6602-
fn check_module(ModuleRef llmod) {
6602+
fn run_passes(ModuleRef llmod, bool opt) {
66036603
auto pm = mk_pass_manager();
6604-
llvm.LLVMAddVerifierPass(pm.llpm);
6605-
llvm.LLVMRunPassManager(pm.llpm, llmod);
66066604

66076605
// TODO: run the linter here also, once there are llvm-c bindings for it.
6606+
6607+
// FIXME: This is mostly a copy of the bits of opt's -O2 that are
6608+
// available in the C api.
6609+
// FIXME2: We might want to add optmization levels like -O1, -O2, -Os, etc
6610+
// FIXME3: Should we expose and use the pass lists used by the opt tool?
6611+
if (opt) {
6612+
auto fpm = mk_pass_manager();
6613+
6614+
// createStandardFunctionPasses
6615+
llvm.LLVMAddCFGSimplificationPass(fpm.llpm);
6616+
llvm.LLVMAddScalarReplAggregatesPass(fpm.llpm);
6617+
//llvm.LLVMAddEarlyCSEPass(fpm.llpm);
6618+
6619+
llvm.LLVMRunPassManager(fpm.llpm, llmod);
6620+
6621+
// createStandardModulePasses
6622+
llvm.LLVMAddGlobalOptimizerPass(pm.llpm);
6623+
llvm.LLVMAddIPSCCPPass(pm.llpm);
6624+
llvm.LLVMAddDeadArgEliminationPass(pm.llpm);
6625+
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
6626+
llvm.LLVMAddCFGSimplificationPass(pm.llpm);
6627+
llvm.LLVMAddPruneEHPass(pm.llpm);
6628+
llvm.LLVMAddFunctionInliningPass(pm.llpm);
6629+
6630+
// FIXME: crashes!
6631+
// llvm.LLVMAddFunctionAttrsPass(pm.llpm);
6632+
6633+
// llvm.LLVMAddScalarReplAggregatesPassSSA(pm.llpm);
6634+
// llvm.LLVMAddEarlyCSEPass(pm.llpm);
6635+
llvm.LLVMAddSimplifyLibCallsPass(pm.llpm);
6636+
llvm.LLVMAddJumpThreadingPass(pm.llpm);
6637+
// llvm.LLVMAddCorrelatedValuePropagationPass(pm.llpm);
6638+
llvm.LLVMAddCFGSimplificationPass(pm.llpm);
6639+
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
6640+
llvm.LLVMAddTailCallEliminationPass(pm.llpm);
6641+
llvm.LLVMAddCFGSimplificationPass(pm.llpm);
6642+
llvm.LLVMAddReassociatePass(pm.llpm);
6643+
llvm.LLVMAddLoopRotatePass(pm.llpm);
6644+
llvm.LLVMAddLICMPass(pm.llpm);
6645+
llvm.LLVMAddLoopUnswitchPass(pm.llpm);
6646+
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
6647+
llvm.LLVMAddIndVarSimplifyPass(pm.llpm);
6648+
// llvm.LLVMAddLoopIdiomPass(pm.llpm);
6649+
llvm.LLVMAddLoopDeletionPass(pm.llpm);
6650+
llvm.LLVMAddLoopUnrollPass(pm.llpm);
6651+
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
6652+
llvm.LLVMAddGVNPass(pm.llpm);
6653+
llvm.LLVMAddMemCpyOptPass(pm.llpm);
6654+
llvm.LLVMAddSCCPPass(pm.llpm);
6655+
llvm.LLVMAddInstructionCombiningPass(pm.llpm);
6656+
llvm.LLVMAddJumpThreadingPass(pm.llpm);
6657+
// llvm.LLVMAddCorrelatedValuePropagationPass(pm.llpm);
6658+
llvm.LLVMAddDeadStoreEliminationPass(pm.llpm);
6659+
llvm.LLVMAddAggressiveDCEPass(pm.llpm);
6660+
llvm.LLVMAddCFGSimplificationPass(pm.llpm);
6661+
llvm.LLVMAddStripDeadPrototypesPass(pm.llpm);
6662+
llvm.LLVMAddDeadTypeEliminationPass(pm.llpm);
6663+
llvm.LLVMAddConstantMergePass(pm.llpm);
6664+
}
6665+
llvm.LLVMAddVerifierPass(pm.llpm);
6666+
llvm.LLVMRunPassManager(pm.llpm, llmod);
66086667
}
66096668

66106669
fn decl_no_op_type_glue(ModuleRef llmod, type_names tn) -> ValueRef {
@@ -6962,7 +7021,8 @@ fn make_common_glue(str output) {
69627021

69637022
trans_exit_task_glue(glues, new_str_hash[ValueRef](), tn, llmod);
69647023

6965-
check_module(llmod);
7024+
run_passes(llmod, true);
7025+
69667026
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
69677027
llvm.LLVMDisposeModule(llmod);
69687028
}
@@ -7031,7 +7091,8 @@ fn trans_crate(session.session sess, @ast.crate crate,
70317091
// Translate the metadata.
70327092
middle.metadata.write_metadata(cx, crate);
70337093

7034-
check_module(llmod);
7094+
// FIXME: Add an -O option
7095+
run_passes(llmod, true);
70357096

70367097
llvm.LLVMWriteBitcodeToFile(llmod, _str.buf(output));
70377098
llvm.LLVMDisposeModule(llmod);

src/comp/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ fn item_ty(@ast.item it) -> ty_params_and_ty {
731731

732732
fn stmt_ty(@ast.stmt s) -> @t {
733733
alt (s.node) {
734-
case (ast.stmt_expr(?e)) {
734+
case (ast.stmt_expr(?e,_)) {
735735
ret expr_ty(e);
736736
}
737737
case (_) {

src/comp/middle/typeck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,12 +2479,12 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
24792479

24802480
fn check_stmt(&@fn_ctxt fcx, &@ast.stmt stmt) -> @ast.stmt {
24812481
alt (stmt.node) {
2482-
case (ast.stmt_decl(?decl)) {
2482+
case (ast.stmt_decl(?decl,?a)) {
24832483
alt (decl.node) {
24842484
case (ast.decl_local(_)) {
24852485
auto decl_1 = check_decl_local(fcx, decl);
24862486
ret @fold.respan[ast.stmt_](stmt.span,
2487-
ast.stmt_decl(decl_1));
2487+
ast.stmt_decl(decl_1, a));
24882488
}
24892489

24902490
case (ast.decl_item(_)) {
@@ -2495,9 +2495,9 @@ fn check_stmt(&@fn_ctxt fcx, &@ast.stmt stmt) -> @ast.stmt {
24952495
ret stmt;
24962496
}
24972497

2498-
case (ast.stmt_expr(?expr)) {
2498+
case (ast.stmt_expr(?expr,?a)) {
24992499
auto expr_t = check_expr(fcx, expr);
2500-
ret @fold.respan[ast.stmt_](stmt.span, ast.stmt_expr(expr_t));
2500+
ret @fold.respan[ast.stmt_](stmt.span, ast.stmt_expr(expr_t, a));
25012501
}
25022502
}
25032503

0 commit comments

Comments
 (0)