Commit Graph

4083 Commits

Author SHA1 Message Date
Nick Lewycky
88427c9696 Add some comments. 2019-10-31 11:48:52 -07:00
Mark McCaskey
16124672a3 Add OS compatibility section to feature matrix 2019-10-31 09:55:55 -07:00
bors[bot]
656491a337
Merge #917
917: feat(runtime-core) Host function without a `vm::Ctx` argument r=Hywan a=Hywan

Extracted from https://github.com/wasmerio/wasmer/pull/882.
~Includes https://github.com/wasmerio/wasmer/pull/916. Must not be merged until #916 lands in `master`.~
~If you want to compare only the different commits, see https://github.com/Hywan/wasmer/compare/feat-runtime-core-tests...Hywan:feat-runtime-core-host-function-without-vmctx?expand=1.~

This patch updates the `ExternalFunction` implementation to support host functions (aka imported functions) without having an explicit `vm::Ctx` argument.

It is thus possible to write:

```rust
fn add_one(x: i32) -> i32 {
    x + 1
}

let import_object = imports! {
    "env" => {
        "add_one" => func!(add_one);
    },
};
```

The previous form is still working though:

```rust
fn add_one(_: &mut vm::Ctx, x: i32) -> i32 {
    x + 1
}
```

The backends aren't modified. It means that the pointer to `vm::Ctx` is still inserted in the stack, but it is not used when the function doesn't need it.

We thought this is an acceptable trade-off.

About the C API. It has not check to ensure the type signature. Since the pointer to `vm::Ctx` is always inserted, the C API can digest host functions with or without a `vm::Ctx` argument. The C API uses [the `Export` + `FuncPointer` API](cf5b3cc09e/lib/runtime-c-api/src/import/mod.rs (L630-L653)) instead of going through the `Func` API (which is modified by this API), which is only possible since the C API only receives an opaque function pointer. Conclusion is: We can't ensure anything on the C side, but it will work with or without the `vm::Ctx` argument in theory.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
2019-10-31 10:00:48 +00:00
Ivan Enderlin
912eb32be8 chore(cargo) Update Cargo.lock. 2019-10-31 11:00:07 +01:00
Ivan Enderlin
2703d48098 Merge branch 'master' into feat-runtime-core-host-function-without-vmctx 2019-10-31 10:59:16 +01:00
bors[bot]
fb0615dc02
Merge #915
915: fix(runtime-core) Share the definition of `Trampoline` across all the backends r=Hywan a=Hywan

Extracted from https://github.com/wasmerio/wasmer/pull/882.

This patch updates all the backends to use the definition of
`Trampoline` as defined in the `wasmer_runtime_core::typed_func`
module. That way, there is no copy of that type, and as such, it is
easier to avoid regression (a simple `cargo check` does the job).

This patch also formats the `use` statements in the updated files.


Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
2019-10-31 09:13:42 +00:00
Nick Lewycky
d10d54a416 Add TBAA to atomic ops. 2019-10-30 16:39:39 -07:00
Nick Lewycky
15ce8bfda7 Label the loads in intrinsics.rs, most of which are the initial accesses off the context.
Move tbaa_label to intrinsics.rs. Move TBAA pass to first in the list, it doesn't get invalidated. Add TBAA labels for internal fields.
2019-10-30 16:18:36 -07:00
Mark McCaskey
25bcadbf74 Export WasmPtr from wasmer_runtime 2019-10-30 16:09:48 -07:00
bors[bot]
36d1c6a638
Merge #919
919: Add start of language intergrations table to feature matrix r=MarkMcCaskey a=MarkMcCaskey



Co-authored-by: Mark McCaskey <mark@wasmer.io>
2019-10-30 22:00:37 +00:00
Nick Lewycky
74eaec968e Remove all *_tbaa fields from LLVMModuleCodeGenerator and LLVMFunctionCodeGenerator. 2019-10-30 14:05:11 -07:00
Mark McCaskey
ea08431ab8 Add start of language intergrations table to feature matrix 2019-10-30 13:51:05 -07:00
Nick Lewycky
e7d1742c63 Update module to be held by Rc<RefCell<>> so that we can pass it to LLVMFunctionCodeGenerator.
Use that to generate distinct TBAA labels for distinct local variables.
2019-10-30 13:11:29 -07:00
Ivan Enderlin
6a1d490a30 doc(runtimecore) Explain ExternalFunctionKind with more details. 2019-10-30 19:34:04 +01:00
Ivan Enderlin
7eef49be12 test(runtime-core) Test host functions without a vm::Ctx argument. 2019-10-30 19:34:04 +01:00
Ivan Enderlin
95e1b85c56 feat(runtime-core) Allow host functions without an explicit vm::Ctx argument.
This patch allows host functions to get a signature without an
explicit `vm::Ctx` argument.

It is for Rust only. The C API receives a function pointer and has no
clue whether a `vm::Ctx` argument is present or not, so it assumes it
is always declared.

From the backend point of view, the pointer to `vm::Ctx` is always
inserted in the stack, but it is not used by the function when the
argument is absent.
2019-10-30 19:34:04 +01:00
Ivan Enderlin
bd9d4d9cc8 test(runtime-core) Add tests for the Func structure. 2019-10-30 19:34:04 +01:00
Ivan Enderlin
77e01f01bd chore(runtime-core) Use vm::Ctx to access it.
Just to be consistent with the rest of the code.
2019-10-30 19:34:04 +01:00
Nick Lewycky
f77d9bfe32 Initial implementation of TBAA for the LLVM backend. 2019-10-30 10:29:51 -07:00
bors[bot]
46cb83738e
Merge #916
916: feat(runtime-core-tests) Introduce the new `wasmer-runtime-core-tests` crate r=Hywan a=Hywan

Extracted from https://github.com/wasmerio/wasmer/pull/882.

This non-publishable new crate contains a test suite for the
`wasmer-runtime-core` crate. So far, the test suite is rather small,
but it aims to be extended in a close future.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
2019-10-30 17:00:18 +00:00
Ivan Enderlin
4e83e1b8e0 chore(runtime-core-tests) Update crate version. 2019-10-30 17:59:07 +01:00
Ivan Enderlin
12a05ca280 chore(makefile) Remove the +nightly flag. 2019-10-30 15:00:31 +01:00
Ivan Enderlin
bdc1ab3412 feat(runtime-core-tests) Introduce the new wasmer-runtime-core-tests crate.
This non-publishable new crate contains a test suite for the
`wasmer-runtime-core` crate. So far, the test suite is rather small,
but it aims to be extended in a close future.
2019-10-30 13:28:01 +01:00
Ivan Enderlin
edb6cbefca fix(runtime-core) Share the definition of Trampoline across all the backends.
This patch updates all the backends to use the definition of
`Trampoline` as defined in the `wasmer_runtime_core::typed_func`
module. That way, there is no copy of that type, and as such, it is
easier to avoid regression (a simple `cargo check` does the job).

This patch also formats the `use` statements in the updated files.
2019-10-30 13:10:34 +01:00
bors[bot]
cf5b3cc09e
Merge #914
914: Fix bug in getting a Memory from export in C API r=Hywan a=MarkMcCaskey

I believe this fixes the non-deterministic crashing on OSX in `go-ext-wasm`

Co-authored-by: Mark McCaskey <mark@wasmer.io>
2019-10-30 11:34:20 +00:00
Nick Lewycky
7fd20e3355 NFC: Fold variable into initializer. 2019-10-29 22:23:46 -07:00
Mark McCaskey
1e4fa78e11 Fix bug in getting a Memory from export in C API 2019-10-29 15:52:42 -07:00
bors[bot]
2dbe80ad34
Merge #856
856: Add WASI support to C API r=MarkMcCaskey a=MarkMcCaskey

This is an additive change (with one unrelated clean up of `*mut ptr -> *const ptr`).  It exposes the functions to get a WASI import object.  It also implements a function on import object to get an `import` with namespace and name.

These changes should be okay to ship now, we can follow up to finish adding methods to ImportObject on the C API side and start migrating away from  `*imports`.

# Review

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


Co-authored-by: Mark McCaskey <mark@wasmer.io>
Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
Co-authored-by: Mark McCaskey <markmccaskey@users.noreply.github.com>
Co-authored-by: nlewycky <nick@wasmer.io>
2019-10-29 22:39:51 +00:00
Mark McCaskey
d87e81cf62
Merge pull request #912 from wasmerio/nlewycky-patch-1
Use printf portably.
2019-10-29 15:34:40 -07:00
Mark McCaskey
6d6b8779d4
Merge pull request #913 from wasmerio/nlewycky-patch-2
Move the linkage before the type.
2019-10-29 15:34:33 -07:00
nlewycky
44f026adfb
Move the linkage before the type.
Though both orders work, this is customary.
2019-10-29 15:30:59 -07:00
nlewycky
ae07620818
Use printf portably.
PRId64 is defined to the right printf format string to print a int64_t on the current system.
2019-10-29 15:28:59 -07:00
Mark McCaskey
bc9b92c323 Add null checks to new destructors in C API 2019-10-29 15:18:45 -07:00
Mark McCaskey
a104d08c04 Update ImportObject C API to use iterators 2019-10-29 14:55:14 -07:00
Nick Lewycky
9224db6d1e Don't emit bounds checks when the offset is less than the minimum memory size. 2019-10-28 15:57:16 -07:00
bors[bot]
d46e5d499c
Merge #910
910: Use getrandom instead of rand r=MarkMcCaskey a=newpavlov

Closes #909

Note: I am reusing `__WASI_EIO` as an error code to denote a potential OS RNG failure.

Co-authored-by: newpavlov <newpavlov@gmail.com>
Co-authored-by: Artyom Pavlov <newpavlov@gmail.com>
2019-10-28 18:07:18 +00:00
Artyom Pavlov
56475594e9
compilation error fix 2019-10-28 17:57:29 +00:00
newpavlov
8e6f4c448b reuse __WASI_EIO error code 2019-10-28 18:37:14 +03:00
newpavlov
b67f2c9f18 use getrandom instead of rand 2019-10-28 18:33:15 +03:00
Mark McCaskey
aa82df7bc5 Fix github merge
move entry in changelog due to release
2019-10-25 14:52:09 -07:00
Mark McCaskey
c2d3f29cb4
Merge branch 'master' into feature/wasi-in-c-api 2019-10-25 14:38:14 -07:00
Mark McCaskey
2a532b8ce5 Add tests for C API import_object and WASI updates 2019-10-25 14:24:22 -07:00
bors[bot]
8653216b1a
Merge #883
883: For floating point operations, allow inputs to be arbitrary, including SNaNs. r=nlewycky a=nlewycky

# Description
For floating point operations, allow inputs to be arbitrary, including SNaNs.

Instead of ensuring inputs are canonical NaNs on every operation, we tag outputs as pending such a canonicalization check, so that a sequence of computations can have a single canonicalization step at the end.

There's an extra wriggle for SIMD. The Wasm type system only indicates them as V128, so it's possible that we might do computations as F32x4Add, I8x16Add, F64x2Add in a row with no other computations in between. Since a canonicalization may change the bit patterns in a way that transforms one non-NaN to another non-NaN in the next subsequent instructions interpretation, most SIMD functions apply pending canonicalizations to their inputs, even the integer SIMD operations.

# Review

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


Co-authored-by: Nick Lewycky <nick@wasmer.io>
Co-authored-by: nlewycky <nick@wasmer.io>
Co-authored-by: Syrus Akbary <me@syrusakbary.com>
2019-10-25 20:16:19 +00:00
Nick Lewycky
dae99497ee Add changelog entry. 2019-10-25 13:15:32 -07:00
Syrus Akbary
1a91f0e9ca
Merge branch 'master' into feature/llvm-nan-but-fast 2019-10-25 12:52:47 -07:00
bors[bot]
03a5b1fbf4
Merge #901
901: Set target triple and datalayout when creating the LLVM module. r=nlewycky a=nlewycky

We were giving LLVM a triple and datalayout only when producing native code from the LLVM IR. With this change, we tell LLVM as early as possible so that the entire optimization stack knows that it's safe to use target-specific constructs (including target intrinsics `@llvm.x86.sse2.ucomieq.sd`) as well as cost models (for autovectorization) and knowing the bitwidth of the registers so that we can know it's profitable to eliminate redundant extend/truncate casts.

Co-authored-by: Nick Lewycky <nick@wasmer.io>
2019-10-25 17:57:11 +00:00
bors[bot]
83c63d0b27
Merge #904
904: Use getelementptr instruction instead of int_to_ptr and ptr_to_int. r=nlewycky a=nlewycky

The main part of this change is that we no longer turn pointers into integers to do arithmetic on them, then turn them back into pointers. Doing so is a signal to LLVM that it should not attempt to analyze the provenance of the pointers, disabling some optimizations. Using getelementptr allows us to perform arithmetic on pointers while keeping them in pointer types, which LLVM can then analyze.

Most of the textual change is a refactoring to reorder the operations. Previously the bounds checking and determining of the base and bounds were combined because you could put both into the same match, since both actions are performed differently depending on whether the memory is static or dynamic. In this case, we simply check the type twice and do two different things, with comments labelling the steps.

Co-authored-by: Nick Lewycky <nick@wasmer.io>
2019-10-25 17:22:25 +00:00
Syrus Akbary
1fee31b525
Merge pull request #905 from Maxgy/master
fix README grammar
2019-10-25 01:03:15 -07:00
Maxwell Anderson
a52246bb9d
fix README grammar 2019-10-24 21:54:30 -04:00
Nick Lewycky
f3d4fde7ef Run cargo update to pick up new commit to wasmerio/inkwell llvm8-0 branch. 2019-10-24 18:15:39 -07:00