Skip to content

cmd/compile: internal compiler error: weird package in name: p.a => a from "test/p", not "" #51423

Closed

Description

@zhuah

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

$ go version
go version devel go1.19-6da16b6ad5 Tue Mar 1 23:49:01 2022 +0000 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

What did you do?

go compiler panicked with generics code, i made a reproduce demo at: https://go.dev/play/p/F8oOkWnPvfG?v=gotip

-- go.mod --
module test
-- p/p.go --
package p

type Comparator[T any] func(v1, v2 T) int

func CompareInt[T ~int](a, b T) int {
	if a < b {
		return -1
	}
	if a == b {
		return 0
	}
	return 1
}
-- main.go --
package main

import "test/p"

func Comparator() p.Comparator[int] {
	return p.CompareInt[int]
}

func main() {
	Comparator()(1, 2)
}

and the error logs:

# test
./main.go:6:11: internal compiler error: weird package in name: p.a => a from "test/p", not ""

goroutine 1 [running]:
runtime/debug.Stack()
	/usr/local/go/src/runtime/debug/stack.go:24 +0x65
cmd/compile/internal/base.FatalfAt({0x0?, 0x0?}, {0xd40041, 0x2f}, {0xc0000c3308, 0x4, 0x4})
	/usr/local/go/src/cmd/compile/internal/base/print.go:227 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	/usr/local/go/src/cmd/compile/internal/base/print.go:196
cmd/compile/internal/typecheck.(*exportWriter).localIdent(0xc0003ed500?, 0xc0003c4870?)
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:2276 +0x287
cmd/compile/internal/typecheck.(*exportWriter).param(0x40a2f3?, 0xc0003c4a00)
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1130 +0xac
cmd/compile/internal/typecheck.(*exportWriter).paramList(0xc0003ed500, {0xc00008ce70, 0x2, 0xb?})
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1124 +0x50
cmd/compile/internal/typecheck.(*exportWriter).signature(0xc0003ed500, 0xc0003d8730?)
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1097 +0x65
cmd/compile/internal/typecheck.(*exportWriter).expr(0xc0003ed500, {0xe945d0?, 0xc0003d8730?})
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1841 +0x105
cmd/compile/internal/typecheck.(*exportWriter).expr(0xc0003ed500, {0xe948f0?, 0xc0003d86e0?})
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:2021 +0x110f
cmd/compile/internal/typecheck.(*exportWriter).exprList(0xc0003ed500, {0xc00008d210?, 0x1, 0xc000378770?})
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1718 +0x76
cmd/compile/internal/typecheck.(*exportWriter).stmt(0xc0003ed500, {0xe95ed0, 0xc0003d8690})
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1611 +0x91f
cmd/compile/internal/typecheck.(*exportWriter).node(0xc0004a3380?, {0xe95ed0, 0xc0003d8690})
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1520 +0x65
cmd/compile/internal/typecheck.(*exportWriter).stmtList(0xc0003ed500, {0xc00008d1f0?, 0x1, 0xcefda0?})
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1513 +0x76
cmd/compile/internal/typecheck.(*exportWriter).funcBody(0xc0003ed500?, 0xc0003b9080)
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1508 +0x5b
cmd/compile/internal/typecheck.(*iexporter).doInline(0xc00031e6e0, 0xc0003c8680)
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:664 +0xc5
cmd/compile/internal/typecheck.(*exportWriter).funcExt(0xc0003ed3b0, 0xc0003c8680)
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:1445 +0x1cd
cmd/compile/internal/typecheck.(*iexporter).doDecl(0xc00031e6e0, 0xc0003c8680)
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:536 +0x215
cmd/compile/internal/typecheck.WriteExports({0xe8e7e0, 0xc0004a3170}, 0x1)
	/usr/local/go/src/cmd/compile/internal/typecheck/iexport.go:334 +0x2f0
cmd/compile/internal/noder.WriteExports(0xc0004a4430)
	/usr/local/go/src/cmd/compile/internal/noder/export.go:40 +0x7a
cmd/compile/internal/gc.dumpCompilerObj(0xc0004a4430?)
	/usr/local/go/src/cmd/compile/internal/gc/obj.go:107 +0x28
cmd/compile/internal/gc.dumpobj1({0x7ffd5299ac6b, 0x24}, 0x3)
	/usr/local/go/src/cmd/compile/internal/gc/obj.go:63 +0x17b
cmd/compile/internal/gc.dumpobj()
	/usr/local/go/src/cmd/compile/internal/gc/obj.go:44 +0x36
cmd/compile/internal/gc.Main(0xd4e0b0)
	/usr/local/go/src/cmd/compile/internal/gc/main.go:318 +0x1105
main.main()
	/usr/local/go/src/cmd/compile/main.go:55 +0xdd


Go build failed.

What did you expect to see?

What did you see instead?

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Mar 2, 2022
  2. mengzhuo commented on Mar 2, 2022

    @mengzhuo
    Contributor
  3. griesemer commented on Mar 2, 2022

    @griesemer
    Contributor

    @mdempsky The error comes from iexport.go from some code changed in CL 281292. Any insights?

  4. added this to the Go1.18 milestone on Mar 2, 2022
  5. cuonglm commented on Mar 2, 2022

    @cuonglm
    Member

    This seems to me a problem with noder pass. Somehow, the instantiated function was processed twice with inlining? Disable inlining make the code compiled.

    FWIW, the non-generic version works well, and also unified IR code.

  6. randall77 commented on Mar 4, 2022

    @randall77
    Contributor

    I'm not sure entirely what is going on here yet. Might have something to do with function values. if you replace the body of Comparator with:

    return func(x, y int) int { return a.CompareInt[int](x,y) }
    

    Then it works.

  7. aclements commented on Mar 9, 2022

    @aclements
    Member

    Ping. This is marked as a release-blocker and we're very close to the release. Do we understand the underlying issue yet? Given that this causes an ICE instead of mis-compilation, should it be a release-blocker at this point?

  8. cuonglm commented on Mar 9, 2022

    @cuonglm
    Member

    Ping. This is marked as a release-blocker and we're very close to the release. Do we understand the underlying issue yet? Given that this causes an ICE instead of mis-compilation, should it be a release-blocker at this point?

    I think this is a release-blocker, since when it's an ICE on valid code.

  9. cuonglm commented on Mar 10, 2022

    @cuonglm
    Member

    Also cc @danscales

  10. gopherbot commented on Mar 10, 2022

    @gopherbot
    Contributor

    Change https://go.dev/cl/391574 mentions this issue: cmd/compile: fix re-export closure

  11. dr2chase commented on Mar 10, 2022

    @dr2chase
    Contributor

    I'm trying a different approach to this, but thus far lack success. The problem appears to be that "wrong" names are left on a closure signature on an Inl.Body, but those names are probably unimportant. Therefore, when constructing an Inl.Body, strip them out from an OCLOSURE node (which is what causes the problem here) to disappear the problem.

    Unfortunately, that doesn't seem to work, not sure why, and it also causes a single inscrutable failure in typeparam/issue49246.go. So this is not a good approach, yet.

  12. randall77 commented on Mar 11, 2022

    @randall77
    Contributor

    Reopening for backport to 1.18 release branch.

  13. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    and removed
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Mar 11, 2022
  14. gopherbot commented on Mar 11, 2022

    @gopherbot
    Contributor

    Change https://go.dev/cl/391774 mentions this issue: cmd/compile: fix re-export closure

  15. added a commit that references this issue on Mar 14, 2022
    4b9b25a
  16. dmitshur commented on Mar 14, 2022

    @dmitshur
    Member

    Closed by merging commit 4b9b25a (CL 391774) to release-branch.go1.18.

  17. locked and limited conversation to collaborators on Mar 14, 2023
  18. added a commit that references this issue on Apr 29, 2024
    9743e9b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions