Skip to content

Commit 07e8d30

Browse files
---
yaml --- r: 55215 b: refs/heads/snap-stage3 c: c64471a h: refs/heads/master i: 55213: cf3610d 55211: a0e34cf 55207: 3558224 55199: 07fde8f v: v3
1 parent 3323d16 commit 07e8d30

File tree

5 files changed

+40
-31
lines changed

5 files changed

+40
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 046a285a4b6ae54aa8f8a1d4b0e1e8d22478b4f6
4+
refs/heads/snap-stage3: c64471ab8624e256c745dfd5d5e89ea6aa9e8228
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/back/abi.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ pub static n_tydesc_fields: uint = 8u;
5757
pub static fn_field_code: uint = 0u;
5858
pub static fn_field_box: uint = 1u;
5959

60+
// The three fields of a trait object/trait instance: vtable, box, and type
61+
// description.
62+
pub static trt_field_vtable: uint = 0u;
63+
pub static trt_field_box: uint = 1u;
64+
// This field is only present in unique trait objects, so it comes last.
65+
pub static trt_field_tydesc: uint = 2u;
66+
6067
pub static vec_elt_fill: uint = 0u;
6168

6269
pub static vec_elt_alloc: uint = 1u;

branches/snap-stage3/src/librustc/middle/trans/glue.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,12 @@ pub fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
549549
closure::make_closure_glue(bcx, v0, t, drop_ty)
550550
}
551551
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
552-
let llbox = Load(bcx, GEPi(bcx, v0, [0u, 1u]));
552+
let llbox = Load(bcx, GEPi(bcx, v0, [0u, abi::trt_field_box]));
553553
decr_refcnt_maybe_free(bcx, llbox, ty::mk_opaque_box(ccx.tcx))
554554
}
555555
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
556-
let lluniquevalue = GEPi(bcx, v0, [0, 1]);
557-
let lltydesc = Load(bcx, GEPi(bcx, v0, [0, 2]));
556+
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
557+
let lltydesc = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_tydesc]));
558558
call_tydesc_glue_full(bcx, lluniquevalue, lltydesc,
559559
abi::tydesc_field_free_glue, None);
560560
bcx
@@ -613,13 +613,13 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
613613
closure::make_closure_glue(bcx, v, t, take_ty)
614614
}
615615
ty::ty_trait(_, _, ty::BoxTraitStore, _) => {
616-
let llbox = Load(bcx, GEPi(bcx, v, [0u, 1u]));
616+
let llbox = Load(bcx, GEPi(bcx, v, [0u, abi::trt_field_box]));
617617
incr_refcnt_of_boxed(bcx, llbox);
618618
bcx
619619
}
620620
ty::ty_trait(_, _, ty::UniqTraitStore, _) => {
621-
let llval = GEPi(bcx, v, [0, 1]);
622-
let lltydesc = Load(bcx, GEPi(bcx, v, [0, 2]));
621+
let llval = GEPi(bcx, v, [0, abi::trt_field_box]);
622+
let lltydesc = Load(bcx, GEPi(bcx, v, [0, abi::trt_field_tydesc]));
623623
call_tydesc_glue_full(bcx, llval, lltydesc,
624624
abi::tydesc_field_take_glue, None);
625625
bcx

branches/snap-stage3/src/librustc/middle/trans/meth.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,15 @@ pub fn trans_trait_callee_from_llval(bcx: block,
637637
val_str(bcx.ccx().tn, llpair));
638638
let llvtable = Load(bcx,
639639
PointerCast(bcx,
640-
GEPi(bcx, llpair, [0u, 0u]),
640+
GEPi(bcx, llpair,
641+
[0u, abi::trt_field_vtable]),
641642
T_ptr(T_ptr(T_vtable()))));
642643
643644
// Load the box from the @Trait pair and GEP over the box header if
644645
// necessary:
645646
let mut llself;
646647
debug!("(translating trait callee) loading second index from pair");
647-
let llbox = Load(bcx, GEPi(bcx, llpair, [0u, 1u]));
648+
let llbox = Load(bcx, GEPi(bcx, llpair, [0u, abi::trt_field_box]));
648649
649650
// Munge `llself` appropriately for the type of `self` in the method.
650651
let self_mode;
@@ -845,27 +846,30 @@ pub fn trans_trait_cast(bcx: block,
845846

846847
match store {
847848
ty::RegionTraitStore(_) | ty::BoxTraitStore => {
848-
let mut llboxdest = GEPi(bcx, lldest, [0u, 1u]);
849-
// Just store the pointer into the pair.
849+
let mut llboxdest = GEPi(bcx, lldest, [0u, abi::trt_field_box]);
850+
// Just store the pointer into the pair. (Region/borrowed
851+
// and boxed trait objects are represented as pairs, and
852+
// have no type descriptor field.)
850853
llboxdest = PointerCast(bcx,
851854
llboxdest,
852855
T_ptr(type_of(bcx.ccx(), v_ty)));
853856
bcx = expr::trans_into(bcx, val, SaveIn(llboxdest));
854857
}
855858
ty::UniqTraitStore => {
856-
// Translate the uniquely-owned value into the second element of
857-
// the triple. (The first element is the vtable.)
858-
let mut llvaldest = GEPi(bcx, lldest, [0, 1]);
859+
// Translate the uniquely-owned value in the
860+
// triple. (Unique trait objects are represented as
861+
// triples.)
862+
let mut llvaldest = GEPi(bcx, lldest, [0, abi::trt_field_box]);
859863
llvaldest = PointerCast(bcx,
860864
llvaldest,
861865
T_ptr(type_of(bcx.ccx(), v_ty)));
862866
bcx = expr::trans_into(bcx, val, SaveIn(llvaldest));
863867

864-
// Get the type descriptor of the wrapped value and store it into
865-
// the third element of the triple as well.
868+
// Get the type descriptor of the wrapped value and store
869+
// it in the triple as well.
866870
let tydesc = get_tydesc(bcx.ccx(), v_ty);
867871
glue::lazily_emit_all_tydesc_glue(bcx.ccx(), tydesc);
868-
let lltydescdest = GEPi(bcx, lldest, [0, 2]);
872+
let lltydescdest = GEPi(bcx, lldest, [0, abi::trt_field_tydesc]);
869873
Store(bcx, tydesc.tydesc, lltydescdest);
870874
}
871875
}
@@ -875,7 +879,7 @@ pub fn trans_trait_cast(bcx: block,
875879
let orig = resolve_vtable_in_fn_ctxt(bcx.fcx, orig);
876880
let vtable = get_vtable(bcx.ccx(), orig);
877881
Store(bcx, vtable, PointerCast(bcx,
878-
GEPi(bcx, lldest, [0u, 0u]),
882+
GEPi(bcx, lldest, [0u, abi::trt_field_vtable]),
879883
T_ptr(val_ty(vtable))));
880884

881885
bcx

branches/snap-stage3/src/libstd/num/bigint.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ A big unsigned integer type.
8080
A BigUint-typed value BigUint { data: @[a, b, c] } represents a number
8181
(a + b * BigDigit::base + c * BigDigit::base^2).
8282
*/
83-
#[deriving(Clone)]
8483
pub struct BigUint {
8584
priv data: ~[BigDigit]
8685
}
@@ -681,7 +680,7 @@ priv fn get_radix_base(radix: uint) -> (uint, uint) {
681680
}
682681

683682
/// A Sign is a BigInt's composing element.
684-
#[deriving(Eq, Clone)]
683+
#[deriving(Eq)]
685684
pub enum Sign { Minus, Zero, Plus }
686685

687686
impl Ord for Sign {
@@ -727,7 +726,6 @@ impl Neg<Sign> for Sign {
727726
}
728727

729728
/// A big signed integer type.
730-
#[deriving(Clone)]
731729
pub struct BigInt {
732730
priv sign: Sign,
733731
priv data: BigUint
@@ -827,8 +825,8 @@ impl Signed for BigInt {
827825
#[inline(always)]
828826
fn abs(&self) -> BigInt {
829827
match self.sign {
830-
Plus | Zero => self.clone(),
831-
Minus => BigInt::from_biguint(Plus, self.data.clone())
828+
Plus | Zero => copy *self,
829+
Minus => BigInt::from_biguint(Plus, copy self.data)
832830
}
833831
}
834832

@@ -852,8 +850,8 @@ impl Add<BigInt, BigInt> for BigInt {
852850
#[inline(always)]
853851
fn add(&self, other: &BigInt) -> BigInt {
854852
match (self.sign, other.sign) {
855-
(Zero, _) => other.clone(),
856-
(_, Zero) => self.clone(),
853+
(Zero, _) => copy *other,
854+
(_, Zero) => copy *self,
857855
(Plus, Plus) => BigInt::from_biguint(Plus,
858856
self.data + other.data),
859857
(Plus, Minus) => self - (-*other),
@@ -868,7 +866,7 @@ impl Sub<BigInt, BigInt> for BigInt {
868866
fn sub(&self, other: &BigInt) -> BigInt {
869867
match (self.sign, other.sign) {
870868
(Zero, _) => -other,
871-
(_, Zero) => self.clone(),
869+
(_, Zero) => copy *self,
872870
(Plus, Plus) => match self.data.cmp(&other.data) {
873871
Less => BigInt::from_biguint(Minus, other.data - self.data),
874872
Greater => BigInt::from_biguint(Plus, self.data - other.data),
@@ -915,7 +913,7 @@ impl Rem<BigInt, BigInt> for BigInt {
915913
impl Neg<BigInt> for BigInt {
916914
#[inline(always)]
917915
fn neg(&self) -> BigInt {
918-
BigInt::from_biguint(self.sign.neg(), self.data.clone())
916+
BigInt::from_biguint(self.sign.neg(), copy self.data)
919917
}
920918
}
921919

@@ -1102,9 +1100,9 @@ pub impl BigInt {
11021100
11031101
#[cfg(test)]
11041102
mod biguint_tests {
1105-
use super::*;
11061103
use core::num::{IntConvertible, Zero, One, FromStrRadix};
11071104
use core::cmp::{Less, Equal, Greater};
1105+
use super::{BigUint, BigDigit};
11081106
11091107
#[test]
11101108
fn test_from_slice() {
@@ -1392,10 +1390,10 @@ mod biguint_tests {
13921390
let c = BigUint::from_slice(cVec);
13931391

13941392
if !a.is_zero() {
1395-
assert!(c.div_rem(&a) == (b.clone(), Zero::zero()));
1393+
assert!(c.div_rem(&a) == (copy b, Zero::zero()));
13961394
}
13971395
if !b.is_zero() {
1398-
assert!(c.div_rem(&b) == (a.clone(), Zero::zero()));
1396+
assert!(c.div_rem(&b) == (copy a, Zero::zero()));
13991397
}
14001398
}
14011399

@@ -1557,7 +1555,7 @@ mod biguint_tests {
15571555
15581556
#[cfg(test)]
15591557
mod bigint_tests {
1560-
use super::*;
1558+
use super::{BigInt, BigUint, BigDigit, Sign, Minus, Zero, Plus};
15611559
use core::cmp::{Less, Equal, Greater};
15621560
use core::num::{IntConvertible, Zero, One, FromStrRadix};
15631561

0 commit comments

Comments
 (0)