Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Commit

Permalink
Auto merge of #160 - japaric:unbreak, r=japaric
Browse files Browse the repository at this point in the history
unbreak build

None
  • Loading branch information
homunkulus committed Jan 23, 2018
2 parents 23882a1 + 25053aa commit 18e89d6
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 422 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sc = "0.2.1"

[dependencies.ralloc]
default-features = false
features = ["allocator"]
git = "https://github.com/redox-os/ralloc"
optional = true

Expand Down
7 changes: 3 additions & 4 deletions Xargo.std.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[dependencies]
collections = {}
rand = {}
core = {}
alloc = {}

[dependencies.compiler_builtins]
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"
stage = 1

[dependencies.std]
git = "https://github.com/japaric/steed"
stage = 2
stage = 2
7 changes: 3 additions & 4 deletions Xargo.test.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[dependencies]
collections = {}
rand = {}
core = {}
alloc = {}

[dependencies.compiler_builtins]
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"
stage = 1

[dependencies.std]
Expand All @@ -13,4 +12,4 @@ stage = 2

[dependencies.test]
git = "https://github.com/japaric/steed"
stage = 3
stage = 3
4 changes: 2 additions & 2 deletions Xargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[dependencies]
collections = {}
rand = {}
core = {}
alloc = {}

[dependencies.compiler_builtins]
features = ["mem"]
Expand Down
3 changes: 3 additions & 0 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ path = "/project/test"
stage = 3
EOF

# blow the old Xargo directory to avoid like "found possibly newer version of crate"
rm -rf $HOME/.xargo

cross test \
--target $TARGET \
--no-default-features \
Expand Down
10 changes: 4 additions & 6 deletions src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use hash::{Hash, Hasher, BuildHasher, SipHasher13};
use iter::{FromIterator, FusedIterator};
use mem::{self, replace};
use ops::{Deref, Index, InPlace, Place, Placer};
use rand::{self, Rng};
use ptr;
use sys;

use super::table::{self, Bucket, EmptyBucket, FullBucket, FullBucketMut, RawTable, SafeHash};
use super::table::BucketState::{Empty, Full};
Expand Down Expand Up @@ -2343,8 +2343,8 @@ impl RandomState {
// rand
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
pub fn new() -> RandomState {
let mut r = rand::thread_rng();
RandomState { k0: r.gen(), k1: r.gen() }
let (k0, k1) = sys::hashmap_random_keys();
RandomState { k0: k0, k1: k1 }
}
#[cfg(issue = "87")]
#[inline]
Expand All @@ -2364,9 +2364,7 @@ impl RandomState {
// increment one of the seeds on every RandomState creation, giving
// every corresponding HashMap a different iteration order.
thread_local!(static KEYS: Cell<(u64, u64)> = {
let r = rand::OsRng::new();
let mut r = r.expect("failed to create an OS RNG");
Cell::new((r.gen(), r.gen()))
Cell::new(sys::hashmap_random_keys())
});

KEYS.with(|keys| {
Expand Down
45 changes: 21 additions & 24 deletions src/collections/hash/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use marker;
use mem::{align_of, size_of, needs_drop};
use mem;
use ops::{Deref, DerefMut};
use ptr::{self, Unique, Shared};
use ptr::{self, Unique, NonNull};

use self::BucketState::*;

Expand Down Expand Up @@ -123,9 +123,6 @@ pub struct RawTable<K, V> {
marker: marker::PhantomData<(K, V)>,
}

unsafe impl<K: Send, V: Send> Send for RawTable<K, V> {}
unsafe impl<K: Sync, V: Sync> Sync for RawTable<K, V> {}

// An unsafe view of a RawTable bucket
// Valid indexes are within [0..table_capacity)
pub struct RawBucket<K, V> {
Expand Down Expand Up @@ -717,26 +714,25 @@ fn calculate_offsets(hashes_size: usize,
(pairs_offset, end_of_pairs, oflo)
}

// Returns a tuple of (minimum required malloc alignment, hash_offset,
// Returns a tuple of (minimum required malloc alignment,
// array_size), from the start of a mallocated array.
fn calculate_allocation(hash_size: usize,
hash_align: usize,
pairs_size: usize,
pairs_align: usize)
-> (usize, usize, usize, bool) {
let hash_offset = 0;
-> (usize, usize, bool) {
let (_, end_of_pairs, oflo) = calculate_offsets(hash_size, pairs_size, pairs_align);

let align = cmp::max(hash_align, pairs_align);

(align, hash_offset, end_of_pairs, oflo)
(align, end_of_pairs, oflo)
}

#[test]
fn test_offset_calculation() {
assert_eq!(calculate_allocation(128, 8, 16, 8), (8, 0, 144, false));
assert_eq!(calculate_allocation(3, 1, 2, 1), (1, 0, 5, false));
assert_eq!(calculate_allocation(6, 2, 12, 4), (4, 0, 20, false));
assert_eq!(calculate_allocation(128, 8, 16, 8), (8, 144, false));
assert_eq!(calculate_allocation(3, 1, 2, 1), (1, 5, false));
assert_eq!(calculate_allocation(6, 2, 12, 4), (4, 20, false));
assert_eq!(calculate_offsets(128, 15, 4), (128, 143, false));
assert_eq!(calculate_offsets(3, 2, 4), (4, 6, false));
assert_eq!(calculate_offsets(6, 12, 4), (8, 20, false));
Expand Down Expand Up @@ -768,10 +764,10 @@ impl<K, V> RawTable<K, V> {
// This is great in theory, but in practice getting the alignment
// right is a little subtle. Therefore, calculating offsets has been
// factored out into a different function.
let (alignment, hash_offset, size, oflo) = calculate_allocation(hashes_size,
align_of::<HashUint>(),
pairs_size,
align_of::<(K, V)>());
let (alignment, size, oflo) = calculate_allocation(hashes_size,
align_of::<HashUint>(),
pairs_size,
align_of::<(K, V)>());
assert!(!oflo, "capacity overflow");

// One check for overflow that covers calculation and rounding of size.
Expand All @@ -784,7 +780,7 @@ impl<K, V> RawTable<K, V> {
let buffer = Heap.alloc(Layout::from_size_align(size, alignment).unwrap())
.unwrap_or_else(|e| Heap.oom(e));

let hashes = buffer.offset(hash_offset as isize) as *mut HashUint;
let hashes = buffer as *mut HashUint;

RawTable {
capacity_mask: capacity.wrapping_sub(1),
Expand Down Expand Up @@ -877,7 +873,7 @@ impl<K, V> RawTable<K, V> {
elems_left,
marker: marker::PhantomData,
},
table: Shared::from(self),
table: NonNull::from(self),
marker: marker::PhantomData,
}
}
Expand Down Expand Up @@ -925,7 +921,7 @@ struct RawBuckets<'a, K, V> {
marker: marker::PhantomData<&'a ()>,
}

// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
impl<'a, K, V> Clone for RawBuckets<'a, K, V> {
fn clone(&self) -> RawBuckets<'a, K, V> {
RawBuckets {
Expand Down Expand Up @@ -976,7 +972,7 @@ pub struct Iter<'a, K: 'a, V: 'a> {
unsafe impl<'a, K: Sync, V: Sync> Sync for Iter<'a, K, V> {}
unsafe impl<'a, K: Sync, V: Sync> Send for Iter<'a, K, V> {}

// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
impl<'a, K, V> Clone for Iter<'a, K, V> {
fn clone(&self) -> Iter<'a, K, V> {
Iter {
Expand Down Expand Up @@ -1024,7 +1020,7 @@ impl<K, V> IntoIter<K, V> {

/// Iterator over the entries in a table, clearing the table.
pub struct Drain<'a, K: 'a, V: 'a> {
table: Shared<RawTable<K, V>>,
table: NonNull<RawTable<K, V>>,
iter: RawBuckets<'static, K, V>,
marker: marker::PhantomData<&'a RawTable<K, V>>,
}
Expand Down Expand Up @@ -1157,6 +1153,7 @@ impl<K: Clone, V: Clone> Clone for RawTable<K, V> {
}

new_ht.size = self.size();
new_ht.set_tag(self.tag());

new_ht
}
Expand All @@ -1183,10 +1180,10 @@ unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for RawTable<K, V> {

let hashes_size = self.capacity() * size_of::<HashUint>();
let pairs_size = self.capacity() * size_of::<(K, V)>();
let (align, _, size, oflo) = calculate_allocation(hashes_size,
align_of::<HashUint>(),
pairs_size,
align_of::<(K, V)>());
let (align, size, oflo) = calculate_allocation(hashes_size,
align_of::<HashUint>(),
pairs_size,
align_of::<(K, V)>());

debug_assert!(!oflo, "should be impossible");

Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#![feature(optin_builtin_traits)]
#![feature(placement_new_protocol)]
#![feature(prelude_import)]
#![feature(ptr_internals)]
#![feature(rand)]
#![feature(raw)]
#![feature(shared)]
Expand Down Expand Up @@ -74,7 +75,6 @@ extern crate naive_ralloc;
#[macro_use]
extern crate sc;
extern crate std_unicode;
extern crate rand as core_rand;
#[cfg(test)]
extern crate test;

Expand Down Expand Up @@ -199,7 +199,6 @@ mod linux;
mod memchr;
#[cfg(not(test))]
mod panicking;
mod rand;
mod sys;
mod sys_common;
mod libc;
Expand Down

0 comments on commit 18e89d6

Please sign in to comment.