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

Address review comments to #1306 #1309

Merged
merged 2 commits into from
May 20, 2024
Merged

Conversation

ahoppen
Copy link
Collaborator

@ahoppen ahoppen commented May 16, 2024

A few minor fixes and the following bigger change

Improve handling of main file vs header file during indexing

Essentially fix two issues in updating the index store:

  1. If there was one task to index HeaderA.h through main.c and one to index HeaderB.h through main.c, we would not declare a dependency between them in the task scheduler, which meant that we could have two concurrent and racing index tasks for main.c. Declare a dependency between any two files that have the same main file
  2. UpdateIndexStoreTaskDescription was computing the target to index a file in independently of SemanticIndexManager. While they currently always line up, we should pass the target in which to index a file to the UpdateIndexStoreTaskDescription. Only this way can we guarantee that we actually prepared the target that the file will be indexed in

@ahoppen
Copy link
Collaborator Author

ahoppen commented May 16, 2024

@swift-ci Please test

Affects all files that include the header (including via other headers). For existing headers, we know which files import a header from the existing index. For new header files, we assume that it hasn’t been included in any file yet and so we don’t re-index any file. If it is, it’s likely that the user will modify the file that includes the new header file shortly after, which will re-index it.
All files that include the header (including via other headers) might be affected by the change, similar to how all `.swift` files that import a module might be affected. Similar to modules, we choose to not re-index all files that include the header because of the same considerations mentioned above.

To re-index the header, we pick one main file that includes the header and re-index that, which will effectively update the index for the header. For existing headers, we know which files import a header from the existing index. For new header files, we assume that it hasn’t been included in any file yet and thus don't re-index it. If the header is included from somewhere lese, it’s likely that the user will modify the file that includes the new header file shortly after, which will index the header and establish the header to main file connection.
Copy link
Contributor

@bnbarham bnbarham May 17, 2024

Choose a reason for hiding this comment

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

For new header files, we assume that it hasn’t been included in any file yet and thus don't re-index it

re-index -> index given we haven't actually indexed it yet?

If the header is included from somewhere lese

lese -> else. But also, is the case you're referring to here if it's no longer included in the original file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lese -> else. But also, is the case you're referring to here if it's no longer included in the original file?

Changed it to

If the user wrote an include to the new header before creating the header itself, we don't know about that include from the existing index.

@@ -350,21 +352,21 @@ public final actor SemanticIndexManager {
switch newState {
case .executing:
for file in files {
if case .scheduled((taskID, let task)) = self.indexStatus[file.uri] {
self.indexStatus[file.uri] = .executing((taskID, task))
if case .scheduled((taskID, let task)) = self.indexStatus[file.file.sourceFile] {
Copy link
Contributor

Choose a reason for hiding this comment

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

file.file.sourceFile is... amusing 😅. I don't have a great suggestion here outside of naming sourceFile -> sourceUri and then maybe the variable file -> fileWithTarget. Or just leave them but add a let sourceFile = file.file.sourceFile so we don't have the many references 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed it to fileAndTarget.file.sourceFile. It’s at least a little better.

@ahoppen
Copy link
Collaborator Author

ahoppen commented May 17, 2024

@swift-ci Please test

@ahoppen
Copy link
Collaborator Author

ahoppen commented May 17, 2024

@swift-ci Please test Windows

Essentially fix two issues in updating the index store:
1. If there was one task to index `HeaderA.h` through `main.c` and one to index `HeaderB.h` through `main.c`, we would not declare a dependency between them in the task scheduler, which meant that we could have two concurrent and racing index tasks for `main.c`. Declare a dependency between any two files that have the same main file
2. `UpdateIndexStoreTaskDescription` was computing the target to index a file in independently of `SemanticIndexManager`. While they currently always line up, we should pass the target in which to index a file to the `UpdateIndexStoreTaskDescription`. Only this way can we guarantee that we actually prepared the target that the file will be indexed in.
@ahoppen
Copy link
Collaborator Author

ahoppen commented May 17, 2024

@swift-ci Please test

@ahoppen
Copy link
Collaborator Author

ahoppen commented May 17, 2024

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Collaborator Author

ahoppen commented May 20, 2024

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 3f9ff29 into apple:main May 20, 2024
3 checks passed
@ahoppen ahoppen deleted the review-comments-1306 branch May 20, 2024 20:41
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

3 participants