mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::error::{self, Error};
|
||||
use super::RuntimeBlob;
|
||||
use std::mem;
|
||||
use crate::error::{self, Error};
|
||||
use pwasm_utils::parity_wasm::elements::Instruction;
|
||||
use std::mem;
|
||||
|
||||
/// This is a snapshot of data segments specialzied for a particular instantiation.
|
||||
///
|
||||
@@ -49,7 +49,7 @@ impl DataSegmentsSnapshot {
|
||||
|
||||
// [op, End]
|
||||
if init_expr.len() != 2 {
|
||||
return Err(Error::InitializerHasTooManyExpressions);
|
||||
return Err(Error::InitializerHasTooManyExpressions)
|
||||
}
|
||||
let offset = match &init_expr[0] {
|
||||
Instruction::I32Const(v) => *v as u32,
|
||||
@@ -60,8 +60,8 @@ impl DataSegmentsSnapshot {
|
||||
// At the moment of writing the Substrate Runtime Interface does not provide
|
||||
// any globals. There is nothing that prevents us from supporting this
|
||||
// if/when we gain those.
|
||||
return Err(Error::ImportedGlobalsUnsupported);
|
||||
}
|
||||
return Err(Error::ImportedGlobalsUnsupported)
|
||||
},
|
||||
insn => return Err(Error::InvalidInitializerExpression(format!("{:?}", insn))),
|
||||
};
|
||||
|
||||
|
||||
@@ -50,17 +50,14 @@ pub trait InstanceGlobals {
|
||||
/// a runtime blob that was instrumented by
|
||||
/// [`RuntimeBlob::expose_mutable_globals`](super::RuntimeBlob::expose_mutable_globals`).
|
||||
|
||||
///
|
||||
/// If the code wasn't instrumented then it would be empty and snapshot would do nothing.
|
||||
pub struct ExposedMutableGlobalsSet(Vec<String>);
|
||||
|
||||
impl ExposedMutableGlobalsSet {
|
||||
/// Collect the set from the given runtime blob. See the struct documentation for details.
|
||||
pub fn collect(runtime_blob: &RuntimeBlob) -> Self {
|
||||
let global_names = runtime_blob
|
||||
.exported_internal_global_names()
|
||||
.map(ToOwned::to_owned)
|
||||
.collect();
|
||||
let global_names =
|
||||
runtime_blob.exported_internal_global_names().map(ToOwned::to_owned).collect();
|
||||
Self(global_names)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,5 +53,5 @@ mod globals_snapshot;
|
||||
mod runtime_blob;
|
||||
|
||||
pub use data_segments_snapshot::DataSegmentsSnapshot;
|
||||
pub use globals_snapshot::{GlobalsSnapshot, ExposedMutableGlobalsSet, InstanceGlobals};
|
||||
pub use globals_snapshot::{ExposedMutableGlobalsSet, GlobalsSnapshot, InstanceGlobals};
|
||||
pub use runtime_blob::RuntimeBlob;
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use pwasm_utils::{
|
||||
parity_wasm::elements::{
|
||||
DataSegment, Module, deserialize_buffer, serialize, Internal,
|
||||
},
|
||||
export_mutable_globals,
|
||||
};
|
||||
use crate::error::WasmError;
|
||||
use pwasm_utils::{
|
||||
export_mutable_globals,
|
||||
parity_wasm::elements::{deserialize_buffer, serialize, DataSegment, Internal, Module},
|
||||
};
|
||||
|
||||
/// A bunch of information collected from a WebAssembly module.
|
||||
#[derive(Clone)]
|
||||
@@ -53,11 +51,7 @@ impl RuntimeBlob {
|
||||
|
||||
/// Extract the data segments from the given wasm code.
|
||||
pub(super) fn data_segments(&self) -> Vec<DataSegment> {
|
||||
self.raw_module
|
||||
.data_section()
|
||||
.map(|ds| ds.entries())
|
||||
.unwrap_or(&[])
|
||||
.to_vec()
|
||||
self.raw_module.data_section().map(|ds| ds.entries()).unwrap_or(&[]).to_vec()
|
||||
}
|
||||
|
||||
/// The number of globals defined in locally in this module.
|
||||
@@ -70,10 +64,7 @@ impl RuntimeBlob {
|
||||
|
||||
/// The number of imports of globals.
|
||||
pub fn imported_globals_count(&self) -> u32 {
|
||||
self.raw_module
|
||||
.import_section()
|
||||
.map(|is| is.globals() as u32)
|
||||
.unwrap_or(0)
|
||||
self.raw_module.import_section().map(|is| is.globals() as u32).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Perform an instrumentation that makes sure that the mutable globals are exported.
|
||||
@@ -95,35 +86,29 @@ impl RuntimeBlob {
|
||||
|e| WasmError::Other(format!("cannot inject the stack limiter: {:?}", e)),
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
raw_module: injected_module,
|
||||
})
|
||||
Ok(Self { raw_module: injected_module })
|
||||
}
|
||||
|
||||
/// Perform an instrumentation that makes sure that a specific function `entry_point` is exported
|
||||
pub fn entry_point_exists(&self, entry_point: &str) -> bool {
|
||||
self.raw_module.export_section().map(|e| {
|
||||
e.entries()
|
||||
.iter()
|
||||
.any(|e| matches!(e.internal(), Internal::Function(_)) && e.field() == entry_point)
|
||||
}).unwrap_or_default()
|
||||
self.raw_module
|
||||
.export_section()
|
||||
.map(|e| {
|
||||
e.entries().iter().any(|e| {
|
||||
matches!(e.internal(), Internal::Function(_)) && e.field() == entry_point
|
||||
})
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Returns an iterator of all globals which were exported by [`expose_mutable_globals`].
|
||||
pub(super) fn exported_internal_global_names<'module>(
|
||||
&'module self,
|
||||
) -> impl Iterator<Item = &'module str> {
|
||||
let exports = self
|
||||
.raw_module
|
||||
.export_section()
|
||||
.map(|es| es.entries())
|
||||
.unwrap_or(&[]);
|
||||
let exports = self.raw_module.export_section().map(|es| es.entries()).unwrap_or(&[]);
|
||||
exports.iter().filter_map(|export| match export.internal() {
|
||||
Internal::Global(_)
|
||||
if export.field().starts_with("exported_internal_global") =>
|
||||
{
|
||||
Some(export.field())
|
||||
}
|
||||
Internal::Global(_) if export.field().starts_with("exported_internal_global") =>
|
||||
Some(export.field()),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
@@ -135,12 +120,11 @@ impl RuntimeBlob {
|
||||
.custom_sections()
|
||||
.find(|cs| cs.name() == section_name)
|
||||
.map(|cs| cs.payload())
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes this runtime blob and serializes it.
|
||||
pub fn serialize(self) -> Vec<u8> {
|
||||
serialize(self.raw_module)
|
||||
.expect("serializing into a vec should succeed; qed")
|
||||
serialize(self.raw_module).expect("serializing into a vec should succeed; qed")
|
||||
}
|
||||
|
||||
/// Destructure this structure into the underlying parity-wasm Module.
|
||||
|
||||
Reference in New Issue
Block a user