Skip to content

Cache declaration diagnostics #1058

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

Merged
merged 1 commit into from
Jun 5, 2025
Merged

Cache declaration diagnostics #1058

merged 1 commit into from
Jun 5, 2025

Conversation

jakebailey
Copy link
Member

All other forms of diags are cached (placed on a SourceFile by parse/bind, or stored in a Checker); declaration diags are calculated on the fly, so we need a separate cache for them.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a cache for declaration diagnostics on the Program to avoid recalculating them on every request.

  • Introduce a declarationDiagnosticCache field using collections.SyncMap
  • Import the collections package
  • Update getDeclarationDiagnosticsForFile to load from and store to the cache
Comments suppressed due to low confidence (3)

internal/compiler/program.go:69

  • Add a comment above declarationDiagnosticCache explaining its purpose, expected lifecycle, and that the zero-value of SyncMap is safe to use, to clarify initialization semantics.
declarationDiagnosticCache collections.SyncMap[*ast.SourceFile, []*ast.Diagnostic]

internal/compiler/program.go:521

  • Consider adding unit tests for getDeclarationDiagnosticsForFile to verify that diagnostics are indeed cached after the first call and not recomputed on subsequent calls.
if cached, ok := p.declarationDiagnosticCache.Load(sourceFile); ok {

internal/compiler/program.go:526

  • [nitpick] In high-concurrency scenarios, multiple goroutines could compute diagnostics simultaneously before the cache is populated; consider using a singleflight or similar mechanism to dedupe concurrent computations.
diagnostics := getDeclarationDiagnostics(host, host.GetEmitResolver(sourceFile, true), sourceFile)

@jakebailey jakebailey added this pull request to the merge queue Jun 5, 2025
Merged via the queue into main with commit e58aed7 Jun 5, 2025
23 checks passed
@jakebailey jakebailey deleted the jabaile/dts-diag-cache branch June 5, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants