Skip to content

Commit 608602d

Browse files
committed
---
yaml --- r: 128318 b: refs/heads/snap-stage3 c: ec9476c h: refs/heads/master v: v3
1 parent f955b6c commit 608602d

File tree

13 files changed

+265
-78
lines changed

13 files changed

+265
-78
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: f1f67b2848f3c8d7c8c82faa4956ce0591b2e71a
4+
refs/heads/snap-stage3: ec9476cd63af58d55e552532d14040d972392bd6
55
refs/heads/try: 73b8f60b60d8a2a7ca5a7d49d59771350b867951
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/doc/rust.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,8 @@ interpreted:
19281928

19291929
### Miscellaneous attributes
19301930

1931+
- `export_name` - on statics and functions, this determines the name of the
1932+
exported symbol.
19311933
- `link_section` - on statics and functions, this specifies the section of the
19321934
object file that this item's contents will be placed into.
19331935
- `macro_export` - export a macro for cross-crate usage.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ 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+
260268
#[test]
261269
#[should_fail]
262270
#[ignore]

branches/snap-stage3/src/librustc/lint/builtin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ impl LintPass for UnusedAttribute {
568568
// FIXME: #14406 these are processed in trans, which happens after the
569569
// lint pass
570570
"cold",
571+
"export_name",
571572
"inline",
572573
"link",
573574
"link_name",
@@ -578,6 +579,7 @@ impl LintPass for UnusedAttribute {
578579
"packed",
579580
"static_assert",
580581
"thread_local",
582+
"no_debug",
581583

582584
// not used anywhere (!?) but apparently we want to keep them around
583585
"comment",

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,12 +1947,10 @@ 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-
19521950
match args {
19531951
callee::ArgExprs(exprs) => {
19541952
let fields = exprs.iter().map(|x| *x).enumerate().collect::<Vec<_>>();
1955-
bcx = expr::trans_adt(bcx, &*repr, disr, fields.as_slice(),
1953+
bcx = expr::trans_adt(bcx, result_ty, disr, fields.as_slice(),
19561954
None, expr::SaveIn(llresult));
19571955
}
19581956
_ => ccx.sess().bug("expected expr as arguments for variant/struct tuple constructor")

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,12 @@ 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());
334333
let lldiscriminant = adt::trans_get_discr(loopback_bcx_out,
335334
&*option_representation,
336335
option_datum.val,
337-
Some(i8_type));
338-
let llzero = C_u8(loopback_bcx_out.ccx(), 0);
339-
let llcondition = ICmp(loopback_bcx_out, IntNE, lldiscriminant, llzero);
336+
None);
337+
let i1_type = Type::i1(loopback_bcx_out.ccx());
338+
let llcondition = Trunc(loopback_bcx_out, lldiscriminant, i1_type);
340339
CondBr(loopback_bcx_out, llcondition, body_bcx_in.llbb, cleanup_llbb);
341340

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

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,10 @@ pub fn create_function_debug_context(cx: &CrateContext,
11281128

11291129
let (ident, fn_decl, generics, top_level_block, span, has_path) = match fnitem {
11301130
ast_map::NodeItem(ref item) => {
1131+
if contains_nodebug_attribute(item.attrs.as_slice()) {
1132+
return FunctionDebugContext { repr: FunctionWithoutDebugInfo };
1133+
}
1134+
11311135
match item.node {
11321136
ast::ItemFn(fn_decl, _, _, ref generics, top_level_block) => {
11331137
(item.ident, fn_decl, generics, top_level_block, item.span, true)
@@ -1141,6 +1145,12 @@ pub fn create_function_debug_context(cx: &CrateContext,
11411145
ast_map::NodeImplItem(ref item) => {
11421146
match **item {
11431147
ast::MethodImplItem(ref method) => {
1148+
if contains_nodebug_attribute(method.attrs.as_slice()) {
1149+
return FunctionDebugContext {
1150+
repr: FunctionWithoutDebugInfo
1151+
};
1152+
}
1153+
11441154
(method.pe_ident(),
11451155
method.pe_fn_decl(),
11461156
method.pe_generics(),
@@ -1173,6 +1183,12 @@ pub fn create_function_debug_context(cx: &CrateContext,
11731183
ast_map::NodeTraitItem(ref trait_method) => {
11741184
match **trait_method {
11751185
ast::ProvidedMethod(ref method) => {
1186+
if contains_nodebug_attribute(method.attrs.as_slice()) {
1187+
return FunctionDebugContext {
1188+
repr: FunctionWithoutDebugInfo
1189+
};
1190+
}
1191+
11761192
(method.pe_ident(),
11771193
method.pe_fn_decl(),
11781194
method.pe_generics(),
@@ -3169,6 +3185,16 @@ fn set_debug_location(cx: &CrateContext, debug_location: DebugLocation) {
31693185
// Utility Functions
31703186
//=-----------------------------------------------------------------------------
31713187

3188+
fn contains_nodebug_attribute(attributes: &[ast::Attribute]) -> bool {
3189+
attributes.iter().any(|attr| {
3190+
let meta_item: &ast::MetaItem = &*attr.node.value;
3191+
match meta_item.node {
3192+
ast::MetaWord(ref value) => value.get() == "no_debug",
3193+
_ => false
3194+
}
3195+
})
3196+
}
3197+
31723198
/// Return codemap::Loc corresponding to the beginning of the span
31733199
fn span_start(cx: &CrateContext, span: Span) -> codemap::Loc {
31743200
cx.sess().codemap().lookup_char_pos(span.lo)

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

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -746,18 +746,17 @@ 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_rec_or_struct(bcx,
750-
fields.as_slice(),
751-
base,
752-
expr.span,
753-
expr.id,
754-
dest)
749+
trans_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));
758757
let numbered_fields: Vec<(uint, Gc<ast::Expr>)> =
759758
args.iter().enumerate().map(|(i, arg)| (i, *arg)).collect();
760-
trans_adt(bcx, &*repr, 0, numbered_fields.as_slice(), None, dest)
759+
trans_adt(bcx, expr_ty(bcx, expr), 0, numbered_fields.as_slice(), None, dest)
761760
}
762761
ast::ExprLit(lit) => {
763762
match lit.node {
@@ -1042,16 +1041,13 @@ pub fn with_field_tys<R>(tcx: &ty::ctxt,
10421041
}
10431042
}
10441043

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> {
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> {
10531050
let _icx = push_ctxt("trans_rec");
1054-
let bcx = bcx;
10551051

10561052
let ty = node_id_type(bcx, id);
10571053
let tcx = bcx.tcx();
@@ -1092,8 +1088,7 @@ fn trans_rec_or_struct<'a>(
10921088
}
10931089
};
10941090

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

@@ -1121,60 +1116,71 @@ pub struct StructBaseInfo {
11211116
* - `optbase` contains information on the base struct (if any) from
11221117
* which remaining fields are copied; see comments on `StructBaseInfo`.
11231118
*/
1124-
pub fn trans_adt<'a>(bcx: &'a Block<'a>,
1125-
repr: &adt::Repr,
1119+
pub fn trans_adt<'a>(mut bcx: &'a Block<'a>,
1120+
ty: ty::t,
11261121
discr: ty::Disr,
11271122
fields: &[(uint, Gc<ast::Expr>)],
11281123
optbase: Option<StructBaseInfo>,
11291124
dest: Dest) -> &'a Block<'a> {
11301125
let _icx = push_ctxt("trans_adt");
11311126
let fcx = bcx.fcx;
1132-
let mut bcx = bcx;
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
11331131
let addr = match dest {
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
1132+
SaveIn(pos) => pos,
1133+
Ignore => alloc_ty(bcx, ty, "temp"),
11451134
};
11461135

11471136
// This scope holds intermediates that must be cleaned should
11481137
// failure occur before the ADT as a whole is ready.
11491138
let custom_cleanup_scope = fcx.push_custom_cleanup_scope();
11501139

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
11511162
for &(i, ref e) in fields.iter() {
1152-
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
1163+
let dest = adt::trans_field_ptr(bcx, &*repr, addr, discr, i);
11531164
let e_ty = expr_ty_adjusted(bcx, &**e);
11541165
bcx = trans_into(bcx, &**e, SaveIn(dest));
11551166
let scope = cleanup::CustomScope(custom_cleanup_scope);
11561167
fcx.schedule_lifetime_end(scope, dest);
11571168
fcx.schedule_drop_mem(scope, dest, e_ty);
11581169
}
11591170

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);
1171+
adt::trans_set_discr(bcx, &*repr, addr, discr);
11741172

11751173
fcx.pop_custom_cleanup_scope(custom_cleanup_scope);
11761174

1177-
return bcx;
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+
}
11781184
}
11791185

11801186

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ 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.
254-
for (i, ty) in st.fields.iter().enumerate() {
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() {
255256
let llfld_a = adt::struct_field_ptr(variant_cx, &*st, value, i, false);
256257
variant_cx.fcx.schedule_drop_mem(cleanup::CustomScope(field_scope),
257258
llfld_a, *ty);

0 commit comments

Comments
 (0)