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 on checking size for type looped chan #47901

Closed
wdvxdr1123 opened this issue Aug 23, 2021 · 4 comments
Closed

cmd/compile: panic on checking size for type looped chan #47901

wdvxdr1123 opened this issue Aug 23, 2021 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@wdvxdr1123
Copy link
Contributor

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

$ go version
go version devel go1.18-86ee89225ae Sun Aug 22 23:49:55 2021 +0000 windows/amd64

What did you do?

package main

type Chan[T any] chan  Chan[T]

func(ch Chan[T]) recv() Chan[T] {
	return <-ch
}

func main() {
	ch := Chan[int](make(chan Chan[int]))
	go func() {
		ch <- make(Chan[int])
	}()
	ch.recv()
}

What did you expect to see?

no error

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0xa0 pc=0xa3f902]

goroutine 1 [running]:
cmd/compile/internal/ir.(*Name).TypeDefn(0x1176100)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/ir/name.go:146 +0x22
cmd/compile/internal/types.findTypeLoop(0xc00038e230, 0xc00009ee98)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/types/size.go:273 +0x290
cmd/compile/internal/types.reportTypeLoop(0xc00038e230)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/types/size.go:311 +0x65
cmd/compile/internal/types.CalcSize(0xc00038e230)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/types/size.go:472 +0x68b
cmd/compile/internal/types.ResumeCheckSize()
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/types/size.go:616 +0x4e
cmd/compile/internal/types.CalcSize(0xc00038e2a0)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/types/size.go:555 +0xb1e
cmd/compile/internal/types.CheckSize(0xc00038e2a0)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/types/size.go:595 +0x156
cmd/compile/internal/typecheck.(*Tsubster).Typ(0xc0000a6598, 0xc000358930)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/typecheck/subr.go:1167 +0x83b
cmd/compile/internal/noder.(*subster).localvar(0xc0000a6580, 0xc00038a270)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:757 +0x69
cmd/compile/internal/noder.(*irgen).genericSubst(0xc0000b2300, 0xc00038d4a0, 0xc00038a0d0, {0xc000006670, 0x1, 0x1}, 0x1, 0xc0003862c0)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:686 +0x72e
cmd/compile/internal/noder.(*irgen).getInstantiation(0xc0000b2300, 0xc00038a0d0, {0xc000006600, 0x1, 0x1}, 0x30)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:600 +0x33d
cmd/compile/internal/noder.(*irgen).instantiateMethods(0xc0000b2300)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:503 +0x1cb
cmd/compile/internal/noder.(*irgen).stencil(0xc0000b2300)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:50 +0x9b
cmd/compile/internal/noder.(*irgen).generate(0xc0000b2300, {0xc000006458, 0x1, 0xc0000f0900})
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:265 +0x272
cmd/compile/internal/noder.check2({0xc000006458, 0x1, 0x1})
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc0000aa110, 0x1, 0x0})
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x365
cmd/compile/internal/gc.Main(0x11b0d38)
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/internal/gc/main.go:190 +0xaf3
main.main()
        C:/Users/wdvxdr/sdk/gotip/src/cmd/compile/main.go:55 +0xdd
@cuonglm
Copy link
Member

cuonglm commented Aug 23, 2021

This seems to be problem with -G=3 cc @danscales @randall77

Unified IR and gotype both accept the program.

@cuonglm cuonglm added this to the Go1.18 milestone Aug 23, 2021
@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 23, 2021
@wdvxdr1123
Copy link
Contributor Author

I deleted these lines, and compiled successfully. But I'not sure it is correct.

if !newt.HasTParam() {
// TODO(danscales): not sure why I have to do this
// only for channels.....
types.CheckSize(newt)
}

@danscales
Copy link
Contributor

One of our other tests, go/test/typeparam/chans.go fails without those lines. But we really don't want those lines (and they cause problems in other cases such as yours), so we will work on figuring out the chans.go issue and a better way to fix it. The CalcSize/CheckSize is always an issue - should really just be done by one pass through all the relevant types closer to the back end.

@mvdan mvdan changed the title cmd/compile: compiler ice on checking size for type looped chan. cmd/compile: panic on checking size for type looped chan Aug 23, 2021
@gopherbot
Copy link

Change https://golang.org/cl/344829 mentions this issue: cmd/compile: fix CheckSize() calculation for -G=3 and stencils

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