Skip to content

Commit 56755f2

Browse files
committed
---
yaml --- r: 146261 b: refs/heads/try2 c: 7309158 h: refs/heads/master i: 146259: 556d5bb v: v3
1 parent af94ea3 commit 56755f2

File tree

11 files changed

+101
-135
lines changed

11 files changed

+101
-135
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: 2290131543af4da764343c546efbd5c6dc9e7d71
8+
refs/heads/try2: 73091583dd42991213e102daefa9181ce500feb0
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/lib/llvm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ pub mod llvm {
693693
pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
694694
pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
695695

696+
pub fn LLVMAddColdAttribute(Fn: ValueRef);
697+
696698
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
697699
PA: c_ulonglong,
698700
HighPA: c_ulonglong);

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,21 @@ pub fn get_extern_fn(externs: &mut ExternMap, llmod: ModuleRef, name: &str,
202202
f
203203
}
204204

205-
pub fn get_extern_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t,
206-
name: &str) -> ValueRef {
205+
fn get_extern_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t,
206+
name: &str, did: ast::DefId) -> ValueRef {
207207
match ccx.externs.find_equiv(&name) {
208208
Some(n) => return *n,
209209
None => ()
210210
}
211211
let f = decl_rust_fn(ccx, inputs, output, name);
212+
do csearch::get_item_attrs(ccx.tcx.cstore, did) |meta_items| {
213+
set_llvm_fn_attrs(meta_items.iter().map(|&x| attr::mk_attr(x)).to_owned_vec(), f)
214+
}
212215
ccx.externs.insert(name.to_owned(), f);
213216
f
214217
}
215218

216-
pub fn decl_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t,
217-
name: &str) -> ValueRef {
219+
fn decl_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t, name: &str) -> ValueRef {
218220
let llfty = type_of_rust_fn(ccx, inputs, output);
219221
let llfn = decl_cdecl_fn(ccx.llmod, name, llfty);
220222

@@ -481,6 +483,10 @@ pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
481483
if contains_name(attrs, "no_split_stack") {
482484
set_no_split_stack(llfn);
483485
}
486+
487+
if contains_name(attrs, "cold") {
488+
unsafe { llvm::LLVMAddColdAttribute(llfn) }
489+
}
484490
}
485491

486492
pub fn set_always_inline(f: ValueRef) {
@@ -840,7 +846,7 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) ->
840846
ty::ty_bare_fn(ref fn_ty) => {
841847
match fn_ty.abis.for_arch(ccx.sess.targ_cfg.arch) {
842848
Some(Rust) | Some(RustIntrinsic) => {
843-
get_extern_rust_fn(ccx, fn_ty.sig.inputs, fn_ty.sig.output, name)
849+
get_extern_rust_fn(ccx, fn_ty.sig.inputs, fn_ty.sig.output, name, did)
844850
}
845851
Some(*) | None => {
846852
let c = foreign::llvm_calling_convention(ccx, fn_ty.abis);
@@ -851,7 +857,7 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) ->
851857
}
852858
}
853859
ty::ty_closure(ref f) => {
854-
get_extern_rust_fn(ccx, f.sig.inputs, f.sig.output, name)
860+
get_extern_rust_fn(ccx, f.sig.inputs, f.sig.output, name, did)
855861
}
856862
_ => {
857863
let llty = type_of(ccx, t);
@@ -2844,6 +2850,8 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
28442850
ifn!(intrinsics, "llvm.umul.with.overflow.i64",
28452851
[Type::i64(), Type::i64()], Type::struct_([Type::i64(), Type::i1()], false));
28462852

2853+
ifn!(intrinsics, "llvm.expect.i1", [Type::i1(), Type::i1()], Type::i1());
2854+
28472855
return intrinsics;
28482856
}
28492857

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,9 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock {
981981
debug!("trans_index: len {}", bcx.val_to_str(len));
982982

983983
let bounds_check = ICmp(bcx, lib::llvm::IntUGE, ix_val, len);
984-
let bcx = do with_cond(bcx, bounds_check) |bcx| {
984+
let expect = ccx.intrinsics.get_copy(&("llvm.expect.i1"));
985+
let expected = Call(bcx, expect, [bounds_check, C_i1(false)], []);
986+
let bcx = do with_cond(bcx, expected) |bcx| {
985987
controlflow::trans_fail_bounds_check(bcx, index_expr.span, ix_val, len)
986988
};
987989
let elt = InBoundsGEP(bcx, base, [ix_val]);

branches/try2/src/libstd/rt/borrowck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn clear_task_borrow_list() {
5757
let _ = try_take_task_borrow_list();
5858
}
5959

60+
#[cold]
6061
unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) -> ! {
6162
debug_borrow("fail_borrowed: ", box, 0, 0, file, line);
6263

branches/try2/src/libstd/rt/io/net/unix.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ mod tests {
243243
let mut stop = false;
244244
while !stop{
245245
do io_error::cond.trap(|e| {
246-
assert_eq!(e.kind, BrokenPipe);
246+
assert!(e.kind == BrokenPipe || e.kind == NotConnected,
247+
"unknown error {:?}", e);
247248
stop = true;
248249
}).inside {
249250
server.write(buf);

branches/try2/src/libstd/unstable/lang.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ use libc::{c_char, size_t, uintptr_t};
1616
use rt::task;
1717
use rt::borrowck;
1818

19+
#[cold]
1920
#[lang="fail_"]
2021
pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
2122
task::begin_unwind(expr, file, line);
2223
}
2324

25+
#[cold]
2426
#[lang="fail_bounds_check"]
2527
pub fn fail_bounds_check(file: *c_char, line: size_t, index: size_t, len: size_t) -> ! {
2628
let msg = format!("index out of bounds: the len is {} but the index is {}",

branches/try2/src/libsyntax/ext/expand.rs

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,11 @@ fn expand_non_macro_stmt(exts: SyntaxEnv, s: &Stmt, fld: &MacroExpander)
566566
// oh dear heaven... this is going to include the enum names, as well....
567567
// ... but that should be okay, as long as the new names are gensyms
568568
// for the old ones.
569-
let idents = @mut ~[];
570-
let name_finder = new_name_finder(idents);
569+
let mut name_finder = new_name_finder(~[]);
571570
name_finder.visit_pat(expanded_pat,());
572571
// generate fresh names, push them to a new pending list
573572
let new_pending_renames = @mut ~[];
574-
for ident in idents.iter() {
573+
for ident in name_finder.ident_accumulator.iter() {
575574
let new_name = fresh_name(ident);
576575
new_pending_renames.push((*ident,new_name));
577576
}
@@ -609,7 +608,7 @@ fn expand_non_macro_stmt(exts: SyntaxEnv, s: &Stmt, fld: &MacroExpander)
609608
// array (passed in to the traversal)
610609
#[deriving(Clone)]
611610
struct NewNameFinderContext {
612-
ident_accumulator: @mut ~[ast::Ident],
611+
ident_accumulator: ~[ast::Ident],
613612
}
614613

615614
impl Visitor<()> for NewNameFinderContext {
@@ -653,50 +652,13 @@ impl Visitor<()> for NewNameFinderContext {
653652

654653
}
655654

656-
// a visitor that extracts the paths
657-
// from a given thingy and puts them in a mutable
658-
// array (passed in to the traversal)
659-
#[deriving(Clone)]
660-
struct NewPathExprFinderContext {
661-
path_accumulator: @mut ~[ast::Path],
662-
}
663-
664-
impl Visitor<()> for NewPathExprFinderContext {
665-
666-
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
667-
match *expr {
668-
ast::Expr{id:_,span:_,node:ast::ExprPath(ref p)} => {
669-
self.path_accumulator.push(p.clone());
670-
// not calling visit_path, should be fine.
671-
}
672-
_ => visit::walk_expr(self,expr,())
673-
}
674-
}
675-
676-
fn visit_ty(&mut self, typ: &ast::Ty, _: ()) {
677-
visit::walk_ty(self, typ, ())
678-
}
679-
680-
}
681-
682655
// return a visitor that extracts the pat_ident paths
683656
// from a given thingy and puts them in a mutable
684657
// array (passed in to the traversal)
685-
pub fn new_name_finder(idents: @mut ~[ast::Ident]) -> @mut Visitor<()> {
686-
let context = @mut NewNameFinderContext {
658+
pub fn new_name_finder(idents: ~[ast::Ident]) -> NewNameFinderContext {
659+
NewNameFinderContext {
687660
ident_accumulator: idents,
688-
};
689-
context as @mut Visitor<()>
690-
}
691-
692-
// return a visitor that extracts the paths
693-
// from a given pattern and puts them in a mutable
694-
// array (passed in to the traversal)
695-
pub fn new_path_finder(paths: @mut ~[ast::Path]) -> @mut Visitor<()> {
696-
let context = @mut NewPathExprFinderContext {
697-
path_accumulator: paths,
698-
};
699-
context as @mut Visitor<()>
661+
}
700662
}
701663

702664
// expand a block. pushes a new exts_frame, then calls expand_block_elts
@@ -1371,6 +1333,42 @@ mod test {
13711333
use util::parser_testing::{string_to_crate, string_to_crate_and_sess};
13721334
use util::parser_testing::{string_to_pat, string_to_tts, strs_to_idents};
13731335
use visit;
1336+
use visit::Visitor;
1337+
1338+
// a visitor that extracts the paths
1339+
// from a given thingy and puts them in a mutable
1340+
// array (passed in to the traversal)
1341+
#[deriving(Clone)]
1342+
struct NewPathExprFinderContext {
1343+
path_accumulator: ~[ast::Path],
1344+
}
1345+
1346+
impl Visitor<()> for NewPathExprFinderContext {
1347+
1348+
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
1349+
match *expr {
1350+
ast::Expr{id:_,span:_,node:ast::ExprPath(ref p)} => {
1351+
self.path_accumulator.push(p.clone());
1352+
// not calling visit_path, should be fine.
1353+
}
1354+
_ => visit::walk_expr(self,expr,())
1355+
}
1356+
}
1357+
1358+
fn visit_ty(&mut self, typ: &ast::Ty, _: ()) {
1359+
visit::walk_ty(self, typ, ())
1360+
}
1361+
1362+
}
1363+
1364+
// return a visitor that extracts the paths
1365+
// from a given pattern and puts them in a mutable
1366+
// array (passed in to the traversal)
1367+
pub fn new_path_finder(paths: ~[ast::Path]) -> NewPathExprFinderContext {
1368+
NewPathExprFinderContext {
1369+
path_accumulator: paths
1370+
}
1371+
}
13741372

13751373
// make sure that fail! is present
13761374
#[test] fn fail_exists_test () {
@@ -1498,10 +1496,11 @@ mod test {
14981496
let renamer = new_rename_folder(ast::Ident{name:a_name,ctxt:EMPTY_CTXT},
14991497
a2_name);
15001498
let renamed_ast = renamer.fold_crate(item_ast.clone());
1501-
let varrefs = @mut ~[];
1502-
visit::walk_crate(&mut new_path_finder(varrefs), &renamed_ast, ());
1503-
match varrefs {
1504-
@[ast::Path{segments:[ref seg],_}] =>
1499+
let mut path_finder = new_path_finder(~[]);
1500+
visit::walk_crate(&mut path_finder, &renamed_ast, ());
1501+
1502+
match path_finder.path_accumulator {
1503+
[ast::Path{segments:[ref seg],_}] =>
15051504
assert_eq!(mtwt_resolve(seg.identifier),a2_name),
15061505
_ => assert_eq!(0,1)
15071506
}
@@ -1513,10 +1512,10 @@ mod test {
15131512
let pending_renames = @mut ~[(ast::Ident::new(a_name),a2_name),
15141513
(ast::Ident{name:a_name,ctxt:ctxt2},a3_name)];
15151514
let double_renamed = renames_to_fold(pending_renames).fold_crate(item_ast);
1516-
let varrefs = @mut ~[];
1517-
visit::walk_crate(&mut new_path_finder(varrefs), &double_renamed, ());
1518-
match varrefs {
1519-
@[ast::Path{segments:[ref seg],_}] =>
1515+
let mut path_finder = new_path_finder(~[]);
1516+
visit::walk_crate(&mut path_finder, &double_renamed, ());
1517+
match path_finder.path_accumulator {
1518+
[ast::Path{segments:[ref seg],_}] =>
15201519
assert_eq!(mtwt_resolve(seg.identifier),a3_name),
15211520
_ => assert_eq!(0,1)
15221521
}
@@ -1623,11 +1622,15 @@ mod test {
16231622
};
16241623
let cr = expand_crate_str(teststr.to_managed());
16251624
// find the bindings:
1626-
let bindings = @mut ~[];
1627-
visit::walk_crate(&mut new_name_finder(bindings),&cr,());
1625+
let mut name_finder = new_name_finder(~[]);
1626+
visit::walk_crate(&mut name_finder,&cr,());
1627+
let bindings = name_finder.ident_accumulator;
1628+
16281629
// find the varrefs:
1629-
let varrefs = @mut ~[];
1630-
visit::walk_crate(&mut new_path_finder(varrefs),&cr,());
1630+
let mut path_finder = new_path_finder(~[]);
1631+
visit::walk_crate(&mut path_finder,&cr,());
1632+
let varrefs = path_finder.path_accumulator;
1633+
16311634
// must be one check clause for each binding:
16321635
assert_eq!(bindings.len(),bound_connections.len());
16331636
for (binding_idx,shouldmatch) in bound_connections.iter().enumerate() {
@@ -1686,8 +1689,10 @@ foo_module!()
16861689
";
16871690
let cr = expand_crate_str(crate_str);
16881691
// find the xx binding
1689-
let bindings = @mut ~[];
1690-
visit::walk_crate(&mut new_name_finder(bindings), &cr, ());
1692+
let mut name_finder = new_name_finder(~[]);
1693+
visit::walk_crate(&mut name_finder, &cr, ());
1694+
let bindings = name_finder.ident_accumulator;
1695+
16911696
let cxbinds : ~[&ast::Ident] =
16921697
bindings.iter().filter(|b|{@"xx" == (ident_to_str(*b))}).collect();
16931698
let cxbind = match cxbinds {
@@ -1696,8 +1701,10 @@ foo_module!()
16961701
};
16971702
let resolved_binding = mtwt_resolve(*cxbind);
16981703
// find all the xx varrefs:
1699-
let varrefs = @mut ~[];
1700-
visit::walk_crate(&mut new_path_finder(varrefs), &cr, ());
1704+
let mut path_finder = new_path_finder(~[]);
1705+
visit::walk_crate(&mut path_finder, &cr, ());
1706+
let varrefs = path_finder.path_accumulator;
1707+
17011708
// the xx binding should bind all of the xx varrefs:
17021709
for (idx,v) in varrefs.iter().filter(|p|{ p.segments.len() == 1
17031710
&& (@"xx" == (ident_to_str(&p.segments[0].identifier)))
@@ -1723,10 +1730,10 @@ foo_module!()
17231730
#[test]
17241731
fn pat_idents(){
17251732
let pat = string_to_pat(@"(a,Foo{x:c @ (b,9),y:Bar(4,d)})");
1726-
let idents = @mut ~[];
1727-
let pat_idents = new_name_finder(idents);
1733+
let mut pat_idents = new_name_finder(~[]);
17281734
pat_idents.visit_pat(pat, ());
1729-
assert_eq!(idents, @mut strs_to_idents(~["a","c","b","d"]));
1735+
assert_eq!(pat_idents.ident_accumulator,
1736+
strs_to_idents(~["a","c","b","d"]));
17301737
}
17311738

17321739
}

0 commit comments

Comments
 (0)