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: out of memory #72063

Open
CarstenLeue opened this issue Mar 2, 2025 · 4 comments
Open

cmd/compile: out of memory #72063

CarstenLeue opened this issue Mar 2, 2025 · 4 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Critical A critical problem that affects the availability or correctness of production systems built using Go FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@CarstenLeue
Copy link

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\CarstenLeue\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\CarstenLeue\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\CARSTE~1\AppData\Local\Temp\go-build2164274435=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=c:\d\golang-y-combinator\go.mod
set GOMODCACHE=C:\Users\CarstenLeue\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\CarstenLeue\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\CarstenLeue\sdk\go1.24.0
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\CarstenLeue\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\CarstenLeue\sdk\go1.24.0\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.0
set GOWORK=
set PKG_CONFIG=pkg-config

What did you do?

Running the folling go program via:

go1.24.0 run main.go

Program:

package main

import "fmt"

// Y is the Y-combinator based on https://dreamsongs.com/Files/WhyOfY.pdf
func Y[Endo ~func(RecFct) RecFct, RecFct ~func(T) R, T, R any](f Endo) RecFct {

	type internal[RecFct ~func(T) R, T, R any] func(internal[RecFct, T, R]) RecFct

	g := func(h internal[RecFct, T, R]) RecFct {
		return func(t T) R {
			return f(h(h))(t)
		}
	}
	return g(g)
}

func main() {

	fct := Y(func(r func(int) int) func(int) int {
		return func(n int) int {
			if n <= 0 {
				return 1
			}
			return n * r(n-1)
		}
	})

	fmt.Println(fct(10))
}

Also available for test at
https://github.com/CarstenLeue/golang-y-combinator

What did you see happen?

The compilation step consumes my complete memory and would not finish but bail out after a couple of minutes with an out ot memory exception. Attached the screenshot of the memory consumption right after starting the program. Memory is consumed by compile.exe.

Image

What did you expect to see?

When running the same program with go 1.23.6 I am not seeing no bump in memory consumption at all and the program returns after a couple of seconds with the correct output:

go1.23.6 run main.go
3628800

I would expect the same for go 1.24.0

@CarstenLeue CarstenLeue changed the title Compiler regression in go1.24.0 Compiler regression in go1.24.0 - out of memory Mar 2, 2025
@seankhliao seankhliao changed the title Compiler regression in go1.24.0 - out of memory cmd/compile: out of memory Mar 2, 2025
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 2, 2025
@Jorropo
Copy link
Member

Jorropo commented Mar 2, 2025

git bisect start '--' 'src/cmd/compile/'
# status: waiting for both good and bad commits
# bad: [3901409b5d0fb7c85a3e6730a59943cc93b2835c] [release-branch.go1.24] go1.24.0
git bisect bad 3901409b5d0fb7c85a3e6730a59943cc93b2835c
# status: waiting for good commit(s), bad commit known
# good: [a991f9c34d454d3d844f21dc08f2d05df35a8c60] [release-branch.go1.23] go1.23.6
git bisect good a991f9c34d454d3d844f21dc08f2d05df35a8c60
# good: [5e8a7316658c2f300a375041b6e0a606fec4c5f2] README: fix CC BY license name
git bisect good 5e8a7316658c2f300a375041b6e0a606fec4c5f2
# good: [87a89fa45130d4406fa4d9f0882b9c5014240d03] runtime: add the checkPtraceScope to skip certain tests
git bisect good 87a89fa45130d4406fa4d9f0882b9c5014240d03
# bad: [a311754d5411c742211a4b56ae3eed00d20898c9] cmd/internal/testdir: print stderr if go list fails while gathering stdlib import config
git bisect bad a311754d5411c742211a4b56ae3eed00d20898c9
# good: [80d306da50aef6334bcb65fb02f5728cb9513691] runtime: prevent weak->strong conversions during mark termination
git bisect good 80d306da50aef6334bcb65fb02f5728cb9513691
# good: [5e82cba9bdf45d81da549477d172f6b5e23106d4] os/user: skip tests that create users when running on dev machines
git bisect good 5e82cba9bdf45d81da549477d172f6b5e23106d4
# bad: [ffb8b1c586a61882b6c362c0454f56f89d2693c9] crypto/internal/mlkem768: make Decapsulate a method
git bisect bad ffb8b1c586a61882b6c362c0454f56f89d2693c9
# bad: [170436c045f1303543e6d0bf8b36fccac57da2cd] cmd/compile: strongly favor closure inlining
git bisect bad 170436c045f1303543e6d0bf8b36fccac57da2cd
# first bad commit: [170436c045f1303543e6d0bf8b36fccac57da2cd] cmd/compile: strongly favor closure inlining

Bisected to 170436c cc @dr2chase
similar to #71680 ?

@Jorropo Jorropo added Critical A critical problem that affects the availability or correctness of production systems built using Go NeedsFix The path to resolution is known, but the work has not been done. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed NeedsFix The path to resolution is known, but the work has not been done. labels Mar 2, 2025
@Jorropo
Copy link
Member

Jorropo commented Mar 2, 2025

@gopherbot please backport to the next go1.24 release.

Valid code that used to compile with 1.23.6 now fails to do so while using all the memory on the system.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #72066 (for 1.23), #72067 (for 1.24).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/654195 mentions this issue: cmd/compile: fix out of memoery when inlining closure

@dmitshur dmitshur added this to the Go1.25 milestone Mar 3, 2025
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. labels Mar 3, 2025
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Critical A critical problem that affects the availability or correctness of production systems built using Go FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants