-
Notifications
You must be signed in to change notification settings - Fork 764
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 usage of sp-std
from Substrate
#7043
Conversation
@@ -1051,6 +1051,29 @@ pub use alloc::borrow::Cow; | |||
#[deprecated = "Use String or Cow<'static, str> instead"] | |||
pub type RuntimeString = alloc::string::String; | |||
|
|||
/// A target for `core::write!` macro - constructs a string in memory. | |||
#[derive(Default)] | |||
pub struct Writer(vec::Vec<u8>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just replace the usage of writer with alloc::string::String
to no require a custom type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great to hear! My concern, however, is that, as far as I know, using alloc::string::String
is discouraged to avoid bloating the runtime size.
@@ -650,7 +650,7 @@ fn expand_functions(def: &EnvDef, expand_mode: ExpandMode) -> TokenStream2 { | |||
let result = #body; | |||
if ::log::log_enabled!(target: "runtime::contracts::strace", ::log::Level::Trace) { | |||
use core::fmt::Write; | |||
let mut w = sp_std::Writer::default(); | |||
let mut w = sp_runtime::Writer::default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut w = sp_runtime::Writer::default(); | |
let mut w = alloc::string::String::default(); |
/cmd prdoc --bump patch --audience runtime_dev --force |
Co-authored-by: Guillaume Thiolliere <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also remove sp_std
from the Cargo.toml
of contracts and revive? It is no longer used there now.
c139739
Description
This PR removes usage of deprecated
sp-std
from Substrate. (following PR of #5010)Integration
This PR doesn't remove re-exported
sp_std
from any crates yet, so downstream projects using re-exportedsp_std
will not be affected.Review Notes
The existing code using
sp-std
is refactored to usealloc
andcore
directly. The key-value maps are instantiated from a vector of tuples directly instead of usingsp_std::map!
macro.sp_std::Writer
is a helper type to useVec<u8>
withcore::fmt::Write
trait. This PR copied it intosp-runtime
, because all crates usingsp_std::Writer
(includingsp-runtime
itself,frame-support
, etc.) depend onsp-runtime
.If this PR is merged, I would write following PRs to remove remaining usage of
sp-std
frombridges
andcumulus
.