Go 1.26'nın yeni özelliği: //go:fix inline ile kaynak seviyesinde inlining
Go 1.26'daki go fix aracı ve //go:fix inline direktifi, API göçlerini otomatikleştiren kaynak seviyesi inliner'ı tanıtıyor. Detaylar devrazzi'de.
Go 1.26 introduces a redesigned go fix command featuring a source-level inliner that helps developers migrate codebases to modern APIs. Built on an algorithm from 2023, this tool permanently rewrites source code by replacing function calls with the callee's body, distinguishing it from the ephemeral inlining performed by compilers. The same engine powers gopls' 'Inline call' refactoring feature.
The new //go:fix inline directive comment lets package authors redirect deprecated APIs to their replacements. For instance, annotating ioutil.ReadFile enables go fix to automatically rewrite all calls to os.ReadFile. The technique extends beyond simple renames—forwarding functions combined with inline directives can also fix API design flaws like incorrect parameter ordering or redundant functions, and the same mechanism works for type aliases and constants.
Unlike arbitrary rewrite tools such as gofmt -r, this approach preserves program behavior because it substitutes the actual function body rather than an arbitrary expression (except for code inspecting the call stack). Google has used similar source-level inliners for Java, Kotlin, and C++ for years, eliminating millions of deprecated calls; Go's inliner has already prepared over 18,000 changelists in Google's monorepo.
Under the hood, the inliner is roughly 7,000 lines of dense, compiler-like logic, carefully handling edge cases such as parameter elimination to ensure safe and correct transformations. This feature empowers library maintainers to automate API migrations for their users, easing the modernization of large-scale Go codebases.