Skip to content

Rollup of 14 pull requests #58878

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

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1fd2f16
Have all methods of Filter and FilterMap use internal iteration
timvermeulen Feb 25, 2019
d89c2f6
Use informational target machine for metadata
nagisa Feb 20, 2019
8884771
Add relevant benchmarks
timvermeulen Feb 27, 2019
ec2e4ba
Improve existing benchmarks to prevent extreme optimizations
timvermeulen Feb 27, 2019
88bd624
Add trailing newline
timvermeulen Feb 27, 2019
4e7d4c7
ManuallyDrop != MaybeUninit
RalfJung Feb 27, 2019
b70a953
Replace `s` with `self` in docs for str methods taking self.
tspiteri Feb 20, 2019
f92c204
improve readability
RalfJung Feb 27, 2019
a998b1f
allow specifying attributes for tool lints
euclio Feb 27, 2019
0c1a38c
Update src/libcore/mem.rs
Centril Feb 28, 2019
96be181
Fixed a syntax error in the pin docs
Feb 28, 2019
f50cf94
Wrap the self-profiler in an `Arc<Mutex<>>`
wesleywiser Feb 10, 2019
979ece9
Remove profiler output and replace with a raw event dump
wesleywiser Feb 11, 2019
2fb8d60
Reduce the size of events by using a u64 instead of Instant
wesleywiser Feb 13, 2019
d1ac877
Use FxHashMap
wesleywiser Feb 25, 2019
3391f6c
tidy: deny(rust_2018_idioms)
Centril Mar 1, 2019
805145f
Revert "Auto merge of #58597 - pietroalbini:appveyor-gce, r=alexcrich…
pietroalbini Mar 1, 2019
260b091
tools/rustbook: deny(rust_2018_idioms)
Centril Mar 1, 2019
c259489
tools/remote-test-{client,server}: deny(rust_2018_idioms)
Centril Mar 1, 2019
670a4d6
Fix typo in Vec#resize_with documentation
jens1o Mar 1, 2019
c3aab14
Forbid duplicating Cargo as a dependency
mati865 Mar 1, 2019
04d0a8c
Fix C-variadic function printing
dlrobertson Mar 2, 2019
72f0ca5
Nit
alexreg Mar 2, 2019
58b16b7
Rollup merge of #58425 - wesleywiser:more_profiler_changes, r=michael…
Mark-Simulacrum Mar 2, 2019
a4ea569
Rollup merge of #58605 - nagisa:fix-the-metadata, r=michaelwoerister
Mark-Simulacrum Mar 2, 2019
43ce943
Rollup merge of #58730 - timvermeulen:internal_iteration, r=scottmcm
Mark-Simulacrum Mar 2, 2019
4ae4777
Rollup merge of #58780 - RalfJung:manually-drop, r=nagisa
Mark-Simulacrum Mar 2, 2019
d017a68
Rollup merge of #58782 - tspiteri:str-escape-self, r=kennytm
Mark-Simulacrum Mar 2, 2019
2ebea54
Rollup merge of #58785 - euclio:tool-lint-attrs, r=estebank
Mark-Simulacrum Mar 2, 2019
11c643d
Rollup merge of #58821 - alex:patch-1, r=Centril
Mark-Simulacrum Mar 2, 2019
c4e3131
Rollup merge of #58830 - Centril:rust_2018_idioms-tidy, r=oli-obk
Mark-Simulacrum Mar 2, 2019
ea65c50
Rollup merge of #58832 - pietroalbini:appveyor-hyperv, r=kennytm
Mark-Simulacrum Mar 2, 2019
fac5293
Rollup merge of #58833 - Centril:rust_2018_idioms-rustbook, r=oli-obk
Mark-Simulacrum Mar 2, 2019
9d67c38
Rollup merge of #58835 - Centril:rust_2018_idioms-remote-test, r=oli-obk
Mark-Simulacrum Mar 2, 2019
71cda62
Rollup merge of #58838 - jens1o:patch-1, r=Centril
Mark-Simulacrum Mar 2, 2019
0dfd28e
Rollup merge of #58842 - mati865:53005, r=alexcrichton
Mark-Simulacrum Mar 2, 2019
8f8f70e
Rollup merge of #58865 - dlrobertson:fix-varargs, r=alexreg
Mark-Simulacrum Mar 2, 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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2624,6 +2624,7 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
"rustc-demangle 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_allocator 0.0.0",
Expand Down
5 changes: 0 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ environment:
# server goes down presumably. See #43333 for more info
CARGO_HTTP_CHECK_REVOKE: false

# Execute the builds on GCE instead of Hyper-V. Those builders have a 3-4
# minute startup overhead, but AppVeyor support recommended this as a
# possible solution for #58160 (spurious 259 exit codes)
appveyor_build_worker_cloud: gce

matrix:
# 32/64 bit MSVC tests
- MSYS_BITS: 64
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ impl<T> Vec<T> {
/// This method uses a closure to create new values on every push. If
/// you'd rather [`Clone`] a given value, use [`resize`]. If you want
/// to use the [`Default`] trait to generate values, you can pass
/// [`Default::default()`] as the second argument..
/// [`Default::default()`] as the second argument.
///
/// # Examples
///
Expand Down
32 changes: 30 additions & 2 deletions src/libcore/benches/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ bench_sums! {
bench_sums! {
bench_filter_sum,
bench_filter_ref_sum,
(0i64..1000000).filter(|x| x % 2 == 0)
(0i64..1000000).filter(|x| x % 3 == 0)
}

bench_sums! {
bench_filter_chain_sum,
bench_filter_chain_ref_sum,
(0i64..1000000).chain(0..1000000).filter(|x| x % 2 == 0)
(0i64..1000000).chain(0..1000000).filter(|x| x % 3 == 0)
}

bench_sums! {
Expand Down Expand Up @@ -306,3 +306,31 @@ fn bench_skip_then_zip(b: &mut Bencher) {
assert_eq!(s, 2009900);
});
}

#[bench]
fn bench_filter_count(b: &mut Bencher) {
b.iter(|| {
(0i64..1000000).map(black_box).filter(|x| x % 3 == 0).count()
})
}

#[bench]
fn bench_filter_ref_count(b: &mut Bencher) {
b.iter(|| {
(0i64..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count()
})
}

#[bench]
fn bench_filter_chain_count(b: &mut Bencher) {
b.iter(|| {
(0i64..1000000).chain(0..1000000).map(black_box).filter(|x| x % 3 == 0).count()
})
}

#[bench]
fn bench_filter_chain_ref_count(b: &mut Bencher) {
b.iter(|| {
(0i64..1000000).chain(0..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count()
})
}
37 changes: 7 additions & 30 deletions src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,7 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool

#[inline]
fn next(&mut self) -> Option<I::Item> {
for x in &mut self.iter {
if (self.predicate)(&x) {
return Some(x);
}
}
None
self.try_for_each(Err).err()
}

#[inline]
Expand All @@ -707,12 +702,9 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
// Using the branchless version will also simplify the LLVM byte code, thus
// leaving more budget for LLVM optimizations.
#[inline]
fn count(mut self) -> usize {
let mut count = 0;
for x in &mut self.iter {
count += (self.predicate)(&x) as usize;
}
count
fn count(self) -> usize {
let mut predicate = self.predicate;
self.iter.map(|x| predicate(&x) as usize).sum()
}

#[inline]
Expand Down Expand Up @@ -746,12 +738,7 @@ impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P>
{
#[inline]
fn next_back(&mut self) -> Option<I::Item> {
for x in self.iter.by_ref().rev() {
if (self.predicate)(&x) {
return Some(x);
}
}
None
self.try_rfold((), |_, x| Err(x)).err()
}

#[inline]
Expand Down Expand Up @@ -820,12 +807,7 @@ impl<B, I: Iterator, F> Iterator for FilterMap<I, F>

#[inline]
fn next(&mut self) -> Option<B> {
for x in self.iter.by_ref() {
if let Some(y) = (self.f)(x) {
return Some(y);
}
}
None
self.try_for_each(Err).err()
}

#[inline]
Expand Down Expand Up @@ -863,12 +845,7 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for FilterMap<I, F>
{
#[inline]
fn next_back(&mut self) -> Option<B> {
for x in self.iter.by_ref().rev() {
if let Some(y) = (self.f)(x) {
return Some(y);
}
}
None
self.try_rfold((), |_, x| Err(x)).err()
}

#[inline]
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,16 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
}
}

// FIXME: Reference `MaybeUninit` from these docs, once that is stable.
/// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
///
/// This wrapper is 0-cost.
///
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
/// As a consequence, it has *no effect* on the assumptions that the compiler makes
/// about all values being initialized at their type. In particular, initializing
/// a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined behavior.
///
/// # Examples
///
/// This wrapper helps with explicitly documenting the drop order dependencies between fields of
Expand Down Expand Up @@ -935,6 +941,8 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
/// }
/// }
/// ```
///
/// [`mem::zeroed`]: fn.zeroed.html
#[stable(feature = "manually_drop", since = "1.20.0")]
#[lang = "manually_drop"]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
//! had a method `fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T>`.
//! Then we could do the following:
//! ```compile_fail
//! fn exploit_ref_cell<T>(rc: Pin<&mut RefCell<T>) {
//! fn exploit_ref_cell<T>(rc: Pin<&mut RefCell<T>>) {
//! { let p = rc.as_mut().get_pin_mut(); } // Here we get pinned access to the `T`.
//! let rc_shr: &RefCell<T> = rc.into_ref().get_ref();
//! let b = rc_shr.borrow_mut();
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3965,7 +3965,7 @@ impl str {
me.make_ascii_lowercase()
}

/// Return an iterator that escapes each char in `s` with [`char::escape_debug`].
/// Return an iterator that escapes each char in `self` with [`char::escape_debug`].
///
/// Note: only extended grapheme codepoints that begin the string will be
/// escaped.
Expand Down Expand Up @@ -4013,7 +4013,7 @@ impl str {
}
}

/// Return an iterator that escapes each char in `s` with [`char::escape_default`].
/// Return an iterator that escapes each char in `self` with [`char::escape_default`].
///
/// [`char::escape_default`]: ../std/primitive.char.html#method.escape_default
///
Expand Down Expand Up @@ -4051,7 +4051,7 @@ impl str {
EscapeDefault { inner: self.chars().flat_map(CharEscapeDefault) }
}

/// Return an iterator that escapes each char in `s` with [`char::escape_unicode`].
/// Return an iterator that escapes each char in `self` with [`char::escape_unicode`].
///
/// [`char::escape_unicode`]: ../std/primitive.char.html#method.escape_unicode
///
Expand Down
20 changes: 14 additions & 6 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,22 @@ macro_rules! declare_lint {

#[macro_export]
macro_rules! declare_tool_lint {
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr) => (
declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, false}
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
) => (
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false}
);
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr,
report_in_external_macro: $rep: expr) => (
declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, $rep}
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
report_in_external_macro: $rep:expr
) => (
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep}
);
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr, $external: expr) => (
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
$external:expr
) => (
$(#[$attr])*
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: &concat!(stringify!($tool), "::", stringify!($NAME)),
default_level: $crate::lint::$Level,
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,9 +1405,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
"inject the given attribute in the crate"),
self_profile: bool = (false, parse_bool, [UNTRACKED],
"run the self profiler"),
profile_json: bool = (false, parse_bool, [UNTRACKED],
"output a json file with profiler results"),
"run the self profiler and output the raw event data"),
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
"emits a section containing stack size metadata"),
plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
43 changes: 19 additions & 24 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ use std::fmt;
use std::io::Write;
use std::path::PathBuf;
use std::time::Duration;
use std::sync::mpsc;
use std::sync::{Arc, mpsc};

use parking_lot::Mutex as PlMutex;

mod code_stats;
pub mod config;
Expand Down Expand Up @@ -127,11 +129,8 @@ pub struct Session {
/// Used by `-Z profile-queries` in `util::common`.
pub profile_channel: Lock<Option<mpsc::Sender<ProfileQueriesMsg>>>,

/// Used by `-Z self-profile`.
pub self_profiling_active: bool,

/// Used by `-Z self-profile`.
pub self_profiling: Lock<SelfProfiler>,
/// Used by -Z self-profile
pub self_profiling: Option<Arc<PlMutex<SelfProfiler>>>,

/// Some measurements that are being gathered during compilation.
pub perf_stats: PerfStats,
Expand Down Expand Up @@ -834,27 +833,23 @@ impl Session {
#[inline(never)]
#[cold]
fn profiler_active<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) {
let mut profiler = self.self_profiling.borrow_mut();
f(&mut profiler);
match &self.self_profiling {
None => bug!("profiler_active() called but there was no profiler active"),
Some(profiler) => {
let mut p = profiler.lock();

f(&mut p);
}
}
}

#[inline(always)]
pub fn profiler<F: FnOnce(&mut SelfProfiler) -> ()>(&self, f: F) {
if unlikely!(self.self_profiling_active) {
if unlikely!(self.self_profiling.is_some()) {
self.profiler_active(f)
}
}

pub fn print_profiler_results(&self) {
let mut profiler = self.self_profiling.borrow_mut();
profiler.print_results(&self.opts);
}

pub fn save_json_results(&self) {
let profiler = self.self_profiling.borrow();
profiler.save_results(&self.opts);
}

pub fn print_perf_stats(&self) {
println!(
"Total time spent computing symbol hashes: {}",
Expand Down Expand Up @@ -1136,6 +1131,10 @@ pub fn build_session_(
source_map: Lrc<source_map::SourceMap>,
driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
) -> Session {
let self_profiler =
if sopts.debugging_opts.self_profile { Some(Arc::new(PlMutex::new(SelfProfiler::new()))) }
else { None };

let host_triple = TargetTriple::from_triple(config::host_triple());
let host = Target::search(&host_triple).unwrap_or_else(|e|
span_diagnostic
Expand Down Expand Up @@ -1185,9 +1184,6 @@ pub fn build_session_(
CguReuseTracker::new_disabled()
};

let self_profiling_active = sopts.debugging_opts.self_profile ||
sopts.debugging_opts.profile_json;

let sess = Session {
target: target_cfg,
host,
Expand Down Expand Up @@ -1216,8 +1212,7 @@ pub fn build_session_(
imported_macro_spans: OneThread::new(RefCell::new(FxHashMap::default())),
incr_comp_session: OneThread::new(RefCell::new(IncrCompSession::NotInitialized)),
cgu_reuse_tracker,
self_profiling_active,
self_profiling: Lock::new(SelfProfiler::new()),
self_profiling: self_profiler,
profile_channel: Lock::new(None),
perf_stats: PerfStats {
symbol_hash_time: Lock::new(Duration::from_secs(0)),
Expand Down
Loading