Commit Graph

5594 Commits

Author SHA1 Message Date
Ivan Enderlin
e4b05d0b00 feat(interface-types) Remove the re-export of InterfaceType in values. 2020-04-09 10:54:09 +02:00
Ivan Enderlin
f955617d17 feat(interface-types) Extract InterfaceType and RecordType into its own types module. 2020-04-09 10:48:50 +02:00
bors[bot]
ad6f939e85
Merge #1362
1362: feat(interface-types) Remove allocator index from `string.lower_memory` r=Hywan a=Hywan

This PR updates `string.lower_memory` to remove the allocator index. Indeed, the string pointer is assumed to be present on the stack.
Also, this PR updates `string.size` to pop, and not to peek, the string to compute the length from.

That way, it matches the WIT proposal.

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-04-09 08:05:50 +00:00
bors[bot]
1ef2fe3ac9
Merge #1368
1368: Fix issue with `kernel-net`; add it to CI r=MarkMcCaskey a=MarkMcCaskey

Resolves #1365 


Co-authored-by: Mark McCaskey <mark@wasmer.io>
2020-04-09 00:26:34 +00:00
Mark McCaskey
23bc0fd720 Fix kernel-net check, fix misc warnings
Split out nightly check step
2020-04-08 17:05:25 -07:00
bors[bot]
3474c31355
Merge #1369
1369: Fix broken makefile commands and improve test consistency r=MarkMcCaskey a=MarkMcCaskey


# Review

- [ ] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Mark McCaskey <mark@wasmer.io>
2020-04-09 00:04:10 +00:00
Mark McCaskey
bb67a11c5f Fix broken makefile commands and improve test consistency 2020-04-08 17:01:32 -07:00
Mark McCaskey
b72000a2d6 Update emscripten in C API to use new API crate 2020-04-08 16:40:41 -07:00
Mark McCaskey
4d58ae2d14 Fix issue with kernel-net; add it to CI 2020-04-08 15:18:04 -07:00
bors[bot]
cd4706fbac
Merge #1367
1367: Move `dev-utils` crate into `tests` r=MarkMcCaskey a=MarkMcCaskey

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description
<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [ ] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Mark McCaskey <5770194+MarkMcCaskey@users.noreply.github.com>
2020-04-08 20:41:23 +00:00
Mark McCaskey
9f99baa732 Fix check CI step
rm dev-utils from makefile
2020-04-08 13:40:34 -07:00
Mark McCaskey
9e8d08a771
Merge branch 'master' into feature/dev-utils-in-tests 2020-04-08 12:15:22 -07:00
Mark McCaskey
3d4ed92466 Move dev-utils crate into tests 2020-04-08 11:59:47 -07:00
bors[bot]
45c412e8dd
Merge #1363
1363: fix(interface-types) Don't duplicate code in the binary encoder. r=MarkMcCaskey a=Hywan

Use the `ToBytes` implementation of `RecordType` to encode the inner
record type of a type, so that it avoids code duplication.

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-04-08 18:48:49 +00:00
bors[bot]
bf2d7e93cf
Merge #1361
1361: doc(interface-types) Add `record` instructions in the `README.md` r=MarkMcCaskey a=Hywan

This PR keeps the documentation up-to-date.

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-04-08 18:00:28 +00:00
Mark McCaskey
db76aea198 Remove more uses of wasmer_runtime_core from the C API 2020-04-07 17:28:23 -07:00
bors[bot]
6857cc543f
Merge #1357
1357: Refactored bin commands into separate files r=syrusakbary a=syrusakbary

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description

Refactored bin commands into separate files.
This PR does not do any sustancial changes other than refactoring into different files for better readability.

<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Syrus <me@syrusakbary.com>
Co-authored-by: Syrus Akbary <me@syrusakbary.com>
2020-04-07 20:30:09 +00:00
Syrus
6e18121cba Fixed last kernel issues 2020-04-07 13:29:02 -07:00
Syrus
daeb0f775e Added kernel subcommand 2020-04-07 12:53:41 -07:00
Syrus
69899bf014 Fixed issues 2020-04-07 12:47:36 -07:00
Syrus
08061f51cb Move kwasmd into wasmer 2020-04-07 12:34:34 -07:00
Syrus
f7c84c8a26 Fixed issues 2020-04-07 10:00:47 -07:00
Ivan Enderlin
4eae19ccc7 fix(interface-types) Don't duplicate code in the binary encoder.
Use the `ToBytes` implementation of `RecordType` to encode the inner
record type of a type, so that it avoids code duplication.
2020-04-07 14:29:57 +02:00
Ivan Enderlin
1687744ec9 feat(interface-types) string.size pops the string.
Previously, `string.size` was just peeking the string.
2020-04-07 12:40:14 +02:00
Ivan Enderlin
bfa5821d98 test(interface-types) Update the test_executable_instruction macro.
It provides a better failure message.
2020-04-07 12:34:30 +02:00
Ivan Enderlin
2fffee32a5 fix(interface-types) Remove allocator index from string.lower_memory. 2020-04-07 12:34:07 +02:00
Ivan Enderlin
c0623b0f8c doc(interface-types) Add record instructions. 2020-04-07 11:58:13 +02:00
Syrus Akbary
cef3dfa3b0
Merge branch 'master' into features/refactor-bin 2020-04-06 18:54:33 -07:00
Syrus
5c0ccc0a4e Trying to fix kwasmd 2020-04-06 18:54:00 -07:00
Syrus Akbary
bc757908cd
Merge pull request #1349 from wasmerio/feature/reorganized-tests
Move integration tests to `tests` dir in workspace root
2020-04-06 18:40:50 -07:00
Mark McCaskey
ade38aa391 Use CRANELIFT instead of CLIF in test env vars 2020-04-06 17:21:57 -07:00
Mark McCaskey
83f0a043e7 Update C API to use new API 2020-04-06 17:09:50 -07:00
Syrus
3735dc2742 Address feedback 2020-04-06 17:02:01 -07:00
Mark McCaskey
3579d0d445 Fix emtests and wasitests to use the correct backend 2020-04-06 16:47:06 -07:00
Syrus Akbary
c47595012a
Merge branch 'master' into features/refactor-bin 2020-04-06 16:32:16 -07:00
Syrus
20d4a5682e Added changes into changelog 2020-04-06 16:31:31 -07:00
Syrus
c312bdc782 Improved imports 2020-04-06 16:31:23 -07:00
Syrus
5572ebd990 Refactored bin commands into separate files 2020-04-06 16:06:49 -07:00
Mark McCaskey
b6011d5dc4 Only run runtime_core tests on Android 2020-04-06 14:13:54 -07:00
Mark McCaskey
9d312f4500 Add support for android in spectests 2020-04-06 12:35:08 -07:00
Mark McCaskey
4c29cd4af3 Merge branch 'master' into feature/reorganized-tests 2020-04-06 12:04:36 -07:00
Mark McCaskey
52cbb60743 Fix up tests for CI 2020-04-06 11:42:44 -07:00
bors[bot]
99f8c949d1
Merge #1354
1354: test(middleware-common) Remove an unused import r=MarkMcCaskey a=Hywan

This PR removes an unused import.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
2020-04-06 17:40:35 +00:00
Syrus Akbary
c5c3ddcfbd
Merge pull request #1355 from Hywan/doc-changelog-1331
doc(changelog) Add #1331
2020-04-06 02:08:30 -07:00
Ivan Enderlin
4ba5d6e4ab doc(changelog) Add #1331. 2020-04-06 09:40:03 +02:00
Ivan Enderlin
ac3288db1c test(middleware-common) Remove an unused import. 2020-04-06 08:34:55 +02:00
bors[bot]
4d33020b35
Merge #1331
1331: feat(interface-types) Implement the `record` instructions r=Hywan a=Hywan

### Description

This PR implements the `record` WIT type, along with the `record.lift` and `record.lower` instructions.

With my current understanding of the draft/specification, here is how it works. Let's say we want to represent a Rust struct like the following:

```rust
struct S {
    x: String,
    y: i32
}
```

First declare a WIT type, such as:

```wat
(@interface type (record (field string) (field i32)))
```

The `record` type is supported by the binary encoder, the WAT encoder, the binary decoder, and the WAT decoder. A new `TypeKind` node has been introduced in the AST to differentiate a function type (`(@interface type (func (param …) (result …)))`) of a record type (see above).

Second, the `record.lower` transforms a host value (here Rust value, `S`) into a WIT value. In our implementation, a record value is defined as:

```rust
InterfaceValue::Record(Vec<InterfaceValue>)
```

Multiple mechanisms are used to type check a record value based on a record type. The code of the `record.lower` is pretty straightforward.

Because transforming a host value into a WIT value isn't obvious, a `Serializer` has been implemented, based on [`serde`](https://serde.rs/). This feature is behind the `serde` flag, which is turned on by default.

Serde is only used to cross the host/Wasm boundary, but it's not used to represent the value in memory or anything. It's only a shortcut to transform a host value into a WIT value, and vice versa.

Use the following code to transform `S` into a WIT value:

```rust
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct S {
    x: String,
    y: i32,
}

let host_value = S { x: "hello".to_string(), y: 42 };
let wit_value = to_interface_value(&host_value).unwrap();

assert_eq!(
    wit_value,
    InterfaceValue::Record(vec![
        InterfaceValue::String("hello".to_string()),
        InterfaceValue::I32(42),
    ])
);
```

Third, the `record.lift`  instruction does the opposite of `record.lower`: It transforms WIT values into a host value. To also facilitate the user experience, this PR contains a `Deserializer` implementation, still based on `serde`, with the `from_interface_values` function. It looks like this:

```rust
let wit_values = vec![
    InterfaceValue::Record(vec![
        InterfaceValue::String("hello".to_string()),
        InterfaceValue::I32(42),
    ])
];
let host_value = from_interface_values::<S>(&wit_values).unwrap();

assert_eq!(
    host_value,
    S { x: "hello".to_string(), y: 42 },
);
```

With the `Serializer` and `Deserializer`, it's super easy for the user to send or receive values from WIT.

The `record.lift` and `record.lower` instructions are kind of basic. The `record.lift` instruction has a little trick to reduce vector allocations, but there is a documentation for that.

#### Opened questions

Records of dimension 1 do not raise any issue. With `record.lift`, all values on the stack (the WIT interpreter stack) are popped, and are used as record field values. Something like:

```
[stack]
i32(1)
i64(2),
string("hello")
record.lift <record_type>
```

generates

```
[stack]
record { i32(1), i64(2), string("hello") }
```

But it's not clear what happens with record of dimension > 1, for instance for a type like `record (field i32) (record (field i32) (field i32)) (field string)`, it is assumed (in this PR) that the stack must be like this:

```
[stack]
i32(1)
i32(2)
i32(3)
string("hello")
record.lift <record_type>
```

to generate:

```
[stack]
record { i32(1), record { i32(2), i32(3) }, string("hello") }
```

If we want the stack to contain an intermediate record, we should have something like this:

```
[stack]
i32(1)
i32(2)
i32(3)
record.lift <record_type_2>
string("hello")
record.lift <record_type_1>
```

But it would imply that `record_type_1` is defined as `record (field i32) (record (type record_type_2)) (field i32)`.

A sub-record defined by another record type isn't support, as it is not specified in the draft. I believe my assumption is fine enough for a first implementation of records in WIT.

### To do

- [x] Encode and decode record type (`(@interface type (record string i32))`):
  - [x] Binary encoder/decoder
  - [x] WAT encoder/decoder
- [x] Implement the `record.lift` instruction
- [x] Implement the `record.lower` instruction
- [x] Test
- [x] Documentation
- [x] Surprise!
  - [x] Serialize a Rust value to WIT values (useful for `record`s)
  - [x] Deserialize WIT values to a Rust value (useful for `record`s)

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
2020-04-06 06:17:45 +00:00
Ivan Enderlin
9f10b7ae50 doc(interface-types) Update from_interface_values's doc.
Using `InterfaceValue::Record` explicitely doesn't change anything
since values are flatten, but it's better for a usual reading to avoid
confusion.
2020-04-06 08:13:10 +02:00
Ivan Enderlin
27053d5ca6 doc(interface-types) Rewrite record_lift_ documentation. 2020-04-06 08:09:10 +02:00
Ivan Enderlin
c2b1b87f9a feat(interface-types) Use VecDeque to remove unsafe code. 2020-04-06 07:55:56 +02:00