-
Notifications
You must be signed in to change notification settings - Fork 47
refactor: remove init$patchDeps mechanism (no longer needed after PR #1450) #1596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xushiwei
merged 1 commit into
goplus:main
from
luoliwoshang:refactor/remove-init-patch-deps
Feb 4, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -484,12 +484,6 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do | |||||||
| p.debugParams(b, block.Parent()) | ||||||||
| } | ||||||||
|
|
||||||||
| // Handle init$hasPatch: split dependency init calls into separate function | ||||||||
| if doModInit && p.state == pkgHasPatch { | ||||||||
| baseName := strings.TrimSuffix(p.fn.Name(), "$hasPatch") | ||||||||
| instrs = p.createInitDepsFunction(pkg, baseName, instrs) | ||||||||
| } | ||||||||
|
|
||||||||
| if doModInit { | ||||||||
| if pyModInit = p.pyMod != ""; pyModInit { | ||||||||
| last = len(instrs) - 1 | ||||||||
|
|
@@ -508,15 +502,7 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do | |||||||
| isCgoCmacro := isCgoCmacro(fnName) | ||||||||
| for i, instr := range instrs { | ||||||||
| if i == 1 && doModInit && p.state == pkgInPatch { // in patch package but no pkgFNoOldInit | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: The comment mentions
Suggested change
This would make it clearer that the comment describes the action being taken, not what's being checked. |
||||||||
| name := p.fn.Name() | ||||||||
| initFnNameOld := initFnNameOfHasPatch(name) | ||||||||
| initPatchDepsFnName := initDepsFnNameOfHasPatch(name) | ||||||||
|
|
||||||||
| // Call deps function first | ||||||||
| fnDeps := pkg.NewFunc(initPatchDepsFnName, llssa.NoArgsNoRet, llssa.InC) | ||||||||
| b.Call(fnDeps.Expr) | ||||||||
|
|
||||||||
| // Then call hasPatch (global vars) | ||||||||
| initFnNameOld := initFnNameOfHasPatch(p.fn.Name()) | ||||||||
| fnOld := pkg.NewFunc(initFnNameOld, llssa.NoArgsNoRet, llssa.InC) | ||||||||
| b.Call(fnOld.Expr) | ||||||||
| } | ||||||||
|
|
@@ -1174,79 +1160,6 @@ func initFnNameOfHasPatch(name string) string { | |||||||
| return name + "$hasPatch" | ||||||||
| } | ||||||||
|
|
||||||||
| func initDepsFnNameOfHasPatch(name string) string { | ||||||||
| return name + "$patchDeps" | ||||||||
| } | ||||||||
|
|
||||||||
| // findFirstNonInitInstruction finds the index of the first non-init instruction | ||||||||
| // in the given instructions. Returns -1 if all instructions are init calls. | ||||||||
| // Skips non-call instructions (like store for guard). | ||||||||
| func findFirstNonInitInstruction(instrs []ssa.Instruction) int { | ||||||||
| for i, instr := range instrs { | ||||||||
| call, ok := instr.(*ssa.Call) | ||||||||
| if !ok { | ||||||||
| // Skip non-call instructions (like guard store) | ||||||||
| continue | ||||||||
| } | ||||||||
| fn, ok := call.Call.Value.(*ssa.Function) | ||||||||
| if !ok { | ||||||||
| // Not a direct function call | ||||||||
| return i | ||||||||
| } | ||||||||
| if fn.Name() == "init" && fn.Signature.Recv() == nil { | ||||||||
| // This is an init call, continue looking | ||||||||
| continue | ||||||||
| } | ||||||||
| // Found a non-init call | ||||||||
| return i | ||||||||
| } | ||||||||
| return -1 | ||||||||
| } | ||||||||
|
|
||||||||
| // createInitDepsFunction creates and fills the init$patchDeps function | ||||||||
| // for the given init function, extracting dependency init calls from instrs. | ||||||||
| // Returns the remaining instructions after removing dependency inits. | ||||||||
| func (p *context) createInitDepsFunction(pkg llssa.Package, baseName string, instrs []ssa.Instruction) []ssa.Instruction { | ||||||||
| // Create deps function | ||||||||
| depsName := initDepsFnNameOfHasPatch(baseName) | ||||||||
| depsFn := pkg.NewFunc(depsName, llssa.NoArgsNoRet, llssa.InC) | ||||||||
| depsFn.MakeBlocks(1) | ||||||||
| depsBuilder := depsFn.NewBuilder() | ||||||||
| depsBuilder.SetBlock(depsFn.Block(0)) | ||||||||
|
|
||||||||
| // Find and split dependency init calls | ||||||||
| firstNonInit := findFirstNonInitInstruction(instrs) | ||||||||
| var depsInstrs []ssa.Instruction | ||||||||
| if firstNonInit > 0 { | ||||||||
| depsInstrs = instrs[:firstNonInit] | ||||||||
| instrs = instrs[firstNonInit:] | ||||||||
|
|
||||||||
| // Fill deps function body with dependency init calls | ||||||||
| for _, instr := range depsInstrs { | ||||||||
| if call, ok := instr.(*ssa.Call); ok { | ||||||||
| if fn, ok := call.Call.Value.(*ssa.Function); ok { | ||||||||
| if fn.Name() == "init" && fn.Signature.Recv() == nil { | ||||||||
| // Skip packages that don't need init (like unsafe) | ||||||||
| if p.pkgNoInit(fn.Pkg.Pkg) { | ||||||||
| continue | ||||||||
| } | ||||||||
| // This is a dependency init call | ||||||||
| // Use funcName to get the correct function name (handles patches, linkname, etc.) | ||||||||
| _, depInitName, ftype := p.funcName(fn) | ||||||||
| if ftype == goFunc { | ||||||||
| depInitFn := pkg.NewFunc(depInitName, llssa.NoArgsNoRet, llssa.InC) | ||||||||
| depsBuilder.Call(depInitFn.Expr) | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| depsBuilder.Return() | ||||||||
|
|
||||||||
| return instrs | ||||||||
| } | ||||||||
|
|
||||||||
| func processPkg(ctx *context, ret llssa.Package, pkg *ssa.Package) { | ||||||||
| type namedMember struct { | ||||||||
| name string | ||||||||
|
|
||||||||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: The comment mentions
pkgFNoOldInitbut the condition doesn't check for it. Consider clarifying what the comment is documenting:This would make it clearer that the comment describes the action being taken, not what's being checked.