Skip to content

Commit 81980b1

Browse files
committed
---
yaml --- r: 227571 b: refs/heads/try c: afd1ed2 h: refs/heads/master i: 227569: d554d0d 227567: 635c8e4 v: v3
1 parent b34c411 commit 81980b1

Some content is hidden

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

57 files changed

+324
-945
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: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: a19ed8ad1579fa8c0a2e5477534da76be5afd3c2
4+
refs/heads/try: afd1ed2ef907498f000346aff12044f258fc45ae
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/doc/trpl/traits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn normal<T: ConvertTo<i64>>(x: &T) -> i64 {
332332
fn inverse<T>() -> T
333333
// this is using ConvertTo as if it were "ConvertFrom<i32>"
334334
where i32: ConvertTo<T> {
335-
42.convert()
335+
1i32.convert()
336336
}
337337
```
338338

branches/try/src/libcollections/vec.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,26 +1469,42 @@ impl<T> ops::DerefMut for Vec<T> {
14691469
impl<T> FromIterator<T> for Vec<T> {
14701470
#[inline]
14711471
fn from_iter<I: IntoIterator<Item=T>>(iterable: I) -> Vec<T> {
1472-
// Unroll the first iteration, as the vector is going to be
1473-
// expanded on this iteration in every case when the iterable is not
1474-
// empty, but the loop in extend_desugared() is not going to see the
1475-
// vector being full in the few subsequent loop iterations.
1476-
// So we get better branch prediction and the possibility to
1477-
// construct the vector with initial estimated capacity.
14781472
let mut iterator = iterable.into_iter();
1479-
let mut vector = match iterator.next() {
1480-
None => return Vec::new(),
1481-
Some(element) => {
1482-
let (lower, _) = iterator.size_hint();
1483-
let mut vector = Vec::with_capacity(1 + lower);
1484-
unsafe {
1485-
ptr::write(vector.get_unchecked_mut(0), element);
1486-
vector.set_len(1);
1487-
}
1488-
vector
1473+
let (lower, _) = iterator.size_hint();
1474+
let mut vector = Vec::with_capacity(lower);
1475+
1476+
// This function should be the moral equivalent of:
1477+
//
1478+
// for item in iterator {
1479+
// vector.push(item);
1480+
// }
1481+
//
1482+
// This equivalent crucially runs the iterator precisely once. Below we
1483+
// actually in theory run the iterator twice (one without bounds checks
1484+
// and one with). To achieve the "moral equivalent", we use the `if`
1485+
// statement below to break out early.
1486+
//
1487+
// If the first loop has terminated, then we have one of two conditions.
1488+
//
1489+
// 1. The underlying iterator returned `None`. In this case we are
1490+
// guaranteed that less than `vector.capacity()` elements have been
1491+
// returned, so we break out early.
1492+
// 2. The underlying iterator yielded `vector.capacity()` elements and
1493+
// has not yielded `None` yet. In this case we run the iterator to
1494+
// its end below.
1495+
for element in iterator.by_ref().take(vector.capacity()) {
1496+
let len = vector.len();
1497+
unsafe {
1498+
ptr::write(vector.get_unchecked_mut(len), element);
1499+
vector.set_len(len + 1);
1500+
}
1501+
}
1502+
1503+
if vector.len() == vector.capacity() {
1504+
for element in iterator {
1505+
vector.push(element);
14891506
}
1490-
};
1491-
vector.extend_desugared(iterator);
1507+
}
14921508
vector
14931509
}
14941510
}
@@ -1553,27 +1569,11 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
15531569
impl<T> Extend<T> for Vec<T> {
15541570
#[inline]
15551571
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
1556-
self.extend_desugared(iterable.into_iter())
1557-
}
1558-
}
1559-
1560-
impl<T> Vec<T> {
1561-
fn extend_desugared<I: Iterator<Item=T>>(&mut self, mut iterator: I) {
1562-
// This function should be the moral equivalent of:
1563-
//
1564-
// for item in iterator {
1565-
// self.push(item);
1566-
// }
1567-
while let Some(element) = iterator.next() {
1568-
let len = self.len();
1569-
if len == self.capacity() {
1570-
let (lower, _) = iterator.size_hint();
1571-
self.reserve(lower + 1);
1572-
}
1573-
unsafe {
1574-
ptr::write(self.get_unchecked_mut(len), element);
1575-
self.set_len(len + 1);
1576-
}
1572+
let iterator = iterable.into_iter();
1573+
let (lower, _) = iterator.size_hint();
1574+
self.reserve(lower);
1575+
for element in iterator {
1576+
self.push(element)
15771577
}
15781578
}
15791579
}

branches/try/src/libcore/char.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,17 @@ pub const MAX: char = '\u{10ffff}';
7474
/// ```
7575
/// use std::char;
7676
///
77-
/// assert_eq!(char::from_u32(0x2764), Some('❤'));
78-
/// assert_eq!(char::from_u32(0x110000), None); // invalid character
77+
/// let c = char::from_u32(10084); // produces `Some(❤)`
78+
/// assert_eq!(c, Some('❤'));
79+
/// ```
80+
///
81+
/// An invalid character:
82+
///
83+
/// ```
84+
/// use std::char;
85+
///
86+
/// let none = char::from_u32(1114112);
87+
/// assert_eq!(none, None);
7988
/// ```
8089
#[inline]
8190
#[stable(feature = "rust1", since = "1.0.0")]

branches/try/src/librustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
285285
fn check_static_type(&self, e: &ast::Expr) {
286286
let ty = ty::node_id_to_type(self.tcx, e.id);
287287
let infcx = infer::new_infer_ctxt(self.tcx);
288-
let mut fulfill_cx = traits::FulfillmentContext::new(false);
288+
let mut fulfill_cx = traits::FulfillmentContext::new();
289289
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
290290
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
291291
let env = ty::empty_parameter_environment(self.tcx);

branches/try/src/librustc/middle/dead.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {
4848
struct_has_extern_repr: bool,
4949
ignore_non_const_paths: bool,
5050
inherited_pub_visibility: bool,
51-
ignore_variant_stack: Vec<ast::NodeId>,
5251
}
5352

5453
impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
@@ -61,7 +60,6 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
6160
struct_has_extern_repr: false,
6261
ignore_non_const_paths: false,
6362
inherited_pub_visibility: false,
64-
ignore_variant_stack: vec![],
6563
}
6664
}
6765

@@ -82,9 +80,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
8280
def::DefPrimTy(_) => (),
8381
def::DefVariant(enum_id, variant_id, _) => {
8482
self.check_def_id(enum_id);
85-
if !self.ignore_variant_stack.contains(&variant_id.node) {
86-
self.check_def_id(variant_id);
87-
}
83+
self.check_def_id(variant_id);
8884
}
8985
_ => {
9086
self.check_def_id(def.def_id());
@@ -276,23 +272,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
276272
visit::walk_expr(self, expr);
277273
}
278274

279-
fn visit_arm(&mut self, arm: &ast::Arm) {
280-
if arm.pats.len() == 1 {
281-
let pat = &*arm.pats[0];
282-
let variants = pat_util::necessary_variants(&self.tcx.def_map, pat);
283-
284-
// Inside the body, ignore constructions of variants
285-
// necessary for the pattern to match. Those construction sites
286-
// can't be reached unless the variant is constructed elsewhere.
287-
let len = self.ignore_variant_stack.len();
288-
self.ignore_variant_stack.push_all(&*variants);
289-
visit::walk_arm(self, arm);
290-
self.ignore_variant_stack.truncate(len);
291-
} else {
292-
visit::walk_arm(self, arm);
293-
}
294-
}
295-
296275
fn visit_pat(&mut self, pat: &ast::Pat) {
297276
let def_map = &self.tcx.def_map;
298277
match pat.node {
@@ -414,11 +393,6 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
414393
worklist.push(*id);
415394
}
416395
for id in reachable_symbols {
417-
// Reachable variants can be dead, because we warn about
418-
// variants never constructed, not variants never used.
419-
if let Some(ast_map::NodeVariant(..)) = tcx.map.find(*id) {
420-
continue;
421-
}
422396
worklist.push(*id);
423397
}
424398

branches/try/src/librustc/middle/pat_util.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -201,27 +201,3 @@ pub fn def_to_path(tcx: &ty::ctxt, id: ast::DefId) -> ast::Path {
201201
span: DUMMY_SP,
202202
})
203203
}
204-
205-
/// Return variants that are necessary to exist for the pattern to match.
206-
pub fn necessary_variants(dm: &DefMap, pat: &ast::Pat) -> Vec<ast::NodeId> {
207-
let mut variants = vec![];
208-
walk_pat(pat, |p| {
209-
match p.node {
210-
ast::PatEnum(_, _) |
211-
ast::PatIdent(_, _, None) |
212-
ast::PatStruct(..) => {
213-
match dm.borrow().get(&p.id) {
214-
Some(&PathResolution { base_def: DefVariant(_, id, _), .. }) => {
215-
variants.push(id.node);
216-
}
217-
_ => ()
218-
}
219-
}
220-
_ => ()
221-
}
222-
true
223-
});
224-
variants.sort();
225-
variants.dedup();
226-
variants
227-
}

branches/try/src/librustc/middle/traits/fulfill.rs

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ use super::select::SelectionContext;
2828
use super::Unimplemented;
2929
use super::util::predicate_for_builtin_bound;
3030

31-
pub struct FulfilledPredicates<'tcx> {
32-
set: HashSet<ty::Predicate<'tcx>>
33-
}
34-
3531
/// The fulfillment context is used to drive trait resolution. It
3632
/// consists of a list of obligations that must be (eventually)
3733
/// satisfied. The job is to track which are satisfied, which yielded
@@ -48,7 +44,7 @@ pub struct FulfillmentContext<'tcx> {
4844
// than the `SelectionCache`: it avoids duplicate errors and
4945
// permits recursive obligations, which are often generated from
5046
// traits like `Send` et al.
51-
duplicate_set: FulfilledPredicates<'tcx>,
47+
duplicate_set: HashSet<ty::Predicate<'tcx>>,
5248

5349
// A list of all obligations that have been registered with this
5450
// fulfillment context.
@@ -84,8 +80,6 @@ pub struct FulfillmentContext<'tcx> {
8480
// obligations (otherwise, it's easy to fail to walk to a
8581
// particular node-id).
8682
region_obligations: NodeMap<Vec<RegionObligation<'tcx>>>,
87-
88-
errors_will_be_reported: bool,
8983
}
9084

9185
#[derive(Clone)]
@@ -96,30 +90,12 @@ pub struct RegionObligation<'tcx> {
9690
}
9791

9892
impl<'tcx> FulfillmentContext<'tcx> {
99-
/// Creates a new fulfillment context.
100-
///
101-
/// `errors_will_be_reported` indicates whether ALL errors that
102-
/// are generated by this fulfillment context will be reported to
103-
/// the end user. This is used to inform caching, because it
104-
/// allows us to conclude that traits that resolve successfully
105-
/// will in fact always resolve successfully (in particular, it
106-
/// guarantees that if some dependent obligation encounters a
107-
/// problem, compilation will be aborted). If you're not sure of
108-
/// the right value here, pass `false`, as that is the more
109-
/// conservative option.
110-
///
111-
/// FIXME -- a better option would be to hold back on modifying
112-
/// the global cache until we know that all dependent obligations
113-
/// are also satisfied. In that case, we could actually remove
114-
/// this boolean flag, and we'd also avoid the problem of squelching
115-
/// duplicate errors that occur across fns.
116-
pub fn new(errors_will_be_reported: bool) -> FulfillmentContext<'tcx> {
93+
pub fn new() -> FulfillmentContext<'tcx> {
11794
FulfillmentContext {
118-
duplicate_set: FulfilledPredicates::new(),
95+
duplicate_set: HashSet::new(),
11996
predicates: Vec::new(),
12097
attempted_mark: 0,
12198
region_obligations: NodeMap(),
122-
errors_will_be_reported: errors_will_be_reported,
12399
}
124100
}
125101

@@ -189,7 +165,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
189165

190166
assert!(!obligation.has_escaping_regions());
191167

192-
if self.is_duplicate_or_add(infcx.tcx, &obligation.predicate) {
168+
if !self.duplicate_set.insert(obligation.predicate.clone()) {
193169
debug!("register_predicate({}) -- already seen, skip", obligation.repr(infcx.tcx));
194170
return;
195171
}
@@ -255,28 +231,6 @@ impl<'tcx> FulfillmentContext<'tcx> {
255231
&self.predicates
256232
}
257233

258-
fn is_duplicate_or_add(&mut self, tcx: &ty::ctxt<'tcx>,
259-
predicate: &ty::Predicate<'tcx>)
260-
-> bool {
261-
// This is a kind of dirty hack to allow us to avoid "rederiving"
262-
// things that we have already proven in other methods.
263-
//
264-
// The idea is that any predicate that doesn't involve type
265-
// parameters and which only involves the 'static region (and
266-
// no other regions) is universally solvable, since impls are global.
267-
//
268-
// This is particularly important since even if we have a
269-
// cache hit in the selection context, we still wind up
270-
// evaluating the 'nested obligations'. This cache lets us
271-
// skip those.
272-
273-
if self.errors_will_be_reported && predicate.is_global() {
274-
tcx.fulfilled_predicates.borrow_mut().is_duplicate_or_add(predicate)
275-
} else {
276-
self.duplicate_set.is_duplicate_or_add(predicate)
277-
}
278-
}
279-
280234
/// Attempts to select obligations using `selcx`. If `only_new_obligations` is true, then it
281235
/// only attempts to select obligations that haven't been seen before.
282236
fn select<'a>(&mut self,
@@ -488,21 +442,3 @@ fn register_region_obligation<'tcx>(tcx: &ty::ctxt<'tcx>,
488442
.push(region_obligation);
489443

490444
}
491-
492-
impl<'tcx> FulfilledPredicates<'tcx> {
493-
pub fn new() -> FulfilledPredicates<'tcx> {
494-
FulfilledPredicates {
495-
set: HashSet::new()
496-
}
497-
}
498-
499-
pub fn is_duplicate(&self, p: &ty::Predicate<'tcx>) -> bool {
500-
self.set.contains(p)
501-
}
502-
503-
fn is_duplicate_or_add(&mut self, p: &ty::Predicate<'tcx>) -> bool {
504-
!self.set.insert(p.clone())
505-
}
506-
}
507-
508-

0 commit comments

Comments
 (0)