-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: unexpected crash when using -G=3 with external symbols. #45597
Comments
Update: I've spent few more hours debugging the last crash, and eventually found a fix. diff --git a/src/cmd/compile/internal/noder/types.go b/src/cmd/compile/internal/noder/types.go
index 8680559a41..fee6b5c09c 100644
--- a/src/cmd/compile/internal/noder/types.go
+++ b/src/cmd/compile/internal/noder/types.go
@@ -61,15 +61,19 @@ func (g *irgen) typ1(typ types2.Type) *types.Type {
// instTypeName2 creates a name for an instantiated type, base on the type args
// (given as types2 types).
-func instTypeName2(name string, targs []types2.Type) string {
+func instTypeName2(root *types2.Package, name string, targs []types2.Type) string {
b := bytes.NewBufferString(name)
b.WriteByte('[')
for i, targ := range targs {
if i > 0 {
b.WriteByte(',')
}
- tname := types2.TypeString(targ,
- func(*types2.Package) string { return "" })
+ tname := types2.TypeString(targ, func(pkg *types2.Package) string {
+ if root == nil || pkg == nil || root.Path() == pkg.Path() {
+ return ""
+ }
+ return pkg.Name()
+ })
if strings.Index(tname, ", ") >= 0 {
// types2.TypeString puts spaces after a comma in a type
// list, but we don't want spaces in our actual type names
@@ -105,7 +109,7 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
// based on the names of the type arguments. We need a
// name to deal with recursive generic types (and it also
// looks better when printing types).
- instName := instTypeName2(typ.Obj().Name(), typ.TArgs())
+ instName := instTypeName2(typ.Obj().Pkg(), typ.Obj().Name(), typ.TArgs())
s := g.pkg(typ.Obj().Pkg()).Lookup(instName)
if s.Def != nil {
// We have already encountered this instantiation,
@@ -262,7 +266,7 @@ func (g *irgen) fillinMethods(typ *types2.Named, ntyp *types.Type) {
// generic type, so we have to do a substitution to get
// the name/type of the method of the instantiated type,
// using m.Type().RParams() and typ.TArgs()
- inst2 := instTypeName2("", typ.TArgs())
+ inst2 := instTypeName2(typ.Obj().Pkg(), "", typ.TArgs())
name := meth.Sym().Name
i1 := strings.Index(name, "[")
i2 := strings.Index(name[i1:], "]") Please let me know if this fix looks good. I'll close this issue and open a PR. |
Project members and code owners don't look at or review patches on the issue tracker (for CLA reasons I believe), if you want to propose a fix you'll need to send a PR or a gerrit change. Also please don't close valid issues, they're closed automatically when a patch fixing them is merged. |
cc @griesemer |
Actually, depending on what |
Reading #43931 (the Flag section in the OP) it looks like |
|
This seems to be working with both -G=3 and GOEXPERIMENT=unified at tip on dev.typeparams. Please ping us to reopen if you're still able to reproduce. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
Firstly, create the following two files.
item/item.go
main.go
Then, execute the following commands to compile the codes.
The compiler will first crash with the following logs:
After a tough debugging, I managed to patch types.Identical to fix this crash.
Basically, a struct with type param now also has a non-nil sym. So if we find a struct with sym, instead of returning false, we should allow it to continue to the compare logic for structs.
However, the codes immediately triggered another crash with the following logs:
Apparently, the target here should be
main.wrapper[item.Int]
. I added some codes that explicitly replace everymain.wrapper[Int]
tomain.wrapper[item.Int]
. The compiler just worked like a charm.Then I spend some time walking around, but failed to find where the compiler introduced the improper symbols. So I decide to file an issue here.
The text was updated successfully, but these errors were encountered: