Skip to content
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

cmd/compile: OOM with mutually-recursive iter.Seq #72090

Closed
finnw opened this issue Mar 4, 2025 · 11 comments
Closed

cmd/compile: OOM with mutually-recursive iter.Seq #72090

finnw opened this issue Mar 4, 2025 · 11 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@finnw
Copy link

finnw commented Mar 4, 2025

Go version

go version go1.24.0 windows/amd64

Output of go env in your module/workspace:

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\dave4\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\dave4\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\dave4\AppData\Local\Temp\go-build453610553=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=C:\Users\dave4\OneDrive\trietest\go.mod
set GOMODCACHE=C:\Users\dave4\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\dave4\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\dave4\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.0
set GOWORK=C:\Users\dave4\OneDrive\trietest\go.work
set PKG_CONFIG=pkg-config

What did you do?

Compiling the following code (not necessary to run the resulting binary):

https://go.dev/play/p/ozUGHBgCjUv

This code implements a Trie data structure

There are two iter.Seq functions that recursively iterate over all paths from the root to the leaves

What did you see happen?

compile.exe memory use grows until it fails with an OOM error

Adding a "//go:noinline" directive to one or both Seq functions prevents this

What did you expect to see?

generate an .exe that outputs the hard-coded example strings when run

With the "//go:noinlne" it works as expected

@gabyhelp
Copy link

gabyhelp commented Mar 4, 2025

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@seankhliao seankhliao changed the title iter: OOM in compile.exe with mutually-recursive iter.Seq's cmd/compile: OOM with mutually-recursive iter.Seq Mar 4, 2025
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 4, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 4, 2025
@thepudds
Copy link
Contributor

thepudds commented Mar 4, 2025

Hi @finnw, would you be able to try your example with https://go.dev/cl/654195 to see if it helps? Some chance this is related to #72063, though maybe not.

$ go install golang.org/dl/gotip@latest
$ gotip download 654195 # download and build CL 654195 
$ gotip run your-example.go

CC @cuonglm (in case interested).

@randall77
Copy link
Contributor

randall77 commented Mar 4, 2025

This is still broken at tip, so I don't think CL 654195 fixes it. It certainly seems related though.

@cuonglm
Copy link
Member

cuonglm commented Mar 4, 2025

This is still broken at tip, so I don't think CL 654195 fixes it. It certainly seems related though.

Yeah, they are different problems.

CL 654195 fixes the issue with a closure call which has the closue itself is one of call arguments.

@JunyangShao
Copy link
Contributor

CC @golang/compiler

@JunyangShao JunyangShao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 4, 2025
@Jorropo
Copy link
Member

Jorropo commented Mar 5, 2025

git bisect start '--' 'src/cmd/compile/'
# status: waiting for both good and bad commits
# bad: [350118666d75445761bef5c45e681415e6d1b326] net/http: don't modify caller's tls.Config.NextProtos
git bisect bad 350118666d75445761bef5c45e681415e6d1b326
# status: waiting for good commit(s), bad commit known
# good: [a991f9c34d454d3d844f21dc08f2d05df35a8c60] [release-branch.go1.23] go1.23.6
git bisect good a991f9c34d454d3d844f21dc08f2d05df35a8c60
# git bisect run bash -c "cd src && git clean -fxd && ./make.bash && systemd-run --user --scope -p MemoryMax=10G ../bin/go build /tmp/a.go; EXIT_CODE=\$?; if [ \$EXIT_CODE -eq 143 ]; then exit 1; else exit \$EXIT_CODE; fi"
# good: [5e8a7316658c2f300a375041b6e0a606fec4c5f2] README: fix CC BY license name
git bisect good 5e8a7316658c2f300a375041b6e0a606fec4c5f2
# good: [5428570af7f668c840569a596cb1c23644f408cf] cmd/compile: use call block instead of entry block for tail call expansion
git bisect good 5428570af7f668c840569a596cb1c23644f408cf
# good: [4a3cef2036097d323b6cc0bbe90fc4d8c7588660] all: rename crypto/internal/fips to crypto/internal/fips140
git bisect good 4a3cef2036097d323b6cc0bbe90fc4d8c7588660
# bad: [072eea9b3b8e3c871707b5661948edd4090fc56a] cmd/compile: avoid ifaceeq call if we know the interface is direct
git bisect bad 072eea9b3b8e3c871707b5661948edd4090fc56a
# bad: [1d20bce981005777424b9c8da199015ab2148810] go/types, types2: expand documentation for Info.Types map
git bisect bad 1d20bce981005777424b9c8da199015ab2148810
# good: [0edea47f264a4185d78e00e1e9e977d99f5c997b] internal/exportdata, cmd/compile/internal/noder: merge export data handling
git bisect good 0edea47f264a4185d78e00e1e9e977d99f5c997b
# bad: [32e19fc4397142b743646ff8a526d07c126bf89b] cmd/compile: document wasmexport directive, update permitted types for wasmimport
git bisect bad 32e19fc4397142b743646ff8a526d07c126bf89b
# bad: [bcb934ad11060b4ed45663cf6e25bd7b7e92c1bb] go/types, types2: fix printing of error message with variadic calls
git bisect bad bcb934ad11060b4ed45663cf6e25bd7b7e92c1bb
# bad: [d524c954b14c861e6a442e09abd38ba074ad376d] cmd/compile: use very high budget for once-called closures
git bisect bad d524c954b14c861e6a442e09abd38ba074ad376d
# good: [c4e6ab9750e9d673a29203a9f41a517bcdc7a64c] cmd/compile: modify CSE to remove redundant OpLocalAddrs
git bisect good c4e6ab9750e9d673a29203a9f41a517bcdc7a64c
# first bad commit: [d524c954b14c861e6a442e09abd38ba074ad376d] cmd/compile: use very high budget for once-called closures

bisected to d524c95 cc @dr2chase
Similar to #71680 and #72063

@dmitshur dmitshur added this to the Go1.25 milestone Mar 5, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/654996 mentions this issue: cmd/compile: correct inlining budget for rangefunc closure

@dr2chase
Copy link
Contributor

dr2chase commented Mar 5, 2025

I have a fix that solves the problem, "once and for all", will try to mail it soon.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/655155 mentions this issue: cmd/compile: use inline-Pos-based recursion test

@Jorropo
Copy link
Member

Jorropo commented Mar 5, 2025

I have a fix that solves the problem, "once and for all", will try to mail it soon.
@dr2chase

Does that means some of the previous fixes can be reverted ?

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 6, 2025
@cherrymui
Copy link
Member

cherrymui commented Mar 6, 2025

Does that means some of the previous fixes can be reverted ?

As the CL description mentioned:

This subsumes all the other
recently-added recursive inlining checks, but they are
left in to make this easier+safer to backport.

They may be removed in a later step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests