Skip to content
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

feat(interface-types) Implement Interface Types (WIT) #787

Merged
merged 81 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
b3af77c
feat(wasmer-interface-types) Draft.
Hywan Sep 11, 2019
7ca546e
feat(interface-types) Continue.
Hywan Sep 12, 2019
45ba77c
feat(interface-types) Continue.
Hywan Sep 12, 2019
1c1b74b
feat(interface-types) Split into multiple files.
Hywan Sep 12, 2019
dc254e0
test(interface-types) Add test case for “unit” parsers.
Hywan Sep 13, 2019
24ac7a6
test(interface-types) Add test cases for higher-level parsers.
Hywan Sep 13, 2019
5a8a2b9
fix(interface-types) Fix visibility of various symbols.
Hywan Sep 13, 2019
a7ffffc
feat(interface-types) Move `TryFrom` from the `ast` to the `binary` m…
Hywan Sep 13, 2019
4ba9aac
fix(interface-types) `get-field` #1 argument is of type `InterfaceType`.
Hywan Sep 13, 2019
40613d3
feat(interface-types) Draft the WAT encoder.
Hywan Sep 13, 2019
6279b3e
feat(interface-types) Continue the WAT encoder.
Hywan Sep 18, 2019
bd3a888
feat(interface-types) Add new instructions.
Hywan Sep 18, 2019
480fe0f
chore(interface-types) Update to Wasmer 0.7.0.
Hywan Sep 18, 2019
6ec35c8
chore(interface-types) Bump to 0.7.0.
Hywan Sep 18, 2019
fc9389d
feat(interface-types) Encode `Interfaces` to WAT.
Hywan Sep 18, 2019
dc3c72e
feat(interface-types) Draft instruction interpreter.
Hywan Sep 18, 2019
2f3c37f
feat(interface-types) Continue.
Hywan Sep 18, 2019
c633450
feat(interface-types) Continue.
Hywan Sep 19, 2019
62e1f78
feat(interface-types) Add an abstract Wasm instance and a runtime to …
Hywan Sep 19, 2019
9d4c983
feat(interface-types) Implement `CallExport` executable instruction.
Hywan Sep 20, 2019
39a8178
feat(interface-types) `Stack` supports `Default`.
Hywan Sep 20, 2019
2237e62
chore(interface-types) Fix clippy warnings.
Hywan Sep 20, 2019
b7b37d2
feat(interface-types) The interpreter stack contains Wasm values.
Hywan Sep 20, 2019
56afb4d
feat(interface-types) Check signature of the exported function to call.
Hywan Sep 20, 2019
8557e83
feat(interface-types) Better error message when calling an exported f…
Hywan Sep 20, 2019
aea18f6
test(interface-types) Test calling a void exported function.
Hywan Sep 20, 2019
be5624e
feat(interface-types) Implement the `read-utf8` instruction.
Hywan Sep 23, 2019
4d9dacb
feat(interface-types) Implement the `call` executable instruction.
Hywan Sep 25, 2019
8d75db9
test(interface-types) Use macros to reduce test boilerplate.
Hywan Sep 25, 2019
ef568ca
feat(interface-types) Update `Instruction`.
Hywan Sep 25, 2019
981692e
chore(interface-types) Re-order match arms.
Hywan Sep 25, 2019
49a7587
feat(interface-types) Implement the `write-utf8` executable instruction.
Hywan Sep 25, 2019
5ce18fc
feat(interface-types) Create vectors with specific capacity when poss…
Hywan Sep 25, 2019
ade098b
fix(interface-types) Fix typos in error messages.
Hywan Sep 25, 2019
fce270a
feat(interface-types) Split the interpreter into multiple modules/files.
Hywan Sep 26, 2019
f537b4d
chore(interface-types) Simplify the `executable_instruction` macro.
Hywan Sep 26, 2019
c35395b
feat(interface-types) Rename a variable.
Hywan Sep 26, 2019
a047e68
Merge branch 'master' into feat-interface-types
Hywan Sep 26, 2019
7e18be1
chore(cargo) Update `Cargo.lock`.
Hywan Sep 26, 2019
63b1391
feat(interface-types) Let the type inference engine do the work.
Hywan Sep 26, 2019
87f61ab
feat(interface-types) Add attributes.
Hywan Sep 26, 2019
9fdaf0c
chore(cargo) Remove patches from version contraints.
Hywan Sep 26, 2019
d813472
feat(interface-types) Introduce the `wasm::structures::MemoryView` tr…
Hywan Sep 27, 2019
7b3ab38
chore(interface-types) Simplify the code.
Hywan Oct 2, 2019
99c9fc4
chore(interface-types) The `tests/` directory has moved in `wasmer-ru…
Hywan Oct 2, 2019
207d69f
feat(interface-types) Change `Instance::local_or_import(&self)` to `I…
Hywan Oct 2, 2019
b562400
feat(interface-types) Simplify code.
Hywan Oct 4, 2019
c8af1b1
feat(interface-types) Remove dev-dependencies to any runtime.
Hywan Feb 10, 2020
ba16d12
Merge branch 'master' into feat-interface-types
Hywan Feb 10, 2020
fe14c5c
chore(interface-types) Update crate version.
Hywan Feb 10, 2020
60a9056
feat(interface-types) Use nom 5.1.
Hywan Feb 10, 2020
0b0a89b
test(interface-types) Fix a documentation message.
Hywan Feb 10, 2020
102ebe8
chore(interface-types) Format code.
Hywan Feb 10, 2020
5ed5ac8
test(interface-types) Improve test cases for `Stack`.
Hywan Feb 10, 2020
e098934
doc(interface-types) Improve documentation of the crate itself.
Hywan Feb 10, 2020
d63508f
doc(interface-types) Improve documentation of the `stack` module.
Hywan Feb 10, 2020
32325c1
doc(interface-types) Improve module descriptions.
Hywan Feb 10, 2020
36c7dbd
feat(interface-types) Rename `ImportedFunction` to `Import`.
Hywan Feb 10, 2020
d667cb8
doc(interface-types) Improve documentation of the `ast` module.
Hywan Feb 10, 2020
2fc1fbb
doc(interface-types) Improve documentation of the `ast` module.
Hywan Feb 10, 2020
9fda6f9
doc(interface-types) Improve documentation of the `binary` module.
Hywan Feb 10, 2020
98fb069
test(interface-types) Test the `parse` parser.
Hywan Feb 10, 2020
55ae0e4
doc(interface-types) Add a doctest for `decoders::binary::parse`.
Hywan Feb 10, 2020
c5b963b
doc(interface-types) Improve documentation of the `wat` module.
Hywan Feb 10, 2020
98c7309
doc(interface-types) Improve documentation of the `macros` module.
Hywan Feb 12, 2020
b3c102d
doc(interface-types) Improve documentation of the `instruction` module.
Hywan Feb 12, 2020
6b0e43b
doc(interface-types) Improve the documentation of the `instruction` m…
Hywan Feb 12, 2020
13b9cb3
doc(interface-types) Improve the documentation of the `interpreter` m…
Hywan Feb 12, 2020
b7941f4
feat(interface-types) Ensure `ast::Type` is always well-formed.
Hywan Feb 13, 2020
1ad42d8
doc(interface-types) Improve documentation of `decoders::binary::leb`.
Hywan Feb 13, 2020
370fd6d
feat(decoders) Improve LEB parser in the `binary` module.
Hywan Feb 13, 2020
3f0c32b
fix(decoders) Remove the `unsafe` block in the `string` parser.
Hywan Feb 13, 2020
d8f9230
chore(decoders) Simplify code.
Hywan Feb 13, 2020
722727b
chore(decoders) Simplify code.
Hywan Feb 13, 2020
13cee90
feat(encoders) Implement `ToString` instead of `From<…> for String`.
Hywan Feb 13, 2020
6891517
chore(encoders) Changing `unimplemented!()` to `todo!()`.
Hywan Feb 13, 2020
ae6e261
chore(interface-types) Simplify code.
Hywan Feb 13, 2020
9559747
doc(interface-types) Add `#[deny(missing_docs)]`.
Hywan Feb 13, 2020
eb2f9db
feat(interface-types) Forbids unsafe code.
Hywan Feb 13, 2020
7f8d916
fix(interface-types) Clean up cargo features.
Hywan Feb 13, 2020
c697e68
Merge branch 'master' into feat-interface-types
Hywan Feb 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
297 changes: 177 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ members = [
"lib/wasi-tests",
"lib/emscripten-tests",
"lib/middleware-common-tests",
"lib/interface-types",
"examples/parallel",
"examples/plugin-for-example",
"examples/parallel-guest",
Expand Down
11 changes: 11 additions & 0 deletions lib/interface-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "wasmer-interface-types"
version = "0.13.1"
description = "WebAssembly Interface Types library for Wasmer"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
repository = "https://github.com/wasmerio/wasmer"
edition = "2018"

[dependencies]
nom = "5.1"
209 changes: 209 additions & 0 deletions lib/interface-types/src/ast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
//! Represents the WIT language as a tree. This is the central
//! representation of the language.

use crate::interpreter::Instruction;
use std::str;

/// Represents the types supported by WIT.
#[derive(PartialEq, Clone, Debug)]
pub enum InterfaceType {
/// An integer.
Int,

/// A float.
Float,

/// Opaque reference.
Any,

/// A string.
String,

/// A sequence.
Seq,

/// A 32-bits integer.
I32,

/// A 64-bits integer.
I64,

/// A 32-bits float.
F32,

/// A 64-bits float.
F64,

/// An `any` reference.
AnyRef,
}

/// Represents the kind of adapter.
#[derive(PartialEq, Debug)]
pub(crate) enum AdapterKind {
/// An adapter defined for an imported function of a WebAssembly instance.
Import,

/// An adapter defined for an exported function of a WebAssembly instance.
Export,

/// A helper function.
HelperFunction,
}

/// Represents an exported function signature.
#[derive(PartialEq, Debug)]
pub struct Export<'input> {
/// The function name.
pub name: &'input str,

/// The function input types.
pub input_types: Vec<InterfaceType>,

/// The function output types.
pub output_types: Vec<InterfaceType>,
}

/// Represents an imported function signature.
#[derive(PartialEq, Debug)]
pub struct Import<'input> {
/// The function namespace.
pub namespace: &'input str,

/// The function name.
pub name: &'input str,

/// The function input types.
pub input_types: Vec<InterfaceType>,

/// The function output types.
pub output_types: Vec<InterfaceType>,
}

/// Represents a structural type.
#[derive(PartialEq, Debug)]
pub struct Type<'input> {
/// The type name.
pub name: &'input str,

/// The field names.
field_names: Vec<&'input str>,

/// The field types.
field_types: Vec<InterfaceType>,
}

impl<'input> Type<'input> {
/// Creates a new `Type`.
///
/// The constructor panics if there is the length of `names` is
/// different than the length of `types`.
pub fn new(type_name: &'input str, names: Vec<&'input str>, types: Vec<InterfaceType>) -> Self {
assert_eq!(
names.len(),
types.len(),
"There must be the same number of field names than field types."
);

Self {
name: type_name,
field_names: names,
field_types: types,
}
}

/// Adds a new field to the type.
pub fn add_field(&mut self, name: &'input str, ty: InterfaceType) {
self.field_names.push(name);
self.field_types.push(ty);
}

/// Returns the field names.
pub fn field_names(&self) -> &Vec<&'input str> {
&self.field_names
}

/// Returns the field types.
pub fn field_types(&self) -> &Vec<InterfaceType> {
&self.field_types
}
}

/// Represents an adapter.
#[derive(PartialEq, Debug)]
pub enum Adapter<'input> {
/// An adapter for an imported function.
Import {
/// The function namespace.
namespace: &'input str,

/// The function name.
name: &'input str,

/// The function input types.
input_types: Vec<InterfaceType>,

/// The function output types.
output_types: Vec<InterfaceType>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth considering using the structs with the same fields inside this enum if you haven't already. It may not make sense given how it's used -- I haven't read most of the code yet; I think this level of duplication can make sense though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by:

It's worth considering using the structs with the same fields inside this enum if you haven't already.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the enum's fields are identical to the structs with the same/similar names. It'd be possible to remove most of the fields in the enum and replace it with 1 instance of the correct struct. It's a minor thing and I think there are convincing arguments for both doing it and not doing it.


/// The instructions of the adapter.
instructions: Vec<Instruction<'input>>,
},

/// An adapter for an exported function.
Export {
/// The function name.
name: &'input str,

/// The function input types.
input_types: Vec<InterfaceType>,

/// The function output types.
output_types: Vec<InterfaceType>,

/// The instructions of the adapter.
instructions: Vec<Instruction<'input>>,
},

/// An adapter for a helper function.
HelperFunction {
/// The helper name.
name: &'input str,

/// The helper input types.
input_types: Vec<InterfaceType>,

/// The helper output types.
output_types: Vec<InterfaceType>,

/// The instructions of the adapter.
instructions: Vec<Instruction<'input>>,
},
}

/// Represented a forwarded export.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the docs should explain what forwarding is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not super defined in the spec yet :-D. It should be used to “rename” an export, like main to _start. I'm not sure it will be kept in the future.

#[derive(PartialEq, Debug)]
pub struct Forward<'input> {
/// The forwarded export name.
pub name: &'input str,
}

/// Represents a set of interfaces, i.e. it entirely describes a WIT
/// definition.
#[derive(PartialEq, Debug)]
pub struct Interfaces<'input> {
/// All the exported functions.
pub exports: Vec<Export<'input>>,

/// All the types.
pub types: Vec<Type<'input>>,

/// All the imported functions.
pub imports: Vec<Import<'input>>,

/// All the adapters.
pub adapters: Vec<Adapter<'input>>,

/// All the forwarded functions.
pub forwards: Vec<Forward<'input>>,
}
Loading