Skip to content

Keep field names of struct types when changing/merging types #7982

@mkustermann

Description

@mkustermann

Binaryen seems to sometimes clear field names which makes code harder to read afterwards.

Take for example after.tar.gz

% tar xvzf after.tar.gz
after.O0.wasm
% wasm-opt --enable-gc --enable-reference-types --enable-multivalue --enable-exception-handling --enable-nontrapping-float-to-int --enable-sign-ext --enable-bulk-memory --enable-threads '--no-inline=*<noInline>*' --closed-world --traps-never-happen --type-unfinalizing -Os --type-ssa --gufa -Os --type-merging -Os --type-finalizing --minimize-rec-groups -g after.O0.wasm -o after.O2.wasm
% wami --full-wat after.O2.wasm -o after.O2.wat
% wami --full-wat after.O0.wasm -o after.O0.wat

We see e.g. that after.O0.wat (the unoptimized version) has

(type $#ClosureBase (;67;) (sub $_Closure (struct
  (field $field0 i32)
  (field $field1 (mut i32))
  (field $context (ref struct))
  (field $vtable (ref $#VtableBase))
  (field $functionType (ref $_FunctionType)))))
(type $#Closure-0-0 (;73;) (sub $#ClosureBase (struct
  (field $field0 i32)
  (field $field1 (mut i32))
  (field $context (ref struct))
  (field $vtable (ref $#Vtable-0-0))
  (field $functionType (ref $_FunctionType)))))
(type $#Closure-0-1 (;119;) (sub $#Closure-0-0 (struct
  (field $field0 i32)
  (field $field1 (mut i32))
  (field $context (ref struct))
  (field $vtable (ref $#Vtable-0-1))
  (field $functionType (ref $_FunctionType)))))
(type $#Closure-0-2 (;125;) (sub final $#Closure-0-1 (struct
  (field $field0 i32)
  (field $field1 (mut i32))
  (field $context (ref struct))
  (field $vtable (ref $#Vtable-0-2))
  (field $functionType (ref $_FunctionType)))))
(type $#Closure-1-0 (;330;) (sub $#ClosureBase (struct
  (field $field0 i32)
  (field $field1 (mut i32))
  (field $context (ref struct))
  (field $vtable (ref $#Vtable-1-0))
  (field $functionType (ref $_FunctionType)))))
(type $#Closure-1-1 (;334;) (sub final $#Closure-1-0 (struct
  (field $field0 i32)
  (field $field1 (mut i32))
  (field $context (ref struct))
  (field $vtable (ref $#Vtable-1-1))
  (field $functionType (ref $_FunctionType)))))

We see e.g. that after.O2.wat (the optimized version) has

  (type $#ClosureBase (;24;) (sub $Object (struct
    (field $field0 i32)
    (field $field1 (mut i32))
    (field $field2 (ref $_FunctionType)))))
  (type $#Closure-0-1 (;25;) (sub final $#ClosureBase (struct
    (field $field0 i32)
    (field $field1 (mut i32))
    (field $field2 (ref $_FunctionType))
    (field $context (ref struct))
    (field $field4 (ref $#Vtable-0-1)))))
  (type $#Closure-1-1 (;31;) (sub final $#ClosureBase (struct
    (field $field0 i32)
    (field $field1 (mut i32))
    (field $field2 (ref $_FunctionType))
    (field $context (ref $<context file:///...>)))))

=> Instead of (field $field2 (ref $_FunctionType)) we should have (field $functionType (ref $_FunctionType)) (i.e. with field name functionType)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions