Repository navigation
interp: improvements to interpret FIPS code - #5903
Merged
Merged
Conversation
Contributor
|
@jakebailey TYVM for working on this. Adding general defer support to interp is useful independent of the FIPS yak shaving. My agent has found one possible problem related to rollbacks expected with this PR |
Contributor
|
@jakebailey oops, it looks like the copy bug has existed for a while, its unrelated to your improvement so I sent #5904 |
davecheney
added a commit
to davecheney/tinygo
that referenced
this pull request
Oct 17, 2026
… 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.
This was referenced Oct 17, 2026
deadprogram
pushed a commit
that referenced
this pull request
Oct 17, 2026
… 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 #5903. This change does not depend on #5903 or on the getWritable fix on dfc/interp-getwritable-rollback.
davecheney
added a commit
to davecheney/tinygo
that referenced
this pull request
Oct 17, 2026
…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
added a commit
to davecheney/tinygo
that referenced
this pull request
Oct 17, 2026
When interp leaves a call for run time, the objects that the call can reach must be marked so that later loads and stores of them are not done at compile time. For a global variable, markExternal followed the pointers in the LLVM initializer of the global. But interp writes its results to those initializers only after it has finished, so a pointer that was stored to a global at compile time was not followed. For example, an init function that sets a global to the address of another global, starts a goroutine with the address of the first global, waits for the goroutine on a channel, and then reads the second global gives the old value. The goroutine changed the value through the pointer before the read. The program has no data race, and the 0.43.0 release has the same problem at all optimization levels. markExternal now follows the pointers in the current value of the object. This also reaches heap objects that interp allocated and that do not have an LLVM global yet. A global with no known value at compile time still uses its LLVM initializer. The problem was found during review of tinygo-org#5903. This change does not depend on tinygo-org#5903 or on the other interp fixes on dfc/interp-getwritable-rollback and dfc/interp-load-alias.
davecheney
added a commit
that referenced
this pull request
Oct 19, 2026
…er is reverted (#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 #5903, which lets interp evaluate functions with defer. This change does not depend on #5903.
Contributor
|
@jakebailey #5905 has landed, please rebase. |
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.
Zeroing local storage should not force otherwise constant initializers to run at startup. Evaluate nonvolatile fills when their destination is known and has not escaped.
Atomic state can be initialized before it becomes visible to other execution contexts. Evaluate operations on known storage while retaining runtime accesses once that storage has escaped.
These runtime helpers no longer use a separate interpreter map model. Keeping them opaque prevents constant callers from being evaluated.
jakebailey
force-pushed
the
interp-init-evaluation
branch
from
October 22, 2026 00:19
575abf3 to
90dd4df
Compare
davecheney
approved these changes
Oct 22, 2026
davecheney
left a comment
Contributor
There was a problem hiding this comment.
LGTM with one suggestion
Defers currently keep otherwise constant initialization at runtime. Evaluate complete calls without runtime recovery bookkeeping, and keep the original call whenever any runtime execution is still required.
jakebailey
force-pushed
the
interp-init-evaluation
branch
from
October 22, 2026 01:19
90dd4df to
9cdd16d
Compare
Member
|
Thanks for working on this @jakebailey and to @davecheney for all the reviewing. Now merging. |
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.
Fixes #5835
See individual commits for more info.
This is an alternative to #5883 that doesn't involve wholesale replacing the
godebugpackage.Combined with #5885, it should still let GODEBUG work but still eliminate FIPS stuff, since the FIPS stuff is determined by package initialization and is not affected by later runtime env calls, so, can be interp'd. Phew!