Skip to content

interp: keep partial loads independent of buffers owned by a caller's memory view - #5905

Merged
deadprogram merged 1 commit into
tinygo-org:devfrom
davecheney:dfc/interp-load-alias
Oct 17, 2026
Merged

deadprogram merged 1 commit into
tinygo-org:devfrom
davecheney:dfc/interp-load-alias

Conversation

@davecheney

Copy link
Copy Markdown
Contributor

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.

… 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 deadprogram left a comment

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.

Looking good @davecheney thank you!

@deadprogram
deadprogram merged commit 9502627 into tinygo-org:dev Oct 17, 2026
33 checks passed
@davecheney
davecheney deleted the dfc/interp-load-alias branch October 17, 2026 22:39
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