Skip to content

Commit 560f9e9

Browse files
committed
---
yaml --- r: 42391 b: refs/heads/master c: e563722 h: refs/heads/master i: 42389: 39b9cab 42387: 3da7491 42383: e1bff77 v: v3
1 parent 9f4f664 commit 560f9e9

27 files changed

+399
-123
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3b8f1fa2b6369c40cdd3d3030e37ce3308d63caf
2+
refs/heads/master: e5637226d85f251c74911389f3ef21adde393d0a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
55
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650

trunk/src/libcargo/cargo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ pub fn try_parse_sources(filename: &Path,
495495
let c = io::read_whole_file_str(filename);
496496
match json::from_str(c.get()) {
497497
Ok(json::Object(j)) => {
498-
for j.each |k, v| {
498+
for j.each |&(k, v)| {
499499
sources.insert(copy *k, parse_source(*k, v));
500500
debug!("source: %s", *k);
501501
}

trunk/src/libcore/container.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pub trait Map<K, V>: Mutable {
2929
/// Return true if the map contains a value for the specified key
3030
pure fn contains_key(&self, key: &K) -> bool;
3131

32-
/// Visit all key-value pairs
33-
pure fn each(&self, f: fn(&K, &V) -> bool);
34-
3532
/// Visit all keys
3633
pure fn each_key(&self, f: fn(&K) -> bool);
3734

trunk/src/libcore/hashmap.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ pub mod linear {
235235
}
236236
}
237237
238+
impl <K: Hash IterBytes Eq, V> LinearMap<K, V>: BaseIter<(&K, &V)> {
239+
/// Visit all key-value pairs
240+
pure fn each(&self, blk: fn(&(&self/K, &self/V)) -> bool) {
241+
for uint::range(0, self.buckets.len()) |i| {
242+
let mut broke = false;
243+
do self.buckets[i].map |bucket| {
244+
if !blk(&(&bucket.key, &bucket.value)) {
245+
broke = true; // FIXME(#3064) just write "break;"
246+
}
247+
};
248+
if broke { break; }
249+
}
250+
}
251+
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
252+
}
253+
254+
238255
impl <K: Hash IterBytes Eq, V> LinearMap<K, V>: Container {
239256
/// Return the number of elements in the map
240257
pure fn len(&self) -> uint { self.size }
@@ -262,27 +279,14 @@ pub mod linear {
262279
}
263280
}
264281
265-
/// Visit all key-value pairs
266-
pure fn each(&self, blk: fn(k: &K, v: &V) -> bool) {
267-
for self.buckets.each |slot| {
268-
let mut broke = false;
269-
do slot.iter |bucket| {
270-
if !blk(&bucket.key, &bucket.value) {
271-
broke = true; // FIXME(#3064) just write "break;"
272-
}
273-
}
274-
if broke { break; }
275-
}
276-
}
277-
278282
/// Visit all keys
279283
pure fn each_key(&self, blk: fn(k: &K) -> bool) {
280-
self.each(|k, _| blk(k))
284+
self.each(|&(k, _)| blk(k))
281285
}
282286
283287
/// Visit all values
284288
pure fn each_value(&self, blk: fn(v: &V) -> bool) {
285-
self.each(|_, v| blk(v))
289+
self.each(|&(_, v)| blk(v))
286290
}
287291
288292
/// Return the value corresponding to the key in the map
@@ -388,7 +392,7 @@ pub mod linear {
388392
pure fn eq(&self, other: &LinearMap<K, V>) -> bool {
389393
if self.len() != other.len() { return false; }
390394

391-
for self.each |key, value| {
395+
for self.each |&(key, value)| {
392396
match other.find(key) {
393397
None => return false,
394398
Some(v) => if value != v { return false },
@@ -603,7 +607,7 @@ mod test_map {
603607
assert m.insert(i, i*2);
604608
}
605609
let mut observed = 0;
606-
for m.each |k, v| {
610+
for m.each |&(k, v)| {
607611
assert *v == *k * 2;
608612
observed |= (1 << *k);
609613
}

trunk/src/libcore/iter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ pub trait BaseIter<A> {
2727
pure fn size_hint(&self) -> Option<uint>;
2828
}
2929

30+
pub trait ReverseIter<A>: BaseIter<A> {
31+
pure fn each_reverse(&self, blk: fn(&A) -> bool);
32+
}
33+
3034
pub trait ExtendedIter<A> {
3135
pure fn eachi(&self, blk: fn(uint, v: &A) -> bool);
3236
pure fn all(&self, blk: fn(&A) -> bool) -> bool;

trunk/src/libcore/option.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
102102
}
103103
104104
#[inline(always)]
105-
pub pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
105+
pub pure fn map<T, U>(opt: &r/Option<T>, f: fn(x: &r/T) -> U) -> Option<U> {
106106
//! Maps a `some` value by reference from one type to another
107107
108108
match *opt { Some(ref x) => Some(f(x)), None => None }
@@ -193,8 +193,8 @@ pub pure fn get_or_default<T: Copy>(opt: Option<T>, def: T) -> T {
193193
}
194194
195195
#[inline(always)]
196-
pub pure fn map_default<T, U>(opt: &Option<T>, def: U,
197-
f: fn(x: &T) -> U) -> U {
196+
pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U,
197+
f: fn(&r/T) -> U) -> U {
198198
//! Applies a function to the contained value or returns a default
199199
200200
match *opt { None => move def, Some(ref t) => f(t) }
@@ -273,7 +273,7 @@ impl<T> Option<T> {
273273
274274
/// Maps a `some` value from one type to another by reference
275275
#[inline(always)]
276-
pure fn map<U>(&self, f: fn(x: &T) -> U) -> Option<U> { map(self, f) }
276+
pure fn map<U>(&self, f: fn(&self/T) -> U) -> Option<U> { map(self, f) }
277277
278278
/// As `map`, but consumes the option and gives `f` ownership to avoid
279279
/// copying.
@@ -284,7 +284,7 @@ impl<T> Option<T> {
284284
285285
/// Applies a function to the contained value or returns a default
286286
#[inline(always)]
287-
pure fn map_default<U>(&self, def: U, f: fn(x: &T) -> U) -> U {
287+
pure fn map_default<U>(&self, def: U, f: fn(&self/T) -> U) -> U {
288288
map_default(self, move def, f)
289289
}
290290

trunk/src/librustc/driver/driver.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,6 @@ pub fn build_session_options(+binary: ~str,
521521
} else {
522522
session::unknown_crate
523523
};
524-
let static = opt_present(matches, ~"static");
525-
let gc = opt_present(matches, ~"gc");
526-
527524
let parse_only = opt_present(matches, ~"parse-only");
528525
let no_trans = opt_present(matches, ~"no-trans");
529526
@@ -570,7 +567,6 @@ pub fn build_session_options(+binary: ~str,
570567
}
571568
}
572569
573-
let jit = opt_present(matches, ~"jit");
574570
let output_type =
575571
if parse_only || no_trans {
576572
link::output_type_none
@@ -584,8 +580,6 @@ pub fn build_session_options(+binary: ~str,
584580
} else if opt_present(matches, ~"emit-llvm") {
585581
link::output_type_bitcode
586582
} else { link::output_type_exe };
587-
let extra_debuginfo = opt_present(matches, ~"xg");
588-
let debuginfo = opt_present(matches, ~"g") || extra_debuginfo;
589583
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
590584
let sysroot_opt = sysroot_opt.map(|m| Path(*m));
591585
let target_opt = getopts::opt_maybe_str(matches, ~"target");
@@ -616,6 +610,12 @@ pub fn build_session_options(+binary: ~str,
616610
}
617611
} else { No }
618612
};
613+
let gc = debugging_opts & session::gc != 0;
614+
let jit = debugging_opts & session::jit != 0;
615+
let extra_debuginfo = debugging_opts & session::extra_debug_info != 0;
616+
let debuginfo = debugging_opts & session::debug_info != 0 ||
617+
extra_debuginfo;
618+
let static = debugging_opts & session::static != 0;
619619
let target =
620620
match target_opt {
621621
None => host_triple(),
@@ -714,14 +714,11 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
714714
environment", ~"SPEC"),
715715
optflag(~"", ~"emit-llvm",
716716
~"Produce an LLVM bitcode file"),
717-
optflag(~"g", ~"", ~"Produce debug info (experimental)"),
718-
optflag(~"", ~"gc", ~"Garbage collect shared data (experimental)"),
719717
optflag(~"h", ~"help",~"Display this message"),
720718
optmulti(~"L", ~"", ~"Add a directory to the library search path",
721719
~"PATH"),
722720
optflag(~"", ~"lib", ~"Compile a library crate"),
723721
optflag(~"", ~"ls", ~"List the symbols defined by a library crate"),
724-
optflag(~"", ~"jit", ~"Execute using JIT (experimental)"),
725722
optflag(~"", ~"no-trans",
726723
~"Run all passes except translation; no output"),
727724
optflag(~"O", ~"", ~"Equivalent to --opt-level=2"),
@@ -741,13 +738,9 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
741738
or identified (fully parenthesized,
742739
AST nodes and blocks with IDs)", ~"TYPE"),
743740
optflag(~"S", ~"", ~"Compile only; do not assemble or link"),
744-
optflag(~"", ~"xg", ~"Extra debugging info (experimental)"),
745741
optflag(~"", ~"save-temps",
746742
~"Write intermediate files (.bc, .opt.bc, .o)
747743
in addition to normal output"),
748-
optflag(~"", ~"static",
749-
~"Use or produce static libraries or binaries
750-
(experimental)"),
751744
optopt(~"", ~"sysroot",
752745
~"Override the system root", ~"PATH"),
753746
optflag(~"", ~"test", ~"Build a test harness"),

trunk/src/librustc/driver/session.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ pub const count_type_sizes: uint = 1 << 14;
7575
pub const meta_stats: uint = 1 << 15;
7676
pub const no_opt: uint = 1 << 16;
7777
pub const no_monomorphic_collapse: uint = 1 << 17;
78+
pub const gc: uint = 1 << 18;
79+
pub const jit: uint = 1 << 19;
80+
pub const debug_info: uint = 1 << 20;
81+
pub const extra_debug_info: uint = 1 << 21;
82+
pub const static: uint = 1 << 22;
7883

7984
pub fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
8085
~[(~"verbose", ~"in general, enable more debug printouts", verbose),
@@ -102,6 +107,13 @@ pub fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
102107
(~"no-opt", ~"do not optimize, even if -O is passed", no_opt),
103108
(~"no-monomorphic-collapse", ~"do not collapse template instantiations",
104109
no_monomorphic_collapse),
110+
(~"gc", ~"Garbage collect shared data (experimental)", gc),
111+
(~"jit", ~"Execute using JIT (experimental)", jit),
112+
(~"extra-debug-info", ~"Extra debugging info (experimental)",
113+
extra_debug_info),
114+
(~"debug-info", ~"Produce debug info (experimental)", debug_info),
115+
(~"static", ~"Use or produce static libraries or binaries " +
116+
"(experimental)", static)
105117
]
106118
}
107119

trunk/src/librustc/lib/llvm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ pub extern mod llvm {
382382
pub unsafe fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
383383

384384
/* Operations on Users */
385+
pub unsafe fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
385386
pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
386387
pub unsafe fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
387388

trunk/src/librustc/middle/trans/consts.rs

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ pub fn const_vec(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr])
7373
let vec_ty = ty::expr_ty(cx.tcx, e);
7474
let unit_ty = ty::sequence_element_type(cx.tcx, vec_ty);
7575
let llunitty = type_of::type_of(cx, unit_ty);
76-
let v = C_array(llunitty, es.map(|e| const_expr(cx, *e)));
7776
let unit_sz = machine::llsize_of(cx, llunitty);
7877
let sz = llvm::LLVMConstMul(C_uint(cx, es.len()), unit_sz);
78+
let vs = es.map(|e| const_expr(cx, *e));
79+
// If the vector contains enums, an LLVM array won't work.
80+
let v = if vs.any(|vi| val_ty(*vi) != llunitty) {
81+
C_struct(vs)
82+
} else {
83+
C_array(llunitty, vs)
84+
};
7985
return (v, sz, llunitty);
8086
}
8187
}
@@ -279,15 +285,17 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
279285
// call. Despite that being "a const", it's not the kind of
280286
// const you can ask for the integer-value of, evidently. This
281287
// might be an LLVM bug, not sure. In any case, to work around
282-
// this we drop down to the array-type level here and just ask
283-
// how long the array-type itself is, ignoring the length we
284-
// pulled out of the slice. This in turn only works because we
285-
// picked out the original globalvar via const_deref and so can
286-
// recover the array-size of the underlying array, and all this
287-
// will hold together exactly as long as we _don't_ support
288-
// const sub-slices (that is, slices that represent something
289-
// other than a whole array). At that point we'll have more and
290-
// uglier work to do here, but for now this should work.
288+
// this we obtain the initializer and count how many elements it
289+
// has, ignoring the length we pulled out of the slice. (Note
290+
// that the initializer might be a struct rather than an array,
291+
// if enums are involved.) This only works because we picked out
292+
// the original globalvar via const_deref and so can recover the
293+
// array-size of the underlying array (or the element count of
294+
// the underlying struct), and all this will hold together
295+
// exactly as long as we _don't_ support const sub-slices (that
296+
// is, slices that represent something other than a whole
297+
// array). At that point we'll have more and uglier work to do
298+
// here, but for now this should work.
291299
//
292300
// In the future, what we should be doing here is the
293301
// moral equivalent of:
@@ -299,7 +307,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
299307
// not want to consider sizeof() a constant expression
300308
// we can get the value (as a number) out of.
301309

302-
let len = llvm::LLVMGetArrayLength(val_ty(arr)) as u64;
310+
let len = llvm::LLVMGetNumOperands(arr) as u64;
303311
let len = match ty::get(bt).sty {
304312
ty::ty_estr(*) => {assert len > 0; len - 1},
305313
_ => len
@@ -346,10 +354,8 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
346354
}
347355
ast::expr_addr_of(ast::m_imm, sub) => {
348356
let cv = const_expr(cx, sub);
349-
let subty = ty::expr_ty(cx.tcx, sub),
350-
llty = type_of::type_of(cx, subty);
351357
let gv = do str::as_c_str("const") |name| {
352-
llvm::LLVMAddGlobal(cx.llmod, llty, name)
358+
llvm::LLVMAddGlobal(cx.llmod, val_ty(cv), name)
353359
};
354360
llvm::LLVMSetInitializer(gv, cv);
355361
llvm::LLVMSetGlobalConstant(gv, True);
@@ -377,8 +383,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
377383
}
378384
})
379385
};
380-
let llty = type_of::type_of(cx, ety);
381-
C_named_struct(llty, [C_struct(cs)])
386+
C_struct([C_struct(cs)])
382387
}
383388
ast::expr_vec(es, ast::m_imm) => {
384389
let (v, _, _) = const_vec(cx, e, es);
@@ -434,7 +439,13 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
434439
let lldiscrim = base::get_discrim_val(cx, e.span,
435440
enum_did,
436441
variant_did);
437-
C_struct(~[lldiscrim])
442+
// However, we still have to pad it out to the
443+
// size of the full enum; see the expr_call case,
444+
// below.
445+
let ety = ty::expr_ty(cx.tcx, e);
446+
let size = machine::static_size_of_enum(cx, ety);
447+
let padding = C_null(T_array(T_i8(), size));
448+
C_struct(~[lldiscrim, padding])
438449
}
439450
Some(ast::def_struct(_)) => {
440451
let ety = ty::expr_ty(cx.tcx, e);
@@ -450,14 +461,12 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
450461
ast::expr_call(callee, args, _) => {
451462
match cx.tcx.def_map.find(&callee.id) {
452463
Some(ast::def_struct(def_id)) => {
453-
let ety = ty::expr_ty(cx.tcx, e);
454-
let llty = type_of::type_of(cx, ety);
455464
let llstructbody =
456465
C_struct(args.map(|a| const_expr(cx, *a)));
457466
if ty::ty_dtor(cx.tcx, def_id).is_present() {
458-
C_named_struct(llty, ~[ llstructbody, C_u8(0) ])
467+
C_struct(~[ llstructbody, C_u8(0) ])
459468
} else {
460-
C_named_struct(llty, ~[ llstructbody ])
469+
C_struct(~[ llstructbody ])
461470
}
462471
}
463472
Some(ast::def_variant(tid, vid)) => {
@@ -470,7 +479,20 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
470479

471480
// FIXME (#1645): enum body alignment is generaly wrong.
472481
if !degen {
473-
C_packed_struct(~[discrim, c_args])
482+
// Pad out the data to the size of its type_of;
483+
// this is necessary if the enum is contained
484+
// within an aggregate (tuple, struct, vector) so
485+
// that the next element is at the right offset.
486+
let actual_size =
487+
machine::llsize_of_real(cx, llvm::LLVMTypeOf(c_args));
488+
let padding =
489+
C_null(T_array(T_i8(), size - actual_size));
490+
// A packed_struct has an alignment of 1; thus,
491+
// wrapping one around c_args will misalign it the
492+
// same way we normally misalign enum bodies
493+
// without affecting its internal alignment or
494+
// changing the alignment of the enum.
495+
C_struct(~[discrim, C_packed_struct(~[c_args]), padding])
474496
} else if size == 0 {
475497
C_struct(~[discrim])
476498
} else {

0 commit comments

Comments
 (0)