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/internal/importer, go/internal/importer (+friends): can't import 'any' underlying #49888

Closed
findleyr opened this issue Nov 30, 2021 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker Soon This needs to be done soon. (regressions, serious bugs, outages)
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Nov 30, 2021

The following logic is replicated to a few of our importers:

	if t, ok := p.typCache[off]; ok && (base == nil || !isInterface(t)) {
		return t
	}

https://cs.opensource.google/go/go/+/master:src/go/internal/gcimporter/iimport.go;l=258;drc=f90a42b41080cf5a289f151f2166d0d0a795e836

As a result, we don't use the cached, predeclared any when considering the RHS of a type declaration, as in

type Any any

When importing this code, we get

cannot import <package> (predeclared type missing from cache: 31), possibly version skew - reinstall package

(it is unfortunate that we did not add test coverage for this pattern, once any was allowed out of constraint position)

Notably, cmd/compile/internal/typecheck does not appear to have this problem:
https://cs.opensource.google/go/go/+/master:src/cmd/compile/internal/typecheck/iimport.go;l=745;drc=229b90931312aa1686f4bace25d1f40f896884ad

Discussing with @griesemer, we're not sure why that guard is necessary. Certainly it seems OK to add an exception for any there. If this doesn't work out, we may need to revert #49583, which would be unfortunate.

CC @mdempsky and @danscales who may have additional context, @heschi for awareness.

@findleyr findleyr added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker Soon This needs to be done soon. (regressions, serious bugs, outages) labels Nov 30, 2021
@findleyr findleyr added this to the Go1.18 milestone Nov 30, 2021
@gopherbot
Copy link

gopherbot commented Nov 30, 2021

Change https://golang.org/cl/367851 mentions this issue: gcimporters: cache and reuse interface types on RHS of type decls

@findleyr
Copy link
Contributor Author

findleyr commented Dec 1, 2021

Looked at this a bit more. The original problem is that we use the LHS of type declaration as the receiver type in interface methods on the RHS, so such RHS interfaces can't be reused. Possibly we could stop doing this, but that's not a decision for now. To fix this bug, we can just allow reusing empty interfaces.

@dmitshur
Copy link
Contributor

dmitshur commented Dec 1, 2021

This issue is currently filed as release blocking and not okay after beta 1, so the Go 1.18 beta 1 is being blocked on it.

@findleyr
Copy link
Contributor Author

findleyr commented Dec 1, 2021

This issue is currently filed as release blocking and not okay after beta 1, so the Go 1.18 beta 1 is being blocked on it.

Yes, this is definitely a release blocker. The CL to fix it is pending.

@findleyr findleyr self-assigned this Dec 1, 2021
@gopherbot
Copy link

gopherbot commented Dec 1, 2021

Change https://golang.org/cl/368254 mentions this issue: all: gofmt -w -r 'interface{} -> any' src

@gopherbot
Copy link

gopherbot commented Dec 1, 2021

Change https://golang.org/cl/368354 mentions this issue: go/internal/gcimporter: allow reusing empty interfaces on the RHS of

gopherbot pushed a commit to golang/tools that referenced this issue Dec 1, 2021
type decls

This is a port of CL 367851 to x/tools. The test set-up is slightly
different; I added a TODO to converge.

Updates golang/go#49888

Change-Id: I31a63c1fc8f9a78526d8eea05fd01dae35770b5f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/368354
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker Soon This needs to be done soon. (regressions, serious bugs, outages)
Projects
None yet
Development

No branches or pull requests

3 participants