[go1.21] Adding new / replace optional override directives#1414
Merged
grantnelson-wf merged 2 commits intogopherjs:go1.21from Feb 24, 2026
Merged
[go1.21] Adding new / replace optional override directives#1414grantnelson-wf merged 2 commits intogopherjs:go1.21from
new / replace optional override directives#1414grantnelson-wf merged 2 commits intogopherjs:go1.21from
Conversation
new / replace optional override directivesnew / replace optional override directives
nevkontakte
approved these changes
Feb 23, 2026
Member
nevkontakte
left a comment
There was a problem hiding this comment.
I like this idea, it can help us get to a better-defined overrides incrementally. Thanks!
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.
This is part of the proposal issue #1330, "Proposal: More strict native override checking". This adds the
gopherjs:newandgopherjs:replaceoptional directives. Additionally, I added the new missing method to bytealg and added these directives as a test. Since this is being added to the go1.21 integration branch, CI will continue to fail. This code includes the update to master so that PR should be merged before this one.Between Go1.20 and Go1.21, the Go developers refactored reflect and internal/reflectlite by moving a lot of code over to internal/abi. Since so much code was in internal packages; the developers weren't required to keep exported code consistent other than in reflect. Since there was so much code being moved, it was difficult for me to determine what was new code to go1.20, code being replaced in go1.20, then which code is new in go1.21 and replaced in go1.21. Any code that was a replacement for go1.20 of code that got moved, removed, or renamed in go1.21 would suddenly become new code we are adding.
I didn't want to leave around a bunch of code that hopefully had no effect (and hopefully just removed with dead code elimination), so I implemented this part of the proposal to help me track how our overrides are being applied.
These overrides are compiler enforced "developer intensions" just like the override modifier in C# and other modifiers in many languages. The code could quietly decide if we are overriding code or adding new code, or with these directives we can ensure that overrides work as the developer intended at compile time.
The full proposal is probably overkill at this time because of how strict is. These directives are not required so we don't have to add them to all of the overrides in one pass. The only change that this will effect is any of the existing override directives (i.e.
purge,keep-original, andoverride-signature) will start acting likegopherjs:replaceand raise an error if the code that they are attached to doesn't exist.Instead of adding this code, then removing it once I have reflect, reflectlite, and abi working, I felt this would be a good time to add these directives. We already have to go through the native overrides while upgrading to go1.21 so any of the existing override directives can be updated as needed and we can add in these new directives if we feel it will help us when we upgrade to go1.22.
However, if you think that this is not a good idea to add; I have no problem skipping it and removing it from the reflect, reflectlite, and abi updates.
Related to #1415