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

cmd/compiler: internal compiler error: converting shape type to interface #48344

mmrath opened this issue Sep 12, 2021 · 6 comments
Assignees
Labels
Milestone

Comments

@mmrath
Copy link

@mmrath 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 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 cuonglm commented Sep 12, 2021

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

Maybe related to #47775

cc @randall77 @danscales

@cuonglm cuonglm added this to the Go1.18 milestone Sep 12, 2021
@korzhao
Copy link
Contributor

@korzhao 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

@danscales danscales commented Sep 13, 2021

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 hidden.

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 16, 2021

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

@gopherbot gopherbot closed this in 9ebe7c8 Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants