diff --git a/src/build.rs b/src/build.rs index 5370563..8f742fc 100644 --- a/src/build.rs +++ b/src/build.rs @@ -8,6 +8,7 @@ use super::{ PackingError, OptimizerError, TargetRuntime, + std::fmt, }; use parity_wasm::elements; @@ -36,8 +37,8 @@ pub enum SourceTarget { Unknown, } -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { use self::Error::*; match self { Encoding(err) => write!(f, "Encoding error ({})", err), diff --git a/src/ext.rs b/src/ext.rs index 11c5f18..3b129e7 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -1,6 +1,6 @@ -use std::string::String; -use std::vec::Vec; -use std::borrow::ToOwned; +use crate::std::string::String; +use crate::std::vec::Vec; +use crate::std::borrow::ToOwned; use parity_wasm::{elements, builder}; use byteorder::{LittleEndian, ByteOrder}; diff --git a/src/gas/mod.rs b/src/gas/mod.rs index 860b1c3..90d63ca 100644 --- a/src/gas/mod.rs +++ b/src/gas/mod.rs @@ -7,9 +7,9 @@ #[cfg(test)] mod validation; -use std::cmp::min; -use std::mem; -use std::vec::Vec; +use crate::std::cmp::min; +use crate::std::mem; +use crate::std::vec::Vec; use parity_wasm::{elements, builder}; use crate::rules::Rules; diff --git a/src/gas/validation.rs b/src/gas/validation.rs index 604906c..5f68dcc 100644 --- a/src/gas/validation.rs +++ b/src/gas/validation.rs @@ -11,9 +11,13 @@ use super::MeteredBlock; use crate::rules::Set as RuleSet; use crate::rules::Rules; +use crate::std::vec::Vec; use parity_wasm::elements::{FuncBody, Instruction}; -use std::collections::HashMap; +#[cfg(features = "std")] +use crate::std::collections::HashMap as Map; +#[cfg(not(features = "std"))] +use crate::std::collections::BTreeMap as Map; /// An ID for a node in a ControlFlowGraph. type NodeId = usize; @@ -288,7 +292,7 @@ fn validate_graph_gas_costs(graph: &ControlFlowGraph) -> bool { node_id: NodeId, mut total_actual: u32, mut total_charged: u32, - loop_costs: &mut HashMap, + loop_costs: &mut Map, ) -> bool { let node = graph.get_node(node_id); @@ -325,7 +329,7 @@ fn validate_graph_gas_costs(graph: &ControlFlowGraph) -> bool { } // Recursively explore all paths through the execution graph starting from the entry node. - visit(graph, 0, 0, 0, &mut HashMap::new()) + visit(graph, 0, 0, 0, &mut Map::new()) } /// Validate that the metered blocks are correct with respect to the function body by exhaustively diff --git a/src/graph.rs b/src/graph.rs index 956cc7f..41c4665 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -4,7 +4,7 @@ use parity_wasm::elements; use super::ref_list::{RefList, EntryRef}; -use std::{ +use crate::std::{ vec::Vec, borrow::ToOwned, string::String, diff --git a/src/lib.rs b/src/lib.rs index 081d99f..8b42ccd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,7 +83,7 @@ impl TargetRuntime { #[cfg(not(feature = "std"))] mod std { - pub use alloc::{borrow, boxed, string, vec}; + pub use ::alloc::{borrow, boxed, string, vec}; pub use core::*; pub mod rc { @@ -94,3 +94,9 @@ mod std { pub use alloc::collections::{BTreeMap, BTreeSet}; } } + + +#[cfg(feature = "std")] +mod std { + pub use std::*; +} diff --git a/src/logger.rs b/src/logger.rs index 222ad50..8993eba 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,4 +1,4 @@ -use std::env; +use crate::std::env; use log::LevelFilter; use env_logger::Builder; use lazy_static::lazy_static; diff --git a/src/optimizer.rs b/src/optimizer.rs index a123cd6..86fc8b0 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -1,9 +1,9 @@ #[cfg(features = "std")] -use std::collections::{HashSet as Set}; +use crate::std::collections::{HashSet as Set}; #[cfg(not(features = "std"))] -use std::collections::{BTreeSet as Set}; -use std::vec::Vec; -use std::mem; +use crate::std::collections::{BTreeSet as Set}; +use crate::std::vec::Vec; +use crate::std::mem; use parity_wasm::elements; diff --git a/src/pack.rs b/src/pack.rs index 0816b5f..becda22 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -1,6 +1,6 @@ -use std::fmt; -use std::vec::Vec; -use std::borrow::ToOwned; +use crate::std::fmt; +use crate::std::vec::Vec; +use crate::std::borrow::ToOwned; use parity_wasm::elements::{ self, Section, DataSection, Instruction, DataSegment, InitExpr, Internal, External, diff --git a/src/ref_list.rs b/src/ref_list.rs index 376486d..1925d8a 100644 --- a/src/ref_list.rs +++ b/src/ref_list.rs @@ -1,9 +1,9 @@ #![warn(missing_docs)] -use std::rc::Rc; -use std::cell::RefCell; -use std::vec::Vec; -use std::slice; +use crate::std::rc::Rc; +use crate::std::cell::RefCell; +use crate::std::vec::Vec; +use crate::std::slice; #[derive(Debug)] enum EntryOrigin { @@ -50,7 +50,7 @@ impl Entry { } } -impl ::std::ops::Deref for Entry { +impl crate::std::ops::Deref for Entry { type Target = T; fn deref(&self) -> &T { @@ -58,7 +58,7 @@ impl ::std::ops::Deref for Entry { } } -impl ::std::ops::DerefMut for Entry { +impl crate::std::ops::DerefMut for Entry { fn deref_mut(&mut self) -> &mut T { &mut self.val } @@ -82,14 +82,14 @@ impl From> for EntryRef { impl EntryRef { /// Read the reference data. - pub fn read(&self) -> ::std::cell::Ref> { + pub fn read(&self) -> crate::std::cell::Ref> { self.0.borrow() } /// Try to modify internal content of the referenced object. /// /// May panic if it is already borrowed. - pub fn write(&self) -> ::std::cell::RefMut> { + pub fn write(&self) -> crate::std::cell::RefMut> { self.0.borrow_mut() } diff --git a/src/rules.rs b/src/rules.rs index 0cefabf..2256a6c 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -1,9 +1,10 @@ #[cfg(features = "std")] -use std::collections::{HashMap as Map}; +use crate::std::collections::HashMap as Map; #[cfg(not(features = "std"))] -use std::collections::{BTreeMap as Map}; +use crate::std::collections::BTreeMap as Map; -use std::num::NonZeroU32; +use crate::std::num::NonZeroU32; +use crate::std::str::FromStr; use parity_wasm::elements; @@ -68,7 +69,7 @@ pub enum InstructionType { GrowMemory, } -impl ::std::str::FromStr for InstructionType { +impl FromStr for InstructionType { type Err = UnknownInstruction; fn from_str(s: &str) -> Result { diff --git a/src/stack_height/max_height.rs b/src/stack_height/max_height.rs index 23c7ea1..4849092 100644 --- a/src/stack_height/max_height.rs +++ b/src/stack_height/max_height.rs @@ -1,4 +1,4 @@ -use std::vec::Vec; +use crate::std::vec::Vec; use parity_wasm::elements::{self, BlockType, Type}; use super::{resolve_func_type, Error}; diff --git a/src/stack_height/mod.rs b/src/stack_height/mod.rs index 737d84a..d619f9e 100644 --- a/src/stack_height/mod.rs +++ b/src/stack_height/mod.rs @@ -49,8 +49,8 @@ //! between the frames. //! - upon entry into the function entire stack frame is allocated. -use std::string::String; -use std::vec::Vec; +use crate::std::string::String; +use crate::std::vec::Vec; use parity_wasm::elements::{self, Type}; use parity_wasm::builder; diff --git a/src/stack_height/thunk.rs b/src/stack_height/thunk.rs index aaa02ee..11a377d 100644 --- a/src/stack_height/thunk.rs +++ b/src/stack_height/thunk.rs @@ -1,8 +1,8 @@ #[cfg(features = "std")] -use std::collections::{HashMap as Map}; +use crate::std::collections::{HashMap as Map}; #[cfg(not(features = "std"))] -use std::collections::{BTreeMap as Map}; -use std::vec::Vec; +use crate::std::collections::{BTreeMap as Map}; +use crate::std::vec::Vec; use parity_wasm::elements::{self, FunctionType, Internal}; use parity_wasm::builder; diff --git a/src/symbols.rs b/src/symbols.rs index 60b6ef1..8586e65 100644 --- a/src/symbols.rs +++ b/src/symbols.rs @@ -1,8 +1,8 @@ #[cfg(features = "std")] -use std::collections::{HashSet as Set}; +use crate::std::collections::{HashSet as Set}; #[cfg(not(features = "std"))] -use std::collections::{BTreeSet as Set}; -use std::vec::Vec; +use crate::std::collections::{BTreeSet as Set}; +use crate::std::vec::Vec; use parity_wasm::elements;