Skip to content

Commit

Permalink
Update marker.Collector to fix bug of markers
Browse files Browse the repository at this point in the history
Markers are saved per `*ast.TypeSpec`, which is specific to `Package` object.
`*ast.TypeSpec` in another `Package` object is different even when
the `Package.ID` is the same, and so collected markers cannot be reused
for another `Package` object.

Therefore, `Package` itself is used as a key for cache of markers
insetead of `Package.ID`.

For more details about the bug, see #783.
  • Loading branch information
ntoofu committed Apr 9, 2023
1 parent 32940b6 commit b73fdf7
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/markers/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
type Collector struct {
*Registry

byPackage map[string]map[ast.Node]MarkerValues
byPackage map[*loader.Package]map[ast.Node]MarkerValues
mu sync.Mutex
}

Expand All @@ -53,7 +53,7 @@ func (c *Collector) init() {
c.Registry = &Registry{}
}
if c.byPackage == nil {
c.byPackage = make(map[string]map[ast.Node]MarkerValues)
c.byPackage = make(map[*loader.Package]map[ast.Node]MarkerValues)
}
}

Expand All @@ -75,7 +75,7 @@ func (c *Collector) init() {
func (c *Collector) MarkersInPackage(pkg *loader.Package) (map[ast.Node]MarkerValues, error) {
c.mu.Lock()
c.init()
if markers, exist := c.byPackage[pkg.ID]; exist {
if markers, exist := c.byPackage[pkg]; exist {
c.mu.Unlock()
return markers, nil
}
Expand All @@ -91,8 +91,7 @@ func (c *Collector) MarkersInPackage(pkg *loader.Package) (map[ast.Node]MarkerVa

c.mu.Lock()
defer c.mu.Unlock()
c.byPackage[pkg.ID] = markers

c.byPackage[pkg] = markers
return markers, nil
}

Expand Down

0 comments on commit b73fdf7

Please sign in to comment.