Skip to content

Commit 08f3b82

Browse files
committed
---
yaml --- r: 140758 b: refs/heads/try2 c: 1b88336 h: refs/heads/master v: v3
1 parent bd080b7 commit 08f3b82

File tree

16 files changed

+224
-14
lines changed

16 files changed

+224
-14
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: ae07170bd8e5d91b80c1ab32c847400a3df1e2ce
8+
refs/heads/try2: 1b883365bc0813f5775c8207e414b7973e947a76
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,8 @@ names are effectively reserved. Some significant attributes include:
14251425
* The `test` attribute, for marking functions as unit tests.
14261426
* The `allow`, `warn`, `forbid`, and `deny` attributes, for controlling lint checks. Lint checks supported
14271427
by the compiler can be found via `rustc -W help`.
1428+
* The `deriving` attribute, for automatically generating
1429+
implementations of certain traits.
14281430

14291431
Other attributes may be added or removed during development of the language.
14301432

@@ -1526,6 +1528,47 @@ A complete list of the built-in language items follows:
15261528
> **Note:** This list is likely to become out of date. We should auto-generate it
15271529
> from `librustc/middle/lang_items.rs`.
15281530
1531+
### Deriving
1532+
1533+
The `deriving` attribute allows certain traits to be automatically
1534+
implemented for data structures. For example, the following will
1535+
create an `impl` for the `Eq` and `Clone` traits for `Foo`, the type
1536+
parameter `T` will be given the `Eq` or `Clone` constraints for the
1537+
appropriate `impl`:
1538+
1539+
~~~
1540+
#[deriving(Eq, Clone)]
1541+
struct Foo<T> {
1542+
a: int,
1543+
b: T
1544+
}
1545+
~~~
1546+
1547+
The generated `impl` for `Eq` is equivalent to
1548+
1549+
~~~
1550+
# struct Foo<T> { a: int, b: T }
1551+
impl<T: Eq> Eq for Foo<T> {
1552+
fn eq(&self, other: &Foo<T>) -> bool {
1553+
self.a == other.a && self.b == other.b
1554+
}
1555+
1556+
fn ne(&self, other: &Foo<T>) -> bool {
1557+
self.a != other.a || self.b != other.b
1558+
}
1559+
}
1560+
~~~
1561+
1562+
Supported traits for `deriving` are:
1563+
1564+
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
1565+
* Serialization: `Encodable`, `Decodable`. These require `std`.
1566+
* `Clone`, to perform deep copies.
1567+
* `IterBytes`, to iterate over the bytes in a data type.
1568+
* `Rand`, to create a random instance of a data type.
1569+
* `ToStr`, to convert to a string. For a type with this instance,
1570+
`obj.to_str()` has the same output as `fmt!("%?", obj)`.
1571+
15291572
# Statements and expressions
15301573

15311574
Rust is _primarily_ an expression language. This means that most forms of

branches/try2/doc/tutorial.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,27 @@ let nonsense = mycircle.radius() * mycircle.area();
22902290

22912291
> ***Note:*** Trait inheritance does not actually work with objects yet
22922292
2293+
## Deriving implementations for traits
2294+
2295+
A small number of traits in `core` and `std` can have implementations
2296+
that can be automatically derived. These instances are specified by
2297+
placing the `deriving` attribute on a data type declaration. For
2298+
example, the following will mean that `Circle` has an implementation
2299+
for `Eq` and can be used with the equality operators, and that a value
2300+
of type `ABC` can be randomly generated and converted to a string:
2301+
2302+
~~~
2303+
#[deriving(Eq)]
2304+
struct Circle { radius: float }
2305+
2306+
#[deriving(Rand, ToStr)]
2307+
enum ABC { A, B, C }
2308+
~~~
2309+
2310+
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
2311+
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `IterBytes`, `Rand` and
2312+
`ToStr`.
2313+
22932314
# Modules and crates
22942315

22952316
The Rust namespace is arranged in a hierarchy of modules. Each source

branches/try2/src/libcore/unstable/intrinsics.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ pub extern "rust-intrinsic" {
2020
pub fn atomic_cxchg_acq(dst: &mut int, old: int, src: int) -> int;
2121
pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;
2222

23+
#[cfg(not(stage0))]
24+
pub fn atomic_load(src: &int) -> int;
25+
#[cfg(not(stage0))]
26+
pub fn atomic_load_acq(src: &int) -> int;
27+
28+
#[cfg(not(stage0))]
29+
pub fn atomic_store(dst: &mut int, val: int);
30+
#[cfg(not(stage0))]
31+
pub fn atomic_store_rel(dst: &mut int, val: int);
32+
2333
pub fn atomic_xchg(dst: &mut int, src: int) -> int;
2434
pub fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
2535
pub fn atomic_xchg_rel(dst: &mut int, src: int) -> int;

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,13 +1339,16 @@ pub mod llvm {
13391339
PointerVal: ValueRef) -> ValueRef;
13401340
#[fast_ffi]
13411341
pub unsafe fn LLVMBuildLoad(B: BuilderRef,
1342-
PointerVal: ValueRef,
1343-
Name: *c_char)
1344-
-> ValueRef;
1342+
PointerVal: ValueRef,
1343+
Name: *c_char)
1344+
-> ValueRef;
1345+
13451346
#[fast_ffi]
13461347
pub unsafe fn LLVMBuildStore(B: BuilderRef,
13471348
Val: ValueRef,
1348-
Ptr: ValueRef) -> ValueRef;
1349+
Ptr: ValueRef)
1350+
-> ValueRef;
1351+
13491352
#[fast_ffi]
13501353
pub unsafe fn LLVMBuildGEP(B: BuilderRef,
13511354
Pointer: ValueRef,
@@ -1561,6 +1564,17 @@ pub mod llvm {
15611564
Name: *c_char) -> ValueRef;
15621565

15631566
/* Atomic Operations */
1567+
pub unsafe fn LLVMBuildAtomicLoad(B: BuilderRef,
1568+
PointerVal: ValueRef,
1569+
Order: AtomicOrdering)
1570+
-> ValueRef;
1571+
1572+
pub unsafe fn LLVMBuildAtomicStore(B: BuilderRef,
1573+
Val: ValueRef,
1574+
Ptr: ValueRef,
1575+
Order: AtomicOrdering)
1576+
-> ValueRef;
1577+
15641578
pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
15651579
LHS: ValueRef,
15661580
CMP: ValueRef,

branches/try2/src/librustc/middle/resolve.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,25 +2282,27 @@ pub impl Resolver {
22822282
}
22832283
22842284
let i = import_resolution;
2285+
let mut resolve_fail = false;
2286+
let mut priv_fail = false;
22852287
match (i.value_target, i.type_target) {
22862288
// If this name wasn't found in either namespace, it's definitely
22872289
// unresolved.
2288-
(None, None) => { return Failed; }
2290+
(None, None) => { resolve_fail = true; }
22892291
// If it's private, it's also unresolved.
22902292
(Some(t), None) | (None, Some(t)) => {
22912293
let bindings = &mut *t.bindings;
22922294
match bindings.type_def {
22932295
Some(ref type_def) => {
22942296
if type_def.privacy == Private {
2295-
return Failed;
2297+
priv_fail = true;
22962298
}
22972299
}
22982300
_ => ()
22992301
}
23002302
match bindings.value_def {
23012303
Some(ref value_def) => {
23022304
if value_def.privacy == Private {
2303-
return Failed;
2305+
priv_fail = true;
23042306
}
23052307
}
23062308
_ => ()
@@ -2313,13 +2315,25 @@ pub impl Resolver {
23132315
(Some(ref value_def), Some(ref type_def)) =>
23142316
if value_def.privacy == Private
23152317
&& type_def.privacy == Private {
2316-
return Failed;
2318+
priv_fail = true;
23172319
},
23182320
_ => ()
23192321
}
23202322
}
23212323
}
23222324
2325+
if resolve_fail {
2326+
self.session.err(fmt!("unresolved import: there is no `%s` in `%s`",
2327+
*self.session.str_of(source),
2328+
self.module_to_str(containing_module)));
2329+
return Failed;
2330+
} else if priv_fail {
2331+
self.session.err(fmt!("unresolved import: found `%s` in `%s` but it is private",
2332+
*self.session.str_of(source),
2333+
self.module_to_str(containing_module)));
2334+
return Failed;
2335+
}
2336+
23232337
assert!(import_resolution.outstanding_references >= 1);
23242338
import_resolution.outstanding_references -= 1;
23252339

@@ -2491,7 +2505,8 @@ pub impl Resolver {
24912505
*segment_name));
24922506
return Failed;
24932507
}
2494-
self.session.span_err(span, ~"unresolved name");
2508+
self.session.span_err(span, fmt!("unresolved import: could not find `%s` in \
2509+
`%s`.", *segment_name, module_name));
24952510
return Failed;
24962511
}
24972512
Indeterminate => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ fn padding(size: u64) -> ValueRef {
574574
}
575575

576576
// XXX this utility routine should be somewhere more general
577-
#[always_inline]
577+
#[inline(always)]
578578
fn roundup(x: u64, a: u64) -> u64 { ((x + (a - 1)) / a) * a }
579579

580580
/// Get the discriminant of a constant value. (Not currently used.)

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,18 @@ pub fn Load(cx: block, PointerVal: ValueRef) -> ValueRef {
537537
}
538538
}
539539
540+
pub fn AtomicLoad(cx: block, PointerVal: ValueRef, order: AtomicOrdering) -> ValueRef {
541+
unsafe {
542+
let ccx = cx.fcx.ccx;
543+
if cx.unreachable {
544+
return llvm::LLVMGetUndef(ccx.int_type);
545+
}
546+
count_insn(cx, "load.atomic");
547+
return llvm::LLVMBuildAtomicLoad(B(cx), PointerVal, order);
548+
}
549+
}
550+
551+
540552
pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,
541553
hi: c_ulonglong, signed: lib::llvm::Bool) -> ValueRef {
542554
let value = Load(cx, PointerVal);
@@ -567,6 +579,17 @@ pub fn Store(cx: block, Val: ValueRef, Ptr: ValueRef) {
567579
}
568580
}
569581
582+
pub fn AtomicStore(cx: block, Val: ValueRef, Ptr: ValueRef, order: AtomicOrdering) {
583+
unsafe {
584+
if cx.unreachable { return; }
585+
debug!("Store %s -> %s",
586+
val_str(cx.ccx().tn, Val),
587+
val_str(cx.ccx().tn, Ptr));
588+
count_insn(cx, "store.atomic");
589+
llvm::LLVMBuildAtomicStore(B(cx), Val, Ptr, order);
590+
}
591+
}
592+
570593
pub fn GEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {
571594
unsafe {
572595
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_nil())); }

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,30 @@ pub fn trans_intrinsic(ccx: @CrateContext,
592592
Release);
593593
Store(bcx, old, fcx.llretptr.get());
594594
}
595+
~"atomic_load" => {
596+
let old = AtomicLoad(bcx,
597+
get_param(decl, first_real_arg),
598+
SequentiallyConsistent);
599+
Store(bcx, old, fcx.llretptr.get());
600+
}
601+
~"atomic_load_acq" => {
602+
let old = AtomicLoad(bcx,
603+
get_param(decl, first_real_arg),
604+
Acquire);
605+
Store(bcx, old, fcx.llretptr.get());
606+
}
607+
~"atomic_store" => {
608+
AtomicStore(bcx,
609+
get_param(decl, first_real_arg + 1u),
610+
get_param(decl, first_real_arg),
611+
SequentiallyConsistent);
612+
}
613+
~"atomic_store_rel" => {
614+
AtomicStore(bcx,
615+
get_param(decl, first_real_arg + 1u),
616+
get_param(decl, first_real_arg),
617+
Release);
618+
}
595619
~"atomic_xchg" => {
596620
let old = AtomicRMW(bcx, Xchg,
597621
get_param(decl, first_real_arg),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
124124
~"get_tydesc" | ~"needs_drop" => use_tydesc,
125125

126126
~"atomic_cxchg" | ~"atomic_cxchg_acq"|
127-
~"atomic_cxchg_rel"| ~"atomic_xchg" |
127+
~"atomic_cxchg_rel"| ~"atomic_load" |
128+
~"atomic_load_acq" | ~"atomic_store" |
129+
~"atomic_store_rel"| ~"atomic_xchg" |
128130
~"atomic_xadd" | ~"atomic_xsub" |
129131
~"atomic_xchg_acq" | ~"atomic_xadd_acq" |
130132
~"atomic_xsub_acq" | ~"atomic_xchg_rel" |

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,25 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
34863486
],
34873487
ty::mk_int())
34883488
}
3489+
~"atomic_load" | ~"atomic_load_acq" => {
3490+
(0,
3491+
~[
3492+
arg(ty::mk_imm_rptr(tcx,
3493+
ty::re_bound(ty::br_anon(0)),
3494+
ty::mk_int()))
3495+
],
3496+
ty::mk_int())
3497+
}
3498+
~"atomic_store" | ~"atomic_store_rel" => {
3499+
(0,
3500+
~[
3501+
arg(ty::mk_mut_rptr(tcx,
3502+
ty::re_bound(ty::br_anon(0)),
3503+
ty::mk_int())),
3504+
arg(ty::mk_int())
3505+
],
3506+
ty::mk_nil())
3507+
}
34893508
~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" |
34903509
~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" |
34913510
~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" => {

branches/try2/src/rt/rust_globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#endif
2121

2222
#if defined(__GNUC__)
23-
#define ALWAYS_INLINE __attribute((always_inline)) INLINE
23+
#define ALWAYS_INLINE __attribute__((always_inline)) INLINE
2424
#elif defined(_MSC_VER)
2525
#define ALWAYS_INLINE __forceinline
2626
#else

branches/try2/src/rustllvm/RustWrapper.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,28 @@ extern "C" LLVMTypeRef LLVMMetadataType(void) {
545545
return LLVMMetadataTypeInContext(LLVMGetGlobalContext());
546546
}
547547

548+
extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
549+
LLVMValueRef source,
550+
const char* Name,
551+
AtomicOrdering order) {
552+
LoadInst* li = new LoadInst(unwrap(source),0);
553+
li->setVolatile(true);
554+
li->setAtomic(order);
555+
li->setAlignment(sizeof(intptr_t));
556+
return wrap(unwrap(B)->Insert(li));
557+
}
558+
559+
extern "C" LLVMValueRef LLVMBuildAtomicStore(LLVMBuilderRef B,
560+
LLVMValueRef val,
561+
LLVMValueRef target,
562+
AtomicOrdering order) {
563+
StoreInst* si = new StoreInst(unwrap(val),unwrap(target));
564+
si->setVolatile(true);
565+
si->setAtomic(order);
566+
si->setAlignment(sizeof(intptr_t));
567+
return wrap(unwrap(B)->Insert(si));
568+
}
569+
548570
extern "C" LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B,
549571
LLVMValueRef target,
550572
LLVMValueRef old,

branches/try2/src/rustllvm/rustllvm.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ LLVMArrayType
8484
LLVMBasicBlockAsValue
8585
LLVMBlockAddress
8686
LLVMBuildAShr
87+
LLVMBuildAtomicLoad
88+
LLVMBuildAtomicStore
8789
LLVMBuildAtomicCmpXchg
8890
LLVMBuildAtomicRMW
8991
LLVMBuildAdd

branches/try2/src/test/compile-fail/import2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use baz::zed::bar; //~ ERROR unresolved name
11+
use baz::zed::bar; //~ ERROR unresolved import
1212
//~^ ERROR failed to resolve import
1313

1414
mod baz {}

0 commit comments

Comments
 (0)