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/compiler: internal compiler error: converting shape type to interface #48344

Closed
mmrath opened this issue Sep 12, 2021 · 6 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mmrath
Copy link

mmrath commented Sep 12, 2021

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

$ go version
go version devel go1.18-0d8a4bfc96 Sun Sep 12 01:06:53 2021 +0000 darwin/amd64

Does this issue reproduce with the latest release?

No, using master as of today

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

Compile repo at https://github.com/mmrath/validation

I am not able to reduce it to a minimal case but I'll try later tomorrow.

What did you expect to see?

Compile successfully or give some meaningful error

What did you see instead?

BAD FUNCTION
.   DCLFUNC tc(1) Iota:-1 ABI:ABIInternal FUNC-func(uintptr, *StringField[.shape.*uint8]) *StringField[.shape.*uint8] # string_field.go:72:6
.   DCLFUNC-Dcl
.   .   NAME-validation..dict tc(1) Class:PPARAM Offset:0 OnStack uintptr # string_field.go:72:6
.   .   NAME-validation.f tc(1) Class:PPARAM Offset:0 OnStack Used PTR-*StringField[.shape.*uint8] # string_field.go:72:7
.   .   NAME-validation.~r0 tc(1) Class:PPARAMOUT Offset:0 OnStack PTR-*StringField[.shape.*uint8] # string_field.go:72:37
.   DCLFUNC-body
.   .   AS tc(1) # string_field.go:73:10
.   .   .   DOT tc(1) SLICE-[]ValidationRule[.shape.*uint8] # string_field.go:73:3 validation.rules SLICE-[]ValidationRule[.shape.*uint8]
.   .   .   .   DOTPTR tc(1) Implicit validation.FieldValidator[.shape.*uint8] # struct_field.go:29:16 validation.FieldValidator validation.FieldValidator[.shape.*uint8]
.   .   .   .   .   NAME-validation.f tc(1) Class:PPARAM Offset:0 OnStack Used PTR-*StringField[.shape.*uint8] # string_field.go:72:7
.   .   .   APPEND tc(1) SLICE-[]ValidationRule[.shape.*uint8] # string_field.go:73:18 SLICE-[]ValidationRule[.shape.*uint8]
.   .   .   APPEND-Args
.   .   .   .   DOT tc(1) SLICE-[]ValidationRule[.shape.*uint8] # string_field.go:73:20 validation.rules SLICE-[]ValidationRule[.shape.*uint8]
.   .   .   .   .   DOTPTR tc(1) Implicit validation.FieldValidator[.shape.*uint8] # struct_field.go:29:16 validation.FieldValidator validation.FieldValidator[.shape.*uint8]
.   .   .   .   .   .   NAME-validation.f tc(1) Class:PPARAM Offset:0 OnStack Used PTR-*StringField[.shape.*uint8] # string_field.go:72:7
.   .   .   .   CONVIFACE tc(1) Implicit validation.ValidationRule[.shape.*uint8] # struct_field.go:29:16 validation.ValidationRule[.shape.*uint8]
.   .   .   .   .   CALL tc(1) PTR-*rule[.shape.*uint8] # string_field.go:73:43 PTR-*rule[.shape.*uint8]
.   .   .   .   .   .   FUNCINST tc(1) Implicit FUNC-func() *rule[.shape.*uint8] # string_field.go:73:40 FUNC-func() *rule[.shape.*uint8]
.   .   .   .   .   .   .   NAME-validation.notEmptyRule tc(1) Class:PFUNC Offset:0 FUNC-func[T₁₆]() *rule[validation.T₁₆] # string_field.go:14:6
.   .   .   .   .   .   FUNCINST-Targs
.   .   .   .   .   .   .   TYPE .shape.*uint8 tc(1) Offset:0 type .shape.*uint8
.   .   RETURN tc(1) # string_field.go:74:2
.   .   RETURN-Results
.   .   .   NAME-validation.f tc(1) Class:PPARAM Offset:0 OnStack Used PTR-*StringField[.shape.*uint8] # string_field.go:72:7
BAD CONVERSION
.   CONVIFACE tc(1) Implicit validation.ValidationRule[.shape.*uint8] # struct_field.go:29:16 validation.ValidationRule[.shape.*uint8]
.   .   CALL tc(1) PTR-*rule[.shape.*uint8] # string_field.go:73:43 PTR-*rule[.shape.*uint8]
.   .   .   FUNCINST tc(1) Implicit FUNC-func() *rule[.shape.*uint8] # string_field.go:73:40 FUNC-func() *rule[.shape.*uint8]
.   .   .   .   NAME-validation.notEmptyRule tc(1) Class:PFUNC Offset:0 FUNC-func[T₁₆]() *rule[validation.T₁₆] # string_field.go:14:6
.   .   .   FUNCINST-Targs
.   .   .   .   TYPE .shape.*uint8 tc(1) Offset:0 type .shape.*uint8
./struct_field.go:29:16: internal compiler error: converting shape type to interface

@mmrath
Copy link
Author

mmrath commented Sep 12, 2021

I was able to narrow down the issue to the code below in file string_field.go. If I remove this function code compiles fine

func (f *StringField[T]) LengthBetween(min, max int) *StringField[T] {
	f.rules = append(f.rules, lengthBetweenRule[T](min, max))
	return f
}

@cuonglm
Copy link
Member

cuonglm commented Sep 12, 2021

go/types accepts this, unified IR also build ok.

Maybe related to #47775

cc @randall77 @danscales

@cuonglm cuonglm added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 12, 2021
@cuonglm cuonglm added this to the Go1.18 milestone Sep 12, 2021
@korzhao
Copy link
Contributor

korzhao commented Sep 13, 2021

simpler example:

package main


type G[T any] interface {
	g()
}

type Foo[T any] struct {

}
func (foo *Foo[T])g()  {

}

func f[T any](){
	v := []G[T]{}
	v = append(v, &Foo[T]{})
}
func main() {
	f[int]()
}

@danscales danscales self-assigned this Sep 13, 2021
@danscales
Copy link
Contributor

Thanks for the issue @mmrath and the simpler example @korzhao

OK, I understand the issue. It relates to the automatic conversion to an interface in the append() call. I have a fix in a much bigger change, so it will take a few days. Just FYI, you can work around this issue for now by making the conversion to interface be explicit. So, in the simpler example, change to:

   v = append(v, G[T](&Foo[T]{}))

@korzhao

This comment has been minimized.

@gopherbot
Copy link

Change https://golang.org/cl/350309 mentions this issue: go/test: add a test for issue 48344

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants