Skip to content

Commit

Permalink
Merge pull request #13 from WAFoundation/fix/table-import-memory-repr…
Browse files Browse the repository at this point in the history
…-rebased

Fix/table import memory repr rebased
  • Loading branch information
syrusakbary authored Nov 17, 2018
2 parents 5c0e404 + 7977d09 commit 501bacc
Show file tree
Hide file tree
Showing 22 changed files with 1,824 additions and 813 deletions.
File renamed without changes.
6 changes: 6 additions & 0 deletions examples/elem.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(module
(table 0 10 anyfunc)
(func $f)
(elem (i32.const 0) $f)
(func $main (export "main"))
)
28 changes: 28 additions & 0 deletions examples/import.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(module
(memory (import "env" "memory") 1)
(table (import "env" "table") 10 anyfunc)
(elem (i32.const 9) $f)
(func $f (param i32) (result i32)
(get_local 0)
)
(func $main (export "main") (result i32)
(local i32)
(set_local 0 (i32.const 65535))
(i32.store (get_local 0) (i32.const 1602))
(i32.load (get_local 0))

(drop)

(call_indirect (param i32) (result i32) (i32.const 4505) (i32.const 9))

(drop)

(memory.grow (i32.const 1))

(drop)

(set_local 0 (i32.const 131071))
(i32.store (get_local 0) (i32.const 1455))
(i32.load (get_local 0))
)
)
24 changes: 24 additions & 0 deletions examples/memory.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(module
(memory 1)
(table 20 anyfunc)
(elem (i32.const 9) $f)
(func $f (param i32) (result i32)
(get_local 0)
)
(func $main (export "main") (result i32)
(local i32)
(set_local 0 (i32.const 100))
(i32.store (get_local 0) (i32.const 1602))
(i32.load (get_local 0))

(drop)
(memory.grow (i32.const 0))


(drop)
(memory.grow (i32.const 2))

(drop)
(memory.grow (i32.const 12))
)
)
33 changes: 33 additions & 0 deletions spectests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,36 @@ There are some cases that we decided to skip for now to fasten the time to relea
- `globals.wast`
- `SKIP_CALL_INDIRECT_TYPE_MISMATCH`: we implemented traps in a fast way. We haven't covered yet the type mismatch on `call_indirect`. Specs affected:
- `call_indirect.wast`

- `SKIP_CALL_UNDEFINED_ELEMENT`
Tables are imported into every spec module, even for modules that don't expect it. We need to figure out a way to prevent import of objects that are not explicitly imported into the module.

Currently cranelift_wasm::ModuleEnvironment does not provide `declare_table_import`, etc. so there is no meaningful way of fixing this yet.
- `call_indirect.wast`

- `SKIP_SHARED_TABLE` [elem.wast]
Currently sharing tables between instances/modules does not work. Below are some of the reasons it is hard to achieve.

- Rust naturally prevents such because of the possibility of race conditions
- ImportObject is just a wrapper, what we really care about is references to its content.
- Instance::new contains a mutation points, the part where after getting the object (memory or table) we push values to it
table[table_element_index] = func_addr
- Instance has its own created memories and tables and references to them must outlive Instance::new()
- Possible strategy
```rust
// ImportObject should be passed by ref
Instance::new<'a>(..., &ImportObject);

// Add OwnedData to Instance struct
struct OwnedData;

// For parts where mutatation is really needed
fn get_mut(&import) -> &mut ImportObject {
unsafe { transmute::<&ImportObject, &mut ImportObject>(import) }
}
```
- `elem.wast`

- `SKIP_GLOBAL_VALUE_OFFSETS`
There is no support for using global values as offset into tables yet. I believe this is an issue from cranelift side as well, so we will have to wait for it to be supported.
- `elem.wast`
8 changes: 5 additions & 3 deletions spectests/call_indirect.wast
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@
;; (assert_trap (invoke "dispatch" (i32.const 0) (i64.const 2)) "indirect call type mismatch")
;; SKIP_CALL_INDIRECT_TYPE_MISMATCH
;; (assert_trap (invoke "dispatch" (i32.const 15) (i64.const 2)) "indirect call type mismatch")
(assert_trap (invoke "dispatch" (i32.const 29) (i64.const 2)) "undefined element")
(assert_trap (invoke "dispatch" (i32.const -1) (i64.const 2)) "undefined element")
(assert_trap (invoke "dispatch" (i32.const 1213432423) (i64.const 2)) "undefined element")

;; SKIP_CALL_UNDEFINED_ELEMENT
;; (assert_trap (invoke "dispatch" (i32.const 29) (i64.const 2)) "undefined element")
;; (assert_trap (invoke "dispatch" (i32.const -1) (i64.const 2)) "undefined element")
;; (assert_trap (invoke "dispatch" (i32.const 1213432423) (i64.const 2)) "undefined element")

(assert_return (invoke "dispatch-structural-i64" (i32.const 5)) (i64.const 9))
(assert_return (invoke "dispatch-structural-i64" (i32.const 12)) (i64.const 362880))
Expand Down
Loading

0 comments on commit 501bacc

Please sign in to comment.