« All posts

Go 1.26's //go:fix inline: source-level inlining for API migrations

Go 1.26 introduces //go:fix inline, a source-level inliner in go fix that automates safe API migrations and deprecated function removal.

Go 1.26 ships a rewritten go fix subcommand built around a source-level inliner — the same engine behind gopls' 'Inline call' refactoring. Package authors can now tag a function with a //go:fix inline directive, and go fix will automatically replace every call site with an inlined copy of the function body, substituting in the actual arguments.

The post walks through practical uses: retiring ioutil.ReadFile in favor of os.ReadFile, and even fixing awkward API designs — like a Sub function with swapped parameter order or a redundant Neg function — by reimplementing the old API in terms of a cleaner new package and letting the inliner rewrite call sites accordingly. Unlike compiler-internal inlining, which operates on ephemeral intermediate representations, this transformation permanently rewrites source code, and because it swaps in an actual function body rather than an arbitrary expression, it's designed to preserve program behavior.

Google's Java, Kotlin, and C++ teams have used similar inliners for years to retire millions of deprecated calls across a monorepo; Go's newer implementation has already driven over 18,000 changelists. For engineers, this means safer, self-service API deprecation without resorting to riskier blanket rewrite tools like gofmt -r.

This synthesis was produced from its source by AI; there is no human editor or manual review step. How we work