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: dictionary for [...] should only use concrete types #52181

Closed
pepjo opened this issue Apr 6, 2022 · 11 comments
Closed

cmd/compile: dictionary for [...] should only use concrete types #52181

pepjo opened this issue Apr 6, 2022 · 11 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@pepjo
Copy link

pepjo commented Apr 6, 2022

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

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/peprf/.cache/go-build"
GOENV="/home/peprf/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/peprf/go/pkg/mod"
GONOPROXY="git.o-c.space*"
GONOSUMDB="git.o-c.space*"
GOOS="linux"
GOPATH="/home/peprf/go"
GOPRIVATE="git.o-c.space*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/peprf/sdk/go1.18"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/peprf/sdk/go1.18/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/peprf/projects/satellite-gateway-service/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2035439223=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I used a complicated mess of generics, interfaces, and maps. Then, tried to run a unit test with the --race flag.

I've only managed to reproduce this using 2 different packages.

  • file at /[your project]/pkg/application/bug/bug_test.go

    package bug
    
    import (
        "testing"
    
        "[your project]/pkg/application/other"
    )
    
    type Provider interface {
        Run(other.FetcherByName[other.Something]) ([]byte, error)
    }
    
    func TestNothing(t *testing.T) {}
  • file at /[your project]/pkg/application/other/entities.go

    package other
    
    import "fmt"
    
    type Fetcher[thingType Something] struct {
        Thing thingType
    }
    
    func (a Fetcher[thingType]) Get() thingType {
        return a.Thing
    }
    
    type Something interface {
        Name() string
    }
    
    type FetcherByName[thingType Something] map[string]Fetcher[thingType]
    
    func (tp FetcherByName[thingType]) GetFetcherOfThing(t thingType) {
        fetcher := tp[t.Name()]
        fmt.Printf("The fetcher %v for things %s", fetcher, t.Name())
    }

With these files, run:

go test --race ./pkg/application/bug --short

What did you expect to see?

The same that I see without the --race flag:

ok      [your project]/pkg/application/bug     0.001s

What did you see instead?

the output of go test --race ./pkg/application/bug --short is:

# [your project]/pkg/application/bug [[your project]/pkg/application/bug.test]
<autogenerated>:1: internal compiler error: dictionary for Fetcher[go.shape.interface { Name() string }_0].Get should only use concrete types: go.shape.interface { Name() string }_0

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
FAIL    [your project]/pkg/application/bug [build failed]
FAIL
@mengzhuo mengzhuo changed the title Compiler error: dictionary for [...] should only use concrete types cmd/compile: dictionary for [...] should only use concrete types Apr 6, 2022
@ianlancetaylor
Copy link
Contributor

CC @randall77 @mdempsky

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 6, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Apr 6, 2022
@ThinkChaos
Copy link

Ran into this with go1.18.1 linux/amd64. Workaround is simple: retry, unfortunately for fixing this, it doesn't seem to occur often.

@pepjo
Copy link
Author

pepjo commented May 7, 2022

At least in 1.18.0, retrying does not seem to solve the issue. We had to add an exception rule in our CI to allow the test to fail. Since I posted this, it has run hundreds of times and it has never worked.

@jfesler
Copy link

jfesler commented Jun 17, 2022

Running into this one too with debug builds inside Goland.

@mdempsky
Copy link
Member

This appears to work correctly at tip, so another CL must have fixed it.

I don't see any other issue reports mentioning the same error message though. I'm also not able to reproduce the issue except with go test -race, which seems novel and surprising.

@mdempsky
Copy link
Member

If anyone wants to bisect the CL that fixed the issue, that would be useful information.

@ZekeLu
Copy link
Contributor

ZekeLu commented Jun 18, 2022

The bisect shows that 5b4fafd is the commit that fixes this issue.

@ianlancetaylor
Copy link
Contributor

Thanks. Closing. Please comment if you disagree.

@iSerganov
Copy link

Can be easily reproduced using golang 1.18.4 during test run with -race flag when there is a generic map used like below:

type CoolCache[TK constraints.Ordered, TV interface{}] struct {
	mux  sync.Mutex
	data map[TK]Item[TV]
	ttl  time.Duration
}

@anacrolix
Copy link
Contributor

I can also reproduce this consistently, when importing github.com/anacrolix/stm/stmutil from a very large program. I cannot share the program, but perhaps the size is resulting in a map that is not deterministically sorted.

@ZekeLu
Copy link
Contributor

ZekeLu commented Aug 29, 2022

The commit 5b4fafd that fixes this issue is in go 1.19. I just confirmed that the original issue does not reproduce in go 1.19.

I have tried to cherry-pick the commit to the release-branch.go1.18 branch, and it works too. Maybe the fix should be backport to go 1.18.

@golang golang locked and limited conversation to collaborators Aug 29, 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

9 participants