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: constraint type inference for generic types is not implemented #54469

Closed
MrFox131 opened this issue Aug 16, 2022 · 6 comments
Closed
Labels
generics Issue is related to generics NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. TypeInference Issue is related to generic type inference
Milestone

Comments

@MrFox131
Copy link

MrFox131 commented Aug 16, 2022

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

$ go version
go version go1.19 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/mrfox131/.cache/go-build"
GOENV="/home/mrfox131/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mrfox131/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mrfox131/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4107873395=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://go.dev/play/p/e4HeQf10djz

What did you expect to see?

According to https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#pointer-method-example
I expected to see that constraint type inference will work for function type definitions too/

What did you see instead?

Constraint type inference does not work for type definitions where type is some function/

@MrFox131
Copy link
Author

Title format was not really clear for me, so I apologize for the inappropriate title.

@MrFox131 MrFox131 changed the title affected: Generics feature cmd/compile: constraint type inference for type definition fails Aug 16, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 16, 2022
@joedian joedian added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 16, 2022
@MrFox131
Copy link
Author

To be honest struct was not meant in docs, but I found out, that type inference for structs does not work too

https://go.dev/play/p/5JcVfw2zxxN

@ianlancetaylor
Copy link
Contributor

In Go 1.19 constraint type inference only applies to functions, not types. See https://go.dev/cl/404875. We can leave this issue open as a request to try to make this work in the future.

CC @griesemer @findleyr

@ianlancetaylor ianlancetaylor added this to the Backlog milestone Aug 17, 2022
@ianlancetaylor ianlancetaylor added generics Issue is related to generics TypeInference Issue is related to generic type inference and removed compiler/runtime Issues related to the Go compiler and/or runtime. labels Aug 17, 2022
@MrFox131
Copy link
Author

Thanks for the reply. I think if this is implemented it will be much more logical than type inference only for functions. Most likely I will try to do this myself, I am already reading the guideline.

@griesemer
Copy link
Contributor

griesemer commented Aug 17, 2022

It turns out that type inference for types is much more difficult than type inference for functions. A function is not a type and thus cannot be used to instantiate another function or type (nor does it need to be inferred). But a type may be used to instantiate another type, and possibly itself. On top of that, if we combine this with type inference, there are all kinds of cycle problems that we currently can't handle correctly (and don't fully understand), and which may require significant (re-)engineering of the type checker. And it's not even clear that it's desirable as it may make code really difficult to read.

@griesemer griesemer changed the title cmd/compile: constraint type inference for type definition fails cmd/compile: constraint type inference for generic types is not implemented Aug 17, 2022
@griesemer griesemer removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 17, 2022
@joedian joedian added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 19, 2022
@griesemer
Copy link
Contributor

We don't plan to do this. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generics Issue is related to generics NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. TypeInference Issue is related to generic type inference
Projects
None yet
Development

No branches or pull requests

5 participants