Skip to content

Make encodings in wit-component harder to get wrong#337

Merged
alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton:encode-immediately
Oct 3, 2022
Merged

Make encodings in wit-component harder to get wrong#337
alexcrichton merged 1 commit intobytecodealliance:mainfrom
alexcrichton:encode-immediately

Conversation

@alexcrichton
Copy link
Member

Currently the wit-component crate's encoding is structured with incremental encoding of a component where sections are added, in bulk, locally within each method. This method of adding sections, however, can lead to mistakes where declaratively assigned indices end up getting wrong indices in the final binary.

In recent changes to wit-component one of my loops of encoding new items got things in the wrong order so I decided to do this refactoring first where items are always immediately encoded into a component to ensure that the assigned index is guaranteed to match. This does have the downside of producing components with more sections since the interleavings currently create a fair number of 1-item sections, but I'm hoping that rewriting this to a more optimal encoding can be done in the future with a post-processing tool if necessary or an otherwise more deliberate local handling of batching things up.

Currently the `wit-component` crate's encoding is structured with
incremental encoding of a component where sections are added, in bulk,
locally within each method. This method of adding sections, however, can
lead to mistakes where declaratively assigned indices end up getting
wrong indices in the final binary.

In recent changes to `wit-component` one of my loops of encoding new
items got things in the wrong order so I decided to do this refactoring
first where items are always immediately encoded into a component to
ensure that the assigned index is guaranteed to match. This does have
the downside of producing components with more sections since the
interleavings currently create a fair number of 1-item sections, but I'm
hoping that rewriting this to a more optimal encoding can be done in the
future with a post-processing tool if necessary or an otherwise more
deliberate local handling of batching things up.
@alexcrichton alexcrichton merged commit f1f54ac into bytecodealliance:main Oct 3, 2022
@alexcrichton alexcrichton deleted the encode-immediately branch October 3, 2022 14:16
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