Skip to content

Move version from source file to document registry #1075

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 3 commits into from
Jun 6, 2025

Conversation

gabritto
Copy link
Member

@gabritto gabritto commented Jun 5, 2025

The version really only concerns the project and document registry, so I moved it there to avoid a data race in #991 where we cache SourceFiles.

@Copilot Copilot AI review requested due to automatic review settings June 5, 2025 23:24
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

This PR relocates version tracking from the AST SourceFile itself into the central DocumentRegistry to prevent data races when caching source files.

  • Replaces direct SourceFile.Version checks with a registry-backed getFileVersion lookup in snapshot and print logic
  • Adds a version field to registryEntry and updates it whenever a new parse occurs
  • Removes the now-unneeded Version field from ast.SourceFile

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/project/project.go Switched version comparisons to use getFileVersion and added a proxy method on Project
internal/project/documentregistry.go Introduced version in registryEntry, updated parsing logic, and added getFileVersion
internal/ast/ast.go Removed the deprecated Version field from SourceFile
Comments suppressed due to low confidence (2)

internal/project/documentregistry.go:122

  • New getFileVersion logic in DocumentRegistry lacks unit tests to ensure it correctly retrieves the stored version (and returns -1 when missing).
func (r *DocumentRegistry) getFileVersion(file *ast.SourceFile, options *core.CompilerOptions) int {

internal/project/project.go:1033

  • The proxy Project.getFileVersion method is untested; consider adding tests to validate it correctly delegates to the registry.
func (p *Project) getFileVersion(file *ast.SourceFile, options *core.CompilerOptions) int {

@gabritto gabritto requested a review from sheetalkamat June 5, 2025 23:26
@gabritto gabritto changed the title Move version from source file to document registry Move version from source file to document registry Jun 5, 2025
@jakebailey jakebailey requested a review from andrewbranch June 5, 2025 23:34
@gabritto gabritto mentioned this pull request Jun 6, 2025
func (r *DocumentRegistry) getFileVersion(file *ast.SourceFile, options *core.CompilerOptions) int {
key := newRegistryKey(options, file.Path(), file.ScriptKind)
if entry, ok := r.documents.Load(key); ok {
return entry.version
Copy link
Member

Choose a reason for hiding this comment

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

This is not enough i think. The source file may have been updated for the compilerOptions by other program and hence the source file may be newer = script info version. You actually want to check if file == entry.sourceFile as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks!

@gabritto gabritto requested a review from sheetalkamat June 6, 2025 14:17
@gabritto gabritto added this pull request to the merge queue Jun 6, 2025
Merged via the queue into main with commit 8188edd Jun 6, 2025
23 checks passed
@gabritto gabritto deleted the gabritto/fileversion branch June 6, 2025 15:50
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.

None yet

4 participants