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 15 pull requests #73745

Closed
wants to merge 52 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f03cf99
Add a fast path for `std::thread::panicking`.
eduardosm May 26, 2020
560a996
Implement slice_strip feature
tesuji Jun 16, 2020
1b47e8f
examples should be of type bool
tshepang Jun 20, 2020
16e741c
explain the logic a bit
tshepang Jun 20, 2020
9766a93
Document the mod keyword
poliorcetics Jun 22, 2020
3c46e36
Document the mut keyword
poliorcetics Jun 22, 2020
e84552e
be more consistent with "defaults" placement
tshepang Jun 22, 2020
ef24faf
Refactor non_ascii_idents lints, exclude ascii pair for confusable_id…
crlf0710 May 10, 2020
b65ea1b
place non-obvious defaults on a separate line
tshepang Jun 22, 2020
9bb414f
Fix ptr doc warnings.
ehuss Jun 23, 2020
5aab1a9
Tweak binop errors
estebank Jun 24, 2020
b23baa7
fix
tshepang Jun 24, 2020
d8ea10c
Document the return keyword
poliorcetics Jun 24, 2020
65becef
Clean up E0701 explanation
GuillaumeGomez Jun 24, 2020
d36d351
Implement intrinsic
doctorn Jun 23, 2020
c2dfc25
Fix tests
doctorn Jun 24, 2020
4931996
Fix tests
doctorn Jun 24, 2020
771a1d8
Make `std::panicking::panic_count::is_zero` inline and move the slow …
eduardosm Jun 24, 2020
09af184
review comments: clean up code
estebank Jun 24, 2020
a5a831f
Emit line info for generator variants
tmandry Jun 17, 2020
eb726c0
Add Artificial flag to generator variants
tmandry Jun 18, 2020
367858a
Add test for generator debuginfo
tmandry Jun 18, 2020
242a5cd
Allow calling GeneratorSubsts::variant_name() without substs
tmandry Jun 20, 2020
547d863
Improve GeneratorLayout debug output
tmandry Jun 20, 2020
477ecc5
Generalize generator-debug test a bit
tmandry Jun 23, 2020
2d652d9
Add generator-debug test for MSVC
tmandry Jun 23, 2020
fe3df64
Give up on checking filename
tmandry Jun 24, 2020
887fbd9
Split out async fn and generator test
tmandry Jun 24, 2020
8f40dae
Suggest type param trait bound for binop only when appropriate
estebank Jun 24, 2020
520461f
Provide suggestions for some moved value errors
estebank Jun 20, 2020
3d09017
Add a compile fail example, binding -> variable, apply suggestions
poliorcetics Jun 25, 2020
2e3f517
Add unstable rustc option to control self-contained linkage mode
mati865 May 28, 2020
54293c1
Rename get_self_contained_lib_path
mati865 Jun 22, 2020
f27dcd7
Rename remaining `fallback` to `self_contained`
mati865 Jun 25, 2020
eb6d9a4
Add E0766 error for unterminated double quote byte string
GuillaumeGomez Jun 21, 2020
33302fa
Update UI test
GuillaumeGomez Jun 21, 2020
25e864e
Implement mixed script confusable lint.
crlf0710 Jun 23, 2020
bf6134d
Rollup merge of #72617 - eduardosm:panicking, r=Amanieu
Manishearth Jun 26, 2020
e98f991
Rollup merge of #72738 - mati865:self-contained-option, r=petrochenkov
Manishearth Jun 26, 2020
885776e
Rollup merge of #72770 - crlf0710:mixed_script_confusable, r=Manishearth
Manishearth Jun 26, 2020
2196bab
Rollup merge of #73414 - lzutao:slice_strip, r=dtolnay
Manishearth Jun 26, 2020
e3807d0
Rollup merge of #73418 - doctorn:variants-intrinsic, r=kennytm
Manishearth Jun 26, 2020
673d7ca
Rollup merge of #73460 - tmandry:variant-lineinfo, r=oli-obk
Manishearth Jun 26, 2020
050cb83
Rollup merge of #73534 - estebank:borrowck-suggestions, r=matthewjasper
Manishearth Jun 26, 2020
59768d4
Rollup merge of #73538 - tshepang:fix-example, r=nikomatsakis
Manishearth Jun 26, 2020
d2f7d6b
Rollup merge of #73581 - GuillaumeGomez:add-0766, r=varkor
Manishearth Jun 26, 2020
f1ca34e
Rollup merge of #73619 - poliorcetics:mod-keyword, r=steveklabnik
Manishearth Jun 26, 2020
7f1eb2e
Rollup merge of #73621 - poliorcetics:mut-keyword, r=steveklabnik
Manishearth Jun 26, 2020
7b744e1
Rollup merge of #73648 - poliorcetics:return-keyword, r=joshtriplett
Manishearth Jun 26, 2020
d51c959
Rollup merge of #73673 - ehuss:fix-ptr-docs, r=oli-obk
Manishearth Jun 26, 2020
f16d62c
Rollup merge of #73674 - estebank:op-trait-bound-suggestion, r=davidtwco
Manishearth Jun 26, 2020
351486a
Rollup merge of #73687 - GuillaumeGomez:cleanup-e0701, r=Dylan-DPC
Manishearth Jun 26, 2020
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
Next Next commit
Add a fast path for std::thread::panicking.
This is done by adding a global atomic variable (non-TLS) that counts how many threads are panicking. In order to check if the current thread is panicking, this variable is read and, if it is zero, no thread (including the one where `panicking` is being called) is panicking and `panicking` can return `false` immediately without needing to access TLS. If the global counter is not zero, the local counter is accessed from TLS to check if the current thread is panicking.
eduardosm committed May 26, 2020
commit f03cf9916a1932f47b788a9de9256269cc172fe9
63 changes: 50 additions & 13 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
@@ -170,7 +170,7 @@ pub fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send> {
fn default_hook(info: &PanicInfo<'_>) {
// If this is a double panic, make sure that we print a backtrace
// for this panic. Otherwise only print it if logging is enabled.
let backtrace_env = if update_panic_count(0) >= 2 {
let backtrace_env = if panic_count::get() >= 2 {
RustBacktrace::Print(backtrace_rs::PrintFmt::Full)
} else {
backtrace::rust_backtrace_env()
@@ -222,19 +222,56 @@ fn default_hook(info: &PanicInfo<'_>) {
#[cfg(not(test))]
#[doc(hidden)]
#[unstable(feature = "update_panic_count", issue = "none")]
pub fn update_panic_count(amt: isize) -> usize {
pub mod panic_count {
use crate::cell::Cell;
thread_local! { static PANIC_COUNT: Cell<usize> = Cell::new(0) }
use crate::sync::atomic::{AtomicUsize, Ordering};

// Panic count for the current thread.
thread_local! { static LOCAL_PANIC_COUNT: Cell<usize> = Cell::new(0) }

// Sum of panic counts from all threads. The purpose of this is to have
// a fast path in `is_zero` (which is used by `panicking`). Access to
// this variable can be always be done with relaxed ordering because
// it is always guaranteed that, if `GLOBAL_PANIC_COUNT` is zero,
// `LOCAL_PANIC_COUNT` will be zero.
static GLOBAL_PANIC_COUNT: AtomicUsize = AtomicUsize::new(0);

pub fn increase() -> usize {
GLOBAL_PANIC_COUNT.fetch_add(1, Ordering::Relaxed);
LOCAL_PANIC_COUNT.with(|c| {
let next = c.get() + 1;
c.set(next);
next
})
}

pub fn decrease() -> usize {
GLOBAL_PANIC_COUNT.fetch_sub(1, Ordering::Relaxed);
LOCAL_PANIC_COUNT.with(|c| {
let next = c.get() - 1;
c.set(next);
next
})
}

PANIC_COUNT.with(|c| {
let next = (c.get() as isize + amt) as usize;
c.set(next);
next
})
pub fn get() -> usize {
LOCAL_PANIC_COUNT.with(|c| c.get())
}

pub fn is_zero() -> bool {
if GLOBAL_PANIC_COUNT.load(Ordering::Relaxed) == 0 {
// Fast path: if `GLOBAL_PANIC_COUNT` is zero, all threads
// (including the current one) will have `LOCAL_PANIC_COUNT`
// equal to zero, so TLS access can be avoided.
true
} else {
LOCAL_PANIC_COUNT.with(|c| c.get() == 0)
}
}
}

#[cfg(test)]
pub use realstd::rt::update_panic_count;
pub use realstd::rt::panic_count;

/// Invoke a closure, capturing the cause of an unwinding panic if one occurs.
pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
@@ -284,7 +321,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
#[cold]
unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send + 'static> {
let obj = Box::from_raw(__rust_panic_cleanup(payload));
update_panic_count(-1);
panic_count::decrease();
obj
}

@@ -314,7 +351,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>

/// Determines whether the current thread is unwinding because of panic.
pub fn panicking() -> bool {
update_panic_count(0) != 0
!panic_count::is_zero()
}

/// The entry point for panicking with a formatted message.
@@ -452,7 +489,7 @@ fn rust_panic_with_hook(
message: Option<&fmt::Arguments<'_>>,
location: &Location<'_>,
) -> ! {
let panics = update_panic_count(1);
let panics = panic_count::increase();

// If this is the third nested call (e.g., panics == 2, this is 0-indexed),
// the panic hook probably triggered the last panic, otherwise the
@@ -514,7 +551,7 @@ fn rust_panic_with_hook(
/// This is the entry point for `resume_unwind`.
/// It just forwards the payload to the panic runtime.
pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
update_panic_count(1);
panic_count::increase();

struct RewrapBox(Box<dyn Any + Send>);

2 changes: 1 addition & 1 deletion src/libstd/rt.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
#![doc(hidden)]

// Re-export some of our utilities which are expected by other crates.
pub use crate::panicking::{begin_panic, begin_panic_fmt, update_panic_count};
pub use crate::panicking::{begin_panic, begin_panic_fmt, panic_count};

// To reduce the generated code of the new `lang_start`, this function is doing
// the real work.