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: panic running code that uses generic interface value #51303

Closed
apmckinlay opened this issue Feb 21, 2022 · 9 comments
Closed

cmd/compile: panic running code that uses generic interface value #51303

apmckinlay opened this issue Feb 21, 2022 · 9 comments
Assignees
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@apmckinlay
Copy link

apmckinlay commented Feb 21, 2022

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

$ go version
go version go1.18rc1 darwin/amd64

Does this issue reproduce with the latest release?

gotip playground also fails

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/andrew/Library/Caches/go-build"
GOENV="/Users/andrew/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/andrew/Go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/andrew/Go:/Users/andrew/Dropbox/suneido_tests"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/andrew/sdk/go1.18rc1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/andrew/sdk/go1.18rc1/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18rc1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/andrew/Dropbox/gsuneido18/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dc/0y3gfqnn56g6pd8d3_b5wz300000gn/T/go-build1447860490=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.17.7 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.18rc1
uname -v: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64
ProductName:	macOS
ProductVersion:	12.2.1
BuildVersion:	21D62
lldb --version: lldb-1205.0.27.3
Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)

What did you do?

https://gotipplay.golang.org/p/Gg7oSlfPoHI

What did you expect to see?

no error

What did you see instead?

It appears to fail on: if x.Equal(xe, ye) {
Although if you comment out the following append line, then it passes.

In the gotip playground it gives:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4b1501]

On my Mac it gives:

runtime: unexpected return pc for runtime.sigpanic
=== RUN   TestIntersectSS
xe [1]
ye [2 3]
x [[1]]
runtime: unexpected return pc for runtime.sigpanic called from 0x1127eda
stack: frame={sp:0xc00007cd80, fp:0xc00007cdd0} stack=[0xc00007c000,0xc00007d000)
0x000000c00007cc80:  0x000000c00007cc88  0x0000000001032580 
0x000000c00007cc90:  0x0000000001047c76   0x000000c00007cd80
0x000000c00007cca0:  0x000000c000138340  0x0000000000000000
0x000000c00007ccb0:  0x000000c00007cd70  0x0000000001032d46 
0x000000c00007ccc0:  0x0000000000000001  0x0000000001101da0
0x000000c00007ccd0:  0x000000c000104078  0x000000c0000240a0
0x000000c00007cce0:  0x0000000000000000  0x0000000000000000
0x000000c00007ccf0:  0x000000000107d6c0   0x000000c000104060
0x000000c00007cd00:  0x000000c00007ccf0  0x000000c00007cd70
0x000000c00007cd10:  0x0000000001068b5e   0x000000c000104060
0x000000c00007cd20:  0x000000c00007cd48  0x000000c000138360
0x000000c00007cd30:  0x000000c000138340  0x0000000000000000
0x000000c00007cd40:  0x0000000001102ac0  0x00000000011f2ca0
0x000000c00007cd50:  0x0000000000000000  0x0000000000000000
0x000000c00007cd60:  0x0000000000000000  0x0000000000000000
0x000000c00007cd70:  0x000000c00007cdc0  0x0000000001047c76 
0x000000c00007cd80: <0x0000000001102ac0  0x00000000011f2ca0
0x000000c00007cd90:  0x0000000000000008  0x000000c00007cdc0
0x000000c00007cda0:  0x0000000000000008  0x000000c000103110
0x000000c00007cdb0:  0x0000000000000000  0x0000000000000000
0x000000c00007cdc0:  0x000000c00007cef8 !0x0000000001127eda
0x000000c00007cdd0: >0x0000000001149620  0x000000c00000e018
0x000000c00007cde0:  0x000000c00007ce98  0x0000000000000002
0x000000c00007cdf0:  0x0000000000000002  0x0000000000000000
0x000000c00007ce00:  0x00000000010b2a80   0x00000000011d40c8
0x000000c00007ce10:  0x0000000000000000  0x0000000000000000
0x000000c00007ce20:  0x0000000000000002  0x0000000000000002
0x000000c00007ce30:  0x0000000000000001  0x0000000000000001
0x000000c00007ce40:  0x0000000000000000  0x0000000000000000
0x000000c00007ce50:  0x0000000000000000  0x000000c0000162c0
0x000000c00007ce60:  0x000000c0000162b8  0x000000c00007cf48
0x000000c00007ce70:  0x000000c00000c090  0x000000c00000c090
0x000000c00007ce80:  0x000000c000088f10  0x0000000000000001
0x000000c00007ce90:  0x0000000000000001  0x00000000010fcd00
0x000000c00007cea0:  0x0000000001148d80  0x0000000001101da0
0x000000c00007ceb0:  0x000000c00000c0d8  0x00000000010fcd00
0x000000c00007cec0:  0x0000000001148d70  0x00000000010fab00
fatal error: unknown caller pc

runtime stack:
runtime.throw({0x111ff47?, 0x11e4180?})
/Users/andrew/sdk/go1.18rc1/src/runtime/panic.go:992 +0x71
runtime.gentraceback(0xc000138340?, 0x10648df?, 0xc00007cbe8?, 0x11fbde0?, 0x0, 0x0, 0x7fffffff, 0x7ff7bfeff468, 0x20?, 0x0)
/Users/andrew/sdk/go1.18rc1/src/runtime/traceback.go:254 +0x1a36
runtime.addOneOpenDeferFrame.func1()
/Users/andrew/sdk/go1.18rc1/src/runtime/panic.go:599 +0x6b
runtime.systemstack()
/Users/andrew/sdk/go1.18rc1/src/runtime/asm_amd64.s:469 +0x49

goroutine 4 [running]:
runtime.systemstack_switch()
/Users/andrew/sdk/go1.18rc1/src/runtime/asm_amd64.s:436 fp=0xc00007cc80 sp=0xc00007cc78 pc=0x1060880
runtime.addOneOpenDeferFrame(0x1?, 0x1101da0?, 0xc000104078?)
/Users/andrew/sdk/go1.18rc1/src/runtime/panic.go:598 +0x69 fp=0xc00007ccc0 sp=0xc00007cc80 pc=0x1032529
panic({0x1102ac0, 0x11f2ca0})
/Users/andrew/sdk/go1.18rc1/src/runtime/panic.go:798 +0x106 fp=0xc00007cd80 sp=0xc00007ccc0 pc=0x1032d46
runtime: unexpected return pc for runtime.sigpanic called from 0x1127eda
stack: frame={sp:0xc00007cd80, fp:0xc00007cdd0} stack=[0xc00007c000,0xc00007d000)
0x000000c00007cc80: 0x000000c00007cc88 0x0000000001032580 <runtime.addOneOpenDeferFrame.func1+0x0000000000000000>
0x000000c00007cc90: 0x0000000001047c76 <runtime.sigpanic+0x0000000000000336> 0x000000c00007cd80
0x000000c00007cca0: 0x000000c000138340 0x0000000000000000
0x000000c00007ccb0: 0x000000c00007cd70 0x0000000001032d46 <runtime.gopanic+0x0000000000000106>
0x000000c00007ccc0: 0x0000000000000001 0x0000000001101da0
0x000000c00007ccd0: 0x000000c000104078 0x000000c0000240a0
0x000000c00007cce0: 0x0000000000000000 0x0000000000000000
0x000000c00007ccf0: 0x000000000107d6c0 <internal/poll.(*FD).Write.func1+0x0000000000000000> 0x000000c000104060
0x000000c00007cd00: 0x000000c00007ccf0 0x000000c00007cd70
0x000000c00007cd10: 0x0000000001068b5e <sync.(*Pool).pin+0x000000000000001e> 0x000000c000104060
0x000000c00007cd20: 0x000000c00007cd48 0x000000c000138360
0x000000c00007cd30: 0x000000c000138340 0x0000000000000000
0x000000c00007cd40: 0x0000000001102ac0 0x00000000011f2ca0
0x000000c00007cd50: 0x0000000000000000 0x0000000000000000
0x000000c00007cd60: 0x0000000000000000 0x0000000000000000
0x000000c00007cd70: 0x000000c00007cdc0 0x0000000001047c76 <runtime.sigpanic+0x0000000000000336>
0x000000c00007cd80: <0x0000000001102ac0 0x00000000011f2ca0
0x000000c00007cd90: 0x0000000000000008 0x000000c00007cdc0
0x000000c00007cda0: 0x0000000000000008 0x000000c000103110
0x000000c00007cdb0: 0x0000000000000000 0x0000000000000000
0x000000c00007cdc0: 0x000000c00007cef8 !0x0000000001127eda
0x000000c00007cdd0: >0x0000000001149620 0x000000c00000e018
0x000000c00007cde0: 0x000000c00007ce98 0x0000000000000002
0x000000c00007cdf0: 0x0000000000000002 0x0000000000000000
0x000000c00007ce00: 0x00000000010b2a80 <testing.tRunner+0x0000000000000000> 0x00000000011d40c8
0x000000c00007ce10: 0x0000000000000000 0x0000000000000000
0x000000c00007ce20: 0x0000000000000002 0x0000000000000002
0x000000c00007ce30: 0x0000000000000001 0x0000000000000001
0x000000c00007ce40: 0x0000000000000000 0x0000000000000000
0x000000c00007ce50: 0x0000000000000000 0x000000c0000162c0
0x000000c00007ce60: 0x000000c0000162b8 0x000000c00007cf48
0x000000c00007ce70: 0x000000c00000c090 0x000000c00000c090
0x000000c00007ce80: 0x000000c000088f10 0x0000000000000001
0x000000c00007ce90: 0x0000000000000001 0x00000000010fcd00
0x000000c00007cea0: 0x0000000001148d80 0x0000000001101da0
0x000000c00007ceb0: 0x000000c00000c0d8 0x00000000010fcd00
0x000000c00007cec0: 0x0000000001148d70 0x00000000010fab00
runtime.panicmem(...)
/Users/andrew/sdk/go1.18rc1/src/runtime/panic.go:220
runtime.sigpanic()
/Users/andrew/sdk/go1.18rc1/src/runtime/signal_unix.go:818 +0x336 fp=0xc00007cdd0 sp=0xc00007cd80 pc=0x1047c76
created by testing.(*T).Run
/Users/andrew/sdk/go1.18rc1/src/testing/testing.go:1486 +0x35f

goroutine 1 [chan receive]:
testing.(*T).Run(0xc000138000, {0x111f5f4?, 0xa93fd983ba5?}, 0x1127d00)
/Users/andrew/sdk/go1.18rc1/src/testing/testing.go:1487 +0x37a
testing.runTests.func1(0xc000100450?)
/Users/andrew/sdk/go1.18rc1/src/testing/testing.go:1839 +0x6e
testing.tRunner(0xc000138000, 0xc000131cd8)
/Users/andrew/sdk/go1.18rc1/src/testing/testing.go:1439 +0x102
testing.runTests(0xc000116140?, {0x11f2f40, 0x1, 0x1}, {0x128c108?, 0x40?, 0x11fb6e0?})
/Users/andrew/sdk/go1.18rc1/src/testing/testing.go:1837 +0x457
testing.(*M).Run(0xc000116140)
/Users/andrew/sdk/go1.18rc1/src/testing/testing.go:1719 +0x5d9
main.main()
_testmain.go:47 +0x1aa
FAIL github.com/apmckinlay/gsuneido/util/generic/bug 0.352s

@ianlancetaylor
Copy link
Contributor

At first glance this does seem to be a bug in the dictionary code somewhere.

CC @randall77 @danscales

@ianlancetaylor ianlancetaylor changed the title generics runtime panic cmd/compile: panic running code that uses generic interface value Feb 21, 2022
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 21, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Feb 21, 2022
@danscales
Copy link
Contributor

This is an interesting issue. I haven't totally figured out all the details, but it relates to the way we create shape types for instantiations. The complex case here is when we already have a shape type, then we construct a new compound type from that that shape, and we end up using that as a type arg to another generic function. I think we're not always handling things correctly in the case where the type arg has a shape type in it, but is not a top-level shape type (i.e. we have a shape type S, and compound type arg we are passing to another generic function is []S).

@danscales danscales self-assigned this Feb 23, 2022
@danscales
Copy link
Contributor

I have a rough fix. Will need to think on it a bit more and discuss with @randall77 .

@gopherbot
Copy link

Change https://go.dev/cl/387674 mentions this issue: cmd/compile: deal with constructed types that have shapes in them

@danscales
Copy link
Contributor

Keith and I are still discussing the most complete way to fix this.

gopherbot pushed a commit that referenced this issue Feb 28, 2022
We convert type args to shape types inside instantiations. If an
instantiation constructs a compound type based on that shape type and
uses that as a type arg to another generic function being called, then
we have a type arg with a shape type embedded inside of it. In that
case, we need to substitute out those embedded shape types with their
underlying type.

If we don't do this, we may create extra unneeded shape types that
have these other shape types embedded in them. This may lead to
generating extra shape instantiations, and a mismatch between the
instantiations that we used in generating dictionaries and the
instantations that are actually called.

Updates #51303

Change-Id: Ieef894a5fac176cfd1415f95926086277ad09759
Reviewed-on: https://go-review.googlesource.com/c/go/+/387674
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@danscales
Copy link
Contributor

I have submitted my fix, after discussion with Keith and some extra prototyping. This issue still needs to be investigated for Go 1.19 (best way to deal with these types created from shape types), but removing it from release blocker.

@apmckinlay
Copy link
Author

Sounds good, thanks.

@randall77 randall77 modified the milestones: Go1.18, Go1.19 Mar 3, 2022
@ianlancetaylor
Copy link
Contributor

@randall77 What is the current status here? This issue is currently in the 1.19 milestone. Should it move to 1.20? To Backlog? Thanks.

@randall77
Copy link
Contributor

I don't think there's anything actionable here right now.
The original reproducer no longer compiles. (Some tightening of type inference rules?)
Dan's CL fixed the immedate bug, we just left this open to think about whether there might be a better fix.

I'm going to close. Please feel free to reopen if we have a compileable reproducer.

@golang golang locked and limited conversation to collaborators Jul 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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