Skip to content

runtime: result of (*runtime.Func).Name is malformed in go1.24 #71835

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
ShoshinNikita opened this issue Feb 19, 2025 · 6 comments
Closed

runtime: result of (*runtime.Func).Name is malformed in go1.24 #71835

ShoshinNikita opened this issue Feb 19, 2025 · 6 comments
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ShoshinNikita
Copy link

go version: go version go1.24.0 linux/amd64

Consider the following code:

package main

import (
	"fmt"
	"runtime"
)

func main() {
	foo()
}

func foo() {
	fmt.Println("0  ", caller())

	func() {
		fmt.Println("1  ", caller())

		func() {
			fmt.Println("2  ", caller())

			func() {
				fmt.Println("3.1", caller())
			}()

			func() {
				fmt.Println("3.2", caller())
			}()
		}()
	}()
}

func caller() string {
	pc, _, _, ok := runtime.Caller(1)
	if !ok {
		return ""
	}

	return runtime.FuncForPC(pc).Name()
}

With go1.23 (https://go.dev/play/p/ZfX43aWfcTe?v=goprev) I get this output:

0   main.foo
1   main.foo.func1
2   main.foo.func1.1
3.1 main.foo.func1.1.1
3.2 main.foo.func1.1.2

With go1.24 (https://go.dev/play/p/ZfX43aWfcTe):

0   main.foo
1   main.foo.func1
2   main.foo.foo.func1.func2
3.1 main.foo.foo.func1.foo.foo.func1.func2.func3
3.2 main.foo.foo.func1.foo.foo.func1.func2.func4

Note the following changes:

  1. foo is repeated twice: main.foo.foo.func1.func2
  2. Func counter is now bound to top-level function - see func3 and func4
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 19, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 19, 2025
@mknyszek
Copy link
Contributor

This is a runtime API but the names come from the compiler. CC @golang/compiler

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 19, 2025
@mknyszek mknyszek added this to the Backlog milestone Feb 19, 2025
@mknyszek
Copy link
Contributor

@dr2chase In triage, we think that this might be related to more aggressive inlining of once-called closures?

@mknyszek
Copy link
Contributor

Possibly helped by CL 639515?

@ShoshinNikita
Copy link
Author

we think that this might be related to more aggressive inlining of once-called closures

I checked the output before and after cmd/compile: use very high budget for once-called closures (https://go.dev/cl/630696), and I believe you are right:

  • Before d524c95:

    # go version devel go1.24-8b97607280 Fri Nov 22 01:58:53 2024 +0000 linux/amd64
    
    0   main.foo
    1   main.foo.func1
    2   main.foo.func1.1
    3.1 main.foo.func1.1.1
    3.2 main.foo.func1.1.2
    
  • On d524c95:

    # go version devel go1.24-d524c954b1 Fri Nov 22 02:04:41 2024 +0000 linux/amd64
    
    0   main.foo
    1   main.foo.func1
    2   main.foo.foo.func1.func2
    3.1 main.foo.foo.func1.foo.foo.func1.func2.func3
    3.2 main.foo.foo.func1.foo.foo.func1.func2.func4
    

For reference, output with mentioned https://go.dev/cl/639515:

# go version devel go1.24-d1c903cb21 Tue Jan 14 16:59:34 2025 +0100 linux/amd64

0   main.foo
1   main.foo.func1
2   main.foo.func2
3.1 main.foo.func3
3.2 main.foo.func4

I think this issue can be closed in favor of #60324

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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

5 participants