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

(WIP) Parse Threaded Modules #477

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 11 additions & 7 deletions ir/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ impl ItemsBuilder {
/// assigned.
pub fn add_item(&mut self, item: Item) -> Id {
let id = item.id;
self.size_added += item.size;
self.items.insert(id, item);
let size = item.size;

let old_value = self.parsed.insert(id);
assert!(
old_value,
"should not parse the same key into multiple items"
);
match self.items.get_mut(&id) {
None => {
self.size_added += size;
self.items.insert(id, item);
self.parsed.insert(id);
}
Some(prev) => {
prev.size += size;
}
}

id
}
Expand Down
74 changes: 74 additions & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
```
;; `threads.wat` fixture
;;
;; Built with `wat2wasm --enable-bulk-memory --enable-threads`
(module
(memory $0 1 1)
(data (i32.const 0) "")
(func $f (data.drop 0))
)
```

```
; wasm-objdump --headers twiggy/tests/all/fixtures/threads.wasm

threads.wasm: file format wasm 0x1

Sections:

Type start=0x0000000a end=0x0000000e (size=0x00000004) count: 1
Function start=0x00000010 end=0x00000012 (size=0x00000002) count: 1
Memory start=0x00000014 end=0x00000018 (size=0x00000004) count: 1
DataCount start=0x0000001a end=0x0000001b (size=0x00000001) count: 1
Code start=0x0000001d end=0x00000024 (size=0x00000007) count: 1
Data start=0x00000026 end=0x0000002c (size=0x00000006) count: 1
```

```
; wasm-objdump --full-contents twiggy/tests/all/fixtures/threads.wasm

threads.wasm: file format wasm 0x1

Contents of section Type:
000000a: 0160 0000 .`..

Contents of section Function:
0000010: 0100 ..

Contents of section Memory:
0000014: 0101 0101 ....

Contents of section DataCount:
000001a: 01 .

Contents of section Code:
000001d: 0105 00fc 0900 0b .......

Contents of section Data:
0000026: 0100 4100 0b00 ..A...
```

```
; target/debug/twiggy top twiggy/tests/all/fixtures/threads.wasm

Shallow Bytes β”‚ Shallow % β”‚ Item
───────────────┼───────────┼───────────────────────
8 β”Š 18.18% β”Š wasm magic bytes
7 β”Š 15.91% β”Š code[0]
6 β”Š 13.64% β”Š code section headers
5 β”Š 11.36% β”Š data[0]
3 β”Š 6.82% β”Š type[0]: () -> nil
3 β”Š 6.82% β”Š type section headers
3 β”Š 6.82% β”Š memory[0]
3 β”Š 6.82% β”Š memory section headers
3 β”Š 6.82% β”Š "data count" section
3 β”Š 6.82% β”Š data section headers
44 β”Š 100.00% β”Š Ξ£ [10 Total Rows]
```

```
; exa -l --header twiggy/tests/all/fixtures/threads.wasm

Permissions Size User Date Modified Name
.rw-rw-r-- 44 katelyn 21 Jun 23:07 twiggy/tests/all/fixtures/threads.wasm
```
1 change: 1 addition & 0 deletions parser/wasm_parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ struct DataCountSection<'a>(wasmparser::Section<'a>);
impl<'a> Parse<'a> for DataCountSection<'a> {
type ItemsExtra = usize;

// Worth looking here...
fn parse_items(
&mut self,
items: &mut ir::ItemsBuilder,
Expand Down
13 changes: 13 additions & 0 deletions twiggy/tests/all/expectations/top_threaded_module
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Shallow Bytes β”‚ Shallow % β”‚ Item
───────────────┼───────────┼───────────────────────
8 β”Š 18.18% β”Š wasm magic bytes
7 β”Š 15.91% β”Š code[0]
6 β”Š 13.64% β”Š code section headers
5 β”Š 11.36% β”Š data[0]
3 β”Š 6.82% β”Š type[0]: () -> nil
3 β”Š 6.82% β”Š type section headers
3 β”Š 6.82% β”Š memory[0]
3 β”Š 6.82% β”Š memory section headers
3 β”Š 6.82% β”Š "data count" section
3 β”Š 6.82% β”Š data section headers
44 β”Š 100.00% β”Š Ξ£ [10 Total Rows]
Binary file added twiggy/tests/all/fixtures/threads.wasm
Binary file not shown.
6 changes: 6 additions & 0 deletions twiggy/tests/all/fixtures/threads.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; Built with `wat2wasm --enable-bulk-memory --enable-threads`
(module
(memory $0 1 1)
(data (i32.const 0) "")
(func $f (data.drop 0))
)
Binary file added twiggy/tests/all/fixtures/threads_test.wasm
Binary file not shown.
Binary file added twiggy/tests/all/fixtures/threads_working.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions twiggy/tests/all/top_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,12 @@ test!(

// Regression test for https://github.com/rustwasm/twiggy/issues/151
test!(top_mono, "top", "./fixtures/mono.wasm", "-n", "10");

// Threaded modules should not cause a panic.
test!(
top_threaded_module,
"top",
"-n",
"25",
"./fixtures/threads.wasm"
);