Skip to content

Do not duplicate DataCountSection and StartSection root items #744

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

Merged
merged 1 commit into from
Feb 13, 2024
Merged
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
1 change: 0 additions & 1 deletion ir/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl ItemsBuilder {
let id = item.id;
self.size_added += item.size;
self.items.insert(id, item);

let old_value = self.parsed.insert(id);
assert!(
old_value,
Expand Down
52 changes: 8 additions & 44 deletions parser/wasm_parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<'a> Parse<'a> for ModuleReader<'a> {
wasmparser::Payload::StartSection { func, range } => {
StartSection {
function_index: func,
data: &self.data[range.start..range.end],
_data: &self.data[range.start..range.end],
}
.parse_items(items, idx)?;
}
Expand All @@ -194,12 +194,6 @@ impl<'a> Parse<'a> for ModuleReader<'a> {
wasmparser::Payload::DataSection(mut reader) => {
reader.parse_items(items, (idx, &names.data_names))?;
}
wasmparser::Payload::DataCountSection { range, .. } => {
DataCountSection {
size: range.end - range.start,
}
.parse_items(items, idx)?;
}
wasmparser::Payload::CodeSectionStart { .. }
| wasmparser::Payload::FunctionSection(_) => {
unreachable!("unexpected code or function section found");
Expand All @@ -212,7 +206,8 @@ impl<'a> Parse<'a> for ModuleReader<'a> {
| wasmparser::Payload::ModuleSectionStart { .. }
| wasmparser::Payload::ModuleSectionEntry { .. }
| wasmparser::Payload::UnknownSection { .. }
| wasmparser::Payload::End { .. } => {}
| wasmparser::Payload::End { .. }
| wasmparser::Payload::DataCountSection { .. } => {}
};
let id = Id::section(idx);
let added = items.size_added() - start;
Expand Down Expand Up @@ -365,7 +360,7 @@ impl<'a> Parse<'a> for ModuleReader<'a> {
wasmparser::Payload::StartSection { func, range } => {
StartSection {
function_index: func,
data: &self.data[range.start..range.end],
_data: &self.data[range.start..range.end],
}
.parse_edges(items, (&indices, idx))?;
}
Expand All @@ -375,12 +370,6 @@ impl<'a> Parse<'a> for ModuleReader<'a> {
wasmparser::Payload::DataSection(mut reader) => {
reader.parse_edges(items, ())?;
}
wasmparser::Payload::DataCountSection { range, .. } => {
DataCountSection {
size: range.end - range.start,
}
.parse_edges(items, ())?;
}
wasmparser::Payload::CodeSectionStart { .. }
| wasmparser::Payload::FunctionSection { .. } => {
unreachable!("unexpected code or function section found");
Expand All @@ -393,7 +382,8 @@ impl<'a> Parse<'a> for ModuleReader<'a> {
| wasmparser::Payload::ModuleSectionStart { .. }
| wasmparser::Payload::ModuleSectionEntry { .. }
| wasmparser::Payload::UnknownSection { .. }
| wasmparser::Payload::End { .. } => {}
| wasmparser::Payload::End { .. }
| wasmparser::Payload::DataCountSection { .. } => {}
}
}

Expand Down Expand Up @@ -889,17 +879,13 @@ impl<'a> Parse<'a> for wasmparser::ExportSectionReader<'a> {

struct StartSection<'a> {
function_index: u32,
data: &'a [u8], // We only need the size.
_data: &'a [u8], // We only need the size.
}

impl<'a> Parse<'a> for StartSection<'a> {
type ItemsExtra = usize;

fn parse_items(&mut self, items: &mut ir::ItemsBuilder, idx: usize) -> anyhow::Result<()> {
let size = self.data.len() as u32;
let id = Id::section(idx);
let name = "\"start\" section";
items.add_root(ir::Item::new(id, name, size, ir::Misc::new()));
fn parse_items(&mut self, _: &mut ir::ItemsBuilder, _: usize) -> anyhow::Result<()> {
Ok(())
}

Expand All @@ -918,28 +904,6 @@ impl<'a> Parse<'a> for StartSection<'a> {
}
}

struct DataCountSection {
size: usize,
}

impl<'a> Parse<'a> for DataCountSection {
type ItemsExtra = usize;

fn parse_items(&mut self, items: &mut ir::ItemsBuilder, idx: usize) -> anyhow::Result<()> {
let size = self.size as u32;
let id = Id::section(idx);
let name = "\"data count\" section";
items.add_root(ir::Item::new(id, name, size, ir::Misc::new()));
Ok(())
}

type EdgesExtra = ();

fn parse_edges(&mut self, _items: &mut ir::ItemsBuilder, (): ()) -> anyhow::Result<()> {
Ok(())
}
}

impl<'a> Parse<'a> for wasmparser::ElementSectionReader<'a> {
type ItemsExtra = usize;

Expand Down
14 changes: 14 additions & 0 deletions twiggy/tests/all/expectations/top_memory_module
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Shallow Bytes │ Shallow % │ Item
───────────────┼───────────┼──────────────────────────────
8 ┊ 12.70% ┊ wasm magic bytes
7 ┊ 11.11% ┊ f
7 ┊ 11.11% ┊ custom section 'name' headers
6 ┊ 9.52% ┊ code section headers
6 ┊ 9.52% ┊ "function names" subsection
6 ┊ 9.52% ┊ "memory names" subsection
5 ┊ 7.94% ┊ data[0]
3 ┊ 4.76% ┊ type[0]: () -> nil
3 ┊ 4.76% ┊ type section headers
3 ┊ 4.76% ┊ memory[0]
9 ┊ 14.29% ┊ ... and 3 more.
63 ┊ 100.00% ┊ Σ [13 Total Rows]
Binary file added twiggy/tests/all/fixtures/memory.wasm
Binary file not shown.
5 changes: 5 additions & 0 deletions twiggy/tests/all/fixtures/memory.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(module
(memory $0 1 1)
(data (i32.const 0) "")
(func $f (data.drop 0))
)
2 changes: 2 additions & 0 deletions twiggy/tests/all/top_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ test!(

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

test!(top_memory_module, "top", "./fixtures/memory.wasm", "-n", "10");