Skip to content

Commit 4f97867

Browse files
committed
---
yaml --- r: 142903 b: refs/heads/try2 c: 4bd716a h: refs/heads/master i: 142901: 03d4eba 142899: 80b4427 142895: 6dae4f3 v: v3
1 parent c2d6bf7 commit 4f97867

File tree

242 files changed

+1433
-761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+1433
-761
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 712ac836c63c3ae98daf9fb98b7b96ed73347848
8+
refs/heads/try2: 4bd716ac8eb60dbaced9e3d2bafee89b713a7849
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,14 +1417,83 @@ names are effectively reserved. Some significant attributes include:
14171417
* The `lang` attribute, for custom definitions of traits and functions that are known to the Rust compiler (see [Language items](#language-items)).
14181418
* The `link` attribute, for describing linkage metadata for a crate.
14191419
* The `test` attribute, for marking functions as unit tests.
1420-
* The `allow`, `warn`, `forbid`, and `deny` attributes, for controlling lint checks. Lint checks supported
1421-
by the compiler can be found via `rustc -W help`.
1420+
* The `allow`, `warn`, `forbid`, and `deny` attributes, for
1421+
controlling lint checks (see [Lint check attributes](#lint-check-attributes)).
14221422
* The `deriving` attribute, for automatically generating
14231423
implementations of certain traits.
14241424
* The `static_assert` attribute, for asserting that a static bool is true at compiletime
14251425

14261426
Other attributes may be added or removed during development of the language.
14271427

1428+
### Lint check attributes
1429+
1430+
A lint check names a potentially undesirable coding pattern, such as
1431+
unreachable code or omitted documentation, for the static entity to
1432+
which the attribute applies.
1433+
1434+
For any lint check `C`:
1435+
1436+
* `warn(C)` warns about violations of `C` but continues compilation,
1437+
* `deny(C)` signals an error after encountering a violation of `C`,
1438+
* `allow(C)` overrides the check for `C` so that violations will go
1439+
unreported,
1440+
* `forbid(C)` is the same as `deny(C)`, but also forbids uses of
1441+
`allow(C)` within the entity.
1442+
1443+
The lint checks supported by the compiler can be found via `rustc -W help`,
1444+
along with their default settings.
1445+
1446+
~~~{.xfail-test}
1447+
mod m1 {
1448+
// Missing documentation is ignored here
1449+
#[allow(missing_doc)]
1450+
pub fn undocumented_one() -> int { 1 }
1451+
1452+
// Missing documentation signals a warning here
1453+
#[warn(missing_doc)]
1454+
pub fn undocumented_too() -> int { 2 }
1455+
1456+
// Missing documentation signals an error here
1457+
#[deny(missing_doc)]
1458+
pub fn undocumented_end() -> int { 3 }
1459+
}
1460+
~~~
1461+
1462+
This example shows how one can use `allow` and `warn` to toggle
1463+
a particular check on and off.
1464+
1465+
~~~
1466+
#[warn(missing_doc)]
1467+
mod m2{
1468+
#[allow(missing_doc)]
1469+
mod nested {
1470+
// Missing documentation is ignored here
1471+
pub fn undocumented_one() -> int { 1 }
1472+
1473+
// Missing documentation signals a warning here,
1474+
// despite the allow above.
1475+
#[warn(missing_doc)]
1476+
pub fn undocumented_two() -> int { 2 }
1477+
}
1478+
1479+
// Missing documentation signals a warning here
1480+
pub fn undocumented_too() -> int { 3 }
1481+
}
1482+
~~~
1483+
1484+
This example shows how one can use `forbid` to disallow uses
1485+
of `allow` for that lint check.
1486+
1487+
~~~{.xfail-test}
1488+
#[forbid(missing_doc)]
1489+
mod m3 {
1490+
// Attempting to toggle warning signals an error here
1491+
#[allow(missing_doc)]
1492+
/// Returns 2.
1493+
pub fn undocumented_too() -> int { 2 }
1494+
}
1495+
~~~
1496+
14281497
### Language items
14291498

14301499
Some primitive Rust operations are defined in Rust code,

branches/try2/src/libextra/smallintmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ impl<V> SmallIntMap<V> {
161161
/// Visit all key-value pairs in reverse order
162162
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
163163
for uint::range_rev(self.v.len(), 0) |i| {
164-
match self.v[i - 1] {
165-
Some(ref elt) => if !it(i - 1, elt) { return false; },
164+
match self.v[i] {
165+
Some(ref elt) => if !it(i, elt) { return false; },
166166
None => ()
167167
}
168168
}

branches/try2/src/librustc/driver/driver.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ pub fn compile_rest(sess: Session,
194194
// mod bar { macro_rules! baz!(() => {{}}) }
195195
//
196196
// baz! should not use this definition unless foo is enabled.
197+
crate = time(time_passes, ~"std macros injection", ||
198+
syntax::ext::expand::inject_std_macros(sess.parse_sess, copy cfg,
199+
crate));
200+
197201
crate = time(time_passes, ~"configuration 1", ||
198202
front::config::strip_unconfigured_items(crate));
199203

@@ -214,7 +218,7 @@ pub fn compile_rest(sess: Session,
214218
assert!(phases.from != cu_no_trans);
215219

216220
let (llcx, llmod, link_meta) = {
217-
crate = time(time_passes, ~"extra injection", ||
221+
crate = time(time_passes, ~"std injection", ||
218222
front::std_inject::maybe_inject_libstd_ref(sess, crate));
219223

220224
let ast_map = time(time_passes, ~"ast indexing", ||

branches/try2/src/librustc/middle/const_eval.rs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,58 @@ pub fn classify(e: &expr,
165165
pub fn lookup_const(tcx: ty::ctxt, e: &expr) -> Option<@expr> {
166166
match tcx.def_map.find(&e.id) {
167167
Some(&ast::def_static(def_id, false)) => lookup_const_by_id(tcx, def_id),
168+
Some(&ast::def_variant(enum_def, variant_def)) => lookup_variant_by_id(tcx,
169+
enum_def,
170+
variant_def),
168171
_ => None
169172
}
170173
}
171174

175+
pub fn lookup_variant_by_id(tcx: ty::ctxt,
176+
enum_def: ast::def_id,
177+
variant_def: ast::def_id)
178+
-> Option<@expr> {
179+
fn variant_expr(variants: &[ast::variant], id: ast::node_id) -> Option<@expr> {
180+
for variants.iter().advance |variant| {
181+
if variant.node.id == id {
182+
return variant.node.disr_expr;
183+
}
184+
}
185+
None
186+
}
187+
188+
if ast_util::is_local(enum_def) {
189+
match tcx.items.find(&enum_def.node) {
190+
None => None,
191+
Some(&ast_map::node_item(it, _)) => match it.node {
192+
item_enum(ast::enum_def { variants: ref variants }, _) => {
193+
variant_expr(*variants, variant_def.node)
194+
}
195+
_ => None
196+
},
197+
Some(_) => None
198+
}
199+
} else {
200+
let maps = astencode::Maps {
201+
root_map: @mut HashMap::new(),
202+
method_map: @mut HashMap::new(),
203+
vtable_map: @mut HashMap::new(),
204+
write_guard_map: @mut HashSet::new(),
205+
capture_map: @mut HashMap::new()
206+
};
207+
match csearch::maybe_get_item_ast(tcx, enum_def,
208+
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, /*bar*/ copy c, d)) {
209+
csearch::found(ast::ii_item(item)) => match item.node {
210+
item_enum(ast::enum_def { variants: ref variants }, _) => {
211+
variant_expr(*variants, variant_def.node)
212+
}
213+
_ => None
214+
},
215+
_ => None
216+
}
217+
}
218+
}
219+
172220
pub fn lookup_const_by_id(tcx: ty::ctxt,
173221
def_id: ast::def_id)
174222
-> Option<@expr> {
@@ -237,13 +285,13 @@ pub enum const_val {
237285
}
238286

239287
pub fn eval_const_expr(tcx: middle::ty::ctxt, e: &expr) -> const_val {
240-
match eval_const_expr_partial(tcx, e) {
288+
match eval_const_expr_partial(&tcx, e) {
241289
Ok(r) => r,
242290
Err(s) => tcx.sess.span_fatal(e.span, s)
243291
}
244292
}
245293

246-
pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
294+
pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &expr)
247295
-> Result<const_val, ~str> {
248296
use middle::ty;
249297
fn fromb(b: bool) -> Result<const_val, ~str> { Ok(const_int(b as i64)) }
@@ -360,7 +408,7 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
360408
}
361409
}
362410
expr_cast(base, _) => {
363-
let ety = ty::expr_ty(tcx, e);
411+
let ety = tcx.expr_ty(e);
364412
let base = eval_const_expr_partial(tcx, base);
365413
match /*bad*/copy base {
366414
Err(_) => base,
@@ -390,8 +438,8 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
390438
}
391439
}
392440
expr_path(_) => {
393-
match lookup_const(tcx, e) {
394-
Some(actual_e) => eval_const_expr_partial(tcx, actual_e),
441+
match lookup_const(tcx.ty_ctxt(), e) {
442+
Some(actual_e) => eval_const_expr_partial(&tcx.ty_ctxt(), actual_e),
395443
None => Err(~"Non-constant path in constant expr")
396444
}
397445
}

branches/try2/src/librustc/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ pub fn check_expr(e: @expr, (cx, v): (Context, visit::vt<Context>)) {
309309
"explicit copy requires a copyable argument");
310310
}
311311
expr_repeat(element, count_expr, _) => {
312-
let count = ty::eval_repeat_count(cx.tcx, count_expr);
312+
let count = ty::eval_repeat_count(&cx.tcx, count_expr);
313313
if count > 1 {
314314
let element_ty = ty::expr_ty(cx.tcx, element);
315315
check_copy(cx, element_ty, element.span,

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ pub fn alloca_maybe_zeroed(cx: block, ty: Type, name: &str, zero: bool) -> Value
15301530
let _icx = push_ctxt("alloca");
15311531
if cx.unreachable {
15321532
unsafe {
1533-
return llvm::LLVMGetUndef(ty.to_ref());
1533+
return llvm::LLVMGetUndef(ty.ptr_to().to_ref());
15341534
}
15351535
}
15361536
let initcx = base::raw_block(cx.fcx, false, cx.fcx.get_llstaticallocas());

branches/try2/src/librustc/middle/trans/build.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -569,15 +569,17 @@ pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,
569569
hi: c_ulonglong, signed: lib::llvm::Bool) -> ValueRef {
570570
let value = Load(cx, PointerVal);
571571

572-
unsafe {
573-
let t = llvm::LLVMGetElementType(llvm::LLVMTypeOf(PointerVal));
574-
let min = llvm::LLVMConstInt(t, lo, signed);
575-
let max = llvm::LLVMConstInt(t, hi, signed);
576-
577-
do [min, max].as_imm_buf |ptr, len| {
578-
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
579-
llvm::LLVMMDNodeInContext(cx.fcx.ccx.llcx,
580-
ptr, len as c_uint));
572+
if !cx.unreachable {
573+
unsafe {
574+
let t = llvm::LLVMGetElementType(llvm::LLVMTypeOf(PointerVal));
575+
let min = llvm::LLVMConstInt(t, lo, signed);
576+
let max = llvm::LLVMConstInt(t, hi, signed);
577+
578+
do [min, max].as_imm_buf |ptr, len| {
579+
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
580+
llvm::LLVMMDNodeInContext(cx.fcx.ccx.llcx,
581+
ptr, len as c_uint));
582+
}
581583
}
582584
}
583585

branches/try2/src/librustc/middle/trans/controlflow.rs

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,38 @@ pub fn trans_if(bcx: block,
6363
let _indenter = indenter();
6464

6565
let _icx = push_ctxt("trans_if");
66+
67+
match cond.node {
68+
// `if true` and `if false` can be trans'd more efficiently,
69+
// by dropping branches that are known to be impossible.
70+
ast::expr_lit(@ref l) => match l.node {
71+
ast::lit_bool(true) => {
72+
// if true { .. } [else { .. }]
73+
let then_bcx_in = scope_block(bcx, thn.info(), "if_true_then");
74+
let then_bcx_out = trans_block(then_bcx_in, thn, dest);
75+
let then_bcx_out = trans_block_cleanups(then_bcx_out,
76+
block_cleanups(then_bcx_in));
77+
Br(bcx, then_bcx_in.llbb);
78+
return then_bcx_out;
79+
}
80+
ast::lit_bool(false) => {
81+
match els {
82+
// if false { .. } else { .. }
83+
Some(elexpr) => {
84+
let (else_bcx_in, else_bcx_out) =
85+
trans_if_else(bcx, elexpr, dest, "if_false_else");
86+
Br(bcx, else_bcx_in.llbb);
87+
return else_bcx_out;
88+
}
89+
// if false { .. }
90+
None => return bcx,
91+
}
92+
}
93+
_ => {}
94+
},
95+
_ => {}
96+
}
97+
6698
let Result {bcx, val: cond_val} =
6799
expr::trans_to_datum(bcx, cond).to_result();
68100

@@ -80,22 +112,8 @@ pub fn trans_if(bcx: block,
80112
// 'else' context
81113
let (else_bcx_in, next_bcx) = match els {
82114
Some(elexpr) => {
83-
let else_bcx_in = scope_block(bcx, els.info(), "else");
84-
let else_bcx_out = match elexpr.node {
85-
ast::expr_if(_, _, _) => {
86-
let elseif_blk = ast_util::block_from_expr(elexpr);
87-
trans_block(else_bcx_in, &elseif_blk, dest)
88-
}
89-
ast::expr_block(ref blk) => {
90-
trans_block(else_bcx_in, blk, dest)
91-
}
92-
// would be nice to have a constraint on ifs
93-
_ => bcx.tcx().sess.bug("strange alternative in if")
94-
};
95-
let else_bcx_out = trans_block_cleanups(else_bcx_out,
96-
block_cleanups(else_bcx_in));
97-
98-
(else_bcx_in, join_blocks(bcx, [then_bcx_out, else_bcx_out]))
115+
let (else_bcx_in, else_bcx_out) = trans_if_else(bcx, elexpr, dest, "else");
116+
(else_bcx_in, join_blocks(bcx, [then_bcx_out, else_bcx_out]))
99117
}
100118
_ => {
101119
let next_bcx = sub_block(bcx, "next");
@@ -109,7 +127,27 @@ pub fn trans_if(bcx: block,
109127
then_bcx_in.to_str(), else_bcx_in.to_str());
110128

111129
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
112-
next_bcx
130+
return next_bcx;
131+
132+
// trans `else [ if { .. } ... | { .. } ]`
133+
fn trans_if_else(bcx: block, elexpr: @ast::expr,
134+
dest: expr::Dest, scope_name: &str) -> (block, block) {
135+
let else_bcx_in = scope_block(bcx, elexpr.info(), scope_name);
136+
let else_bcx_out = match elexpr.node {
137+
ast::expr_if(_, _, _) => {
138+
let elseif_blk = ast_util::block_from_expr(elexpr);
139+
trans_block(else_bcx_in, &elseif_blk, dest)
140+
}
141+
ast::expr_block(ref blk) => {
142+
trans_block(else_bcx_in, blk, dest)
143+
}
144+
// would be nice to have a constraint on ifs
145+
_ => bcx.tcx().sess.bug("strange alternative in if")
146+
};
147+
let else_bcx_out = trans_block_cleanups(else_bcx_out,
148+
block_cleanups(else_bcx_in));
149+
(else_bcx_in, else_bcx_out)
150+
}
113151
}
114152

115153
pub fn join_blocks(parent_bcx: block, in_cxs: &[block]) -> block {

branches/try2/src/librustc/middle/trans/datum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ impl Datum {
413413
pub fn to_value_datum(&self, bcx: block) -> Datum {
414414
/*!
415415
*
416-
* Yields a by-ref form of this datum. This may involve
416+
* Yields a by-value form of this datum. This may involve
417417
* creation of a temporary stack slot. The value returned by
418418
* this function is not separately rooted from this datum, so
419419
* it will not live longer than the current datum. */

branches/try2/src/librustc/middle/trans/tvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ pub fn write_content(bcx: block,
417417
return expr::trans_into(bcx, element, Ignore);
418418
}
419419
SaveIn(lldest) => {
420-
let count = ty::eval_repeat_count(bcx.tcx(), count_expr);
420+
let count = ty::eval_repeat_count(&bcx.tcx(), count_expr);
421421
if count == 0 {
422422
return bcx;
423423
}
@@ -509,7 +509,7 @@ pub fn elements_required(bcx: block, content_expr: &ast::expr) -> uint {
509509
},
510510
ast::expr_vec(ref es, _) => es.len(),
511511
ast::expr_repeat(_, count_expr, _) => {
512-
ty::eval_repeat_count(bcx.tcx(), count_expr)
512+
ty::eval_repeat_count(&bcx.tcx(), count_expr)
513513
}
514514
_ => bcx.tcx().sess.span_bug(content_expr.span,
515515
"Unexpected evec content")

0 commit comments

Comments
 (0)