Skip to content

Commit 9cfc43c

Browse files
committed
---
yaml --- r: 128319 b: refs/heads/snap-stage3 c: 48edb32 h: refs/heads/master i: 128317: f955b6c 128315: 4b13034 128311: f31883b 128303: 4e40055 128287: 57fd85a 128255: 5fe6864 v: v3
1 parent 608602d commit 9cfc43c

File tree

10 files changed

+87
-201
lines changed

10 files changed

+87
-201
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: cb9c1e0e702f4a1a5dfc909b15b74e8556013c06
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ec9476cd63af58d55e552532d14040d972392bd6
4+
refs/heads/snap-stage3: 48edb32a3fc8ba6cc3db9a9d11f5201a919391f5
55
refs/heads/try: 73b8f60b60d8a2a7ca5a7d49d59771350b867951
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libnum/complex.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,6 @@ mod test {
257257
assert_eq!(_1_0i.inv(), _1_0i.inv());
258258
}
259259

260-
#[test]
261-
#[should_fail]
262-
fn test_divide_by_zero_natural() {
263-
let n = Complex::new(2i, 3i);
264-
let d = Complex::new(0, 0);
265-
let _x = n / d;
266-
}
267-
268260
#[test]
269261
#[should_fail]
270262
#[ignore]

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,10 +1947,12 @@ pub fn trans_named_tuple_constructor<'a>(mut bcx: &'a Block<'a>,
19471947
};
19481948

19491949
if !type_is_zero_size(ccx, result_ty) {
1950+
let repr = adt::represent_type(ccx, result_ty);
1951+
19501952
match args {
19511953
callee::ArgExprs(exprs) => {
19521954
let fields = exprs.iter().map(|x| *x).enumerate().collect::<Vec<_>>();
1953-
bcx = expr::trans_adt(bcx, result_ty, disr, fields.as_slice(),
1955+
bcx = expr::trans_adt(bcx, &*repr, disr, fields.as_slice(),
19541956
None, expr::SaveIn(llresult));
19551957
}
19561958
_ => ccx.sess().bug("expected expr as arguments for variant/struct tuple constructor")
@@ -2278,7 +2280,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
22782280
match ty::get(ret_ty).sty {
22792281
// `~` pointer return values never alias because ownership
22802282
// is transferred
2281-
ty::ty_uniq(it) if match ty::get(it).sty {
2283+
ty::ty_uniq(it) if match ty::get(it).sty {
22822284
ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false
22832285
} => {}
22842286
ty::ty_uniq(_) => {
@@ -2354,15 +2356,21 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
23542356
}
23552357

23562358
// `&mut` pointer parameters never alias other parameters, or mutable global data
2357-
// `&` pointer parameters never alias either (for LLVM's purposes) as long as the
2358-
// interior is safe
2359+
//
2360+
// `&T` where `T` contains no `UnsafeCell<U>` is immutable, and can be marked as both
2361+
// `readonly` and `noalias`, as LLVM's definition of `noalias` is based solely on
2362+
// memory dependencies rather than pointer equality
23592363
ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable ||
23602364
!ty::type_contents(ccx.tcx(), mt.ty).interior_unsafe() => {
23612365

23622366
let llsz = llsize_of_real(ccx, type_of::type_of(ccx, mt.ty));
23632367
attrs.arg(idx, llvm::NoAliasAttribute)
23642368
.arg(idx, llvm::DereferenceableAttribute(llsz));
23652369

2370+
if mt.mutbl == ast::MutImmutable {
2371+
attrs.arg(idx, llvm::ReadOnlyAttribute);
2372+
}
2373+
23662374
match b {
23672375
ReLateBound(_, BrAnon(_)) => {
23682376
attrs.arg(idx, llvm::NoCaptureAttribute);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,13 @@ pub fn trans_for<'a>(
330330
// Check the discriminant; if the `None` case, exit the loop.
331331
let option_representation = adt::represent_type(loopback_bcx_out.ccx(),
332332
method_result_type);
333+
let i8_type = Type::i8(loopback_bcx_out.ccx());
333334
let lldiscriminant = adt::trans_get_discr(loopback_bcx_out,
334335
&*option_representation,
335336
option_datum.val,
336-
None);
337-
let i1_type = Type::i1(loopback_bcx_out.ccx());
338-
let llcondition = Trunc(loopback_bcx_out, lldiscriminant, i1_type);
337+
Some(i8_type));
338+
let llzero = C_u8(loopback_bcx_out.ccx(), 0);
339+
let llcondition = ICmp(loopback_bcx_out, IntNE, lldiscriminant, llzero);
339340
CondBr(loopback_bcx_out, llcondition, body_bcx_in.llbb, cleanup_llbb);
340341

341342
// Now we're in the body. Unpack the `Option` value into the programmer-

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

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -746,17 +746,18 @@ fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>,
746746
controlflow::trans_block(bcx, &**blk, dest)
747747
}
748748
ast::ExprStruct(_, ref fields, base) => {
749-
trans_struct(bcx,
750-
fields.as_slice(),
751-
base,
752-
expr.span,
753-
expr.id,
754-
dest)
749+
trans_rec_or_struct(bcx,
750+
fields.as_slice(),
751+
base,
752+
expr.span,
753+
expr.id,
754+
dest)
755755
}
756756
ast::ExprTup(ref args) => {
757+
let repr = adt::represent_type(bcx.ccx(), expr_ty(bcx, expr));
757758
let numbered_fields: Vec<(uint, Gc<ast::Expr>)> =
758759
args.iter().enumerate().map(|(i, arg)| (i, *arg)).collect();
759-
trans_adt(bcx, expr_ty(bcx, expr), 0, numbered_fields.as_slice(), None, dest)
760+
trans_adt(bcx, &*repr, 0, numbered_fields.as_slice(), None, dest)
760761
}
761762
ast::ExprLit(lit) => {
762763
match lit.node {
@@ -1041,13 +1042,16 @@ pub fn with_field_tys<R>(tcx: &ty::ctxt,
10411042
}
10421043
}
10431044

1044-
fn trans_struct<'a>(bcx: &'a Block<'a>,
1045-
fields: &[ast::Field],
1046-
base: Option<Gc<ast::Expr>>,
1047-
expr_span: codemap::Span,
1048-
id: ast::NodeId,
1049-
dest: Dest) -> &'a Block<'a> {
1045+
fn trans_rec_or_struct<'a>(
1046+
bcx: &'a Block<'a>,
1047+
fields: &[ast::Field],
1048+
base: Option<Gc<ast::Expr>>,
1049+
expr_span: codemap::Span,
1050+
id: ast::NodeId,
1051+
dest: Dest)
1052+
-> &'a Block<'a> {
10501053
let _icx = push_ctxt("trans_rec");
1054+
let bcx = bcx;
10511055

10521056
let ty = node_id_type(bcx, id);
10531057
let tcx = bcx.tcx();
@@ -1088,7 +1092,8 @@ fn trans_struct<'a>(bcx: &'a Block<'a>,
10881092
}
10891093
};
10901094

1091-
trans_adt(bcx, ty, discr, numbered_fields.as_slice(), optbase, dest)
1095+
let repr = adt::represent_type(bcx.ccx(), ty);
1096+
trans_adt(bcx, &*repr, discr, numbered_fields.as_slice(), optbase, dest)
10921097
})
10931098
}
10941099

@@ -1116,71 +1121,60 @@ pub struct StructBaseInfo {
11161121
* - `optbase` contains information on the base struct (if any) from
11171122
* which remaining fields are copied; see comments on `StructBaseInfo`.
11181123
*/
1119-
pub fn trans_adt<'a>(mut bcx: &'a Block<'a>,
1120-
ty: ty::t,
1124+
pub fn trans_adt<'a>(bcx: &'a Block<'a>,
1125+
repr: &adt::Repr,
11211126
discr: ty::Disr,
11221127
fields: &[(uint, Gc<ast::Expr>)],
11231128
optbase: Option<StructBaseInfo>,
11241129
dest: Dest) -> &'a Block<'a> {
11251130
let _icx = push_ctxt("trans_adt");
11261131
let fcx = bcx.fcx;
1127-
let repr = adt::represent_type(bcx.ccx(), ty);
1128-
1129-
// If we don't care about the result, just make a
1130-
// temporary stack slot
1132+
let mut bcx = bcx;
11311133
let addr = match dest {
1132-
SaveIn(pos) => pos,
1133-
Ignore => alloc_ty(bcx, ty, "temp"),
1134+
Ignore => {
1135+
for &(_i, ref e) in fields.iter() {
1136+
bcx = trans_into(bcx, &**e, Ignore);
1137+
}
1138+
for sbi in optbase.iter() {
1139+
// FIXME #7261: this moves entire base, not just certain fields
1140+
bcx = trans_into(bcx, &*sbi.expr, Ignore);
1141+
}
1142+
return bcx;
1143+
}
1144+
SaveIn(pos) => pos
11341145
};
11351146

11361147
// This scope holds intermediates that must be cleaned should
11371148
// failure occur before the ADT as a whole is ready.
11381149
let custom_cleanup_scope = fcx.push_custom_cleanup_scope();
11391150

1140-
// First we trans the base, if we have one, to the dest
1141-
for base in optbase.iter() {
1142-
assert_eq!(discr, 0);
1143-
1144-
match ty::expr_kind(bcx.tcx(), &*base.expr) {
1145-
ty::LvalueExpr => {
1146-
let base_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, &*base.expr, "base"));
1147-
for &(i, t) in base.fields.iter() {
1148-
let datum = base_datum.get_element(
1149-
t, |srcval| adt::trans_field_ptr(bcx, &*repr, srcval, discr, i));
1150-
let dest = adt::trans_field_ptr(bcx, &*repr, addr, discr, i);
1151-
bcx = datum.store_to(bcx, dest);
1152-
}
1153-
},
1154-
ty::RvalueDpsExpr | ty::RvalueDatumExpr => {
1155-
bcx = trans_into(bcx, &*base.expr, SaveIn(addr));
1156-
},
1157-
ty::RvalueStmtExpr => bcx.tcx().sess.bug("unexpected expr kind for struct base expr")
1158-
}
1159-
}
1160-
1161-
// Now, we just overwrite the fields we've explicity specified
11621151
for &(i, ref e) in fields.iter() {
1163-
let dest = adt::trans_field_ptr(bcx, &*repr, addr, discr, i);
1152+
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
11641153
let e_ty = expr_ty_adjusted(bcx, &**e);
11651154
bcx = trans_into(bcx, &**e, SaveIn(dest));
11661155
let scope = cleanup::CustomScope(custom_cleanup_scope);
11671156
fcx.schedule_lifetime_end(scope, dest);
11681157
fcx.schedule_drop_mem(scope, dest, e_ty);
11691158
}
11701159

1171-
adt::trans_set_discr(bcx, &*repr, addr, discr);
1160+
for base in optbase.iter() {
1161+
// FIXME #6573: is it sound to use the destination's repr on the base?
1162+
// And, would it ever be reasonable to be here with discr != 0?
1163+
let base_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, &*base.expr, "base"));
1164+
for &(i, t) in base.fields.iter() {
1165+
let datum = base_datum.get_element(
1166+
t,
1167+
|srcval| adt::trans_field_ptr(bcx, repr, srcval, discr, i));
1168+
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
1169+
bcx = datum.store_to(bcx, dest);
1170+
}
1171+
}
1172+
1173+
adt::trans_set_discr(bcx, repr, addr, discr);
11721174

11731175
fcx.pop_custom_cleanup_scope(custom_cleanup_scope);
11741176

1175-
// If we don't care about the result drop the temporary we made
1176-
match dest {
1177-
SaveIn(_) => bcx,
1178-
Ignore => {
1179-
bcx = glue::drop_ty(bcx, addr, ty);
1180-
base::call_lifetime_end(bcx, addr);
1181-
bcx
1182-
}
1183-
}
1177+
return bcx;
11841178
}
11851179

11861180

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,8 @@ fn trans_struct_drop<'a>(bcx: &'a Block<'a>,
250250
let args = vec!(self_arg);
251251

252252
// Add all the fields as a value which needs to be cleaned at the end of
253-
// this scope. Iterate in reverse order so a Drop impl doesn't reverse
254-
// the order in which fields get dropped.
255-
for (i, ty) in st.fields.iter().enumerate().rev() {
253+
// this scope.
254+
for (i, ty) in st.fields.iter().enumerate() {
256255
let llfld_a = adt::struct_field_ptr(variant_cx, &*st, value, i, false);
257256
variant_cx.fcx.schedule_drop_mem(cleanup::CustomScope(field_scope),
258257
llfld_a, *ty);

branches/snap-stage3/src/libstd/io/util.rs

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ impl<R: Reader> Reader for LimitReader<R> {
4848
}
4949

5050
let len = cmp::min(self.limit, buf.len());
51-
let res = self.inner.read(buf.mut_slice_to(len));
52-
match res {
53-
Ok(len) => self.limit -= len,
54-
_ => {}
55-
}
56-
res
51+
self.inner.read(buf.mut_slice_to(len)).map(|len| {
52+
self.limit -= len;
53+
len
54+
})
5755
}
5856
}
5957

@@ -69,8 +67,6 @@ impl<R: Buffer> Buffer for LimitReader<R> {
6967
}
7068

7169
fn consume(&mut self, amt: uint) {
72-
// Don't let callers reset the limit by passing an overlarge value
73-
let amt = cmp::min(amt, self.limit);
7470
self.limit -= amt;
7571
self.inner.consume(amt);
7672
}
@@ -101,7 +97,6 @@ impl Buffer for ZeroReader {
10197
static DATA: [u8, ..64] = [0, ..64];
10298
Ok(DATA.as_slice())
10399
}
104-
105100
fn consume(&mut self, _amt: uint) {}
106101
}
107102

@@ -122,10 +117,7 @@ impl Buffer for NullReader {
122117
fn consume(&mut self, _amt: uint) {}
123118
}
124119

125-
/// A `Writer` which multiplexes writes to a set of `Writer`s.
126-
///
127-
/// The `Writer`s are delegated to in order. If any `Writer` returns an error,
128-
/// that error is returned immediately and remaining `Writer`s are not called.
120+
/// A `Writer` which multiplexes writes to a set of `Writers`.
129121
pub struct MultiWriter {
130122
writers: Vec<Box<Writer>>
131123
}
@@ -140,22 +132,24 @@ impl MultiWriter {
140132
impl Writer for MultiWriter {
141133
#[inline]
142134
fn write(&mut self, buf: &[u8]) -> io::IoResult<()> {
135+
let mut ret = Ok(());
143136
for writer in self.writers.mut_iter() {
144-
try!(writer.write(buf));
137+
ret = ret.and(writer.write(buf));
145138
}
146-
Ok(())
139+
return ret;
147140
}
148141

149142
#[inline]
150143
fn flush(&mut self) -> io::IoResult<()> {
144+
let mut ret = Ok(());
151145
for writer in self.writers.mut_iter() {
152-
try!(writer.flush());
146+
ret = ret.and(writer.flush());
153147
}
154-
Ok(())
148+
return ret;
155149
}
156150
}
157151

158-
/// A `Reader` which chains input from multiple `Reader`s, reading each to
152+
/// A `Reader` which chains input from multiple `Readers`, reading each to
159153
/// completion before moving onto the next.
160154
pub struct ChainedReader<I, R> {
161155
readers: I,
@@ -235,16 +229,17 @@ pub fn copy<R: Reader, W: Writer>(r: &mut R, w: &mut W) -> io::IoResult<()> {
235229
}
236230
}
237231

238-
/// An adaptor converting an `Iterator<u8>` to a `Reader`.
232+
/// A `Reader` which converts an `Iterator<u8>` into a `Reader`.
239233
pub struct IterReader<T> {
240234
iter: T,
241235
}
242236

243237
impl<T: Iterator<u8>> IterReader<T> {
244-
/// Creates a new `IterReader` which will read from the specified
245-
/// `Iterator`.
238+
/// Create a new `IterReader` which will read from the specified `Iterator`.
246239
pub fn new(iter: T) -> IterReader<T> {
247-
IterReader { iter: iter }
240+
IterReader {
241+
iter: iter,
242+
}
248243
}
249244
}
250245

@@ -256,7 +251,7 @@ impl<T: Iterator<u8>> Reader for IterReader<T> {
256251
*slot = elt;
257252
len += 1;
258253
}
259-
if len == 0 && buf.len() != 0 {
254+
if len == 0 {
260255
Err(io::standard_error(io::EndOfFile))
261256
} else {
262257
Ok(len)
@@ -302,14 +297,6 @@ mod test {
302297
assert_eq!(0, r.limit());
303298
}
304299

305-
#[test]
306-
fn test_limit_reader_overlong_consume() {
307-
let mut r = MemReader::new(vec![0, 1, 2, 3, 4, 5]);
308-
let mut r = LimitReader::new(r.by_ref(), 1);
309-
r.consume(2);
310-
assert_eq!(vec![], r.read_to_end().unwrap());
311-
}
312-
313300
#[test]
314301
fn test_null_writer() {
315302
let mut s = NullWriter;
@@ -428,11 +415,4 @@ mod test {
428415

429416
assert_eq!(r.read(buf).unwrap_err().kind, io::EndOfFile);
430417
}
431-
432-
#[test]
433-
fn iter_reader_zero_length() {
434-
let mut r = IterReader::new(range(0u8, 8));
435-
let mut buf = [];
436-
assert_eq!(Ok(0), r.read(buf));
437-
}
438418
}

0 commit comments

Comments
 (0)