Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scratch local optimizations when emitting string slice #6649

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

tlively
Copy link
Member

@tlively tlively commented Jun 11, 2024

The binary writing of stringview_wtf16.slice requires scratch locals to store the start and end operands while the string operand is converted to a stringview. To avoid unbounded binary bloat when round-tripping, we detect the case that start and end are already local.gets and avoid using scratch locals by deferring the binary writing of the local.get operands until after the stringview conversoins is emitted.

We previously optimized the scratch locals for start and end independently, but this could produce incorrect code in the case where the local.get for start is deferred but its value is changed by a local.set in the code for end. Fix the problem by only optimizing to avoid scratch locals in the case where both start and end are already local.gets, so they will still be emitted in the original relative order and they cannot interfere with each other anyway.

The binary writing of `stringview_wtf16.slice` requires scratch locals to store
the `start` and `end` operands while the string operand is converted to a
stringview. To avoid unbounded binary bloat when round-tripping, we detect the
case that `start` and `end` are already `local.get`s and avoid using scratch
locals by deferring the binary writing of the `local.get` operands until after
the stringview conversoins is emitted.

We previously optimized the scratch locals for `start` and `end` independently,
but this could produce incorrect code in the case where the `local.get` for
`start` is deferred but its value is changed by a `local.set` in the code for
`end`. Fix the problem by only optimizing to avoid scratch locals in the case
where both `start` and `end` are already `local.get`s, so they will still be
emitted in the original relative order and they cannot interfere with each other
anyway.
@tlively tlively requested a review from kripken June 11, 2024 19:27
@tlively tlively merged commit cdd94a0 into main Jun 11, 2024
13 checks passed
@tlively tlively deleted the fix-slice-gets branch June 11, 2024 20:11
@gkdn gkdn mentioned this pull request Aug 31, 2024
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