[go] cmd/compile: test that time.Duration.String is inlineable

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Feb 27, 2026, 11:26:23 PM (18 hours ago) Feb 27
to Daniel Martí, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, David Chase, Keith Randall, Keith Randall, Go LUCI, Matthew Dempsky, Martin Möhrmann, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
cmd/compile: test that time.Duration.String is inlineable

This matters for encodings supporting time.Duration,
which cannot add an AppendText method due to the encoding package godoc:

Adding encoding/decoding methods to existing types may constitute
a breaking change, [...] The policy for packages maintained by
the Go project is to only allow the addition of marshaling functions
if no existing, reasonable marshaling exists.

And indeed, time.Duration does have an existing marshaling today:
as an integer, which encoding/json still uses to this day.

Thankfully, with the String method being inlineable, we can rely on
the following not allocating in the heap:

var td time.Duration = ...
b = append(b, td.String()...)

Lock this in so that we can rely on this pattern going forward.

For #77851.
Change-Id: I57ce0bc099f293b0e36aa4c74b5410f8bda347a5
Reviewed-by: Keith Randall <k...@google.com>
Auto-Submit: Keith Randall <k...@golang.org>
Reviewed-by: David Chase <drc...@google.com>
Reviewed-by: Keith Randall <k...@golang.org>
Files:
  • M src/cmd/compile/internal/test/inl_test.go
Change size: XS
Delta: 1 file changed, 3 insertions(+), 0 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Keith Randall, +1 by David Chase, +1 by Keith Randall
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I57ce0bc099f293b0e36aa4c74b5410f8bda347a5
Gerrit-Change-Number: 750100
Gerrit-PatchSet: 2
Gerrit-Owner: Daniel Martí <mv...@mvdan.cc>
Gerrit-Reviewer: Daniel Martí <mv...@mvdan.cc>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@google.com>
Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
Gerrit-Reviewer: Matthew Dempsky <mat...@go.dev>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages