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/go/internal/modload: use atomic.Pointer for Requirements.graph #54888

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/cmd/go/internal/modload/buildlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ type Requirements struct {
// nested module back into a parent module).
direct map[string]bool

graphOnce sync.Once // guards writes to (but not reads from) graph
graph atomic.Value // cachedGraph
graphOnce sync.Once // guards writes to (but not reads from) graph
graph atomic.Pointer[cachedGraph]
}

// A cachedGraph is a non-nil *ModuleGraph, together with any error discovered
Expand Down Expand Up @@ -199,7 +199,7 @@ func (rs *Requirements) initVendor(vendorList []module.Version) {
mg.g.Require(vendorMod, vendorList)
}

rs.graph.Store(cachedGraph{mg, nil})
rs.graph.Store(&cachedGraph{mg, nil})
})
}

Expand Down Expand Up @@ -240,9 +240,9 @@ func (rs *Requirements) hasRedundantRoot() bool {
func (rs *Requirements) Graph(ctx context.Context) (*ModuleGraph, error) {
rs.graphOnce.Do(func() {
mg, mgErr := readModGraph(ctx, rs.pruning, rs.rootModules)
rs.graph.Store(cachedGraph{mg, mgErr})
rs.graph.Store(&cachedGraph{mg, mgErr})
})
cached := rs.graph.Load().(cachedGraph)
cached := rs.graph.Load()
return cached.mg, cached.err
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modload/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ func (ld *loader) computePatternAll() (all []string) {
func (ld *loader) checkMultiplePaths() {
mods := ld.requirements.rootModules
if cached := ld.requirements.graph.Load(); cached != nil {
if mg := cached.(cachedGraph).mg; mg != nil {
if mg := cached.mg; mg != nil {
mods = mg.BuildList()
}
}
Expand Down