Fixes necessary for having no_std imports work with edition2018

This commit is contained in:
Alexander Theißen
2020-10-22 12:26:24 +02:00
parent a2653cff5a
commit aebfc0fbd7
15 changed files with 54 additions and 42 deletions
+3 -2
View File
@@ -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),
+3 -3
View File
@@ -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};
+3 -3
View File
@@ -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;
+7 -3
View File
@@ -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<NodeId, (u32, u32)>,
loop_costs: &mut Map<NodeId, (u32, u32)>,
) -> 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
+1 -1
View File
@@ -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,
+7 -1
View File
@@ -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::*;
}
+1 -1
View File
@@ -1,4 +1,4 @@
use std::env;
use crate::std::env;
use log::LevelFilter;
use env_logger::Builder;
use lazy_static::lazy_static;
+4 -4
View File
@@ -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;
+3 -3
View File
@@ -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,
+8 -8
View File
@@ -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<T> Entry<T> {
}
}
impl<T> ::std::ops::Deref for Entry<T> {
impl<T> crate::std::ops::Deref for Entry<T> {
type Target = T;
fn deref(&self) -> &T {
@@ -58,7 +58,7 @@ impl<T> ::std::ops::Deref for Entry<T> {
}
}
impl<T> ::std::ops::DerefMut for Entry<T> {
impl<T> crate::std::ops::DerefMut for Entry<T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.val
}
@@ -82,14 +82,14 @@ impl<T> From<Entry<T>> for EntryRef<T> {
impl<T> EntryRef<T> {
/// Read the reference data.
pub fn read(&self) -> ::std::cell::Ref<Entry<T>> {
pub fn read(&self) -> crate::std::cell::Ref<Entry<T>> {
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<Entry<T>> {
pub fn write(&self) -> crate::std::cell::RefMut<Entry<T>> {
self.0.borrow_mut()
}
+5 -4
View File
@@ -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<Self, Self::Err> {
+1 -1
View File
@@ -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};
+2 -2
View File
@@ -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;
+3 -3
View File
@@ -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;
+3 -3
View File
@@ -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;