Skip to content

Commit 11323d4

Browse files
committed
---
yaml --- r: 44374 b: refs/heads/master c: f2a8a71 h: refs/heads/master v: v3
1 parent a7f7145 commit 11323d4

File tree

6 files changed

+97
-75
lines changed

6 files changed

+97
-75
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: f9c7ba009b51f39629d74ac67781c034643e74e8
2+
refs/heads/master: f2a8a712669911eb36166c35199fe18ce19ed7e9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
407407
// variant or we wouldn't have gotten here -- the constant
408408
// checker forbids paths that don't map to C-like enum
409409
// variants.
410+
if ty::enum_is_univariant(cx.tcx, enum_did) {
411+
// Univariants have no discriminant field.
412+
C_struct(~[])
413+
} else {
410414
let lldiscrim = base::get_discrim_val(cx, e.span,
411415
enum_did,
412416
variant_did);
@@ -418,6 +422,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
418422
let padding = C_null(T_array(T_i8(), size));
419423
C_struct(~[lldiscrim, padding])
420424
}
425+
}
421426
Some(ast::def_struct(_)) => {
422427
let ety = ty::expr_ty(cx.tcx, e);
423428
let llty = type_of::type_of(cx, ety);
@@ -442,14 +447,14 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
442447
}
443448
Some(ast::def_variant(tid, vid)) => {
444449
let ety = ty::expr_ty(cx.tcx, e);
445-
let degen = ty::enum_is_univariant(cx.tcx, tid);
450+
let univar = ty::enum_is_univariant(cx.tcx, tid);
446451
let size = machine::static_size_of_enum(cx, ety);
447452

448453
let discrim = base::get_discrim_val(cx, e.span, tid, vid);
449454
let c_args = C_struct(args.map(|a| const_expr(cx, *a)));
450455

451456
// FIXME (#1645): enum body alignment is generaly wrong.
452-
if !degen {
457+
if !univar {
453458
// Pad out the data to the size of its type_of;
454459
// this is necessary if the enum is contained
455460
// within an aggregate (tuple, struct, vector) so
@@ -464,8 +469,6 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
464469
// without affecting its internal alignment or
465470
// changing the alignment of the enum.
466471
C_struct(~[discrim, C_packed_struct(~[c_args]), padding])
467-
} else if size == 0 {
468-
C_struct(~[discrim])
469472
} else {
470473
C_struct(~[c_args])
471474
}

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,15 @@ fn trans_def_dps_unadjusted(bcx: block, ref_expr: @ast::expr,
674674
// N-ary variant.
675675
let fn_data = callee::trans_fn_ref(bcx, vid, ref_expr.id);
676676
return fn_data_to_datum(bcx, vid, fn_data, lldest);
677-
} else {
677+
} else if !ty::enum_is_univariant(ccx.tcx, tid) {
678678
// Nullary variant.
679679
let lldiscrimptr = GEPi(bcx, lldest, [0u, 0u]);
680680
let lldiscrim = C_int(bcx.ccx(), variant_info.disr_val);
681681
Store(bcx, lldiscrim, lldiscrimptr);
682682
return bcx;
683+
} else {
684+
// Nullary univariant.
685+
return bcx;
683686
}
684687
}
685688
ast::def_struct(*) => {
@@ -1591,10 +1594,22 @@ fn trans_imm_cast(bcx: block, expr: @ast::expr,
15911594
{in: cast_enum, out: cast_integral} |
15921595
{in: cast_enum, out: cast_float} => {
15931596
let bcx = bcx;
1594-
let llenumty = T_opaque_enum_ptr(ccx);
1595-
let av_enum = PointerCast(bcx, llexpr, llenumty);
1596-
let lldiscrim_a_ptr = GEPi(bcx, av_enum, [0u, 0u]);
1597-
let lldiscrim_a = Load(bcx, lldiscrim_a_ptr);
1597+
let in_tid = match ty::get(t_in).sty {
1598+
ty::ty_enum(did, _) => did,
1599+
_ => ccx.sess.bug(~"enum cast source is not enum")
1600+
};
1601+
let variants = ty::enum_variants(ccx.tcx, in_tid);
1602+
let lldiscrim_a = if variants.len() == 1 {
1603+
// Univariants don't have a discriminant field,
1604+
// because there's only one value it could have:
1605+
C_integral(T_enum_discrim(ccx),
1606+
variants[0].disr_val as u64, True)
1607+
} else {
1608+
let llenumty = T_opaque_enum_ptr(ccx);
1609+
let av_enum = PointerCast(bcx, llexpr, llenumty);
1610+
let lldiscrim_a_ptr = GEPi(bcx, av_enum, [0u, 0u]);
1611+
Load(bcx, lldiscrim_a_ptr)
1612+
};
15981613
match k_out {
15991614
cast_integral => int_cast(bcx, ll_t_out,
16001615
val_ty(lldiscrim_a),

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,11 @@ pub fn fill_type_of_enum(cx: @crate_ctxt, did: ast::def_id, t: ty::t,
242242
debug!("type_of_enum %?: %?", t, ty::get(t));
243243

244244
let lltys = {
245-
let degen = ty::enum_is_univariant(cx.tcx, did);
245+
let univar = ty::enum_is_univariant(cx.tcx, did);
246246
let size = machine::static_size_of_enum(cx, t);
247-
if !degen {
247+
if !univar {
248248
~[T_enum_discrim(cx), T_array(T_i8(), size)]
249249
}
250-
else if size == 0u {
251-
~[T_enum_discrim(cx)]
252-
}
253250
else {
254251
~[T_array(T_i8(), size)]
255252
}

trunk/src/libstd/treemap.rs

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -576,62 +576,63 @@ pure fn each_reverse<K: Ord, V>(node: &r/Option<~TreeNode<K, V>>,
576576
}
577577

578578
// Remove left horizontal link by rotating right
579-
fn skew<K: Ord, V>(node: &mut ~TreeNode<K, V>) {
579+
fn skew<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
580580
if node.left.map_default(false, |x| x.level == node.level) {
581581
let mut save = node.left.swap_unwrap();
582582
node.left <-> save.right; // save.right now None
583-
*node <-> save;
584-
node.right = Some(save);
583+
save.right = Some(node);
584+
save
585+
} else {
586+
node // nothing to do
585587
}
586588
}
587589

588590
// Remove dual horizontal link by rotating left and increasing level of
589591
// the parent
590-
fn split<K: Ord, V>(node: &mut ~TreeNode<K, V>) {
592+
fn split<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
591593
if node.right.map_default(false,
592594
|x| x.right.map_default(false, |y| y.level == node.level)) {
593595
let mut save = node.right.swap_unwrap();
594596
node.right <-> save.left; // save.left now None
597+
save.left = Some(node);
595598
save.level += 1;
596-
*node <-> save;
597-
node.left = Some(save);
599+
save
600+
} else {
601+
node // nothing to do
598602
}
599603
}
600604

601605
fn insert<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: K,
602606
value: V) -> bool {
603-
match *node {
604-
Some(ref mut save) => {
607+
if node.is_none() {
608+
*node = Some(~TreeNode::new(key, value));
609+
true
610+
} else {
611+
let mut save = node.swap_unwrap();
605612
if key < save.key {
606613
let inserted = insert(&mut save.left, key, value);
607-
skew(save);
608-
split(save);
614+
*node = Some(split(skew(save))); // re-balance, if necessary
609615
inserted
610616
} else if save.key < key {
611617
let inserted = insert(&mut save.right, key, value);
612-
skew(save);
613-
split(save);
618+
*node = Some(split(skew(save))); // re-balance, if necessary
614619
inserted
615620
} else {
616621
save.key = key;
617622
save.value = value;
623+
*node = Some(save);
618624
false
619625
}
620-
}
621-
None => {
622-
*node = Some(~TreeNode::new(key, value));
623-
true
624-
}
625626
}
626627
}
627628

628629
fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
629-
fn heir_swap<K: Ord, V>(node: &mut ~TreeNode<K, V>,
630+
fn heir_swap<K: Ord, V>(node: &mut TreeNode<K, V>,
630631
child: &mut Option<~TreeNode<K, V>>) {
631632
// *could* be done without recursion, but it won't borrow check
632633
do child.mutate |mut child| {
633634
if child.right.is_some() {
634-
heir_swap(node, &mut child.right);
635+
heir_swap(&mut *node, &mut child.right);
635636
} else {
636637
node.key <-> child.key;
637638
node.value <-> child.value;
@@ -640,15 +641,15 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
640641
}
641642
}
642643

643-
match *node {
644-
None => {
644+
if node.is_none() {
645645
return false // bottom of tree
646-
}
647-
Some(ref mut save) => {
648-
let (removed, this) = if save.key < *key {
649-
(remove(&mut save.right, key), false)
646+
} else {
647+
let mut save = node.swap_unwrap();
648+
649+
let removed = if save.key < *key {
650+
remove(&mut save.right, key)
650651
} else if *key < save.key {
651-
(remove(&mut save.left, key), false)
652+
remove(&mut save.left, key)
652653
} else {
653654
if save.left.is_some() {
654655
if save.right.is_some() {
@@ -662,22 +663,16 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
662663
save.left = Some(left);
663664
remove(&mut save.left, key);
664665
} else {
665-
*save = save.left.swap_unwrap();
666+
save = save.left.swap_unwrap();
666667
}
667-
(true, false)
668668
} else if save.right.is_some() {
669-
*save = save.right.swap_unwrap();
670-
(true, false)
669+
save = save.right.swap_unwrap();
671670
} else {
672-
(true, true)
671+
return true // leaf
673672
}
673+
true
674674
};
675675

676-
if this {
677-
*node = None;
678-
return true;
679-
}
680-
681676
let left_level = save.left.map_default(0, |x| x.level);
682677
let right_level = save.right.map_default(0, |x| x.level);
683678

@@ -689,28 +684,19 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
689684
do save.right.mutate |mut x| { x.level = save.level; x }
690685
}
691686

692-
skew(save);
693-
694-
match save.right {
695-
Some(ref mut right) => {
696-
skew(right);
697-
match right.right {
698-
Some(ref mut x) => { skew(x) },
699-
None => ()
700-
}
701-
}
702-
None => ()
703-
}
687+
save = skew(save);
704688

705-
split(save);
706-
match save.right {
707-
Some(ref mut x) => { split(x) },
708-
None => ()
689+
do save.right.mutate |mut right| {
690+
right = skew(right);
691+
right.right.mutate(skew);
692+
right
709693
}
694+
save = split(save);
695+
save.right.mutate(split);
710696
}
711697

698+
*node = Some(save);
712699
removed
713-
}
714700
}
715701
}
716702

trunk/src/libsyntax/ext/source_util.rs

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

1111
use codemap;
12-
use codemap::{FileMap, Loc, Pos, span};
12+
use codemap::{FileMap, Loc, Pos, ExpandedFrom, span};
1313
use ext::base::*;
1414
use ext::base;
1515
use ext::build::{mk_base_vec_e, mk_uint, mk_u8, mk_base_str};
@@ -21,20 +21,39 @@ use core::result;
2121
use core::str;
2222
use core::vec;
2323

24+
fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo {
25+
let ExpandedFrom({call_site, _}) = *expn_info;
26+
match call_site.expn_info {
27+
Some(next_expn_info) => {
28+
let ExpandedFrom({callie: {name, _}, _}) = *next_expn_info;
29+
// Don't recurse into file using "include!"
30+
if name == ~"include" { return expn_info; }
31+
32+
topmost_expn_info(next_expn_info)
33+
},
34+
None => expn_info
35+
}
36+
}
37+
2438
/* line!(): expands to the current line number */
2539
pub fn expand_line(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
2640
-> base::MacResult {
2741
base::check_zero_tts(cx, sp, tts, "line!");
28-
let loc = cx.codemap().lookup_char_pos(sp.lo);
29-
base::MRExpr(mk_uint(cx, sp, loc.line))
42+
43+
let topmost = topmost_expn_info(cx.backtrace().get());
44+
let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
45+
46+
base::MRExpr(mk_uint(cx, topmost.call_site, loc.line))
3047
}
3148

3249
/* col!(): expands to the current column number */
3350
pub fn expand_col(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
3451
-> base::MacResult {
3552
base::check_zero_tts(cx, sp, tts, "col!");
36-
let loc = cx.codemap().lookup_char_pos(sp.lo);
37-
base::MRExpr(mk_uint(cx, sp, loc.col.to_uint()))
53+
54+
let topmost = topmost_expn_info(cx.backtrace().get());
55+
let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo);
56+
base::MRExpr(mk_uint(cx, topmost.call_site, loc.col.to_uint()))
3857
}
3958

4059
/* file!(): expands to the current filename */
@@ -43,9 +62,11 @@ pub fn expand_col(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
4362
pub fn expand_file(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
4463
-> base::MacResult {
4564
base::check_zero_tts(cx, sp, tts, "file!");
65+
66+
let topmost = topmost_expn_info(cx.backtrace().get());
4667
let Loc { file: @FileMap { name: filename, _ }, _ } =
47-
cx.codemap().lookup_char_pos(sp.lo);
48-
base::MRExpr(mk_base_str(cx, sp, filename))
68+
cx.codemap().lookup_char_pos(topmost.call_site.lo);
69+
base::MRExpr(mk_base_str(cx, topmost.call_site, filename))
4970
}
5071

5172
pub fn expand_stringify(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])

0 commit comments

Comments
 (0)