-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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/go: missing entry in ImportMap for runtime/cgo [runtime.test]
when -compiled is set
#46462
Comments
972e883 seems to be the commit that introduces the Edit: to clarify, the commit causes the problem to become visible, but it's probably not the underlying reason for the incomplete ImportMap. |
cc @matloob as well. This might be working as intended, but I'm not completely sure. Would be good for others to confirm. Also I'm not at all sure if
I think this is only true for mapping import strings from source files to packages passed to the linker (for example, after vendor resolution). It's not true for implicitly imported packages like The I think this only shows up with the |
[Adding to the Go 1.17 milestone, at least until we can confirm whether this is working as intended.] |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I agree with Jay's assessment. The IMO the real bug here is the fact that there is no |
@dominikh, can you give some more detail on why the entry in |
@bcmills Concretely I ran into this issue because of the logic in https://github.com/golang/tools/blob/7ac129f24ace03f9aa0fa6097083e825536363e9/go/packages/golist.go#L635-L654 which populates a mapping from import paths as they appear in source code to the Package being imported. In Staticcheck I use this mapping when type-checking a package to resolve imports. Concretely, I am currently getting the following error in Staticcheck when checking
The file in question is generated by cmd/cgo and starts like this:
Because of the logic in go/packages, there is no mapping from Now, this might well be a bug in go/packages instead and someone might have to come up with different logic. But I disagree with the notion that "Since the source code does not itself contain the string". No, the code as written by the user does not in fact import runtime/cgo. However, that is not the input to the compiler or linker, either. First, cmd/cgo preprocesses the user's code, and the result of that very much imports runtime/cgo. That code is reflected in CompiledGoFiles. IMO it would make sense for ImportMap to match CompiledGoFiles, not GoFiles. |
Ahh, I see what you mean. The |
runtime/cgo [runtime.test]
runtime/cgo [runtime.test]
when -compiled is set
Thanks for reporting this; I have uncovered a rat's nest under this issue.
go/src/cmd/go/internal/list/list.go Line 505 in 6551763
In then modifies those packages extensively in-place, including expanding the go/src/cmd/go/internal/list/list.go Lines 613 to 615 in 6551763
That is, in fact, the only place where the
The package dependencies actually added to the |
I see a loop here that generates go/src/cmd/go/internal/work/exec.go Lines 734 to 739 in 6551763
But that loop only traverses |
Change https://golang.org/cl/326610 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
go list -json -compiled -test -deps runtime
What did you see?
The package with the ImportPath
net [runtime.test]
has an entry inImports
that readsruntime/cgo [runtime.test]
. However, there is no corresponding entry inImportMap
.It is my understanding that all non-identity imports should have a corresponding entry in
ImportMap
, andgo/packages
has matching logic for populating go/packages.Imports, a mapping from import paths to packages.Note that this does not reproduce without the
-compiled
flag. It also does not reproduce in Go 1.16.4, but in that version, there is no packageruntime/cgo [runtime.test]
in the first place.I am tentatively marking this as a release blocker because it is a regression and affects third party tools, but I may be overstepping here.
/cc @bcmills
The text was updated successfully, but these errors were encountered: