[go] cmd/compile, go/types: disable constant string size check

0 views
Skip to first unread message

Cherry Mui (Gerrit)

unread,
Apr 29, 2026, 4:32:26 PM (20 hours ago) Apr 29
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, golang...@luci-project-accounts.iam.gserviceaccount.com, Robert Griesemer, Dmitri Shuralyov, Dmitri Shuralyov, golang-co...@googlegroups.com

Cherry Mui submitted the change with unreviewed changes

Unreviewed changes

1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: src/cmd/compile/internal/types2/const.go
Insertions: 1, Deletions: 0.

@@ -53,6 +53,7 @@
// Disable the length check for now, as calling constant.StringVal
// eagerly constructs the string and can lead to significant memory
// usage increase. We may want a StringLen function.
+ // TODO(go.dev/issue/78346): reenable the check.
if false && x.val.Kind() == constant.String && len(constant.StringVal(x.val)) > maxLen {
check.errorf(atPos(opPos), InvalidConstVal, "constant string too long (%d bytes > %d bytes)",
len(constant.StringVal(x.val)), maxLen)
```
```
The name of the file: src/go/types/const.go
Insertions: 1, Deletions: 0.

@@ -55,6 +55,7 @@
// Disable the length check for now, as calling constant.StringVal
// eagerly constructs the string and can lead to significant memory
// usage increase. We may want a StringLen function.
+ // TODO(go.dev/issue/78346): reenable the check.
if false && x.val.Kind() == constant.String && len(constant.StringVal(x.val)) > maxLen {
check.errorf(atPos(opPos), InvalidConstVal, "constant string too long (%d bytes > %d bytes)",
len(constant.StringVal(x.val)), maxLen)
```

Change information

Commit message:
cmd/compile, go/types: disable constant string size check

The go/constant and go/types packages try very hard not to eagerly
construct string constant. The length check now calls
constant.StringVal effectively on every string constant, which
eagerly constructs the strings and can cause it to use
significantly more memory. We may need a different mechanism to do
the length check, like a new API that returns the length without
constructing the string. For now, disable the code.

Updates #78346.
Change-Id: I46a9586614150e7d5353803904e101d808a683f5
Reviewed-by: Robert Griesemer <g...@google.com>
Reviewed-by: Dmitri Shuralyov <dmit...@golang.org>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
Files:
  • M src/cmd/compile/internal/types2/const.go
  • M src/go/types/const.go
  • M src/internal/types/testdata/fixedbugs/issue78346.go
Change size: S
Delta: 3 files changed, 11 insertions(+), 3 deletions(-)
Branch: refs/heads/master
Submit Requirements:
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: I46a9586614150e7d5353803904e101d808a683f5
Gerrit-Change-Number: 772220
Gerrit-PatchSet: 3
Gerrit-Owner: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
Gerrit-Reviewer: Robert Griesemer <g...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages