Skip to content

cmd/compile: functions with type parameters cannot inline multiple levels deep across packages #56280

@prattmic

Description

@prattmic

What version of Go are you using (go version)?

$ go version
go version devel go1.20-da6042e82e Mon Oct 17 15:59:12 2022 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes (1.19)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/usr/local/google/home/mpratt/.cache/go-build"
GOENV="/usr/local/google/home/mpratt/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/google/home/mpratt/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/usr/local/google/home/mpratt/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/google-golang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20-pre3 cl/474093167 +a813be86df"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/usr/local/google/home/mpratt/Downloads/inlinegenerics/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build512352002=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Build https://go.dev/play/p/X7fahXzzE38

What did you expect to see?

result = input.ViaGenericPageOffset inlined as a single AND.

What did you see instead?

input.ViaGenericPageOffset() is inlined as pkg.GenericPageOffset[example.com/pkg.Addr](input), even though the non-inline version of pkg.Addr.ViaGenericPageOffset fully inlines GenericPageOffset.

TEXT example.com/pkg.Addr.ViaGenericPageOffset(SB) /usr/local/google/home/mpratt/Downloads/inlinegenerics/pkg/pkg.go
  pkg.go:24             0x457600                25ff0f0000              ANDL $0xfff, AX         
  pkg.go:24             0x457605                c3                      RET                     

TEXT example.com/pkg.Addr.ViaConcretePageOffset(SB) /usr/local/google/home/mpratt/Downloads/inlinegenerics/pkg/pkg.go
  pkg.go:28             0x457620                25ff0f0000              ANDL $0xfff, AX         
  pkg.go:28             0x457625                c3                      RET                     

TEXT example.com/pkg.GenericPageOffset[go.shape.uintptr](SB) /usr/local/google/home/mpratt/Downloads/inlinegenerics/pkg/pkg.go
  pkg.go:14             0x457640                81e3ff0f0000            ANDL $0xfff, BX         
  pkg.go:14             0x457646                4889d8                  MOVQ BX, AX             
  pkg.go:14             0x457649                c3                      RET                     

TEXT main.main(SB) /usr/local/google/home/mpratt/Downloads/inlinegenerics/main.go
  main.go:12            0x457660                493b6610                CMPQ 0x10(R14), SP                                                              
  main.go:12            0x457664                767b                    JBE 0x4576e1                                                                    
  main.go:12            0x457666                4883ec18                SUBQ $0x18, SP                                                                  
  main.go:12            0x45766a                48896c2410              MOVQ BP, 0x10(SP)                                                               
  main.go:12            0x45766f                488d6c2410              LEAQ 0x10(SP), BP
# result = input.ViaConcretePageOffset()
  main.go:13            0x457674                488b0dc58a0900          MOVQ main.input(SB), CX                                                         
  pkg.go:28             0x45767b                90                      NOPL                                                                            
  pkg.go:18             0x45767c                81e1ff0f0000            ANDL $0xfff, CX                                                                 
  main.go:13            0x457682                48890dbf8a0900          MOVQ CX, main.result(SB)      
# result = input.ViaGenericPageOffset()
  main.go:14            0x457689                488b1db08a0900          MOVQ main.input(SB), BX                                                         
  pkg.go:24             0x457690                488d05593b0200          LEAQ example.com/pkg..dict.GenericPageOffset[example.com/pkg.Addr](SB), AX      
  pkg.go:24             0x457697                e8a4ffffff              CALL example.com/pkg.GenericPageOffset[go.shape.uintptr](SB)                    
  main.go:14            0x45769c                488905a58a0900          MOVQ AX, main.result(SB)          
...

If the contents of pkg are moved into package main (https://go.dev/play/p/8WY0mElNpV3), then input.ViaGenericPageOffset is inlined into main.main exactly the same as input.ViaConcretePageOffset. I do not expect this behavior to depend on which package the code is in.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgecompiler/runtimeIssues related to the Go compiler and/or runtime.genericsIssue is related to generics

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions