Skip to content

Commit 5859201

Browse files
committed
---
yaml --- r: 144342 b: refs/heads/try2 c: 3479436 h: refs/heads/master v: v3
1 parent 4001619 commit 5859201

30 files changed

+909
-122
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: f9979247d1d69c1a8fb7cd1d2829a629baf9d965
8+
refs/heads/try2: 347943640e9ea1db18d5a7401c0b50a44544599d
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/mk/rt.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ endif
6363
endif
6464

6565
RUNTIME_CXXS_$(1)_$(2) := \
66+
rt/sync/timer.cpp \
6667
rt/sync/lock_and_signal.cpp \
6768
rt/sync/rust_thread.cpp \
6869
rt/rust_builtin.cpp \
@@ -71,9 +72,13 @@ RUNTIME_CXXS_$(1)_$(2) := \
7172
rt/rust_upcall.cpp \
7273
rt/rust_uv.cpp \
7374
rt/rust_crate_map.cpp \
75+
rt/rust_gc_metadata.cpp \
76+
rt/rust_util.cpp \
7477
rt/rust_log.cpp \
78+
rt/rust_exchange_alloc.cpp \
7579
rt/isaac/randport.cpp \
7680
rt/miniz.cpp \
81+
rt/rust_abi.cpp \
7782
rt/memory_region.cpp \
7883
rt/boxed_region.cpp \
7984
rt/arch/$$(HOST_$(1))/context.cpp \

branches/try2/src/libextra/time.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ pub struct Tm {
121121
}
122122

123123
pub fn empty_tm() -> Tm {
124-
// 64 is the max size of the timezone buffer allocated on windows
125-
// in rust_localtime. In glibc the max timezone size is supposedly 3.
126-
let zone = str::with_capacity(64);
127124
Tm {
128125
tm_sec: 0_i32,
129126
tm_min: 0_i32,
@@ -135,7 +132,7 @@ pub fn empty_tm() -> Tm {
135132
tm_yday: 0_i32,
136133
tm_isdst: 0_i32,
137134
tm_gmtoff: 0_i32,
138-
tm_zone: zone,
135+
tm_zone: ~"",
139136
tm_nsec: 0_i32,
140137
}
141138
}

branches/try2/src/libextra/uuid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ mod bench {
787787
pub fn parse_str(bh: &mut BenchHarness) {
788788
let s = "urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4";
789789
do bh.iter {
790-
let u = Uuid::parse_string(s);
790+
Uuid::parse_string(s);
791791
}
792792
}
793793
}

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

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ use middle::trans::type_of;
2626
use middle::trans::type_use;
2727
use middle::trans::intrinsic;
2828
use middle::ty;
29+
use middle::ty::{FnSig};
2930
use middle::typeck;
3031
use util::ppaux::{Repr,ty_to_str};
3132

3233
use syntax::ast;
3334
use syntax::ast_map;
3435
use syntax::ast_map::path_name;
3536
use syntax::ast_util::local_def;
37+
use syntax::opt_vec;
38+
use syntax::abi::AbiSet;
3639

3740
pub fn monomorphic_fn(ccx: @mut CrateContext,
3841
fn_id: ast::def_id,
@@ -58,10 +61,17 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
5861
let _icx = push_ctxt("monomorphic_fn");
5962
let mut must_cast = false;
6063

64+
let do_normalize = |t: &ty::t| {
65+
match normalize_for_monomorphization(ccx.tcx, *t) {
66+
Some(t) => { must_cast = true; t }
67+
None => *t
68+
}
69+
};
70+
6171
let psubsts = @param_substs {
62-
tys: real_substs.tps.to_owned(),
72+
tys: real_substs.tps.map(|x| do_normalize(x)),
6373
vtables: vtables,
64-
self_ty: real_substs.self_ty.clone(),
74+
self_ty: real_substs.self_ty.map(|x| do_normalize(x)),
6575
self_vtables: self_vtables
6676
};
6777

@@ -295,6 +305,61 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
295305
(lldecl, must_cast)
296306
}
297307

308+
pub fn normalize_for_monomorphization(tcx: ty::ctxt,
309+
ty: ty::t) -> Option<ty::t> {
310+
// FIXME[mono] could do this recursively. is that worthwhile? (#2529)
311+
return match ty::get(ty).sty {
312+
ty::ty_box(*) => {
313+
Some(ty::mk_opaque_box(tcx))
314+
}
315+
ty::ty_bare_fn(_) => {
316+
Some(ty::mk_bare_fn(
317+
tcx,
318+
ty::BareFnTy {
319+
purity: ast::impure_fn,
320+
abis: AbiSet::Rust(),
321+
sig: FnSig {bound_lifetime_names: opt_vec::Empty,
322+
inputs: ~[],
323+
output: ty::mk_nil()}}))
324+
}
325+
ty::ty_closure(ref fty) => {
326+
Some(normalized_closure_ty(tcx, fty.sigil))
327+
}
328+
ty::ty_trait(_, _, ref store, _, _) => {
329+
let sigil = match *store {
330+
ty::UniqTraitStore => ast::OwnedSigil,
331+
ty::BoxTraitStore => ast::ManagedSigil,
332+
ty::RegionTraitStore(_) => ast::BorrowedSigil,
333+
};
334+
335+
// Traits have the same runtime representation as closures.
336+
Some(normalized_closure_ty(tcx, sigil))
337+
}
338+
ty::ty_ptr(_) => {
339+
Some(ty::mk_uint())
340+
}
341+
_ => {
342+
None
343+
}
344+
};
345+
346+
fn normalized_closure_ty(tcx: ty::ctxt,
347+
sigil: ast::Sigil) -> ty::t
348+
{
349+
ty::mk_closure(
350+
tcx,
351+
ty::ClosureTy {
352+
purity: ast::impure_fn,
353+
sigil: sigil,
354+
onceness: ast::Many,
355+
region: ty::re_static,
356+
bounds: ty::EmptyBuiltinBounds(),
357+
sig: ty::FnSig {bound_lifetime_names: opt_vec::Empty,
358+
inputs: ~[],
359+
output: ty::mk_nil()}})
360+
}
361+
}
362+
298363
pub fn make_mono_id(ccx: @mut CrateContext,
299364
item: ast::def_id,
300365
substs: &param_substs,

branches/try2/src/libstd/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ fn test_repr() {
590590
exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\"");
591591

592592
exact_test(&(@10), "@10");
593-
exact_test(&(@mut 10), "@mut 10");
593+
exact_test(&(@mut 10), "@10"); // FIXME: #4210: incorrect
594594
exact_test(&((@mut 10, 2)), "(@mut 10, 2)");
595595
exact_test(&(~10), "~10");
596596
exact_test(&(&10), "&10");

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ impl LocalHeap {
4040
#[fixed_stack_segment] #[inline(never)]
4141
pub fn new() -> LocalHeap {
4242
unsafe {
43+
// Don't need synchronization for the single-threaded local heap
44+
let synchronized = false as uintptr_t;
4345
// XXX: These usually come from the environment
4446
let detailed_leaks = false as uintptr_t;
4547
let poison_on_free = false as uintptr_t;
46-
let region = rust_new_memory_region(detailed_leaks, poison_on_free);
48+
let region = rust_new_memory_region(synchronized, detailed_leaks, poison_on_free);
4749
assert!(region.is_not_null());
4850
let boxed = rust_new_boxed_region(region, poison_on_free);
4951
assert!(boxed.is_not_null());
@@ -107,7 +109,8 @@ pub fn live_allocs() -> *raw::Box<()> {
107109

108110
extern {
109111
#[fast_ffi]
110-
fn rust_new_memory_region(detailed_leaks: uintptr_t,
112+
fn rust_new_memory_region(synchronized: uintptr_t,
113+
detailed_leaks: uintptr_t,
111114
poison_on_free: uintptr_t) -> *MemoryRegion;
112115
#[fast_ffi]
113116
fn rust_delete_memory_region(region: *MemoryRegion);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ pub fn init(argc: int, argv: **u8, crate_map: *u8) {
224224
args::init(argc, argv);
225225
env::init();
226226
logging::init(crate_map);
227+
rust_update_gc_metadata(crate_map);
227228
}
229+
230+
externfn!(fn rust_update_gc_metadata(crate_map: *u8));
228231
}
229232

230233
/// One-time runtime cleanup.

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use libc;
1414
use option::{Some, None};
1515
use os;
1616
use str::StrSlice;
17-
use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
1817

1918
#[cfg(target_os="macos")]
2019
use unstable::running_on_valgrind;
@@ -130,12 +129,24 @@ memory and partly incapable of presentation to others.",
130129
}
131130
}
132131

133-
static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
134-
135132
pub fn set_exit_status(code: int) {
136-
unsafe { EXIT_STATUS.store(code, SeqCst) }
133+
#[fixed_stack_segment]; #[inline(never)];
134+
unsafe {
135+
return rust_set_exit_status_newrt(code as libc::uintptr_t);
136+
}
137+
138+
extern {
139+
fn rust_set_exit_status_newrt(code: libc::uintptr_t);
140+
}
137141
}
138142

139143
pub fn get_exit_status() -> int {
140-
unsafe { EXIT_STATUS.load(SeqCst) }
144+
#[fixed_stack_segment]; #[inline(never)];
145+
unsafe {
146+
return rust_get_exit_status_newrt() as int;
147+
}
148+
149+
extern {
150+
fn rust_get_exit_status_newrt() -> libc::uintptr_t;
151+
}
141152
}

branches/try2/src/libstd/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ fn waitpid(pid: pid_t) -> int {
949949
#[cfg(test)]
950950
mod tests {
951951
use io;
952-
use libc::{c_int, uintptr_t};
952+
use libc::c_int;
953953
use option::{Option, None, Some};
954954
use os;
955955
use path::Path;

branches/try2/src/rt/memory_region.cpp

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

1111

12+
#include "sync/sync.h"
1213
#include "memory_region.h"
1314

1415
#if RUSTRT_TRACK_ALLOCATIONS >= 3
@@ -41,25 +42,30 @@ inline void memory_region::maybe_print_backtrace(const alloc_header *header) con
4142
# endif
4243
}
4344

44-
memory_region::memory_region(bool detailed_leaks,
45+
memory_region::memory_region(bool synchronized,
46+
bool detailed_leaks,
4547
bool poison_on_free) :
4648
_parent(NULL), _live_allocations(0),
4749
_detailed_leaks(detailed_leaks),
48-
_poison_on_free(poison_on_free) {
50+
_poison_on_free(poison_on_free),
51+
_synchronized(synchronized) {
4952
}
5053

5154
memory_region::memory_region(memory_region *parent) :
5255
_parent(parent), _live_allocations(0),
5356
_detailed_leaks(parent->_detailed_leaks),
54-
_poison_on_free(parent->_poison_on_free) {
57+
_poison_on_free(parent->_poison_on_free),
58+
_synchronized(parent->_synchronized) {
5559
}
5660

5761
void memory_region::add_alloc() {
58-
_live_allocations++;
62+
//_live_allocations++;
63+
sync::increment(_live_allocations);
5964
}
6065

6166
void memory_region::dec_alloc() {
62-
_live_allocations--;
67+
//_live_allocations--;
68+
sync::decrement(_live_allocations);
6369
}
6470

6571
void memory_region::free(void *mem) {
@@ -106,6 +112,7 @@ memory_region::realloc(void *mem, size_t orig_size) {
106112
# endif
107113

108114
# if RUSTRT_TRACK_ALLOCATIONS >= 2
115+
if (_synchronized) { _lock.lock(); }
109116
if (_allocation_list[newMem->index] != alloc) {
110117
printf("at index %d, found %p, expected %p\n",
111118
alloc->index, _allocation_list[alloc->index], alloc);
@@ -118,6 +125,7 @@ memory_region::realloc(void *mem, size_t orig_size) {
118125
// printf("realloc: stored %p at index %d, replacing %p\n",
119126
// newMem, index, mem);
120127
}
128+
if (_synchronized) { _lock.unlock(); }
121129
# endif
122130

123131
return get_data(newMem);
@@ -152,7 +160,9 @@ memory_region::malloc(size_t size, const char *tag) {
152160
}
153161

154162
memory_region::~memory_region() {
163+
if (_synchronized) { _lock.lock(); }
155164
if (_live_allocations == 0 && !_detailed_leaks) {
165+
if (_synchronized) { _lock.unlock(); }
156166
return;
157167
}
158168
char msg[128];
@@ -183,6 +193,7 @@ memory_region::~memory_region() {
183193
fprintf(stderr, "%s\n", msg);
184194
assert(false);
185195
}
196+
if (_synchronized) { _lock.unlock(); }
186197
}
187198

188199
void
@@ -193,6 +204,7 @@ memory_region::release_alloc(void *mem) {
193204
# endif
194205

195206
# if RUSTRT_TRACK_ALLOCATIONS >= 2
207+
if (_synchronized) { _lock.lock(); }
196208
if (((size_t) alloc->index) >= _allocation_list.size()) {
197209
printf("free: ptr 0x%" PRIxPTR " (%s) index %d is beyond allocation_list of size %zu\n",
198210
(uintptr_t) get_data(alloc), alloc->tag, alloc->index, _allocation_list.size());
@@ -210,6 +222,7 @@ memory_region::release_alloc(void *mem) {
210222
_allocation_list[alloc->index] = NULL;
211223
alloc->index = -1;
212224
}
225+
if (_synchronized) { _lock.unlock(); }
213226
# endif
214227

215228
dec_alloc();
@@ -223,7 +236,9 @@ memory_region::claim_alloc(void *mem) {
223236
# endif
224237

225238
# if RUSTRT_TRACK_ALLOCATIONS >= 2
239+
if (_synchronized) { _lock.lock(); }
226240
alloc->index = _allocation_list.append(alloc);
241+
if (_synchronized) { _lock.unlock(); }
227242
# endif
228243

229244
# if RUSTRT_TRACK_ALLOCATIONS >= 3

branches/try2/src/rt/memory_region.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class memory_region {
5959
array_list<alloc_header *> _allocation_list;
6060
const bool _detailed_leaks;
6161
const bool _poison_on_free;
62+
const bool _synchronized;
6263
lock_and_signal _lock;
6364

6465
void add_alloc();
@@ -76,7 +77,8 @@ class memory_region {
7677
memory_region& operator=(const memory_region& rhs);
7778

7879
public:
79-
memory_region(bool detailed_leaks, bool poison_on_free);
80+
memory_region(bool synchronized,
81+
bool detailed_leaks, bool poison_on_free);
8082
memory_region(memory_region *parent);
8183
void *malloc(size_t size, const char *tag);
8284
void *realloc(void *mem, size_t size);

0 commit comments

Comments
 (0)