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: interface conversion with generics reports "types from different scopes" [1.18 backport] #53883

Closed
fractalqb opened this issue Jul 14, 2022 · 9 comments
Assignees
Labels
CherryPickApproved Used during the release process for point releases compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge generics Issue is related to generics
Milestone

Comments

@fractalqb
Copy link

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

$ go version
go version go1.18.4 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/USER/.cache/go-build"
GOENV="/home/USER/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/USER/gows/pkg/mod"
GONOPROXY="athome.fractalqb.de"
GONOSUMDB="athome.fractalqb.de"
GOOS="linux"
GOPATH="/home/USER/gows"
GOPRIVATE="athome.fractalqb.de"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/USER/bin/go1.18.4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/USER/bin/go1.18.4/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/USER/gows/src/git.fractalqb.de/proto/different-scopes-1.18.3/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-build131321195=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Compile this code
package main

import (
	"fmt"

	"github.com/fractalqb/change"
	"github.com/fractalqb/change/chgsql"
)

var id change.Val[uint64]

func main() {
	v := chgsql.Nullable[uint64](&id, 0)
	fmt.Println(v)
}
  1. Run the program
$ ./different-scopes
panic: interface conversion: change.Changeable[go.shape.uint64_0] is *change.Val[uint64], not *change.Val[uint64] (types from different scopes)

goroutine 1 [running]:
github.com/fractalqb/change/chgsql.Nullable[...](...)
	/home/USERgows/pkg/mod/github.com/fractalqb/change@v0.4.1/chgsql/type.go:27
main.main()
	/home/USER/gows/src/git.fractalqb.de/proto/different-scopes-1.18.3/main.go:16 +0x2e

What did you expect to see?

When running the program I expect the output to be: <nil>

When compiling and running with Go 1.18.2 it works as expected. Please also read my remarks on #52027

What did you see instead?

As already mentioned above. Running the Program (compiled with 1.8.4) gives me the output:

panic: interface conversion: change.Changeable[go.shape.uint64_0] is *change.Val[uint64], not *change.Val[uint64] (types from different scopes)

goroutine 1 [running]:
github.com/fractalqb/change/chgsql.Nullable[...](...)
	/home/USERgows/pkg/mod/github.com/fractalqb/change@v0.4.1/chgsql/type.go:27
main.main()
	/home/USER/gows/src/git.fractalqb.de/proto/different-scopes-1.18.3/main.go:16 +0x2e
@fractalqb fractalqb changed the title affected/package: Interface conversion with generics reports "types from different scopes" Jul 14, 2022
@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. generics Issue is related to generics labels Jul 14, 2022
@mknyszek mknyszek added this to the Backlog milestone Jul 14, 2022
@mknyszek mknyszek changed the title Interface conversion with generics reports "types from different scopes" cmd/compile: interface conversion with generics reports "types from different scopes" Jul 14, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 14, 2022
@mknyszek
Copy link
Contributor

CC @golang/compiler

@mdempsky mdempsky self-assigned this Jul 14, 2022
@dr2chase
Copy link
Contributor

So, works okay at go1.19 tip, does not work with the revert to the cause of #53852.

* 2aab162041 (HEAD) Revert "[release-branch.go1.18] cmd/compile: fix missing dict pass for type assertions"
* 460a93b54a [release-branch.go1.18] cmd/compile: fix missing dict pass for type assertions
* 3da88c0bdc [release-branch.go1.18] cmd/compile: fix wrong unsafe.Offsetof evaluation inside generic function
* f0eca661ea [release-branch.go1.18] runtime: store consistent total allocation stats as uint64
* 4068be56ce (tag: go1.18.3) [release-branch.go1.18] go1.18.3

@mdempsky
Copy link
Member

Git bisect seems to have identified e1b14f5 for me. But I was also chasing some false leads earlier due to git bisects and I can't immediately see how that commit could be related, so I'm a bit suspicious still.

@dr2chase
Copy link
Contributor

This is strengthening the case for "generics backports considered harmful".

@mdempsky
Copy link
Member

Adding yet further questions, I think the assert added in that CL is backwards: base.Assertf(typ.Kind() == types.TNIL, "unexpected untyped nil")

But then why are we ending up with a runtime panic, rather than an ICE.

@gopherbot
Copy link

Change https://go.dev/cl/417616 mentions this issue: Revert "[release-branch.go1.18] cmd/compile: backport fix for #51840"

@ernado
Copy link
Contributor

ernado commented Jul 14, 2022

Same as #53376?

@ernado
Copy link
Contributor

ernado commented Jul 14, 2022

IMO this should be fixed in go1.18.5 as unfortunate regression, because this works in go1.18.2.

Probably with reverting some backported CL-s that have introduced this between go1.18.2 and go1.18.3.

If not, there is workaround to use

func f[T a, C A[T]](foo T, bar C)

Instead of

func f[T a](foo T, bar A[T])

@mdempsky mdempsky modified the milestones: Backlog, Go1.18.5 Jul 15, 2022
@mdempsky mdempsky added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 15, 2022
@toothrot toothrot added the CherryPickApproved Used during the release process for point releases label Jul 20, 2022
@toothrot toothrot changed the title cmd/compile: interface conversion with generics reports "types from different scopes" cmd/compile: interface conversion with generics reports "types from different scopes" [1.18 backport] Jul 20, 2022
@dmitshur dmitshur removed the NeedsFix The path to resolution is known, but the work has not been done. label Jul 20, 2022
@gopherbot
Copy link

Closed by merging 76ba1a5 to release-branch.go1.18.

gopherbot pushed a commit that referenced this issue Jul 27, 2022
This reverts CL 405436 (commit e1b14f5).

Fixes #53883.
Updates #51840.

Change-Id: Ide5a9568a7ae5b449ef154c29b69699a7e4b3f6b
Reviewed-on: https://go-review.googlesource.com/c/go/+/417616
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Jul 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CherryPickApproved Used during the release process for point releases compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge generics Issue is related to generics
Projects
None yet
Development

No branches or pull requests

8 participants