Skip to content

Commit 3f30dba

Browse files
committed
---
yaml --- r: 155135 b: refs/heads/try2 c: 946654a h: refs/heads/master i: 155133: e138b30 155131: 510e8cf 155127: cfc4c2b 155119: 8e9d9df 155103: c748b25 155071: 0d2544c 155007: a9b5006 154879: 42cf376 154623: 960db48 v: v3
1 parent 2a1ebdd commit 3f30dba

File tree

23 files changed

+274
-73
lines changed

23 files changed

+274
-73
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: eafeb335a0731b4bfcd8be6203d0d29a3668cd76
8+
refs/heads/try2: 946654a721d6fd5eeb91e93293cdc2cba83c78b9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Save the file, and then type this into your terminal window:
152152

153153
```{bash}
154154
$ rustc main.rs
155-
$ ./hello_world # or hello_world.exe on Windows
155+
$ ./main # or main.exe on Windows
156156
Hello, world!
157157
```
158158

@@ -164,7 +164,7 @@ fn main() {
164164
}
165165
```
166166

167-
These two lines define a **function** in Rust. The `main` function is special:
167+
These lines define a **function** in Rust. The `main` function is special:
168168
it's the beginning of every Rust program. The first line says "I'm declaring a
169169
function named `main`, which takes no arguments and returns nothing." If there
170170
were arguments, they would go inside the parentheses (`(` and `)`), and because
@@ -232,10 +232,10 @@ main.exe main.rs
232232
```
233233

234234
There are now two files: our source code, with the `.rs` extension, and the
235-
executable (`hello_world.exe` on Windows, `hello_world` everywhere else)
235+
executable (`main.exe` on Windows, `main` everywhere else)
236236

237237
```{bash}
238-
$ ./hello_world # or hello_world.exe on Windows
238+
$ ./main # or main.exe on Windows
239239
```
240240

241241
This prints out our `Hello, world!` text to our terminal.

branches/try2/src/liballoc/heap.rs

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

11-
// FIXME: #13994: port to the sized deallocation API when available
1211
// FIXME: #13996: mark the `allocate` and `reallocate` return value as `noalias`
13-
// and `nonnull`
1412

15-
#[cfg(not(test))] use core::raw;
13+
#[cfg(stage0, not(test))] use core::raw;
1614
#[cfg(stage0, not(test))] use util;
1715

1816
/// Returns a pointer to `size` bytes of memory.
@@ -88,18 +86,19 @@ pub fn stats_print() {
8886
imp::stats_print();
8987
}
9088

91-
// The compiler never calls `exchange_free` on Box<ZeroSizeType>, so zero-size
92-
// allocations can point to this `static`. It would be incorrect to use a null
93-
// pointer, due to enums assuming types like unique pointers are never null.
94-
pub static mut EMPTY: uint = 12345;
89+
/// An arbitrary non-null address to represent zero-size allocations.
90+
///
91+
/// This preserves the non-null invariant for types like `Box<T>`. The address may overlap with
92+
/// non-zero-size memory allocations.
93+
pub static EMPTY: *mut () = 0x1 as *mut ();
9594

9695
/// The allocator for unique pointers.
9796
#[cfg(not(test))]
9897
#[lang="exchange_malloc"]
9998
#[inline]
10099
unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 {
101100
if size == 0 {
102-
&EMPTY as *const uint as *mut u8
101+
EMPTY as *mut u8
103102
} else {
104103
allocate(size, align)
105104
}
@@ -112,7 +111,6 @@ unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
112111
deallocate(ptr, size, align);
113112
}
114113

115-
// FIXME: #7496
116114
#[cfg(stage0, not(test))]
117115
#[lang="closure_exchange_malloc"]
118116
#[inline]
@@ -128,21 +126,6 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
128126
alloc as *mut u8
129127
}
130128

131-
// FIXME: #7496
132-
#[cfg(not(stage0), not(test))]
133-
#[lang="closure_exchange_malloc"]
134-
#[inline]
135-
#[allow(deprecated)]
136-
unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
137-
align: uint) -> *mut u8 {
138-
let p = allocate(size, align);
139-
140-
let alloc = p as *mut raw::Box<()>;
141-
(*alloc).drop_glue = drop_glue;
142-
143-
alloc as *mut u8
144-
}
145-
146129
// The minimum alignment guaranteed by the architecture. This value is used to
147130
// add fast paths for low alignment values. In practice, the alignment is a
148131
// constant at the call site and the branch will be optimized out.

branches/try2/src/libcollections/enum_set.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,31 @@
1414
//! representation to hold C-like enum variants.
1515
1616
use core::prelude::*;
17+
use core::fmt;
1718

18-
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
19+
#[deriving(Clone, PartialEq, Eq, Hash)]
1920
/// A specialized `Set` implementation to use enum types.
2021
pub struct EnumSet<E> {
2122
// We must maintain the invariant that no bits are set
2223
// for which no variant exists
2324
bits: uint
2425
}
2526

27+
impl<E:CLike+fmt::Show> fmt::Show for EnumSet<E> {
28+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
29+
try!(write!(fmt, "{{"));
30+
let mut first = true;
31+
for e in self.iter() {
32+
if !first {
33+
try!(write!(fmt, ", "));
34+
}
35+
try!(write!(fmt, "{}", e));
36+
first = false;
37+
}
38+
write!(fmt, "}}")
39+
}
40+
}
41+
2642
/// An interface for casting C-like enum to uint and back.
2743
pub trait CLike {
2844
/// Converts a C-like enum to a `uint`.
@@ -165,6 +181,16 @@ mod test {
165181
assert!(e.is_empty());
166182
}
167183

184+
#[test]
185+
fn test_show() {
186+
let mut e = EnumSet::empty();
187+
assert_eq!("{}", e.to_string().as_slice());
188+
e.add(A);
189+
assert_eq!("{A}", e.to_string().as_slice());
190+
e.add(C);
191+
assert_eq!("{A, C}", e.to_string().as_slice());
192+
}
193+
168194
///////////////////////////////////////////////////////////////////////////
169195
// intersect
170196

branches/try2/src/libcollections/vec.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use core::prelude::*;
1616

17-
use alloc::heap::{allocate, reallocate, deallocate};
17+
use alloc::heap::{EMPTY, allocate, reallocate, deallocate};
1818
use core::cmp::max;
1919
use core::default::Default;
2020
use core::fmt;
@@ -28,10 +28,6 @@ use {Mutable, MutableSeq};
2828
use slice::{MutableOrdSlice, MutableSliceAllocating, CloneableVector};
2929
use slice::{Items, MutItems};
3030

31-
32-
#[doc(hidden)]
33-
pub static PTR_MARKER: u8 = 0;
34-
3531
/// An owned, growable vector.
3632
///
3733
/// # Examples
@@ -124,7 +120,7 @@ impl<T> Vec<T> {
124120
// non-null value which is fine since we never call deallocate on the ptr
125121
// if cap is 0. The reason for this is because the pointer of a slice
126122
// being NULL would break the null pointer optimization for enums.
127-
Vec { len: 0, cap: 0, ptr: &PTR_MARKER as *const _ as *mut T }
123+
Vec { len: 0, cap: 0, ptr: EMPTY as *mut T }
128124
}
129125

130126
/// Constructs a new, empty `Vec` with the specified capacity.
@@ -157,7 +153,7 @@ impl<T> Vec<T> {
157153
#[inline]
158154
pub fn with_capacity(capacity: uint) -> Vec<T> {
159155
if mem::size_of::<T>() == 0 {
160-
Vec { len: 0, cap: uint::MAX, ptr: &PTR_MARKER as *const _ as *mut T }
156+
Vec { len: 0, cap: uint::MAX, ptr: EMPTY as *mut T }
161157
} else if capacity == 0 {
162158
Vec::new()
163159
} else {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ lets_do_this! {
276276
BeginUnwindLangItem, "begin_unwind", begin_unwind;
277277

278278
ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
279-
ClosureExchangeMallocFnLangItem, "closure_exchange_malloc", closure_exchange_malloc_fn;
280279
ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn;
281280
MallocFnLangItem, "malloc", malloc_fn;
282281
FreeFnLangItem, "free", free_fn;

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,10 @@ pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
382382
Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
383383
}
384384

385-
pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
386-
t: ty::t, alloc_fn: LangItem)
387-
-> Result<'blk, 'tcx> {
385+
pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: ty::t) -> Result<'blk, 'tcx> {
388386
let _icx = push_ctxt("malloc_raw_dyn_proc");
389387
let ccx = bcx.ccx();
390388

391-
let langcall = require_alloc_fn(bcx, t, alloc_fn);
392-
393389
// Grab the TypeRef type of ptr_ty.
394390
let ptr_ty = ty::mk_uniq(bcx.tcx(), t);
395391
let ptr_llty = type_of(ccx, ptr_ty);
@@ -398,18 +394,15 @@ pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
398394
let size = llsize_of(bcx.ccx(), llty);
399395
let llalign = C_uint(ccx, llalign_of_min(bcx.ccx(), llty) as uint);
400396

401-
// Allocate space:
402-
let drop_glue = glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t));
403-
let r = callee::trans_lang_call(
404-
bcx,
405-
langcall,
406-
[
407-
PointerCast(bcx, drop_glue, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to()),
408-
size,
409-
llalign
410-
],
411-
None);
412-
Result::new(r.bcx, PointerCast(r.bcx, r.val, ptr_llty))
397+
// Allocate space and store the destructor pointer:
398+
let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, ptr_llty, t, size, llalign);
399+
let dtor_ptr = GEPi(bcx, llbox, [0u, abi::box_field_drop_glue]);
400+
let drop_glue_field_ty = type_of(ccx, ty::mk_nil_ptr(bcx.tcx()));
401+
let drop_glue = PointerCast(bcx, glue::get_drop_glue(ccx, ty::mk_uniq(bcx.tcx(), t)),
402+
drop_glue_field_ty);
403+
Store(bcx, drop_glue, dtor_ptr);
404+
405+
Result::new(bcx, llbox)
413406
}
414407

415408

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use driver::config::FullDebugInfo;
1515
use llvm::ValueRef;
1616
use middle::def;
1717
use middle::freevars;
18-
use middle::lang_items::ClosureExchangeMallocFnLangItem;
1918
use middle::trans::adt;
2019
use middle::trans::base::*;
2120
use middle::trans::build::*;
@@ -146,7 +145,7 @@ fn allocate_cbox<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
146145
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
147146
match store {
148147
ty::UniqTraitStore => {
149-
malloc_raw_dyn_proc(bcx, cbox_ty, ClosureExchangeMallocFnLangItem)
148+
malloc_raw_dyn_proc(bcx, cbox_ty)
150149
}
151150
ty::RegionTraitStore(..) => {
152151
let llbox = alloc_ty(bcx, cbox_ty, "__closure");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t)
519519
let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
520520
let env = PointerCast(bcx, env, env_ptr_ty);
521521
with_cond(bcx, IsNotNull(bcx, env), |bcx| {
522-
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_tydesc]);
522+
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_drop_glue]);
523523
let dtor = Load(bcx, dtor_ptr);
524524
Call(bcx, dtor, [PointerCast(bcx, box_cell_v, Type::i8p(bcx.ccx()))], None);
525525
bcx

branches/try2/src/librustc_back/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
pub static box_field_refcnt: uint = 0u;
12-
pub static box_field_tydesc: uint = 1u;
12+
pub static box_field_drop_glue: uint = 1u;
1313
pub static box_field_body: uint = 4u;
1414

1515
pub static tydesc_field_visit_glue: uint = 3u;

branches/try2/src/libsyntax/owned_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::fmt;
1212
use std::default::Default;
1313
use std::hash;
1414
use std::{mem, raw, ptr, slice, vec};
15+
use std::rt::heap::EMPTY;
1516
use serialize::{Encodable, Decodable, Encoder, Decoder};
1617

1718
/// A non-growable owned slice. This would preferably become `~[T]`
@@ -81,10 +82,9 @@ impl<T> OwnedSlice<T> {
8182
}
8283

8384
pub fn as_slice<'a>(&'a self) -> &'a [T] {
84-
static PTR_MARKER: u8 = 0;
8585
let ptr = if self.data.is_null() {
8686
// length zero, i.e. this will never be read as a T.
87-
&PTR_MARKER as *const u8 as *const T
87+
EMPTY as *const T
8888
} else {
8989
self.data as *const T
9090
};

branches/try2/src/libsyntax/util/interner.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::cell::RefCell;
1919
use std::cmp::Equiv;
2020
use std::fmt;
2121
use std::hash::Hash;
22-
use std::mem;
2322
use std::rc::Rc;
2423

2524
pub struct Interner<T> {
@@ -192,16 +191,6 @@ impl StrInterner {
192191
(*self.vect.borrow().get(idx.uint())).clone()
193192
}
194193

195-
/// Returns this string with lifetime tied to the interner. Since
196-
/// strings may never be removed from the interner, this is safe.
197-
pub fn get_ref<'a>(&'a self, idx: Name) -> &'a str {
198-
let vect = self.vect.borrow();
199-
let s: &str = vect.get(idx.uint()).as_slice();
200-
unsafe {
201-
mem::transmute(s)
202-
}
203-
}
204-
205194
pub fn len(&self) -> uint {
206195
self.vect.borrow().len()
207196
}

branches/try2/src/snapshots.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
S 2014-09-10 6faa4f3
22
winnt-x86_64 939eb546469cb936441cff3b6f2478f562f77c46
33
winnt-i386 cfe4f8b519bb9d62588f9310a8f94bc919d5423b
4-
linux-x86_64 72c92895fa9a1dba7880073f2b2b5d0e3e1a2ab6
4+
linux-x86_64 40e2ab1b67d0a2859f7da15e13bfd2748b50f0c7
55
linux-i386 6f5464c9ab191d93bfea0894ca7c6f90c3506f2b
66
freebsd-x86_64 648f35800ba98f1121d418b6d0c13c63b7a8951b
77
macos-i386 545fc45a0071142714639c6be377e6d308c3a4e1
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::io;
12+
use std::vec;
13+
14+
pub struct Container<'a> {
15+
reader: &'a mut Reader //~ ERROR explicit lifetime bound required
16+
}
17+
18+
impl<'a> Container<'a> {
19+
pub fn wrap<'s>(reader: &'s mut Reader) -> Container<'s> {
20+
Container { reader: reader }
21+
}
22+
23+
pub fn read_to(&mut self, vec: &mut [u8]) {
24+
self.reader.read(vec);
25+
}
26+
}
27+
28+
pub fn for_stdin<'a>() -> Container<'a> {
29+
let mut r = io::stdin();
30+
Container::wrap(&mut r as &mut Reader)
31+
}
32+
33+
fn main() {
34+
let mut c = for_stdin();
35+
let mut v = vec::Vec::from_elem(10, 0u8);
36+
c.read_to(v.as_mut_slice());
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn blah() -> int { //~ ERROR not all control paths return a value
12+
1i
13+
14+
; //~ NOTE consider removing this semicolon:
15+
}
16+
17+
fn main() { }

0 commit comments

Comments
 (0)