]> Cypherpunks repositories - gostls13.git/commit
fmt: avoid storing input arguments on pp to help escape analysis
authorthepudds <thepudds1460@gmail.com>
Wed, 21 Jun 2023 17:27:11 +0000 (13:27 -0400)
committert hepudds <thepudds1460@gmail.com>
Fri, 30 Jan 2026 22:22:48 +0000 (14:22 -0800)
commit045fe9aa8c7e175b5894b6f0c85d76a1ec27a91c
treeb1267b256c569f207f310f5f90eea4ace15517e7
parentf14d8975a21e24aa33e0b496e822fdcb285879b9
fmt: avoid storing input arguments on pp to help escape analysis

This is part of a series of CLs that aim to reduce how often
interface arguments escape for the print functions in fmt,
such as val here:

  func f(val int) {
      fmt.Sprintf("%d", val)
  }

Prior to this change, arguments immediately escape in doPrintf
because they are stored on the *pp in printArg:

  parameter a leaks to <heap> for (*pp).doPrintf with derefs=1:
    flow: <heap> ← *a:
      from a[argNum] (dot of pointer) at .\print.go:1077:18
      from (*pp).printArg(p, a[argNum], rune(c)) (call parameter) at .\print.go:1077:16

  parameter arg leaks to <heap> for (*pp).printArg with derefs=0:
    flow: <heap> ← arg:
      from p.arg = arg (assign) at .\print.go:682:8

The *pp is heap allocated, and the heap cannot point to stack
variables, so the arguments currently cannot be on the stack.

This change instead threads through the input arguments as individual
type any and reflect.Value parameters, rather than storing on the *pp.

After this change, input arguments still escape, but now for
other reasons.

Updates #8618
Updates #62653

Change-Id: I81984daeceb761ce4ce269b150b888950ce2c5d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/524938
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/fmt/print.go