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

Remove stdlib.rs #1008

Merged
merged 2 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 8 additions & 10 deletions tracing-core/src/callsite.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
//! Callsites represent the source locations from which spans or events
//! originate.
use crate::stdlib::{
fmt,
hash::{Hash, Hasher},
ptr,
sync::{
atomic::{AtomicPtr, Ordering},
Mutex, MutexGuard,
},
vec::Vec,
};
use crate::{
dispatcher::{self, Dispatch},
metadata::{LevelFilter, Metadata},
subscriber::Interest,
sync::{Mutex, MutexGuard},
};
use alloc::vec::Vec;
use core::{
fmt,
hash::{Hash, Hasher},
ptr,
sync::atomic::{AtomicPtr, Ordering},
};

lazy_static! {
Expand Down
12 changes: 4 additions & 8 deletions tracing-core/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,15 @@ use crate::{
Event, LevelFilter, Metadata,
};

use crate::stdlib::{
use alloc::sync::{Arc, Weak};
use core::{
any::Any,
fmt,
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
Arc, Weak,
},
sync::atomic::{AtomicBool, AtomicUsize, Ordering},
};

#[cfg(feature = "std")]
use crate::stdlib::{
use std::{
cell::{Cell, RefCell, RefMut},
error,
};
Expand Down Expand Up @@ -777,8 +775,6 @@ impl Drop for DefaultGuard {
mod test {

use super::*;
#[cfg(feature = "std")]
use crate::stdlib::sync::atomic::{AtomicUsize, Ordering};
use crate::{
callsite::Callsite,
metadata::{Kind, Level, Metadata},
Expand Down
10 changes: 5 additions & 5 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! [`record`]: super::subscriber::Subscriber::record
//! [`event`]: super::subscriber::Subscriber::event
use crate::callsite;
use crate::stdlib::{
use core::{
borrow::Borrow,
fmt,
hash::{Hash, Hasher},
Expand Down Expand Up @@ -828,7 +828,7 @@ impl_valid_len! {
mod test {
use super::*;
use crate::metadata::{Kind, Level, Metadata};
use crate::stdlib::{borrow::ToOwned, string::String};
use alloc::{borrow::ToOwned, string::String};

struct TestCallsite1;
static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1;
Expand Down Expand Up @@ -929,7 +929,7 @@ mod test {

struct MyVisitor;
impl Visit for MyVisitor {
fn record_debug(&mut self, field: &Field, _: &dyn (crate::stdlib::fmt::Debug)) {
fn record_debug(&mut self, field: &Field, _: &dyn (core::fmt::Debug)) {
assert_eq!(field.callsite(), TEST_META_1.callsite())
}
}
Expand All @@ -948,7 +948,7 @@ mod test {

struct MyVisitor;
impl Visit for MyVisitor {
fn record_debug(&mut self, field: &Field, _: &dyn (crate::stdlib::fmt::Debug)) {
fn record_debug(&mut self, field: &Field, _: &dyn (core::fmt::Debug)) {
assert_eq!(field.name(), "bar")
}
}
Expand All @@ -967,7 +967,7 @@ mod test {
let valueset = fields.value_set(values);
let mut result = String::new();
valueset.record(&mut |_: &Field, value: &dyn fmt::Debug| {
use crate::stdlib::fmt::Write;
use core::fmt::Write;
write!(&mut result, "{:?}", value).unwrap();
});
assert_eq!(result, "123".to_owned());
Expand Down
25 changes: 17 additions & 8 deletions tracing-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
unused_parens,
while_true
)]
#[cfg(not(feature = "std"))]

extern crate alloc;
jyn514 marked this conversation as resolved.
Show resolved Hide resolved

/// Statically constructs an [`Identifier`] for the provided [`Callsite`].
Expand Down Expand Up @@ -240,17 +240,27 @@ extern crate lazy_static;
#[macro_use]
mod lazy_static;

// Trimmed-down vendored version of spin 0.5.2 (0387621)
// Dependency of no_std lazy_static, not required in a std build
// Facade module: `no_std` uses spinlocks, `std` uses the mutexes in the standard library
#[cfg(not(feature = "std"))]
pub(crate) mod spin;
mod sync {
#[doc(hidden)]
pub type Once = crate::spin::Once<()>;
pub(crate) use crate::spin::*;
}

#[cfg(not(feature = "std"))]
#[doc(hidden)]
pub type Once = self::spin::Once<()>;
// Trimmed-down vendored version of spin 0.5.2 (0387621)
// Dependency of no_std lazy_static, not required in a std build
pub(crate) mod spin;

#[cfg(feature = "std")]
pub use stdlib::sync::Once;
mod sync {
pub use std::sync::Once;
pub(crate) use std::sync::{Mutex, MutexGuard};
}

#[doc(hidden)]
pub use self::sync::Once;

pub mod callsite;
pub mod dispatcher;
Expand All @@ -259,7 +269,6 @@ pub mod field;
pub mod metadata;
mod parent;
pub mod span;
pub(crate) mod stdlib;
pub mod subscriber;

#[doc(inline)]
Expand Down
8 changes: 4 additions & 4 deletions tracing-core/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Metadata describing trace data.
use super::{callsite, field};
use crate::stdlib::{
use core::{
cmp, fmt,
str::FromStr,
sync::atomic::{AtomicUsize, Ordering},
Expand Down Expand Up @@ -299,7 +299,7 @@ impl fmt::Display for Level {

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl crate::stdlib::error::Error for ParseLevelError {}
impl std::error::Error for ParseLevelError {}

impl FromStr for Level {
type Err = ParseLevelError;
Expand Down Expand Up @@ -481,7 +481,7 @@ impl LevelFilter {
// the inputs to `set_max` to the set of valid discriminants.
// Therefore, **as long as `MAX_VALUE` is only ever set by
// `set_max`**, this is safe.
crate::stdlib::hint::unreachable_unchecked()
core::hint::unreachable_unchecked()
},
}
}
Expand Down Expand Up @@ -799,7 +799,7 @@ impl PartialOrd<Level> for LevelFilter {
#[cfg(test)]
mod tests {
use super::*;
use crate::stdlib::mem;
use core::mem;

#[test]
fn level_from_str() {
Expand Down
2 changes: 1 addition & 1 deletion tracing-core/src/span.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Spans represent periods of time in the execution of a program.
use crate::parent::Parent;
use crate::stdlib::num::NonZeroU64;
use crate::{field, Metadata};
use core::num::NonZeroU64;

/// Identifies a span within the context of a subscriber.
///
Expand Down
6 changes: 3 additions & 3 deletions tracing-core/src/spin/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ impl<T: ?Sized> Mutex<T> {
///
/// The returned value may be dereferenced for data access
/// and the lock will be dropped when the guard falls out of scope.
pub(crate) fn lock(&self) -> MutexGuard<'_, T> {
pub(crate) fn lock(&self) -> Result<MutexGuard<'_, T>, core::convert::Infallible> {
self.obtain_lock();
MutexGuard {
Ok(MutexGuard {
lock: &self.lock,
data: unsafe { &mut *self.data.get() },
}
})
}

/// Tries to lock the mutex. If it is already locked, it will return None. Otherwise it returns
Expand Down
78 changes: 0 additions & 78 deletions tracing-core/src/stdlib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tracing-core/src/subscriber.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Subscribers collect and record trace data.
use crate::{span, Event, LevelFilter, Metadata};

use crate::stdlib::any::{Any, TypeId};
use core::any::{Any, TypeId};

/// Trait representing the functions required to collect trace data.
///
Expand Down
2 changes: 1 addition & 1 deletion tracing-futures/src/executor/futures_preview.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::stdlib::future::Future;
use crate::{Instrument, Instrumented, WithDispatch};
use core::future::Future;
use futures_core_preview::{
future::FutureObj,
task::{LocalSpawn, Spawn, SpawnError},
Expand Down
12 changes: 5 additions & 7 deletions tracing-futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@
#[cfg(feature = "std-future")]
use pin_project::pin_project;

pub(crate) mod stdlib;

#[cfg(feature = "std-future")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably just remove the feature flag for std::future in the upcoming release.... it was added way back in the day before std::future was stable, so it could be enabled by users on nightly. now, it's stable in our MSRV, so this is definitely no longer necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to remove all the uses of the feature here? I can keep std-future = [] as a no-op so it doesn't break existing code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually it looks like enabling std-future conflicts with futures_01 ... do you plan to remove futures_01 in tracing 0.2?

use crate::stdlib::{pin::Pin, task::Context};
use core::{pin::Pin, task::Context};

#[cfg(feature = "std")]
use tracing::{dispatcher, Dispatch};
Expand Down Expand Up @@ -274,10 +272,10 @@ impl<T: Sized> Instrument for T {}

#[cfg(feature = "std-future")]
#[cfg_attr(docsrs, doc(cfg(feature = "std-future")))]
impl<T: crate::stdlib::future::Future> crate::stdlib::future::Future for Instrumented<T> {
impl<T: core::future::Future> core::future::Future for Instrumented<T> {
type Output = T::Output;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> crate::stdlib::task::Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> core::task::Poll<Self::Output> {
let this = self.project();
let _enter = this.span.enter();
this.inner.poll(cx)
Expand Down Expand Up @@ -445,10 +443,10 @@ impl<T: futures_01::Future> futures_01::Future for WithDispatch<T> {

#[cfg(all(feature = "std-future", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "std-future", feature = "std"))))]
impl<T: crate::stdlib::future::Future> crate::stdlib::future::Future for WithDispatch<T> {
impl<T: core::future::Future> core::future::Future for WithDispatch<T> {
type Output = T::Output;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> crate::stdlib::task::Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> core::task::Poll<Self::Output> {
let this = self.project();
let dispatch = this.dispatch;
let future = this.inner;
Expand Down
44 changes: 0 additions & 44 deletions tracing-futures/src/stdlib.rs

This file was deleted.

Loading