-
Notifications
You must be signed in to change notification settings - Fork 379
Index targets top-down instead of bottom up #2684
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -781,10 +781,15 @@ package actor SwiftPMBuildServer: BuiltInBuildServer { | |
|
|
||
| package func prepare(request: BuildTargetPrepareRequest) async throws -> BuildTargetPrepareResponse { | ||
| // TODO: Support preparation of multiple targets at once. (https://github.com/swiftlang/sourcekit-lsp/issues/1262) | ||
| var implicitlyPreparedTargets: [BuildTargetIdentifier] = [] | ||
| for target in request.targets { | ||
| await orLog("Preparing") { try await prepare(singleTarget: target) } | ||
| await orLog("Preparing") { | ||
| try await prepare(singleTarget: target) | ||
| implicitlyPreparedTargets += transitiveClosure(of: [target], successors: { targetDependencies[$0] ?? [] }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to worry about BSP servers that may choose a different platform for the target vs one of its dependencies? e.g If the current run destination is macOS and we try to prepare A, a BSP might reasonably decide to fallback and prepare it using iOS instead, since that's the only thing it supports. B then also gets prepared for iOS. But if you ask for preparation of B with a macOS run destination, naturally you'd expect macOS. cc @AnthonyLatsis who might also have thoughts here
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Targets in BSP are always configured targets for one particular platform. So we can’t have a target that is for multiple platforms here. |
||
| .filter { !request.targets.contains($0) } | ||
| } | ||
| } | ||
| return BuildTargetPrepareResponse() | ||
| return BuildTargetPrepareResponse(implicitlyPreparedTargets: implicitlyPreparedTargets) | ||
| } | ||
|
|
||
| private func prepare(singleTarget target: BuildTargetIdentifier) async throws { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -960,7 +960,9 @@ package final actor SemanticIndexManager { | |
| // The targets sorted in reverse topological order, low-level targets before high-level targets. If topological | ||
| // sorting fails, sorted in another deterministic way where the actual order doesn't matter. | ||
| var sortedTargets: [BuildTargetIdentifier] = | ||
| await orLog("Sorting targets") { try await buildServerManager.topologicalSort(of: Array(filesByTarget.keys)) } | ||
| await orLog("Sorting targets") { | ||
| try await buildServerManager.targetsSortedForIndexing(Array(filesByTarget.keys)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you think it sorts them in an odd way? It shouldn’t be any more odd than it is today, right? |
||
| } | ||
| ?? Array(filesByTarget.keys).sorted { $0.uri.stringValue < $1.uri.stringValue } | ||
|
|
||
| if Set(sortedTargets) != Set(filesByTarget.keys) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this does feel like it's undermining the previous sorting a bit, since now this means we'll potentially index files from dependency packages before files in the root package, right? Should we be maintaining the root/dependency package split?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does. But in practice I have found that the bottleneck to indexing is exclusively target preparation. So, if we chose to not index these files, a processor core would likely just be sitting idle. Furthermore, since all the preparation tasks are scheduled before the file index tasks, we should always prefer a target preparation over file indexing.