2018 edition (#266)

* 2018 edition fixes

* arrange uses

* fix for nightly (but not tests)

* fix for tests as well

* fix spec runner
This commit is contained in:
Nikolay Volf 2019-02-11 18:43:13 +03:00 committed by GitHub
parent f9224f1ec1
commit a959bb50a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 112 additions and 103 deletions

View File

@ -11,6 +11,7 @@ description = "WebAssembly binary format serialization/deserialization/interpret
keywords = ["wasm", "webassembly", "bytecode", "serde", "interpreter"]
categories = ["wasm", "parser-implementations"]
exclude = [ "res/*", "spec/*" ]
edition = "2018"
[dev-dependencies]
time = "0.1"

View File

@ -1,7 +1,9 @@
use std::vec::Vec;
use elements;
use super::invoke::{Invoke, Identity};
use super::misc::{ValueTypeBuilder, ValueTypesBuilder, OptionalValueTypeBuilder};
use crate::rust::vec::Vec;
use crate::elements;
use super::{
invoke::{Invoke, Identity},
misc::{ValueTypeBuilder, ValueTypesBuilder, OptionalValueTypeBuilder},
};
/// Signature template description
pub enum Signature {
@ -373,7 +375,7 @@ pub fn function() -> FunctionBuilder {
mod tests {
use super::{signatures, function};
use elements;
use crate::elements;
#[test]
fn example() {

View File

@ -1,6 +1,6 @@
use std::vec::Vec;
use crate::rust::vec::Vec;
use super::invoke::{Identity, Invoke};
use elements;
use crate::elements;
/// Data segment builder
pub struct DataSegmentBuilder<F=Identity> {

View File

@ -1,7 +1,6 @@
use std::string::String;
use std::borrow::ToOwned;
use crate::rust::{string::String, borrow::ToOwned};
use super::invoke::{Invoke, Identity};
use elements;
use crate::elements;
/// Export entry builder
pub struct ExportBuilder<F=Identity> {

View File

@ -1,6 +1,9 @@
use super::invoke::{Invoke, Identity};
use super::misc::ValueTypeBuilder;
use elements;
use super::{
invoke::{Invoke, Identity},
misc::ValueTypeBuilder,
};
use crate::elements;
/// Global builder
pub struct GlobalBuilder<F=Identity> {
@ -79,7 +82,7 @@ pub fn global() -> GlobalBuilder {
#[cfg(test)]
mod tests {
use super::global;
use elements;
use crate::elements;
#[test]
fn example() {

View File

@ -1,7 +1,6 @@
use crate::rust::{borrow::ToOwned, string::String};
use super::invoke::{Identity, Invoke};
use elements;
use std::borrow::ToOwned;
use std::string::String;
use crate::elements;
/// Import builder
pub struct ImportBuilder<F=Identity> {

View File

@ -1,5 +1,5 @@
use std::vec::Vec;
use elements;
use crate::rust::vec::Vec;
use crate::elements;
use super::invoke::{Invoke, Identity};
/// Memory definition struct

View File

@ -1,6 +1,6 @@
use std::vec::Vec;
use crate::rust::vec::Vec;
use super::invoke::{Invoke, Identity};
use elements;
use crate::elements;
pub struct ValueTypeBuilder<F=Identity> {
callback: F,

View File

@ -1,10 +1,15 @@
use std::vec::Vec;
use super::invoke::{Invoke, Identity};
use super::code::{self, SignaturesBuilder, FunctionBuilder};
use super::memory::{self, MemoryBuilder};
use super::table::{self, TableBuilder};
use super::{import, export, global, data};
use elements;
use crate::rust::vec::Vec;
use crate::elements;
use super::{
import,
export,
global,
data,
invoke::{Invoke, Identity},
code::{self, SignaturesBuilder, FunctionBuilder},
memory::{self, MemoryBuilder},
table::{self, TableBuilder},
};
/// Module builder
pub struct ModuleBuilder<F=Identity> {
@ -522,6 +527,7 @@ pub fn from_module(module: elements::Module) -> ModuleBuilder {
#[cfg(test)]
mod tests {
use crate::elements;
use super::module;
#[test]
@ -556,7 +562,7 @@ mod tests {
#[test]
fn global() {
let module = module()
.global().value_type().i64().mutable().init_expr(::elements::Instruction::I64Const(5)).build()
.global().value_type().i64().mutable().init_expr(elements::Instruction::I64Const(5)).build()
.build();
assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);
@ -566,7 +572,7 @@ mod tests {
fn data() {
let module = module()
.data()
.offset(::elements::Instruction::I32Const(16))
.offset(elements::Instruction::I32Const(16))
.value(vec![0u8, 15, 10, 5, 25])
.build()
.build();

View File

@ -1,5 +1,5 @@
use std::vec::Vec;
use elements;
use crate::rust::vec::Vec;
use crate::elements;
use super::invoke::{Invoke, Identity};
/// Table definition

View File

@ -1,6 +1,6 @@
use std::string::String;
use crate::rust::string::String;
use super::{Deserialize, Serialize, Error, VarUint7, VarUint32};
use io;
use crate::io;
/// Internal reference of the exported entry.
#[derive(Debug, Clone, Copy, PartialEq)]

View File

@ -1,10 +1,9 @@
use io;
use std::vec::Vec;
use crate::rust::vec::Vec;
use super::{
Deserialize, Error, ValueType, VarUint32, CountedList, Instructions,
Serialize, CountedWriter, CountedListWriter,
};
use elements::section::SectionReader;
use crate::{io, elements::section::SectionReader};
/// Function signature (type reference)
#[derive(Debug, Copy, Clone, PartialEq)]

View File

@ -1,4 +1,4 @@
use io;
use crate::io;
use super::{Deserialize, Serialize, Error, GlobalType, InitExpr};
/// Global entry in the module.

View File

@ -1,5 +1,5 @@
use io;
use std::string::String;
use crate::rust::string::String;
use crate::io;
use super::{
Deserialize, Serialize, Error, VarUint7, VarInt7, VarUint32, VarUint1, Uint8,
ValueType, TableElementType

View File

@ -1,10 +1,12 @@
use std::cmp::min;
use std::iter::{FromIterator, IntoIterator};
use std::mem;
use std::slice;
use std::vec;
use std::vec::Vec;
use io;
use crate::rust::{
cmp::min,
iter::{FromIterator, IntoIterator},
mem,
slice,
vec::{self, Vec},
};
use crate::io;
use super::{Deserialize, Error, Serialize, VarUint32};
@ -86,7 +88,7 @@ impl<T> IndexMap<T> {
existing
};
if mem::size_of::<usize>() > 4 {
debug_assert!(self.entries.len() <= (::std::u32::MAX as usize) + 1);
debug_assert!(self.entries.len() <= (u32::max_value() as usize) + 1);
}
#[cfg(slow_assertions)]
debug_assert_eq!(self.len, self.slow_len());
@ -357,7 +359,7 @@ where
#[cfg(test)]
mod tests {
use io;
use crate::io;
use super::*;
#[test]

View File

@ -1,9 +1,7 @@
//! Elements of the WebAssembly binary format.
use std::fmt;
use io;
use std::vec::Vec;
use std::string::String;
use crate::rust::{fmt, vec::Vec, format, string::String};
use crate::io;
macro_rules! buffered_read {
($buffer_size: expr, $length: expr, $reader: expr) => {

View File

@ -1,7 +1,5 @@
use io;
use std::vec::Vec;
use std::borrow::ToOwned;
use std::string::String;
use crate::rust::{vec::Vec, borrow::ToOwned, string::String, cmp};
use crate::io;
use super::{Deserialize, Serialize, Error, Uint32, External};
use super::section::{
@ -539,7 +537,7 @@ struct PeekSection<'a> {
impl<'a> io::Read for PeekSection<'a> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<()> {
let available = ::std::cmp::min(buf.len(), self.region.len() - self.cursor);
let available = cmp::min(buf.len(), self.region.len() - self.cursor);
if available < buf.len() {
return Err(io::Error::UnexpectedEof);
}

View File

@ -1,6 +1,5 @@
use io;
use std::vec::Vec;
use std::string::String;
use crate::rust::{vec::Vec, string::String};
use crate::io;
use super::{Deserialize, Error, Module, Serialize, VarUint32, VarUint7, Type};
use super::index_map::IndexMap;

View File

@ -1,7 +1,5 @@
use std::fmt;
use std::vec::Vec;
use std::boxed::Box;
use io;
use crate::rust::{fmt, vec::Vec, boxed::Box};
use crate::io;
use super::{
Serialize, Deserialize, Error,
Uint8, VarUint32, CountedList, BlockType,

View File

@ -1,6 +1,5 @@
use io;
use std::vec::Vec;
use std::string::String;
use crate::rust::{vec::Vec, string::String};
use crate::{io, elements};
use super::{Error, Deserialize, Serialize};
/// Unsigned variable-length integer, limited to 32 bits,
@ -28,7 +27,7 @@ impl From<u32> for VarUint32 {
impl From<usize> for VarUint32 {
fn from(i: usize) -> VarUint32 {
assert!(i <= ::std::u32::MAX as usize);
assert!(i <= u32::max_value() as usize);
VarUint32(i as u32)
}
}
@ -600,9 +599,9 @@ impl<'a, W: 'a + io::Write> io::Write for CountedWriter<'a, W> {
/// Helper struct to write series of `T` preceded by the length of the sequence
/// serialized as VarUint32.
#[derive(Debug, Clone)]
pub struct CountedListWriter<I: Serialize<Error=::elements::Error>, T: IntoIterator<Item=I>>(pub usize, pub T);
pub struct CountedListWriter<I: Serialize<Error=elements::Error>, T: IntoIterator<Item=I>>(pub usize, pub T);
impl<I: Serialize<Error=::elements::Error>, T: IntoIterator<Item=I>> Serialize for CountedListWriter<I, T> {
impl<I: Serialize<Error=elements::Error>, T: IntoIterator<Item=I>> Serialize for CountedListWriter<I, T> {
type Error = Error;
fn serialize<W: io::Write>(self, writer: &mut W) -> Result<(), Self::Error> {
@ -622,7 +621,7 @@ mod tests {
use super::super::{deserialize_buffer, Serialize};
use super::{CountedList, VarInt7, VarUint32, VarInt32, VarInt64, VarUint64};
use elements::Error;
use crate::elements::Error;
fn varuint32_ser_test(val: u32, expected: Vec<u8>) {
let mut buf = Vec::new();

View File

@ -1,6 +1,5 @@
use io;
use std::vec::Vec;
use std::string::String;
use crate::rust::{vec::Vec, string::String};
use crate::io;
use super::{CountedList, CountedListWriter, CountedWriter, Deserialize, Error, Serialize, VarInt32, VarUint32, VarUint7};

View File

@ -1,7 +1,5 @@
use io;
use std::vec::Vec;
use std::string::String;
use std::borrow::ToOwned;
use crate::rust::{vec::Vec, string::String, borrow::ToOwned};
use crate::{io, elements};
use super::{
Serialize,
Deserialize,
@ -254,7 +252,7 @@ pub(crate) struct SectionReader {
}
impl SectionReader {
pub fn new<R: io::Read>(reader: &mut R) -> Result<Self, ::elements::Error> {
pub fn new<R: io::Read>(reader: &mut R) -> Result<Self, elements::Error> {
let length = u32::from(VarUint32::deserialize(reader)?) as usize;
let inner_buffer = buffered_read!(ENTRIES_BUFFER_LENGTH, length, reader);
let buf_length = inner_buffer.len();
@ -285,8 +283,8 @@ impl io::Read for SectionReader {
}
}
fn read_entries<R: io::Read, T: Deserialize<Error=::elements::Error>>(reader: &mut R)
-> Result<Vec<T>, ::elements::Error>
fn read_entries<R: io::Read, T: Deserialize<Error=elements::Error>>(reader: &mut R)
-> Result<Vec<T>, elements::Error>
{
let mut section_reader = SectionReader::new(reader)?;
let result = CountedList::<T>::deserialize(&mut section_reader)?.into_inner();

View File

@ -1,5 +1,5 @@
use io;
use std::vec::Vec;
use crate::rust::vec::Vec;
use crate::io;
use super::{Deserialize, Serialize, Error, VarUint32, CountedList, InitExpr, CountedListWriter};
const FLAG_MEMZERO: u32 = 0;

View File

@ -1,6 +1,5 @@
use io;
use std::fmt;
use std::vec::Vec;
use crate::rust::{fmt, vec::Vec};
use crate::io;
use super::{
Deserialize, Serialize, Error, VarUint7, VarInt7, VarUint1, CountedList,
CountedListWriter, VarUint32,

View File

@ -3,6 +3,14 @@
//! Basically it just a replacement for the std::io that is usable from
//! the `no_std` environment.
use crate::rust::result;
#[cfg(feature="std")]
use crate::rust::io;
#[cfg(not(feature="std"))]
use crate::rust::vec::Vec;
/// IO specific error.
#[derive(Debug)]
pub enum Error {
@ -16,11 +24,11 @@ pub enum Error {
InvalidData,
#[cfg(feature = "std")]
IoError(::std::io::Error),
IoError(io::Error),
}
/// IO specific Result.
pub type Result<T> = ::std::result::Result<T, Error>;
pub type Result<T> = result::Result<T, Error>;
pub trait Write {
/// Write a buffer of data into this write.
@ -70,7 +78,7 @@ impl<T: AsRef<[u8]>> Read for Cursor<T> {
}
#[cfg(not(feature = "std"))]
impl Write for ::std::vec::Vec<u8> {
impl Write for Vec<u8> {
fn write(&mut self, buf: &[u8]) -> Result<()> {
self.extend(buf);
Ok(())
@ -78,7 +86,7 @@ impl Write for ::std::vec::Vec<u8> {
}
#[cfg(feature = "std")]
impl<T: ::std::io::Read> Read for T {
impl<T: io::Read> Read for T {
fn read(&mut self, buf: &mut [u8]) -> Result<()> {
self.read_exact(buf)
.map_err(Error::IoError)
@ -86,7 +94,7 @@ impl<T: ::std::io::Read> Read for T {
}
#[cfg(feature = "std")]
impl<T: ::std::io::Write> Write for T {
impl<T: io::Write> Write for T {
fn write(&mut self, buf: &[u8]) -> Result<()> {
self.write_all(buf).map_err(Error::IoError)
}

View File

@ -1,12 +1,10 @@
//! WebAssembly format library
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
#![warn(missing_docs)]
#[cfg(not(feature = "std"))]
#[macro_use]
#[cfg(not(feature="std"))] #[macro_use]
extern crate alloc;
pub mod elements;
@ -26,13 +24,17 @@ pub use elements::{
serialize_to_file,
};
#[cfg(not(feature = "std"))]
mod std {
pub (crate) mod rust {
pub use core::*;
pub use alloc::vec;
pub use alloc::string;
pub use alloc::boxed;
pub use alloc::borrow;
pub use ::alloc::format;
pub use ::alloc::vec;
pub use ::alloc::string;
pub use ::alloc::boxed;
pub use ::alloc::borrow;
}
#[cfg(feature="std")]
pub (crate) mod rust {
pub use std::*;
}