Skip to content

Commit 203ffb0

Browse files
committed
---
yaml --- r: 150895 b: refs/heads/try2 c: 29a3970 h: refs/heads/master i: 150893: cd33181 150891: 02e6191 150887: 789071a 150879: efed65a v: v3
1 parent 1a733d0 commit 203ffb0

File tree

18 files changed

+486
-136
lines changed

18 files changed

+486
-136
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: f829d208a30a4a8880ffb07ce4582e30c8f8d57f
8+
refs/heads/try2: 29a39700a1a46de2046bd6913da9c38d064a5a8f
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcollections/bitv.rs

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ impl SmallBitv {
9797
pub fn set_all(&mut self) { self.bits = !0; }
9898

9999
#[inline]
100-
pub fn is_true(&self, nbits: uint) -> bool {
100+
pub fn all(&self, nbits: uint) -> bool {
101101
small_mask(nbits) & !self.bits == 0
102102
}
103103

104104
#[inline]
105-
pub fn is_false(&self, nbits: uint) -> bool {
105+
pub fn none(&self, nbits: uint) -> bool {
106106
small_mask(nbits) & self.bits == 0
107107
}
108108

@@ -412,13 +412,10 @@ impl Bitv {
412412

413413
/// Returns `true` if all bits are 1
414414
#[inline]
415-
pub fn is_true(&self) -> bool {
415+
pub fn all(&self) -> bool {
416416
match self.rep {
417-
Small(ref b) => b.is_true(self.nbits),
418-
_ => {
419-
for i in self.iter() { if !i { return false; } }
420-
true
421-
}
417+
Small(ref b) => b.all(self.nbits),
418+
_ => self.iter().all(|x| x)
422419
}
423420
}
424421

@@ -433,16 +430,19 @@ impl Bitv {
433430
}
434431

435432
/// Returns `true` if all bits are 0
436-
pub fn is_false(&self) -> bool {
433+
pub fn none(&self) -> bool {
437434
match self.rep {
438-
Small(ref b) => b.is_false(self.nbits),
439-
Big(_) => {
440-
for i in self.iter() { if i { return false; } }
441-
true
442-
}
435+
Small(ref b) => b.none(self.nbits),
436+
_ => self.iter().all(|x| !x)
443437
}
444438
}
445439

440+
#[inline]
441+
/// Returns `true` if any bit is 1
442+
pub fn any(&self) -> bool {
443+
!self.none()
444+
}
445+
446446
pub fn init_to_vec(&self, i: uint) -> uint {
447447
return if self.get(i) { 1 } else { 0 };
448448
}
@@ -1551,6 +1551,51 @@ mod tests {
15511551
assert!(b.contains(&1000));
15521552
}
15531553

1554+
#[test]
1555+
fn test_small_bitv_tests() {
1556+
let v = from_bytes([0]);
1557+
assert!(!v.all());
1558+
assert!(!v.any());
1559+
assert!(v.none());
1560+
1561+
let v = from_bytes([0b00010100]);
1562+
assert!(!v.all());
1563+
assert!(v.any());
1564+
assert!(!v.none());
1565+
1566+
let v = from_bytes([0xFF]);
1567+
assert!(v.all());
1568+
assert!(v.any());
1569+
assert!(!v.none());
1570+
}
1571+
1572+
#[test]
1573+
fn test_big_bitv_tests() {
1574+
let v = from_bytes([ // 88 bits
1575+
0, 0, 0, 0,
1576+
0, 0, 0, 0,
1577+
0, 0, 0]);
1578+
assert!(!v.all());
1579+
assert!(!v.any());
1580+
assert!(v.none());
1581+
1582+
let v = from_bytes([ // 88 bits
1583+
0, 0, 0b00010100, 0,
1584+
0, 0, 0, 0b00110100,
1585+
0, 0, 0]);
1586+
assert!(!v.all());
1587+
assert!(v.any());
1588+
assert!(!v.none());
1589+
1590+
let v = from_bytes([ // 88 bits
1591+
0xFF, 0xFF, 0xFF, 0xFF,
1592+
0xFF, 0xFF, 0xFF, 0xFF,
1593+
0xFF, 0xFF, 0xFF]);
1594+
assert!(v.all());
1595+
assert!(v.any());
1596+
assert!(!v.none());
1597+
}
1598+
15541599
fn rng() -> rand::IsaacRng {
15551600
let seed = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
15561601
rand::SeedableRng::from_seed(seed)

branches/try2/src/librustc/metadata/creader.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,6 @@ fn resolve_crate<'a>(e: &mut Env,
300300
dylib, rlib, metadata
301301
} = load_ctxt.load_library_crate(root);
302302

303-
// Claim this crate number and cache it
304-
let cnum = e.next_crate_num;
305-
e.next_crate_num += 1;
306-
307303
// Stash paths for top-most crate locally if necessary.
308304
let crate_paths = if root.is_none() {
309305
Some(CratePaths {
@@ -324,6 +320,17 @@ fn resolve_crate<'a>(e: &mut Env,
324320
@RefCell::new(HashMap::new())
325321
};
326322

323+
// Claim this crate number and cache it if we're linking to the
324+
// crate, otherwise it's a syntax-only crate and we don't need to
325+
// reserve a number
326+
let cnum = if should_link {
327+
let n = e.next_crate_num;
328+
e.next_crate_num += 1;
329+
n
330+
} else {
331+
-1
332+
};
333+
327334
let cmeta = @cstore::crate_metadata {
328335
name: load_ctxt.crate_id.name.to_owned(),
329336
data: metadata,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
272272
}
273273

274274
// Ugh -- but this ensures any new variants won't be forgotten
275+
ast_map::NodeLifetime(..) |
275276
ast_map::NodeExpr(..) |
276277
ast_map::NodeStmt(..) |
277278
ast_map::NodeArg(..) |

branches/try2/src/librustc/middle/typeck/variance.rs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ use arena::Arena;
198198
use middle::ty;
199199
use std::fmt;
200200
use syntax::ast;
201+
use syntax::ast_map;
201202
use syntax::ast_util;
202203
use syntax::owned_slice::OwnedSlice;
203204
use syntax::visit;
@@ -517,6 +518,13 @@ impl<'a> Visitor<()> for ConstraintContext<'a> {
517518
}
518519
}
519520

521+
/// Is `param_id` a lifetime according to `map`?
522+
fn is_lifetime(map: &ast_map::Map, param_id: ast::NodeId) -> bool {
523+
match map.find(param_id) {
524+
Some(ast_map::NodeLifetime(..)) => true, _ => false
525+
}
526+
}
527+
520528
impl<'a> ConstraintContext<'a> {
521529
fn tcx(&self) -> &'a ty::ctxt {
522530
self.terms_cx.tcx
@@ -533,6 +541,70 @@ impl<'a> ConstraintContext<'a> {
533541
}
534542
}
535543

544+
fn find_binding_for_lifetime(&self, param_id: ast::NodeId) -> ast::NodeId {
545+
let tcx = self.terms_cx.tcx;
546+
assert!(is_lifetime(&tcx.map, param_id));
547+
match tcx.named_region_map.find(&param_id) {
548+
Some(&ast::DefEarlyBoundRegion(_, lifetime_decl_id))
549+
=> lifetime_decl_id,
550+
Some(_) => fail!("should not encounter non early-bound cases"),
551+
552+
// The lookup should only fail when `param_id` is
553+
// itself a lifetime binding: use it as the decl_id.
554+
None => param_id,
555+
}
556+
557+
}
558+
559+
/// Is `param_id` a type parameter for which we infer variance?
560+
fn is_to_be_inferred(&self, param_id: ast::NodeId) -> bool {
561+
let result = self.terms_cx.inferred_map.contains_key(&param_id);
562+
563+
// To safe-guard against invalid inferred_map constructions,
564+
// double-check if variance is inferred at some use of a type
565+
// parameter (by inspecting parent of its binding declaration
566+
// to see if it is introduced by a type or by a fn/impl).
567+
568+
let check_result = |this:&ConstraintContext| -> bool {
569+
let tcx = this.terms_cx.tcx;
570+
let decl_id = this.find_binding_for_lifetime(param_id);
571+
// Currently only called on lifetimes; double-checking that.
572+
assert!(is_lifetime(&tcx.map, param_id));
573+
let parent_id = tcx.map.get_parent(decl_id);
574+
let parent = tcx.map.find(parent_id).unwrap_or_else(
575+
|| fail!("tcx.map missing entry for id: {}", parent_id));
576+
577+
let is_inferred;
578+
macro_rules! cannot_happen { () => { {
579+
fail!("invalid parent: {:s} for {:s}",
580+
tcx.map.node_to_str(parent_id),
581+
tcx.map.node_to_str(param_id));
582+
} } }
583+
584+
match parent {
585+
ast_map::NodeItem(p) => {
586+
match p.node {
587+
ast::ItemTy(..) |
588+
ast::ItemEnum(..) |
589+
ast::ItemStruct(..) |
590+
ast::ItemTrait(..) => is_inferred = true,
591+
ast::ItemFn(..) => is_inferred = false,
592+
_ => cannot_happen!(),
593+
}
594+
}
595+
ast_map::NodeTraitMethod(..) => is_inferred = false,
596+
ast_map::NodeMethod(_) => is_inferred = false,
597+
_ => cannot_happen!(),
598+
}
599+
600+
return is_inferred;
601+
};
602+
603+
assert_eq!(result, check_result(self));
604+
605+
return result;
606+
}
607+
536608
fn declared_variance(&self,
537609
param_def_id: ast::DefId,
538610
item_def_id: ast::DefId,
@@ -788,8 +860,10 @@ impl<'a> ConstraintContext<'a> {
788860
variance: VarianceTermPtr<'a>) {
789861
match region {
790862
ty::ReEarlyBound(param_id, _, _) => {
791-
let index = self.inferred_index(param_id);
792-
self.add_constraint(index, variance);
863+
if self.is_to_be_inferred(param_id) {
864+
let index = self.inferred_index(param_id);
865+
self.add_constraint(index, variance);
866+
}
793867
}
794868

795869
ty::ReStatic => { }

branches/try2/src/libstd/intrinsics.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,7 @@ extern "rust-intrinsic" {
394394

395395
pub fn roundf32(x: f32) -> f32;
396396
pub fn roundf64(x: f64) -> f64;
397-
}
398-
#[cfg(not(stage0))]
399-
extern "rust-intrinsic" {
397+
400398
pub fn ctpop8(x: u8) -> u8;
401399
pub fn ctpop16(x: u16) -> u16;
402400
pub fn ctpop32(x: u32) -> u32;
@@ -415,29 +413,7 @@ extern "rust-intrinsic" {
415413
pub fn bswap16(x: u16) -> u16;
416414
pub fn bswap32(x: u32) -> u32;
417415
pub fn bswap64(x: u64) -> u64;
418-
}
419416

420-
// NOTE: remove this after a snap, and merge the extern block above
421-
macro_rules! stage0_hack {
422-
($( $u_ty:ty, $i_ty:ty => $($name:ident),*);*) => {
423-
$(
424-
$(
425-
#[cfg(stage0)]
426-
pub unsafe fn $name(x: $u_ty) -> $u_ty {
427-
extern "rust-intrinsic" { fn $name(x: $i_ty) -> $i_ty; }
428-
$name(x as $i_ty) as $u_ty
429-
}
430-
)*)*
431-
}
432-
}
433-
stage0_hack! {
434-
u8, i8 => ctpop8, ctlz8, cttz8;
435-
u16, i16 => ctpop16, ctlz16, cttz16, bswap16;
436-
u32, i32 => ctpop32, ctlz32, cttz32, bswap32;
437-
u64, i64 => ctpop64, ctlz64, cttz64, bswap64
438-
}
439-
440-
extern "rust-intrinsic" {
441417
pub fn i8_add_with_overflow(x: i8, y: i8) -> (i8, bool);
442418
pub fn i16_add_with_overflow(x: i16, y: i16) -> (i16, bool);
443419
pub fn i32_add_with_overflow(x: i32, y: i32) -> (i32, bool);

branches/try2/src/libsyntax/ast_map.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pub enum Node {
107107

108108
/// NodeStructCtor represents a tuple struct.
109109
NodeStructCtor(@StructDef),
110+
111+
NodeLifetime(@Lifetime),
110112
}
111113

112114
// The odd layout is to bring down the total size.
@@ -127,6 +129,7 @@ enum MapEntry {
127129
EntryLocal(NodeId, @Pat),
128130
EntryBlock(NodeId, P<Block>),
129131
EntryStructCtor(NodeId, @StructDef),
132+
EntryLifetime(NodeId, @Lifetime),
130133

131134
// Roots for node trees.
132135
RootCrate,
@@ -153,6 +156,7 @@ impl MapEntry {
153156
EntryLocal(id, _) => id,
154157
EntryBlock(id, _) => id,
155158
EntryStructCtor(id, _) => id,
159+
EntryLifetime(id, _) => id,
156160
_ => return None
157161
})
158162
}
@@ -170,6 +174,7 @@ impl MapEntry {
170174
EntryLocal(_, p) => NodeLocal(p),
171175
EntryBlock(_, p) => NodeBlock(p),
172176
EntryStructCtor(_, p) => NodeStructCtor(p),
177+
EntryLifetime(_, p) => NodeLifetime(p),
173178
_ => return None
174179
})
175180
}
@@ -213,6 +218,8 @@ impl Map {
213218
self.find_entry(id).and_then(|x| x.to_node())
214219
}
215220

221+
/// Retrieve the parent NodeId for `id`, or `id` itself if no
222+
/// parent is registered in this map.
216223
pub fn get_parent(&self, id: NodeId) -> NodeId {
217224
self.find_entry(id).and_then(|x| x.parent()).unwrap_or(id)
218225
}
@@ -500,6 +507,15 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> {
500507
SmallVector::one(stmt)
501508
}
502509

510+
fn fold_type_method(&mut self, m: &TypeMethod) -> TypeMethod {
511+
let parent = self.parent;
512+
self.parent = DUMMY_NODE_ID;
513+
let m = fold::noop_fold_type_method(m, self);
514+
assert_eq!(self.parent, m.id);
515+
self.parent = parent;
516+
m
517+
}
518+
503519
fn fold_method(&mut self, m: @Method) -> @Method {
504520
let parent = self.parent;
505521
self.parent = DUMMY_NODE_ID;
@@ -522,6 +538,12 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> {
522538
self.insert(block.id, EntryBlock(self.parent, block));
523539
block
524540
}
541+
542+
fn fold_lifetime(&mut self, lifetime: &Lifetime) -> Lifetime {
543+
let lifetime = fold::noop_fold_lifetime(lifetime, self);
544+
self.insert(lifetime.id, EntryLifetime(self.parent, @lifetime));
545+
lifetime
546+
}
525547
}
526548

527549
pub fn map_crate<F: FoldOps>(krate: Crate, fold_ops: F) -> (Crate, Map) {
@@ -658,6 +680,9 @@ fn node_id_to_str(map: &Map, id: NodeId) -> ~str {
658680
Some(NodeStructCtor(_)) => {
659681
format!("struct_ctor {} (id={})", map.path_to_str(id), id)
660682
}
683+
Some(NodeLifetime(ref l)) => {
684+
format!("lifetime {} (id={})", pprust::lifetime_to_str(*l), id)
685+
}
661686
None => {
662687
format!("unknown node (id={})", id)
663688
}

0 commit comments

Comments
 (0)