diff --git a/ir/ir.rs b/ir/ir.rs index f36af5d6..5cb3d228 100644 --- a/ir/ir.rs +++ b/ir/ir.rs @@ -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, diff --git a/parser/wasm_parse/mod.rs b/parser/wasm_parse/mod.rs index d4682106..dee53132 100644 --- a/parser/wasm_parse/mod.rs +++ b/parser/wasm_parse/mod.rs @@ -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)?; } @@ -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"); @@ -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; @@ -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))?; } @@ -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"); @@ -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 { .. } => {} } } @@ -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(()) } @@ -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; diff --git a/twiggy/tests/all/expectations/top_memory_module b/twiggy/tests/all/expectations/top_memory_module new file mode 100644 index 00000000..4720a99a --- /dev/null +++ b/twiggy/tests/all/expectations/top_memory_module @@ -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] diff --git a/twiggy/tests/all/fixtures/memory.wasm b/twiggy/tests/all/fixtures/memory.wasm new file mode 100644 index 00000000..c9201061 Binary files /dev/null and b/twiggy/tests/all/fixtures/memory.wasm differ diff --git a/twiggy/tests/all/fixtures/memory.wat b/twiggy/tests/all/fixtures/memory.wat new file mode 100644 index 00000000..34667d10 --- /dev/null +++ b/twiggy/tests/all/fixtures/memory.wat @@ -0,0 +1,5 @@ +(module + (memory $0 1 1) + (data (i32.const 0) "") + (func $f (data.drop 0)) +) diff --git a/twiggy/tests/all/top_tests.rs b/twiggy/tests/all/top_tests.rs index 6e8173ef..9ab221d7 100644 --- a/twiggy/tests/all/top_tests.rs +++ b/twiggy/tests/all/top_tests.rs @@ -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");