Repository navigation
interp: keep partial loads independent of buffers owned by a caller's memory view - #5905
Merged
Merged
Conversation
… memory view A value that a function loads during package initialization must not change when the caller later stores to the same object. Since f5bd750, a partial store changes the buffer of an object in place when the current memory view already owns that object. 3a0d724 made load copy the loaded slice in that case, but it checked only the current view. When a callee loads part of an object that its caller owns, the callee has its own view, so the returned value still shares the caller's buffer, and the caller's next partial store changes it. For example, an init function that sets a struct field to 1, reads it through a helper function, sets it to 2, and then copies the value it read gives 2 instead of 1. This needs no defer and no revert, and the 0.43.0 release has the same problem. Objects in the runner's base table are never changed in place, so loads from objects that no view owns still return a slice of the buffer without a copy. The problem was found during review of tinygo-org#5903. This change does not depend on tinygo-org#5903 or on the getWritable fix on dfc/interp-getwritable-rollback.
deadprogram
approved these changes
Oct 17, 2026
deadprogram
left a comment
Member
There was a problem hiding this comment.
Looking good @davecheney thank you!
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.
A value that a function loads during package initialization must not change when the caller later stores to the same object. Since f5bd750, a partial store changes the buffer of an object in place when the current memory view already owns that object. 3a0d724 made load copy the loaded slice in that case, but it checked only the current view. When a callee loads part of an object that its caller owns, the callee has its own view, so the returned value still shares the caller's buffer, and the caller's next partial store changes it. For example, an init function that sets a struct field to 1, reads it through a helper function, sets it to 2, and then copies the value it read gives 2 instead of 1. This needs no defer and no revert, and the 0.43.0 release has the same problem.
Objects in the runner's base table are never changed in place, so loads from objects that no view owns still return a slice of the buffer without a copy.
The problem was found during review of #5903. This change does not depend on #5903 or on the getWritable fix on dfc/interp-getwritable-rollback.