-
Notifications
You must be signed in to change notification settings - Fork 740
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 sp_runtime::RuntimeString
and replace with Cow<'static, str>
or String
depending on use case
#5693
Conversation
f0df22e
to
308d2a9
Compare
I do not understand why formatter in CI wants those trailing whitespaces, I'm unable to commit them for some reason in IDE. UPD: |
096e2d6
to
f3778c1
Compare
…>` or `String` depending on use case
f3778c1
to
d9de518
Compare
…>` or `String` depending on use case (paritytech#5693)
# Conflicts: # cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs # polkadot/runtime/rococo/src/genesis_config_presets.rs # templates/parachain/runtime/src/genesis_config_presets.rs
Fixed merge conflicts and restored |
Anything I can do to move this PR forward? It seems to just accumulate merge conflicts over time. |
$crate::Cow::Borrowed($y) | ||
}}; | ||
} | ||
// Re-export for ^ macro, should be removed once macro is gone | ||
#[doc(hidden)] | ||
pub use alloc::borrow::Cow; |
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.
This doesn't work?
$crate::Cow::Borrowed($y) | |
}}; | |
} | |
// Re-export for ^ macro, should be removed once macro is gone | |
#[doc(hidden)] | |
pub use alloc::borrow::Cow; | |
$crate::alloc::borrow::Cow::Borrowed($y) | |
}}; | |
} |
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.
Even better to wrap it in a mod __private
module, so others dont assume that it is part of the public API.
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.
$crate::alloc::borrow::Cow::Borrowed($y)
does not work because alloc
is a private import of the crate.
I only did it like this originally due similar example code on line 52 above. I could move both into __private
, but I wanted to keep it close to the now deprecated macro. Let me know if you have a strong opinion about this one or feel free to push changes directly.
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.
Ah yes, you can also have a __private_create_runtime_str
module if you want to keep stuff together.
It is good so user don't start using it in when it is recommended by rustc.
Anyway it is fine.
substrate/primitives/version/proc-macro/src/decl_runtime_version.rs
Outdated
Show resolved
Hide resolved
/cmd prdoc --bump major --audience runtime_dev |
@@ -202,7 +202,7 @@ macro_rules! impl_node_runtime_apis { | |||
|
|||
fn dispatch_benchmark( | |||
_: frame_benchmarking::BenchmarkConfig | |||
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> { | |||
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> { |
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.
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> { | |
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, String> { |
This code is never compiled for no_std
.
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.
It actually is used like that in CI, had to revert this suggestion
cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/mod.rs
Outdated
Show resolved
Hide resolved
# Conflicts: # cumulus/parachains/runtimes/starters/seedling/src/lib.rs # cumulus/parachains/runtimes/starters/shell/src/lib.rs # cumulus/test/runtime/src/lib.rs # substrate/test-utils/runtime/src/lib.rs
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.
Applied review suggestions improving upgrade experience and resolved merge conflicts
$crate::Cow::Borrowed($y) | ||
}}; | ||
} | ||
// Re-export for ^ macro, should be removed once macro is gone | ||
#[doc(hidden)] | ||
pub use alloc::borrow::Cow; |
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.
$crate::alloc::borrow::Cow::Borrowed($y)
does not work because alloc
is a private import of the crate.
I only did it like this originally due similar example code on line 52 above. I could move both into __private
, but I wanted to keep it close to the now deprecated macro. Let me know if you have a strong opinion about this one or feel free to push changes directly.
needs to fix CI:
|
Right, that is why it was in there from the beginning, bringing it back too |
c5444f3
Description
As described in #4001
RuntimeVersion
was not encoded consistently using serde. Turned out it was a remnant of old times and no longer actually needed. As such I removed it completely in this PR and replaced withCow<'static, str>
for spec/impl names andString
for error cases.Fixes #4001.
Integration
For downstream projects the upgrade will primarily consist of following two changes:
SCALE encoding/decoding remains the same as before, but serde encoding in runtime has changed from bytes to string (it was like this in
std
environment already), which most projects shouldn't have issues with. I consider the impact of serde encoding here low due to the type only being used in runtime version struct and mostly limited to runtime internals, where serde encoding/decoding of this data structure is quite unlikely (though we did hit exactly this edge-case ourselves 😅).Review Notes
Most of the changes are trivial and mechanical, the only non-trivial change is in
substrate/primitives/version/proc-macro/src/decl_runtime_version.rs
where macro call expectation insp_version::runtime_version
implementation was replaced with function call expectation.Checklist
T
required)