Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 18 pull requests #58637

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
81cd1e6
Deprecate the unstable Vec::resize_default
scottmcm Jan 16, 2019
c654968
Deny the `overflowing_literals` lint for all editions
ollie27 Jan 17, 2019
6bfb280
deprecate before_exec in favor of unsafe pre_exec
RalfJung Feb 1, 2019
d48433d
also replace before_exec by pre_exec on redox
RalfJung Feb 1, 2019
b1709d2
update test
RalfJung Feb 1, 2019
cbbf8a7
deprecate things a bit slower
RalfJung Feb 2, 2019
6c67a76
pre_exec: expand docs
RalfJung Feb 2, 2019
59da97d
rustfmt the test
RalfJung Feb 2, 2019
33ee99b
more formatting
RalfJung Feb 3, 2019
e023403
POSIX requires async signal safety for fork in signal handlers, not i…
RalfJung Feb 3, 2019
f753d30
Suggest removing parentheses surrounding lifetimes
igorsdv Feb 5, 2019
9312ca1
Add a note about 2018e if someone uses `try {` in 2015e
scottmcm Feb 18, 2019
64c915e
override `VecDeque::try_rfold`, also update iterator
llogiq Feb 2, 2019
dae149c
improve worst-case performance of BTreeSet intersection
ssomers Feb 19, 2019
fab1fa9
remove the #[stable] thingy
ssomers Feb 19, 2019
f536f7a
remove another #[stable] thingy and superfluous comma's
ssomers Feb 19, 2019
0186d90
renamed enum variants, moved struct declaration down, condensed Inter…
ssomers Feb 19, 2019
abb07c4
remove a bit of dead code
matklad Feb 20, 2019
65622e3
cleanup macro after 2018 transition
matklad Feb 20, 2019
ad096d1
Dedup a rustdoc diagnostic construction
dwijnand Feb 20, 2019
8cf3605
fix typo
llogiq Feb 20, 2019
103ed0c
Search for target_triple.json only if builtin target not found
gnzlbg Feb 20, 2019
b2a02c8
Fixes #58586: Make E0505 explain example fail for 2018 edition
gurgalex Feb 20, 2019
102436d
Put Future trait into spotlight
Feb 20, 2019
6a5abea
Remove braces from most E0505 examples
gurgalex Feb 20, 2019
0f6d363
explain why we use static alignment in ref-to-place conversion
RalfJung Feb 21, 2019
b01f81b
remark about the one place where place computation calls size_and_ali…
RalfJung Feb 21, 2019
09a2454
introduce benchmarks of BTreeSet.intersection
ssomers Feb 21, 2019
4fd0cc1
Merge branch 'btreeset_intersection_benchmarks' into btreeset_interse…
ssomers Feb 21, 2019
4867a8c
Update miri links
phansch Feb 21, 2019
36f6652
Fix more nursery links in CONTRIBUTING.md
phansch Feb 21, 2019
88d55f5
Make std feature list sorted
matklad Feb 22, 2019
599ddc5
Rollup merge of #55632 - ollie27:deny_overflowing_literals, r=Centril
Centril Feb 22, 2019
90a122e
Rollup merge of #57656 - scottmcm:deprecate-resize_default, r=SimonSapin
Centril Feb 22, 2019
16dfbbf
Rollup merge of #58059 - RalfJung:before_exec, r=alexcrichton
Centril Feb 22, 2019
82a1763
Rollup merge of #58064 - llogiq:vec-deque-try-rfold, r=scottmcm
Centril Feb 22, 2019
2b26261
Rollup merge of #58198 - igorsdv:suggest-removing-parentheses-surroun…
Centril Feb 22, 2019
52fd337
Rollup merge of #58555 - scottmcm:try-2015, r=Centril
Centril Feb 22, 2019
ef1faf4
Rollup merge of #58577 - ssomers:btreeset_intersection, r=KodrAus
Centril Feb 22, 2019
bb36117
Rollup merge of #58588 - matklad:dead-code, r=petrochenkov
Centril Feb 22, 2019
e8cf01b
Rollup merge of #58589 - matklad:remove-hack, r=petrochenkov
Centril Feb 22, 2019
43e0268
Rollup merge of #58591 - dwijnand:dedup-a-rustdoc-diag-construction, …
Centril Feb 22, 2019
7fafdc1
Rollup merge of #58600 - llogiq:documentation-tests-typo, r=frewsxcv
Centril Feb 22, 2019
067cb21
Rollup merge of #58601 - gnzlbg:json_error, r=oli-obk
Centril Feb 22, 2019
49ef8cf
Rollup merge of #58606 - stjepang:put-future-into-spotlight, r=alexcr…
Centril Feb 22, 2019
30b69c5
Rollup merge of #58607 - gurgalex:fail_E0505_for_2018_edition, r=matt…
Centril Feb 22, 2019
0f3bbbc
Rollup merge of #58615 - RalfJung:ref-to-place-alignment, r=oli-obk
Centril Feb 22, 2019
be29df7
Rollup merge of #58621 - phansch:update_miri_links, r=oli-obk
Centril Feb 22, 2019
6ce5b28
Rollup merge of #58632 - matklad:reduce-contention, r=Centril
Centril Feb 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ it can be found [here][rctd].

Currently building Rust will also build the following external projects:

* [clippy](https://github.com/rust-lang-nursery/rust-clippy)
* [miri](https://github.com/solson/miri)
* [rustfmt](https://github.com/rust-lang-nursery/rustfmt)
* [rls](https://github.com/rust-lang-nursery/rls/)
* [clippy](https://github.com/rust-lang/rust-clippy)
* [miri](https://github.com/rust-lang/miri)
* [rustfmt](https://github.com/rust-lang/rustfmt)
* [rls](https://github.com/rust-lang/rls/)

We allow breakage of these tools in the nightly channel. Maintainers of these
projects will be notified of the breakages and should fix them as soon as
Expand All @@ -191,9 +191,9 @@ before the PR is merged.

Rust's build system builds a number of tools that make use of the
internals of the compiler. This includes
[Clippy](https://github.com/rust-lang-nursery/rust-clippy),
[RLS](https://github.com/rust-lang-nursery/rls) and
[rustfmt](https://github.com/rust-lang-nursery/rustfmt). If these tools
[Clippy](https://github.com/rust-lang/rust-clippy),
[RLS](https://github.com/rust-lang/rls) and
[rustfmt](https://github.com/rust-lang/rustfmt). If these tools
break because of your changes, you may run into a sort of "chicken and egg"
problem. These tools rely on the latest compiler to be built so you can't update
them to reflect your changes to the compiler until those changes are merged into
Expand Down Expand Up @@ -253,10 +253,10 @@ to complete a few more steps which are outlined with their rationale below.

*(This error may change in the future to include more information.)*
```
error: failed to resolve patches for `https://github.com/rust-lang-nursery/rustfmt`
error: failed to resolve patches for `https://github.com/rust-lang/rustfmt`

Caused by:
patch for `rustfmt-nightly` in `https://github.com/rust-lang-nursery/rustfmt` did not resolve to any crates
patch for `rustfmt-nightly` in `https://github.com/rust-lang/rustfmt` did not resolve to any crates
failed to run: ~/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path ~/rust/src/bootstrap/Cargo.toml
```

Expand Down
20 changes: 20 additions & 0 deletions src/doc/rustc/src/lints/listing/deny-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,26 @@ error: const items should never be #[no_mangle]
|
```

## overflowing-literals

This lint detects literal out of range for its type. Some
example code that triggers this lint:

```rust,compile_fail
let x: u8 = 1000;
```

This will produce:

```text
error: literal out of range for u8
--> src/main.rs:2:17
|
2 | let x: u8 = 1000;
| ^^^^
|
```

## parenthesized-params-in-types-and-modules

This lint detects incorrect parentheses. Some example code that triggers this
Expand Down
20 changes: 0 additions & 20 deletions src/doc/rustc/src/lints/listing/warn-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,26 +285,6 @@ warning: functions generic over types must be mangled
|
```

## overflowing-literals

This lint detects literal out of range for its type. Some
example code that triggers this lint:

```rust
let x: u8 = 1000;
```

This will produce:

```text
warning: literal out of range for u8
--> src/main.rs:2:17
|
2 | let x: u8 = 1000;
| ^^^^
|
```

## path-statements

This lint detects path statements with no effect. Some example code that
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustdoc/src/documentation-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ disambiguate the error type:
/// use std::io;
/// let mut input = String::new();
/// io::stdin().read_line(&mut input)?;
/// # Ok::<(), io:Error>(())
/// # Ok::<(), io::Error>(())
/// ```
```

Expand Down
1 change: 1 addition & 0 deletions src/liballoc/benches/btree/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod map;
mod set;
88 changes: 88 additions & 0 deletions src/liballoc/benches/btree/set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use std::collections::BTreeSet;

use rand::{thread_rng, Rng};
use test::{black_box, Bencher};

fn random(n1: u32, n2: u32) -> [BTreeSet<usize>; 2] {
let mut rng = thread_rng();
let mut set1 = BTreeSet::new();
let mut set2 = BTreeSet::new();
for _ in 0..n1 {
let i = rng.gen::<usize>();
set1.insert(i);
}
for _ in 0..n2 {
let i = rng.gen::<usize>();
set2.insert(i);
}
[set1, set2]
}

fn staggered(n1: u32, n2: u32) -> [BTreeSet<u32>; 2] {
let mut even = BTreeSet::new();
let mut odd = BTreeSet::new();
for i in 0..n1 {
even.insert(i * 2);
}
for i in 0..n2 {
odd.insert(i * 2 + 1);
}
[even, odd]
}

fn neg_vs_pos(n1: u32, n2: u32) -> [BTreeSet<i32>; 2] {
let mut neg = BTreeSet::new();
let mut pos = BTreeSet::new();
for i in -(n1 as i32)..=-1 {
neg.insert(i);
}
for i in 1..=(n2 as i32) {
pos.insert(i);
}
[neg, pos]
}

fn pos_vs_neg(n1: u32, n2: u32) -> [BTreeSet<i32>; 2] {
let mut neg = BTreeSet::new();
let mut pos = BTreeSet::new();
for i in -(n1 as i32)..=-1 {
neg.insert(i);
}
for i in 1..=(n2 as i32) {
pos.insert(i);
}
[pos, neg]
}

macro_rules! set_intersection_bench {
($name: ident, $sets: expr) => {
#[bench]
pub fn $name(b: &mut Bencher) {
// setup
let sets = $sets;

// measure
b.iter(|| {
let x = sets[0].intersection(&sets[1]).count();
black_box(x);
})
}
};
}

set_intersection_bench! {intersect_random_100, random(100, 100)}
set_intersection_bench! {intersect_random_10k, random(10_000, 10_000)}
set_intersection_bench! {intersect_random_10_vs_10k, random(10, 10_000)}
set_intersection_bench! {intersect_random_10k_vs_10, random(10_000, 10)}
set_intersection_bench! {intersect_staggered_100, staggered(100, 100)}
set_intersection_bench! {intersect_staggered_10k, staggered(10_000, 10_000)}
set_intersection_bench! {intersect_staggered_10_vs_10k, staggered(10, 10_000)}
set_intersection_bench! {intersect_staggered_10k_vs_10, staggered(10_000, 10)}
set_intersection_bench! {intersect_neg_vs_pos_100, neg_vs_pos(100, 100)}
set_intersection_bench! {intersect_neg_vs_pos_10k, neg_vs_pos(10_000, 10_000)}
set_intersection_bench! {intersect_neg_vs_pos_10_vs_10k,neg_vs_pos(10, 10_000)}
set_intersection_bench! {intersect_neg_vs_pos_10k_vs_10,neg_vs_pos(10_000, 10)}
set_intersection_bench! {intersect_pos_vs_neg_100, pos_vs_neg(100, 100)}
set_intersection_bench! {intersect_pos_vs_neg_10k, pos_vs_neg(10_000, 10_000)}
set_intersection_bench! {intersect_pos_vs_neg_10_vs_10k,pos_vs_neg(10, 10_000)}
set_intersection_bench! {intersect_pos_vs_neg_10k_vs_10,pos_vs_neg(10_000, 10)}
7 changes: 7 additions & 0 deletions src/liballoc/benches/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ fn bench_mut_iter_1000(b: &mut Bencher) {
black_box(sum);
})
}

#[bench]
fn bench_try_fold(b: &mut Bencher) {
let ring: VecDeque<_> = (0..1000).collect();

b.iter(|| black_box(ring.iter().try_fold(0, |a, b| Some(a + b))))
}
102 changes: 87 additions & 15 deletions src/liballoc/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ impl<T: fmt::Debug> fmt::Debug for SymmetricDifference<'_, T> {
}
}

/// Whether the sizes of two sets are roughly the same order of magnitude.
///
/// If they are, or if either set is empty, then their intersection
/// is efficiently calculated by iterating both sets jointly.
/// If they aren't, then it is more scalable to iterate over the small set
/// and find matches in the large set (except if the largest element in
/// the small set hardly surpasses the smallest element in the large set).
fn are_proportionate_for_intersection(len1: usize, len2: usize) -> bool {
let (small, large) = if len1 <= len2 {
(len1, len2)
} else {
(len2, len1)
};
(large >> 7) <= small
}

/// A lazy iterator producing elements in the intersection of `BTreeSet`s.
///
/// This `struct` is created by the [`intersection`] method on [`BTreeSet`].
Expand All @@ -165,7 +181,13 @@ impl<T: fmt::Debug> fmt::Debug for SymmetricDifference<'_, T> {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Intersection<'a, T: 'a> {
a: Peekable<Iter<'a, T>>,
b: Peekable<Iter<'a, T>>,
b: IntersectionOther<'a, T>,
}

#[derive(Debug)]
enum IntersectionOther<'a, T> {
Stitch(Peekable<Iter<'a, T>>),
Search(&'a BTreeSet<T>),
}

#[stable(feature = "collection_debug", since = "1.17.0")]
Expand Down Expand Up @@ -326,9 +348,21 @@ impl<T: Ord> BTreeSet<T> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn intersection<'a>(&'a self, other: &'a BTreeSet<T>) -> Intersection<'a, T> {
Intersection {
a: self.iter().peekable(),
b: other.iter().peekable(),
if are_proportionate_for_intersection(self.len(), other.len()) {
Intersection {
a: self.iter().peekable(),
b: IntersectionOther::Stitch(other.iter().peekable()),
}
} else if self.len() <= other.len() {
Intersection {
a: self.iter().peekable(),
b: IntersectionOther::Search(&other),
}
} else {
Intersection {
a: other.iter().peekable(),
b: IntersectionOther::Search(&self),
}
}
}

Expand Down Expand Up @@ -1069,6 +1103,14 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
#[stable(feature = "fused", since = "1.26.0")]
impl<T: Ord> FusedIterator for SymmetricDifference<'_, T> {}

impl<'a, T> Clone for IntersectionOther<'a, T> {
fn clone(&self) -> IntersectionOther<'a, T> {
match self {
IntersectionOther::Stitch(ref iter) => IntersectionOther::Stitch(iter.clone()),
IntersectionOther::Search(set) => IntersectionOther::Search(set),
}
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Clone for Intersection<'_, T> {
fn clone(&self) -> Self {
Expand All @@ -1083,24 +1125,36 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
type Item = &'a T;

fn next(&mut self) -> Option<&'a T> {
loop {
match Ord::cmp(self.a.peek()?, self.b.peek()?) {
Less => {
self.a.next();
}
Equal => {
self.b.next();
return self.a.next();
match self.b {
IntersectionOther::Stitch(ref mut self_b) => loop {
match Ord::cmp(self.a.peek()?, self_b.peek()?) {
Less => {
self.a.next();
}
Equal => {
self_b.next();
return self.a.next();
}
Greater => {
self_b.next();
}
}
Greater => {
self.b.next();
}
IntersectionOther::Search(set) => loop {
let e = self.a.next()?;
if set.contains(&e) {
return Some(e);
}
}
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(min(self.a.len(), self.b.len())))
let b_len = match self.b {
IntersectionOther::Stitch(ref iter) => iter.len(),
IntersectionOther::Search(set) => set.len(),
};
(0, Some(min(self.a.len(), b_len)))
}
}

Expand Down Expand Up @@ -1140,3 +1194,21 @@ impl<'a, T: Ord> Iterator for Union<'a, T> {

#[stable(feature = "fused", since = "1.26.0")]
impl<T: Ord> FusedIterator for Union<'_, T> {}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_are_proportionate_for_intersection() {
assert!(are_proportionate_for_intersection(0, 0));
assert!(are_proportionate_for_intersection(0, 127));
assert!(!are_proportionate_for_intersection(0, 128));
assert!(are_proportionate_for_intersection(1, 255));
assert!(!are_proportionate_for_intersection(1, 256));
assert!(are_proportionate_for_intersection(127, 0));
assert!(!are_proportionate_for_intersection(128, 0));
assert!(are_proportionate_for_intersection(255, 1));
assert!(!are_proportionate_for_intersection(256, 1));
}
}
Loading