Skip to content

Commit 4e2295f

Browse files
committed
---
yaml --- r: 141053 b: refs/heads/try2 c: 0b39bc2 h: refs/heads/master i: 141051: 4405a44 v: v3
1 parent 5baf1d4 commit 4e2295f

File tree

8 files changed

+258
-17
lines changed

8 files changed

+258
-17
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: 91d3e7f1a0757bf314ab3a4c4be8f910e2355d35
8+
refs/heads/try2: 0b39bc275e8f573238ad23fc8f86c87cec5e103d
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/io.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,16 @@ pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> @Reader {
10401040
// top-level functions that take a reader, or a set of default methods on
10411041
// reader (which can then be called reader)
10421042

1043+
/**
1044+
* Gives a `Reader` that allows you to read values from standard input.
1045+
*
1046+
* # Examples
1047+
* ~~~
1048+
* let stdin = core::io::stdin();
1049+
* let line = stdin.read_line();
1050+
* core::io::print(line);
1051+
* ~~~
1052+
*/
10431053
pub fn stdin() -> @Reader {
10441054
unsafe {
10451055
@rustrt::rust_get_stdin() as @Reader
@@ -1591,13 +1601,57 @@ pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
15911601
// FIXME (#2004) it would be great if this could be a const
15921602
// FIXME (#2004) why are these different from the way stdin() is
15931603
// implemented?
1604+
1605+
1606+
/**
1607+
* Gives a `Writer` which allows you to write to the standard output.
1608+
*
1609+
* # Examples
1610+
* ~~~
1611+
* let stdout = core::io::stdout();
1612+
* stdout.write_str("hello\n");
1613+
* ~~~
1614+
*/
15941615
pub fn stdout() -> @Writer { fd_writer(libc::STDOUT_FILENO as c_int, false) }
1616+
1617+
/**
1618+
* Gives a `Writer` which allows you to write to standard error.
1619+
*
1620+
* # Examples
1621+
* ~~~
1622+
* let stderr = core::io::stderr();
1623+
* stderr.write_str("hello\n");
1624+
* ~~~
1625+
*/
15951626
pub fn stderr() -> @Writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
15961627

1628+
/**
1629+
* Prints a string to standard output.
1630+
*
1631+
* This string will not have an implicit newline at the end. If you want
1632+
* an implicit newline, please see `println`.
1633+
*
1634+
* # Examples
1635+
* ~~~
1636+
* // print is imported into the prelude, and so is always available.
1637+
* print("hello");
1638+
* ~~~
1639+
*/
15971640
pub fn print(s: &str) {
15981641
stdout().write_str(s);
15991642
}
16001643

1644+
/**
1645+
* Prints a string to standard output, followed by a newline.
1646+
*
1647+
* If you do not want an implicit newline, please see `print`.
1648+
*
1649+
* # Examples
1650+
* ~~~
1651+
* // println is imported into the prelude, and so is always available.
1652+
* println("hello");
1653+
* ~~~
1654+
*/
16011655
pub fn println(s: &str) {
16021656
stdout().write_line(s);
16031657
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use core::hashmap::HashMap;
12-
use core::libc::c_uint;
12+
use core::libc::{c_uint, c_ushort};
1313

1414
pub type Opcode = u32;
1515
pub type Bool = c_uint;
@@ -221,7 +221,7 @@ pub mod llvm {
221221
use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
222222
use super::{ValueRef};
223223

224-
use core::libc::{c_char, c_int, c_longlong, c_uint, c_ulonglong};
224+
use core::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};
225225

226226
#[link_args = "-Lrustllvm -lrustllvm"]
227227
#[link_name = "rustllvm"]
@@ -451,6 +451,10 @@ pub mod llvm {
451451
/* all zeroes */
452452
#[fast_ffi]
453453
pub unsafe fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
454+
#[fast_ffi]
455+
pub unsafe fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) -> ValueRef;
456+
#[fast_ffi]
457+
pub unsafe fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) -> ValueRef;
454458
/* only for int/vector */
455459
#[fast_ffi]
456460
pub unsafe fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
@@ -1914,6 +1918,16 @@ pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
19141918
}
19151919
}
19161920

1921+
pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1922+
unsafe {
1923+
llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
1924+
}
1925+
}
1926+
pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1927+
unsafe {
1928+
llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
1929+
}
1930+
}
19171931
/* Memory-managed object interface to type handles. */
19181932

19191933
pub struct TypeNames {

branches/try2/src/librustc/metadata/encoder.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,20 @@ fn encode_reexported_static_methods(ecx: @EncodeContext,
386386
match ecx.tcx.trait_methods_cache.find(&exp.def_id) {
387387
Some(methods) => {
388388
match ecx.tcx.items.find(&exp.def_id.node) {
389-
Some(&ast_map::node_item(_, path)) => {
390-
if mod_path != *path {
389+
Some(&ast_map::node_item(item, path)) => {
390+
let original_name = ecx.tcx.sess.str_of(item.ident);
391+
392+
//
393+
// We don't need to reexport static methods on traits
394+
// declared in the same module as our `pub use ...` since
395+
// that's done when we encode the trait item.
396+
//
397+
// The only exception is when the reexport *changes* the
398+
// name e.g. `pub use Foo = self::Bar` -- we have
399+
// encoded metadata for static methods relative to Bar,
400+
// but not yet for Foo.
401+
//
402+
if mod_path != *path || *exp.name != *original_name {
391403
for methods.each |&m| {
392404
if m.explicit_self == ast::sty_static {
393405
encode_reexported_static_method(ecx,

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

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
// except according to those terms.
1010

1111
use back::abi;
12-
use lib::llvm::{llvm, SetLinkage, PrivateLinkage,
13-
ValueRef, TypeRef, Bool, True, False};
12+
use lib::llvm::{llvm, ConstFCmp, ConstICmp, SetLinkage, PrivateLinkage, ValueRef, TypeRef, Bool,
13+
True, False};
14+
use lib::llvm::{IntEQ, IntNE, IntUGT, IntUGE, IntULT, IntULE, IntSGT, IntSGE, IntSLT, IntSLE,
15+
RealOEQ, RealOGT, RealOGE, RealOLT, RealOLE, RealONE};
16+
1417
use metadata::csearch;
1518
use middle::const_eval;
1619
use middle::trans::adt;
@@ -280,8 +283,8 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
280283
else if signed { llvm::LLVMConstSRem(te1, te2) }
281284
else { llvm::LLVMConstURem(te1, te2) }
282285
}
283-
ast::and |
284-
ast::or => cx.sess.span_unimpl(e.span, "binop logic"),
286+
ast::and => llvm::LLVMConstAnd(te1, te2),
287+
ast::or => llvm::LLVMConstOr(te1, te2),
285288
ast::bitxor => llvm::LLVMConstXor(te1, te2),
286289
ast::bitand => llvm::LLVMConstAnd(te1, te2),
287290
ast::bitor => llvm::LLVMConstOr(te1, te2),
@@ -290,14 +293,44 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
290293
if signed { llvm::LLVMConstAShr(te1, te2) }
291294
else { llvm::LLVMConstLShr(te1, te2) }
292295
}
293-
ast::eq |
294-
ast::lt |
295-
ast::le |
296-
ast::ne |
297-
ast::ge |
298-
ast::gt => cx.sess.span_unimpl(e.span, "binop comparator")
299-
}
300-
}
296+
ast::eq => {
297+
if is_float { ConstFCmp(RealOEQ, te1, te2) }
298+
else { ConstICmp(IntEQ, te1, te2) }
299+
},
300+
ast::lt => {
301+
if is_float { ConstFCmp(RealOLT, te1, te2) }
302+
else {
303+
if signed { ConstICmp(IntSLT, te1, te2) }
304+
else { ConstICmp(IntULT, te1, te2) }
305+
}
306+
},
307+
ast::le => {
308+
if is_float { ConstFCmp(RealOLE, te1, te2) }
309+
else {
310+
if signed { ConstICmp(IntSLE, te1, te2) }
311+
else { ConstICmp(IntULE, te1, te2) }
312+
}
313+
},
314+
ast::ne => {
315+
if is_float { ConstFCmp(RealONE, te1, te2) }
316+
else { ConstICmp(IntNE, te1, te2) }
317+
},
318+
ast::ge => {
319+
if is_float { ConstFCmp(RealOGE, te1, te2) }
320+
else {
321+
if signed { ConstICmp(IntSGE, te1, te2) }
322+
else { ConstICmp(IntUGE, te1, te2) }
323+
}
324+
},
325+
ast::gt => {
326+
if is_float { ConstFCmp(RealOGT, te1, te2) }
327+
else {
328+
if signed { ConstICmp(IntSGT, te1, te2) }
329+
else { ConstICmp(IntUGT, te1, te2) }
330+
}
331+
},
332+
};
333+
},
301334
ast::expr_unary(u, e) => {
302335
let te = const_expr(cx, e);
303336
let ty = ty::expr_ty(cx.tcx, e);

branches/try2/src/test/auxiliary/mod_trait_with_static_methods_lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
// except according to those terms.
1010

1111
pub use sub_foo::Foo;
12+
pub use Baz = self::Bar;
13+
14+
pub trait Bar {
15+
pub fn bar() -> Self;
16+
}
17+
18+
impl Bar for int {
19+
pub fn bar() -> int { 84 }
20+
}
1221

1322
pub mod sub_foo {
1423
pub trait Foo {
@@ -18,4 +27,5 @@ pub mod sub_foo {
1827
impl Foo for int {
1928
pub fn foo() -> int { 42 }
2029
}
30+
2131
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
static a: int = -4 + 3;
2+
static a2: uint = 3 + 3;
3+
static b: float = 3.0 + 2.7;
4+
5+
static c: int = 3 - 4;
6+
static d: uint = 3 - 3;
7+
static e: float = 3.0 - 2.7;
8+
9+
static e2: int = -3 * 3;
10+
static f: uint = 3 * 3;
11+
static g: float = 3.3 * 3.3;
12+
13+
static h: int = 3 / -1;
14+
static i: uint = 3 / 3;
15+
static j: float = 3.3 / 3.3;
16+
17+
static n: bool = true && false;
18+
19+
static o: bool = true || false;
20+
21+
static p: int = 3 & 1;
22+
static q: uint = 1 & 3;
23+
24+
static r: int = 3 | 1;
25+
static s: uint = 1 | 3;
26+
27+
static t: int = 3 ^ 1;
28+
static u: uint = 1 ^ 3;
29+
30+
static v: int = 1 << 3;
31+
32+
// NOTE: better shr coverage
33+
static w: int = 1024 >> 4;
34+
static x: uint = 1024 >> 4;
35+
36+
static y: bool = 1 == 1;
37+
static z: bool = 1.0 == 1.0;
38+
39+
static aa: bool = 1 <= 2;
40+
static ab: bool = -1 <= 2;
41+
static ac: bool = 1.0 <= 2.0;
42+
43+
static ad: bool = 1 < 2;
44+
static ae: bool = -1 < 2;
45+
static af: bool = 1.0 < 2.0;
46+
47+
static ag: bool = 1 != 2;
48+
static ah: bool = -1 != 2;
49+
static ai: bool = 1.0 != 2.0;
50+
51+
static aj: bool = 2 >= 1;
52+
static ak: bool = 2 >= -2;
53+
static al: bool = 1.0 >= -2.0;
54+
55+
static am: bool = 2 > 1;
56+
static an: bool = 2 > -2;
57+
static ao: bool = 1.0 > -2.0;
58+
59+
fn main() {
60+
assert_eq!(a, -1);
61+
assert_eq!(a2, 6);
62+
assert_approx_eq!(b, 5.7);
63+
64+
assert_eq!(c, -1);
65+
assert_eq!(d, 0);
66+
assert_approx_eq!(e, 0.3);
67+
68+
assert_eq!(e2, -9);
69+
assert_eq!(f, 9);
70+
assert_approx_eq!(g, 10.89);
71+
72+
assert_eq!(h, -3);
73+
assert_eq!(i, 1);
74+
assert_approx_eq!(j, 1.0);
75+
76+
assert_eq!(n, false);
77+
78+
assert_eq!(o, true);
79+
80+
assert_eq!(p, 1);
81+
assert_eq!(q, 1);
82+
83+
assert_eq!(r, 3);
84+
assert_eq!(s, 3);
85+
86+
assert_eq!(t, 2);
87+
assert_eq!(u, 2);
88+
89+
assert_eq!(v, 8);
90+
91+
assert_eq!(w, 64);
92+
assert_eq!(x, 64);
93+
94+
assert_eq!(y, true);
95+
assert_eq!(z, true);
96+
97+
assert_eq!(aa, true);
98+
assert_eq!(ab, true);
99+
assert_eq!(ac, true);
100+
101+
assert_eq!(ad, true);
102+
assert_eq!(ae, true);
103+
assert_eq!(af, true);
104+
105+
assert_eq!(ag, true);
106+
assert_eq!(ah, true);
107+
assert_eq!(ai, true);
108+
109+
assert_eq!(aj, true);
110+
assert_eq!(ak, true);
111+
assert_eq!(al, true);
112+
113+
assert_eq!(am, true);
114+
assert_eq!(an, true);
115+
assert_eq!(ao, true);
116+
}

branches/try2/src/test/run-pass/trait_with_static_methods_cross_crate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
extern mod mod_trait_with_static_methods_lib;
1414

1515
use mod_trait_with_static_methods_lib::Foo;
16+
use mod_trait_with_static_methods_lib::Baz;
1617

1718
pub fn main() {
1819
assert_eq!(42, Foo::foo());
20+
assert_eq!(84, Baz::bar());
1921
}

0 commit comments

Comments
 (0)