Skip to content

Commit

Permalink
ssa: fix map key has typeargs
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Sep 16, 2024
1 parent a1572d5 commit 0436d18
Show file tree
Hide file tree
Showing 17 changed files with 11,854 additions and 9,469 deletions.
504 changes: 270 additions & 234 deletions cl/_testgo/equal/out.ll

Large diffs are not rendered by default.

313 changes: 157 additions & 156 deletions cl/_testgo/errors/out.ll

Large diffs are not rendered by default.

860 changes: 485 additions & 375 deletions cl/_testgo/interface/out.ll

Large diffs are not rendered by default.

2,010 changes: 1,025 additions & 985 deletions cl/_testgo/invoke/out.ll

Large diffs are not rendered by default.

2,879 changes: 1,467 additions & 1,412 deletions cl/_testgo/reader/out.ll

Large diffs are not rendered by default.

409 changes: 212 additions & 197 deletions cl/_testgo/strucintf/out.ll

Large diffs are not rendered by default.

469 changes: 242 additions & 227 deletions cl/_testgo/struczero/out.ll

Large diffs are not rendered by default.

9,507 changes: 5,298 additions & 4,209 deletions cl/_testrt/abinamed/out.ll

Large diffs are not rendered by default.

669 changes: 354 additions & 315 deletions cl/_testrt/eface/out.ll

Large diffs are not rendered by default.

341 changes: 191 additions & 150 deletions cl/_testrt/funcdecl/out.ll

Large diffs are not rendered by default.

933 changes: 476 additions & 457 deletions cl/_testrt/makemap/out.ll

Large diffs are not rendered by default.

481 changes: 247 additions & 234 deletions cl/_testrt/tpabi/out.ll

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions cl/_testrt/tpmap/in.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

type T1 int

type T2 struct {
v int
}

type T3[T any] struct {
v T
}

type cacheKey struct {
t1 T1
t2 T2
t3 T3[any]
t4 *int
t5 uintptr
}

func main() {
m := map[cacheKey]string{}
m[cacheKey{0, T2{0}, T3[any]{0}, nil, 0}] = "world"
v, ok := m[cacheKey{0, T2{0}, T3[any]{0}, nil, 0}]
println(v, ok)
}
708 changes: 708 additions & 0 deletions cl/_testrt/tpmap/out.ll

Large diffs are not rendered by default.

1,192 changes: 675 additions & 517 deletions cl/_testrt/tpmethod/out.ll

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,19 @@ func (p *context) patchType(typ types.Type) types.Type {
if pkg := o.Pkg(); typepatch.IsPatched(pkg) {
if patch, ok := p.patches[pkg.Path()]; ok {
if obj := patch.Types.Scope().Lookup(o.Name()); obj != nil {
return p.prog.Type(obj.Type(), llssa.InGo).RawType()
otyp := obj.Type()
if tp := t.TypeArgs(); tp != nil {
targs := make([]types.Type, tp.Len())
for i := 0; i < tp.Len(); i++ {
targs[i] = tp.At(i)

Check warning on line 927 in cl/compile.go

View check run for this annotation

Codecov / codecov/patch

cl/compile.go#L923-L927

Added lines #L923 - L927 were not covered by tests
}
var err error
otyp, err = types.Instantiate(nil, obj.Type(), targs, true)
if err != nil {
panic(fmt.Errorf("patchType error: %v", err))

Check warning on line 932 in cl/compile.go

View check run for this annotation

Codecov / codecov/patch

cl/compile.go#L929-L932

Added lines #L929 - L932 were not covered by tests
}
}
return p.prog.Type(otyp, llssa.InGo).RawType()

Check warning on line 935 in cl/compile.go

View check run for this annotation

Codecov / codecov/patch

cl/compile.go#L935

Added line #L935 was not covered by tests
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions ssa/abitype.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,14 @@ func (b Builder) abiType(t types.Type) Expr {
case *types.Map:
b.abiType(t.Key())
b.abiType(t.Elem())
case *types.Slice:
b.abiType(t.Elem())
case *types.Chan:
b.abiType(t.Elem())
case *types.Struct:
for i := 0; i < t.NumFields(); i++ {
b.abiType(t.Field(i).Type())
}
}
g := b.loadType(t)
return b.Load(g.Expr)
Expand Down

0 comments on commit 0436d18

Please sign in to comment.