Skip to content

Don’t re-index all files that include a header when a header is modified #1306

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
May 16, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 16, 2024

When a header is modified, we don’t we want to re-index all main files that include it. Instead, we just want to index one main to effectively re-index the header itself.

I originally implemented re-indexing of all files that include the header but on second thought, headers are like Swift modules, where we also don’t re-index all dependencies either. And if you change a low-level header that’s included by the entire project, you probably don’t want the indexer to go off and re-index the entire project.

When a header is modified, we don’t we want to re-index all main files that include it. Instead, we just want to index one main to effectively re-index the header itself.

I originally implemented re-indexing of all files that include the header but on second thought, headers are like Swift modules, where we also don’t re-index all dependencies either. And if you change a low-level header that’s included by the entire project, you probably don’t want the indexer to go off and re-index the entire project.
@ahoppen ahoppen requested review from bnbarham and hamishknight May 16, 2024 03:10
@ahoppen ahoppen requested a review from benlangmuir as a code owner May 16, 2024 03:10
@ahoppen
Copy link
Member Author

ahoppen commented May 16, 2024

@swift-ci Please test

Comment on lines -542 to -548
"MyLibrary/include/OtherHeader.h": "",
"MyLibrary/include/Header.h": """
#include "OtherHeader.h"
void 1️⃣someFunc();
""",
"MyFile.c": """
#include "Header.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth keeping a test that at least checks that transitive includes work for a single file?

let filesToReIndex = await filesToReIndex(changedFiles: events.map(\.uri))

// We only re-index the files that were changed and don't re-index any of their dependencies. See the
// `Documentation/Files_To_Reindex.md` file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does that need updating to mention we only pick one file to reindex?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, thought about that on my way home last night as well and wanted to put up a PR to change that anyway. But well spotted 👍🏽

Comment on lines +305 to +306
guard let target = await buildSystemManager.canonicalConfiguredTarget(for: file.uri) else {
logger.error("Not indexing \(file.uri.forLogging) because the target could not be determined")
Copy link
Contributor

Choose a reason for hiding this comment

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

It probably(?) doesn't matter, but IMO passing the main file here makes more sense since that's the thing we're indexing

Copy link
Member Author

Choose a reason for hiding this comment

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

For canonicalConfiguredTarget(for:): Yes, you’re right, we should use file.mainFile ?? file.uri

For logger.error: Added both file.uri and file.mainFile to the logging message.

// module if one of its dependent modules has changed.
return index.checked(for: .deletedFiles).mainFilesContainingFile(uri: uri, crossLanguage: false)
}.flatMap { $0 }
return Set(filesToReIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given we're no longer uniquing, is there any concern that if e.g 5 headers get modified, and those headers are all included by a single main file, that we could end up running 5 concurrent indexing jobs for that main file?

Copy link
Contributor

Choose a reason for hiding this comment

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

I also didn't really think about the scheduling logic here :) Looking at it again, we'll block the requests on each other, and then they should all be considered up-to-date

Copy link
Member Author

Choose a reason for hiding this comment

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

We don’t actually, because they all have different FileToIndex.uri and thus they would actually be executing in parallel. Fixing that now.

@ahoppen
Copy link
Member Author

ahoppen commented May 16, 2024

Will address review comments in a follow-up PR.

@ahoppen ahoppen merged commit 012a64f into swiftlang:main May 16, 2024
@ahoppen ahoppen deleted the dont-re-index-all-main-files branch May 16, 2024 17:46
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request May 16, 2024
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this pull request May 16, 2024
ahoppen added a commit that referenced this pull request May 20, 2024
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