Repository navigation
interp: keep memcpy results out of the global state when an initializer is reverted - #5904
Merged
davecheney merged 1 commit intoOct 19, 2026
Conversation
Member
|
Please rebase and resolve merge conflicts @davecheney thank you. |
…er is reverted When interp reverts a package initializer and runs it at run time, a memcpy or memmove that interp already evaluated must not change the initial value of the destination. getWritable put its clone in the runner's global object table instead of in the current memory view, so the copy stayed in the initial value after the revert, and the initializer then did the copy again at run time. For example, an initializer that does copy(data[1:], data[:3]) on "ABCD" and then calls println in a function with a defer gives "AAAB" instead of "AABC". The same program gives the correct result when it runs from main, and the 0.43.0 release has the same problem. getWritable has done this since the interp rewrite in 30df912. The problem was found during review of tinygo-org#5903, which lets interp evaluate functions with defer. This change does not depend on tinygo-org#5903.
davecheney
force-pushed
the
dfc/interp-getwritable-rollback
branch
from
October 17, 2026 22:41
bd73585 to
08cdc5e
Compare
Contributor
Author
|
@deadprogram rebased, PTAL |
deadprogram
approved these changes
Oct 19, 2026
deadprogram
left a comment
Member
There was a problem hiding this comment.
Thanks @davecheney for tracking this one down. I ran the tests on my local machine. Working as expected, thank you very much!
mklocdev
pushed a commit
to mklocdev/tinygo
that referenced
this pull request
Oct 21, 2026
…er is reverted (tinygo-org#5904) When interp reverts a package initializer and runs it at run time, a memcpy or memmove that interp already evaluated must not change the initial value of the destination. getWritable put its clone in the runner's global object table instead of in the current memory view, so the copy stayed in the initial value after the revert, and the initializer then did the copy again at run time. For example, an initializer that does copy(data[1:], data[:3]) on "ABCD" and then calls println in a function with a defer gives "AAAB" instead of "AABC". The same program gives the correct result when it runs from main, and the 0.43.0 release has the same problem. getWritable has done this since the interp rewrite in 30df912. The problem was found during review of tinygo-org#5903, which lets interp evaluate functions with defer. This change does not depend on tinygo-org#5903.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When interp reverts a package initializer and runs it at run time, a memcpy or memmove that interp already evaluated must not change the initial value of the destination. getWritable put its clone in the runner's global object table instead of in the current memory view, so the copy stayed in the initial value after the revert, and the initializer then did the copy again at run time. For example, an initializer that does copy(data[1:], data[:3]) on "ABCD" and then calls println in a function with a defer gives "AAAB" instead of "AABC". The same program gives the correct result when it runs from main, and the 0.43.0 release has the same problem. getWritable has done this since the interp rewrite in 30df912.
The problem was found during review of #5903, which lets interp evaluate functions with defer. This change does not depend on #5903.