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 compiler error: found illegal assignment on test example #56916

Open
esimov opened this issue Nov 23, 2022 · 4 comments
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@esimov
Copy link

esimov commented Nov 23, 2022

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

$ go version
go version go1.18.5 linux/amd64

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/esimo/.cache/go-build"
GOENV="/home/esimo/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/esimo/projects/Go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/esimo/projects/Go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/esimo/projects/Go/src/esimov/torx/go.mod"
GOWORK="/home/esimo/projects/Go/src/esimov/go.work"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1479111117=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I was experimenting with generics and implemented a service retry utility function which looks like the following (some irrelevant part might be skipped):

func TestFunc_RetryWithDelay(t *testing.T) {
	rand.Seed(time.Now().UTC().UnixNano())

	assert := assert.New(t)

	n := 5
	idx := 0
	ForEach([]int{1, 2, 3, 4, 5, 6, 7}, func(val int) {
		rt := RType[int]{Input: val}
		d, att, e := rt.RetryWithDelay(n, 20*time.Millisecond, func(d time.Duration, elem int) (err error) {
			if elem%2 != 0 {
				err = fmt.Errorf("retry failed: number of %d attempts exceeded", n)
			}
			return err
		})
		switch idx {
		case 0, 2:
			assert.GreaterOrEqual(int(d.Milliseconds()), 100)
			assert.Equal(5, att)
			assert.Error(e)
		case 1, 3:
			assert.LessOrEqual(int(d.Milliseconds()), 10)
			assert.Equal(0, att)
			assert.NoError(e)
		}
		idx++
	})

	// In this example we are simulating an external service. In case the response time
	// exceeds a certain time limit we stop retrying and an error is returned.
	services := []struct {
		service string
		time    time.Duration
	}{
		{service: "AWS1"},
		{service: "AWS2"},
	}

	type Service[T ~string] struct {
		Service T
		Time    time.Duration
	}

	for _, srv := range services {
		r := random(1, 10)

		// Here we are simulating the response time of the external service
		// by generating some random duration between 1ms and 10ms.
		// All the test should pass because all of the responses are inside the predefined limit (10ms).
		service := Service[string]{
			Service: srv.service,
			Time:    time.Duration(r) * time.Millisecond,
		}
		rtyp := RType[Service[string]]{
			Input: service,
		}

		d, att, e := rtyp.RetryWithDelay(n, 20*time.Millisecond, func(d time.Duration, srv Service[string]) (err error) {
			if srv.Time.Milliseconds() > 10 {
				err = fmt.Errorf("retry failed: service time exceeded")
			}
			return err
		})
		assert.NoError(e)
		assert.Equal(0, att)
		assert.LessOrEqual(int(d.Milliseconds()), 10)
	}

	for _, srv := range services {
		r := random(20, 30)

		// Here we are simulating the response time of the external service
		// by generating some random duration between 20ms and 30ms.
		// All the test should fail because all of the responses are outside the predefined limit (10ms).
		service := Service[string]{
			Service: srv.service,
			Time:    time.Duration(r) * time.Millisecond,
		}
		rtyp := RType[Service[string]]{
			Input: service,
		}

		d, att, e := rtyp.RetryWithDelay(n, 20*time.Millisecond, func(d time.Duration, srv Service[string]) (err error) {
			if srv.Time.Milliseconds() > 10 {
				err = fmt.Errorf("retry failed: service time exceeded")
			}
			return err
		})
		assert.Error(e)
		assert.Equal(5, att)
		assert.Greater(int(d.Milliseconds()), 10)
	}
}

This is working correctly, without producing any kind of issues, but if I'm trying to replicate the same test function as an example, I'm getting the following error:

internal compiler error: found illegal assignment torx.Service[string] -> torx.Service[string];
Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
func Example_FuncRetryWithDelay() {
	n := 5

	// Here we are simulating an external service. In case the response time
	// exceeds a certain limit we stop retrying and we are returning an error.
	services := []struct {
		service string
		time    time.Duration
	}{
		{service: "AWS1"},
		{service: "AWS2"},
	}

	type Service[T ~string] struct {
		Service T
		Time    time.Duration
	}

	for _, srv := range services {
		r := random(1, 10)
		// Here we are simulating the response time of the external service
		// by generating some random duration between 1ms and 10ms.
		// All the test should pass because all of the responses are inside the predefined limit (10ms).
		service := Service[string]{
			Service: srv.service,
			Time:    time.Duration(r) * time.Millisecond,
		}
		rtyp := RType[Service[string]]{
			Input: service, // -------> this is causing the above error.
		}

		d, att, e := rtyp.RetryWithDelay(n, 20*time.Millisecond, func(d time.Duration, srv Service[string]) (err error) {
			if srv.Time.Milliseconds() > 10 {
				err = fmt.Errorf("retry failed: service time exceeded")
			}
			return err
		})
		fmt.Println(e)
		fmt.Println(att)
		fmt.Println(d.Milliseconds())
	}

	// Output:
	// 
}

What did you expect to see?

To run without any kind of errors.

What did you see instead?

The error I mentioned above.

@andig
Copy link
Contributor

andig commented Nov 23, 2022

Does this reproduce on 1.19?

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 23, 2022
@esimov
Copy link
Author

esimov commented Nov 23, 2022

Yes, it's still reproducing with Go 1.19.3.

$ go version
go version go1.19.3 linux/amd64

@seankhliao
Copy link
Member

seankhliao commented Nov 23, 2022

does it reproduce with tip and can you provide a self contained reproducer?

@esimov
Copy link
Author

esimov commented Nov 24, 2022

Here is the self contained reproducer: https://go.dev/play/p/fKiLojMe4D5. Interestingly enough it does not reproduce here. But I have tried on two different instances: go1.19.3 running under Windows WSL and another one go1.18.5 and it does reproduce on both instances.

@seankhliao seankhliao changed the title test: internal compiler error: found illegal assignment on test example cmd/compile: internal compiler error: found illegal assignment on test example Nov 24, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 24, 2022
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. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants