Skip to content

Consider self-referential HeapTypes to be canonical - #3626

Merged
tlively merged 1 commit into
WebAssembly:mainfrom
tlively:recursive-heaptypes-are-canonical
Feb 28, 2021
Merged

tlively merged 1 commit into
WebAssembly:mainfrom
tlively:recursive-heaptypes-are-canonical

Conversation

@tlively

@tlively tlively commented Feb 27, 2021

Copy link
Copy Markdown
Member

This PR makes the TypeBuilder move self-referential HeapTypes to global HeapType
store so that they are considered canonical. This means that when a HeapType is
constructed with an identical definition, it will be equivalent to the original
HeapType constructed by the TypeBuilder, but it does not mean that
self-referential HeapTypes are deduplicated.

This fixes a bug in which two versions of each self-referential function
signature were emitted. Before this PR, the global HeapType store was not aware
of the original self-referential HeapTypes. When the function signatures were
used to construct HeapTypes during type collection, new HeapTypes were allocated
and emitted in addition to the original HeapTypes. Now the global HeapType store
returns the original HeapTypes, so the extra HeapType is never allocated.

@kripken you were totally right when you said you expected to see a move here!

This PR makes the TypeBuilder move self-referential HeapTypes to global HeapType
store so that they are considered canonical. This means that when a HeapType is
constructed with an identical definition, it will be equivalent to the original
HeapType constructed by the TypeBuilder, but it does _not_ mean that
self-referential HeapTypes are deduplicated.

This fixes a bug in which two versions of each self-referential function
signature were emitted. Before this PR, the global HeapType store was not aware
of the original self-referential HeapTypes. When the function signatures were
used to construct HeapTypes during type collection, new HeapTypes were allocated
and emitted in addition to the original HeapTypes. Now the global HeapType store
returns the original HeapTypes, so the extra HeapType is never allocated.
@tlively
tlively requested a review from kripken February 27, 2021 06:28
@tlively
tlively enabled auto-merge (squash) February 27, 2021 20:03
@tlively

tlively commented Feb 27, 2021

Copy link
Copy Markdown
Member Author

Automerge enabled, FYI.

@tlively tlively mentioned this pull request Feb 27, 2021

;; CHECK: (module
;; CHECK-NEXT: (type $ref?|...0|_=>_ref?|...0| (func (param (ref null $ref?|...0|_=>_ref?|...0|)) (result (ref null $ref?|...0|_=>_ref?|...0|))))
;; CHECK-NEXT: (type $ref?|...0|_=>_ref?|...0| (func (param (ref null $ref?|...0|_=>_ref?|...0|)) (result (ref null $ref?|...0|_=>_ref?|...0|))))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, this output looks like it emits two types with the exact same name, which should be invalid - that is, I think this file would error on round-tripping through the text format?

(I guess #3627 could fix that?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, correct on both counts 👍

@tlively
tlively merged commit 0eb513d into WebAssembly:main Feb 28, 2021
@tlively
tlively deleted the recursive-heaptypes-are-canonical branch February 28, 2021 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants