sp-std -> core (#3199)

First in a series of PRs that reduces our use of sp-std with a view to
deprecating it.

This is just looking at /substrate and moving some of the references
from `sp-std` to `core`.
These particular changes should be uncontroversial.

Where macros are used `::core` should be used to remove any ambiguity.

part of https://github.com/paritytech/polkadot-sdk/issues/2101
This commit is contained in:
Squirrel
2024-02-06 13:01:29 +00:00
committed by GitHub
parent c552fb5495
commit bc2e5e1fe2
75 changed files with 125 additions and 125 deletions
@@ -243,7 +243,7 @@ fn generate_wasm_interface(impls: &[ItemImpl]) -> Result<TokenStream> {
&[0u8; 0]
} else {
unsafe {
#c::slice::from_raw_parts(input_data, input_len)
::core::slice::from_raw_parts(input_data, input_len)
}
};
@@ -345,7 +345,7 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
&self,
backend: &B,
parent_hash: Block::Hash,
) -> core::result::Result<
) -> ::core::result::Result<
#crate_::StorageChanges<Block>,
String
> where Self: Sized {
@@ -22,7 +22,7 @@
//! multiplication implementation provided there.
use crate::{biguint, Rounding};
use sp_std::cmp::{max, min};
use core::cmp::{max, min};
/// Helper gcd function used in Rational128 implementation.
pub fn gcd(a: u128, b: u128) -> u128 {
@@ -18,6 +18,9 @@
//! Primitive traits for the runtime arithmetic.
use codec::HasCompact;
use core::ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Shl, Shr, Sub, SubAssign,
};
pub use ensure::{
ensure_pow, Ensure, EnsureAdd, EnsureAddAssign, EnsureDiv, EnsureDivAssign,
EnsureFixedPointNumber, EnsureFrom, EnsureInto, EnsureMul, EnsureMulAssign, EnsureOp,
@@ -28,9 +31,6 @@ pub use num_traits::{
checked_pow, Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl,
CheckedShr, CheckedSub, One, Signed, Unsigned, Zero,
};
use sp_std::ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Shl, Shr, Sub, SubAssign,
};
use crate::MultiplyRational;
@@ -262,7 +262,7 @@ pub trait Saturating {
Self: One,
{
let mut o = Self::one();
sp_std::mem::swap(&mut o, self);
core::mem::swap(&mut o, self);
*self = o.saturating_add(One::one());
}
@@ -272,7 +272,7 @@ pub trait Saturating {
Self: One,
{
let mut o = Self::one();
sp_std::mem::swap(&mut o, self);
core::mem::swap(&mut o, self);
*self = o.saturating_sub(One::one());
}
@@ -282,7 +282,7 @@ pub trait Saturating {
Self: One,
{
let mut o = Self::one();
sp_std::mem::swap(&mut o, self);
core::mem::swap(&mut o, self);
*self = o.saturating_add(amount);
}
@@ -292,7 +292,7 @@ pub trait Saturating {
Self: One,
{
let mut o = Self::one();
sp_std::mem::swap(&mut o, self);
core::mem::swap(&mut o, self);
*self = o.saturating_sub(amount);
}
}
@@ -949,7 +949,7 @@ mod ensure {
}
}
impl sp_std::ops::Mul for Signum {
impl core::ops::Mul for Signum {
type Output = Self;
fn mul(self, rhs: Self) -> Self {
@@ -69,7 +69,7 @@ impl InherentDataProvider {
}
#[cfg(feature = "std")]
impl sp_std::ops::Deref for InherentDataProvider {
impl core::ops::Deref for InherentDataProvider {
type Target = InherentType;
fn deref(&self) -> &Self::Target {
@@ -17,8 +17,8 @@
//! Inherents for BABE
use core::result::Result;
use sp_inherents::{Error, InherentData, InherentIdentifier};
use sp_std::result::Result;
/// The BABE inherent identifier.
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"babeslot";
@@ -75,7 +75,7 @@ impl InherentDataProvider {
}
#[cfg(feature = "std")]
impl sp_std::ops::Deref for InherentDataProvider {
impl core::ops::Deref for InherentDataProvider {
type Target = InherentType;
fn deref(&self) -> &Self::Target {
@@ -155,9 +155,9 @@ impl SlotDuration {
#[cfg(feature = "std")]
impl SlotDuration {
/// Returns `self` as [`sp_std::time::Duration`].
pub const fn as_duration(&self) -> sp_std::time::Duration {
sp_std::time::Duration::from_millis(self.0)
/// Returns `self` as [`core::time::Duration`].
pub const fn as_duration(&self) -> core::time::Duration {
core::time::Duration::from_millis(self.0)
}
}
+2 -2
View File
@@ -89,7 +89,7 @@ macro_rules! wasm_export_functions {
&[0u8; 0]
} else {
unsafe {
$crate::sp_std::slice::from_raw_parts(input_data, input_len)
::core::slice::from_raw_parts(input_data, input_len)
}
};
@@ -117,7 +117,7 @@ macro_rules! wasm_export_functions {
&[0u8; 0]
} else {
unsafe {
$crate::sp_std::slice::from_raw_parts(input_data, input_len)
::core::slice::from_raw_parts(input_data, input_len)
}
};
@@ -21,7 +21,7 @@
pub fn pack_ptr_and_len(ptr: u32, len: u32) -> u64 {
// The static assertions from above are changed into a runtime check.
#[cfg(all(not(feature = "std"), feature = "disable_target_static_assertions"))]
assert_eq!(4, sp_std::mem::size_of::<usize>());
assert_eq!(4, core::mem::size_of::<usize>());
(u64::from(len) << 32) | u64::from(ptr)
}
@@ -34,7 +34,7 @@ pub fn pack_ptr_and_len(ptr: u32, len: u32) -> u64 {
pub fn unpack_ptr_and_len(val: u64) -> (u32, u32) {
// The static assertions from above are changed into a runtime check.
#[cfg(all(not(feature = "std"), feature = "disable_target_static_assertions"))]
assert_eq!(4, sp_std::mem::size_of::<usize>());
assert_eq!(4, core::mem::size_of::<usize>());
let ptr = (val & (!0u32 as u64)) as u32;
let len = (val >> 32) as u32;
@@ -19,7 +19,7 @@
use crate::RIType;
use sp_std::cell::Cell;
use core::cell::Cell;
/// Something that can be created from a ffi value.
///
@@ -133,7 +133,7 @@ where
impl<Number, Hash> Header<Number, Hash>
where
Number: Member
+ sp_std::hash::Hash
+ core::hash::Hash
+ Copy
+ MaybeDisplay
+ AtLeast32BitUnsigned
@@ -66,9 +66,9 @@ use crate::{
traits::BlockNumberProvider,
};
use codec::{Codec, Decode, Encode};
use core::fmt;
use sp_core::offchain::{Duration, Timestamp};
use sp_io::offchain;
use sp_std::fmt;
/// Default expiry duration for time based locks in milliseconds.
const STORAGE_LOCK_DEFAULT_EXPIRY_DURATION: Duration = Duration::from_millis(20_000);
@@ -16,7 +16,7 @@
// limitations under the License.
/// State Machine Errors
use sp_std::fmt;
use core::fmt;
/// State Machine Error bound.
///
@@ -79,7 +79,7 @@ where
/// Apply the given transaction to this backend and set the root to the given value.
pub fn apply_transaction(&mut self, root: H::Out, transaction: PrefixedMemoryDB<H>) {
let mut storage = sp_std::mem::take(self).into_storage();
let mut storage = core::mem::take(self).into_storage();
storage.consolidate(transaction);
*self = TrieBackendBuilder::new(storage, root).build();
@@ -17,7 +17,7 @@
//! Usage statistics for state db
use sp_std::cell::RefCell;
use core::cell::RefCell;
#[cfg(feature = "std")]
use std::time::{Duration, Instant};
+3 -3
View File
@@ -20,8 +20,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, Encode};
use core::time::Duration;
use sp_inherents::{InherentData, InherentIdentifier, IsFatalError};
use sp_std::time::Duration;
/// The identifier for the `timestamp` inherent.
pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"timstap0";
@@ -69,7 +69,7 @@ impl Timestamp {
}
}
impl sp_std::ops::Deref for Timestamp {
impl core::ops::Deref for Timestamp {
type Target = u64;
fn deref(&self) -> &Self::Target {
@@ -219,7 +219,7 @@ impl InherentDataProvider {
}
#[cfg(feature = "std")]
impl sp_std::ops::Deref for InherentDataProvider {
impl core::ops::Deref for InherentDataProvider {
type Target = InherentType;
fn deref(&self) -> &Self::Target {
+3 -3
View File
@@ -19,7 +19,7 @@
use crate::trie_constants;
use codec::{Decode, Encode, Input, Output};
use sp_std::iter::once;
use core::iter::once;
/// A node header
#[derive(Copy, Clone, PartialEq, Eq, sp_core::RuntimeDebug)]
@@ -118,7 +118,7 @@ pub(crate) fn size_and_prefix_iterator(
prefix_mask: usize,
) -> impl Iterator<Item = u8> {
let max_value = 255u8 >> prefix_mask;
let l1 = sp_std::cmp::min((max_value as usize).saturating_sub(1), size);
let l1 = core::cmp::min((max_value as usize).saturating_sub(1), size);
let (first_byte, mut rem) = if size == l1 {
(once(prefix + l1 as u8), 0)
} else {
@@ -138,7 +138,7 @@ pub(crate) fn size_and_prefix_iterator(
None
}
};
first_byte.chain(sp_std::iter::from_fn(next_bytes))
first_byte.chain(core::iter::from_fn(next_bytes))
}
/// Encodes size and prefix to a stream output.
+3 -3
View File
@@ -235,7 +235,7 @@ where
}
/// Implementor of `WeightToFee` that maps one unit of weight to one unit of fee.
pub struct IdentityFee<T>(sp_std::marker::PhantomData<T>);
pub struct IdentityFee<T>(core::marker::PhantomData<T>);
impl<T> WeightToFee for IdentityFee<T>
where
@@ -249,7 +249,7 @@ where
}
/// Implementor of [`WeightToFee`] such that it maps any unit of weight to a fixed fee.
pub struct FixedFee<const F: u32, T>(sp_std::marker::PhantomData<T>);
pub struct FixedFee<const F: u32, T>(core::marker::PhantomData<T>);
impl<const F: u32, T> WeightToFee for FixedFee<F, T>
where
@@ -275,7 +275,7 @@ pub type NoFee<T> = FixedFee<0, T>;
/// // Results in a multiplier of 10 for each unit of weight (or length)
/// type LengthToFee = ConstantMultiplier::<u128, ConstU128<10u128>>;
/// ```
pub struct ConstantMultiplier<T, M>(sp_std::marker::PhantomData<(T, M)>);
pub struct ConstantMultiplier<T, M>(core::marker::PhantomData<(T, M)>);
impl<T, M> WeightToFee for ConstantMultiplier<T, M>
where