Skip to content

Pass IPI Clang module names to the Swift compiler#1404

Merged
sepy97 merged 1 commit into
swiftlang:mainfrom
sepy97:ipi-clang-modules
Jun 30, 2026
Merged

Pass IPI Clang module names to the Swift compiler#1404
sepy97 merged 1 commit into
swiftlang:mainfrom
sepy97:ipi-clang-modules

Conversation

@sepy97

@sepy97 sepy97 commented May 14, 2026

Copy link
Copy Markdown
Contributor

When a Swift target is compiled, swift-build now computes which Clang modules in its transitive dependency closure should be treated as IPI (project-internal) and passes their names via frontend flags.

The SKIP_INSTALL condition covers target-produced modules including auto-generated modulemaps. The SRCROOT condition covers explicit modulemaps committed to a project's source tree regardless of SKIP_INSTALL.

rdar://177010683

@sepy97

sepy97 commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@sepy97

sepy97 commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test Windows

@sepy97 sepy97 force-pushed the ipi-clang-modules branch from 0f31e31 to 31593d9 Compare May 15, 2026 17:58
@sepy97

sepy97 commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@sepy97

sepy97 commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test macOS

@sepy97

sepy97 commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test Linux

@sepy97 sepy97 force-pushed the ipi-clang-modules branch from 31593d9 to b1bda18 Compare May 27, 2026 20:05
@sepy97

sepy97 commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@sepy97 sepy97 force-pushed the ipi-clang-modules branch from b1bda18 to 6c17a71 Compare June 1, 2026 22:15
@sepy97

sepy97 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@sepy97 sepy97 marked this pull request as ready for review June 1, 2026 22:15
/// For each consumer target, the names of Clang modules in its transitive deps that should
/// be treated as IPI — a dep with `SKIP_INSTALL=YES` and a `MODULEMAP_FILE` resolving to a
/// path under any `SRCROOT` in the closure.
package private(set) var ipiClangModuleNamesByTarget: [ConfiguredTarget: [String]]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Instead of exposing this via settings and adding it to all the cache keys, can we access it from the task producer directly via the globalProductPlan?

}()
guard skipInstall || modulemapUnderSRCROOT else { continue }
let name = scope.evaluate(BuiltinMacros.PRODUCT_MODULE_NAME)
if !name.isEmpty {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It might be an ok heuristic to use, but if MODULEMAP_FILE or MODULEMAP_FILE_CONTENTS is set the module(s) defined by the modulemap might not actually be named $(PRODUCT_MODULE_NAME)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great catch! This change should also support manually written modulemaps. I was thinking of using knownClangModuleNames via computeModuleInfo(), but this case is there under FIXME...

// Test -ipi-clang-module emission for a Clang IPI (SKIP_INSTALL=YES + MODULEMAP_FILE under SRCROOT).
@Test(.requireSDKs(.macOS))
func ipiClangModuleBasic() async throws {
if try await !swiftFeatures.has(.ipiClangModule) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you can use requireSwiftFeatures(.foo) to skip the test entirely instead

@sepy97 sepy97 force-pushed the ipi-clang-modules branch from 6c17a71 to 5d9d48d Compare June 4, 2026 22:33
@sepy97

sepy97 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

let allTargets = [configuredTarget] + deps
// Collect the set of project-internal roots for this consumer.
var srcroots: Set<Path> = []
for target in allTargets {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will repeat the module name calculation for a target every time it appears in the transitive closure of another. Can we have a top level loop over all the targets which first computes the module name, then do the transitive closure computation later?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, thanks for catching it!

@sepy97 sepy97 force-pushed the ipi-clang-modules branch from 5d9d48d to 2b8779e Compare June 9, 2026 21:06
@sepy97 sepy97 requested a review from owenv June 9, 2026 21:07
@sepy97

sepy97 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@sepy97 sepy97 enabled auto-merge June 9, 2026 22:54
}
var names: Set<String> = []
for target in allTargets {
guard let info = ipiInfoByTarget[target], info.producesClangModule else { continue }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This inner loop is still pretty expensive, can we build the sets up incrementally while doing a postorder DFS of the graph?

@sepy97 sepy97 disabled auto-merge June 11, 2026 18:29
@sepy97 sepy97 force-pushed the ipi-clang-modules branch from 2b8779e to a1418a2 Compare June 30, 2026 19:09
@sepy97 sepy97 requested a review from rjmansfield as a code owner June 30, 2026 19:09
When a Swift target is compiled, swift-build now computes which Clang
modules in its transitive dependency closure should be treated as IPI
(project-internal) and passes their names via compiler flags.

The SKIP_INSTALL condition covers target-produced modules including
auto-generated modulemaps. The SRCROOT condition covers explicit
modulemaps committed to a project's source tree regardless of SKIP_INSTALL.

rdar://177010683
@sepy97 sepy97 force-pushed the ipi-clang-modules branch from a1418a2 to 20ce517 Compare June 30, 2026 19:10
@sepy97

sepy97 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@sepy97 sepy97 requested a review from owenv June 30, 2026 21:59
@sepy97 sepy97 merged commit 7053c2f into swiftlang:main Jun 30, 2026
111 of 126 checks passed
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