Skip to content

[IncrementalCompilation] Support prefix-mapped paths and external module resolution#2128

Open
cachemeifyoucan wants to merge 1 commit into
swiftlang:mainfrom
cachemeifyoucan:eng/PR-174330691
Open

[IncrementalCompilation] Support prefix-mapped paths and external module resolution#2128
cachemeifyoucan wants to merge 1 commit into
swiftlang:mainfrom
cachemeifyoucan:eng/PR-174330691

Conversation

@cachemeifyoucan
Copy link
Copy Markdown
Contributor

@cachemeifyoucan cachemeifyoucan commented Apr 27, 2026

  • Add prefixMapping to IncrementalDependencyAndInputSetup, threaded from Driver. Provide reverseMapPath() to convert prefix-mapped paths back to real paths during .swiftdeps and priors deserialization.
  • Add pathReverser to SourceFileDependencyGraph deserialization so all identifier strings in .swiftdeps files are reverse-mapped at read time.
  • Apply pathReverser during priors graph deserialization as well.
  • Add externalModulePathMap to ExternalDependencyCurrencyCache for resolving abstract module paths (e.g. "B.swiftmodule") to absolute paths during filesystem currency checks. Populated from ExplicitDependencyBuildPlanner scanning results.
  • Serialize/deserialize externalModulePathMap in priors file via new externalModulePathNode record (version bumped to 1.6.0).
  • Add integration tests for caching and prefix-mapped caching incremental builds, including upstream dependency invalidation with diagnostics.

Assisted-By: Claude

  • Explanation: Fixes incremental build for caching prefix mapping configuration to correctly identify unchanged dependency to avoid rebuilds.
  • Scope: Caching incremental build only.
  • Issues: rdar://174330691
  • Risk: Low. Limited scope and supports a configuration that wasn't previously well supported.
  • Testing: Unit-tests

Copy link
Copy Markdown
Contributor

@hjyamauchi hjyamauchi left a comment

Choose a reason for hiding this comment

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

Does this cover the cases for the abstract paths for binary modules as in swiftlang/swift#88113 (comment) ?

@cachemeifyoucan
Copy link
Copy Markdown
Contributor Author

I don't know why issue 88113 is related here. That problem should be resolved and the example is not using prefix mapping.

Prefix mapping is to abstract the path away to allow cache hits regardless of the source/module path and in such case, swift-driver will abstract the path away so that can happen. For regular caching build, there is no path abstraction anymore, so it should just work.

If you want to try path prefix mapping, I think this patch should fix the incremental build. If you try it and let me know if you still see problem.

@cachemeifyoucan
Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@cachemeifyoucan
Copy link
Copy Markdown
Contributor Author

@swift-ci please test

Comment thread Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift Outdated
Comment thread Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift Outdated
Comment thread Sources/SwiftDriver/IncrementalCompilation/ModuleDependencyGraph.swift Outdated
let resolvedPath = VirtualPath.lookup(details.compiledModulePath.path).name
return (abstractPath, resolvedPath)
})
initialState.graph.setExternalModulePathMap(map)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure I follow: when will the deserialized external module map path from a prior build get used if we re-compute it from scan results every time?

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.

Sometimes you don't scan when doing incremental build, and you need to map the path to figure out if you need to scan or not. This is for that purpose.

…ule resolution

- Add prefixMapping to IncrementalDependencyAndInputSetup, threaded from
  Driver. Provide reverseMapPath() to convert prefix-mapped paths back to
  real paths during .swiftdeps and priors deserialization.
- Add pathReverser to SourceFileDependencyGraph deserialization so all
  identifier strings in .swiftdeps files are reverse-mapped at read time.
- Apply pathReverser during priors graph deserialization as well.
- Add externalModulePathMap to ExternalDependencyCurrencyCache for
  resolving abstract module paths (e.g. "B.swiftmodule") to absolute
  paths during filesystem currency checks. Populated from
  ExplicitDependencyBuildPlanner scanning results.
- Serialize/deserialize externalModulePathMap in priors file via new
  externalModulePathNode record (version bumped to 1.6.0).
- Add integration tests for caching and prefix-mapped caching incremental
  builds, including upstream dependency invalidation with diagnostics.

rdar://174330691

Assisted-By: Claude
@cachemeifyoucan
Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@cachemeifyoucan
Copy link
Copy Markdown
Contributor Author

@swift-ci please test windows platform

@cachemeifyoucan
Copy link
Copy Markdown
Contributor Author

ping

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.

3 participants