mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
gen_wasm: correctly detect empty ElementSection and don't emit TableSection
This commit is contained in:
parent
2a963ca3ba
commit
06f8af6b1e
2 changed files with 12 additions and 4 deletions
|
@ -64,7 +64,9 @@ impl<'a> WasmModule<'a> {
|
|||
self.types.serialize(buffer);
|
||||
self.import.serialize(buffer);
|
||||
self.function.serialize(buffer);
|
||||
self.table.serialize(buffer);
|
||||
if !self.element.is_empty() {
|
||||
self.table.serialize(buffer);
|
||||
}
|
||||
self.memory.serialize(buffer);
|
||||
self.global.serialize(buffer);
|
||||
self.export.serialize(buffer);
|
||||
|
|
|
@ -1118,6 +1118,10 @@ impl<'a> ElementSection<'a> {
|
|||
pub fn size(&self) -> usize {
|
||||
self.segments.iter().map(|seg| seg.size()).sum()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.segments.iter().all(|seg| seg.fn_indices.is_empty())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Parse<&'a Bump> for ElementSection<'a> {
|
||||
|
@ -1148,9 +1152,11 @@ impl<'a> Parse<&'a Bump> for ElementSection<'a> {
|
|||
|
||||
impl<'a> Serialize for ElementSection<'a> {
|
||||
fn serialize<T: SerialBuffer>(&self, buffer: &mut T) {
|
||||
let header_indices = write_section_header(buffer, Self::ID);
|
||||
self.segments.serialize(buffer);
|
||||
update_section_size(buffer, header_indices);
|
||||
if !self.is_empty() {
|
||||
let header_indices = write_section_header(buffer, Self::ID);
|
||||
self.segments.serialize(buffer);
|
||||
update_section_size(buffer, header_indices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue