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/base, cmd/compile/internal/noder: "importmap" verb of -importcfg file has no effect #61206

Closed
podtserkovskiy opened this issue Jul 6, 2023 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@podtserkovskiy
Copy link
Contributor

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

$ go version
go version go1.20.5 darwin/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="/Users/michaelpo/Library/Caches/go-build"
GOENV="/Users/michaelpo/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/michaelpo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/michaelpo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.20.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.20.5/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/Users/michaelpo/code/gotest/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pc/tv8rh9c925g6dx1wpcc3bpjh0000gn/T/go-build284202503=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I was trying to use "importmap" verb of -importcfg file when run the compiler, but it had no effect.
Looking into the code, I found out that the compiler never use "importmap" from importcfg.
It happens because of this condition which is always true when -importcfg provided.
Because of base.Flag.Cfg.PackageFile never equal to nil due to this line

What did you expect to see?

Actually I don't expect this to be fixed as I've started to use "packagefile" verb instead.
This functionality is dead at the moment (after removing -importmap flag) and -I flag is dead too (unless no -importmap flag provided).
Probably "importmap" verb and -I flag should be just removed to simplify the compiler interface and avoid further confusion.

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. compiler/runtime Issues related to the Go compiler and/or runtime. labels Jul 6, 2023
@seankhliao
Copy link
Member

cc @golang/compiler

@mdempsky
Copy link
Member

mdempsky commented Jul 6, 2023

ImportMap is used here:

if mapped, ok := base.Flag.Cfg.ImportMap[path]; ok {

@mdempsky mdempsky closed this as completed Jul 6, 2023
@podtserkovskiy
Copy link
Contributor Author

podtserkovskiy commented Jul 6, 2023

Sorry I meant it doesn't work in the same way as -importmap flag, so these lines (which searching mapped imports in directories provided by -I) are never executed when -importcfg provided.

@mdempsky
Copy link
Member

mdempsky commented Jul 6, 2023

That's by design. If you use -importcfg, you need to provide a packagefile entry for each imported package. There's no fallback behavior.

@podtserkovskiy
Copy link
Contributor Author

Thanks, I got the idea. The only thing confusing me is that-I flag makes sense only when -importcfg is unset, because the compiler doesn't use base.Flag.Cfg.ImportDirs if base.Flag.Cfg.PackageFile is not nil.
Probably the compiler should return an error if both -I and -importcfg were provided.

@gopherbot
Copy link

Change https://go.dev/cl/577315 mentions this issue: cmd/compile/internal/base: Return error if both flags -I and -importcfg provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants