Skip to content

unique: string arguments do not need to escape #73680

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

Closed
mknyszek opened this issue May 12, 2025 · 3 comments
Closed

unique: string arguments do not need to escape #73680

mknyszek opened this issue May 12, 2025 · 3 comments
Labels
Implementation Issues describing a semantics-preserving change to the Go implementation. NeedsFix The path to resolution is known, but the work has not been done. Performance
Milestone

Comments

@mknyszek
Copy link
Contributor

mknyszek commented May 12, 2025

unique clones any strings it finds in its input, if it can find them statically. (strings hidden somewhere in an interface value are excepted.) This means string arguments (or types whose only reference types are strings) never need to escape.

Note that pointer arguments still need to escape, because stack objects have no stable identity. But string arguments' identity is their data.

@mknyszek mknyszek added Performance NeedsFix The path to resolution is known, but the work has not been done. labels May 12, 2025
@mknyszek mknyszek added this to the Backlog milestone May 12, 2025
@jakebailey
Copy link
Contributor

Funnily this is effectively what I was fixing in CL 671955, mistakenly thinking I was fixing #71926.

@gabyhelp gabyhelp added the Implementation Issues describing a semantics-preserving change to the Go implementation. label May 12, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/671955 mentions this issue: cmd/compile: do not escape strings passed to unique.Make

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/675156 mentions this issue: cmd/compile, unique: model data flow of non-string pointers

@dmitshur dmitshur modified the milestones: Backlog, Go1.25 May 22, 2025
Sirherobrine23 pushed a commit to Sirherobrine23/go that referenced this issue May 24, 2025
Currently, hash/maphash.Comparable escapes its parameter if it
contains non-string pointers, but does not escape strings or types
that contain strings but no other pointers. This is achieved by a
compiler intrinsic.

unique.Make does something similar: it stores its parameter to a
central map, with strings cloned. So from the escape analysis's
perspective, the non-string pointers are passed through, whereas
string pointers are not. We currently cannot model this type of
type-dependent data flow directly in Go. So we do this with a
compiler intrinsic. In fact, we can unify this and the intrinsic
above.

Tests are from Jake Bailey's CL 671955 (thanks!).

Fixes golang#73680.

Change-Id: Ia6a78e09dee39f8d9198a16758e4b5322ee2c56a
Reviewed-on: https://go-review.googlesource.com/c/go/+/675156
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: David Chase <[email protected]>
Reviewed-by: Jake Bailey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation Issues describing a semantics-preserving change to the Go implementation. NeedsFix The path to resolution is known, but the work has not been done. Performance
Projects
None yet
Development

No branches or pull requests

5 participants