Skip to content

Conversation

@rjmansfield
Copy link
Contributor

This PR fixes several issues with the optimization record handling and is a continuation of #2054 with multiple commits.

Handles multiple producers error by ensuring each input file gets a unique optimization record output path across all compilation modes.

All the various compilation modes make path selection somewhat complicated so the priority is output file map > explicit flags > derived from input filename

Within output file map entries:

For single-threaded WMO: module-level entry > per-file entry > derived
For multi-threaded WMO: per-file entry > derived (but never module-level)
For non-WMO: per-file entry > derived

If both output file map entries and explicit -save-optimization-record-path flags are specified, the output file map wins and a warning is emitted.

When no output file map entry exists, explicit -save-optimization-record-path flags are used. Otherwise, paths are derived from input filenames.

Several tests were added to cover the various compilation modes and scenarios.

rdar://164884975
rdar://164494085

@rjmansfield rjmansfield requested a review from artemcm January 13, 2026 20:26
@rjmansfield
Copy link
Contributor Author

@swift-ci please test

@rjmansfield
Copy link
Contributor Author

@swift-ci please test

@rjmansfield
Copy link
Contributor Author

@swift-ci please test

@rjmansfield rjmansfield force-pushed the fix-opt-record-handling branch from bb85e95 to 248e531 Compare January 14, 2026 18:07

// In multi-threaded WMO with -save-optimization-record but no explicit paths or file map entries,
// pass nil to trigger per-file path generation
let isMultiThreadedWMOWithAutoGenPaths = !compilerMode.usesPrimaryFileInputs && numThreads > 1 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

This scenario adds a decent amount of complexity overall. What do you think of not supporting this flow? That is, rely on the build system to ensure it either specifies a single top-level entry for single-threaded WMO or specifies per-file entries otherwise.

Would there be an existing use case or build system we break if we emit an error on this kind of configuration (single output path flag but per-input opt records)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know enough about all the use cases to say how much we'd break if we made this an error. I suspect not a lot, but I was considering cases like: swiftc -wmo -num-threads 2 -save-optimization-record file1.swift file2.swift, or makefiles in embedded projects that use -wmo that might also use -num_threads > 1 with -save-optimization-record. I suspect erroring would mainly break the command line usage, and partial output file map entries, but probably both are edge cases.

The other option would be to add this as a temporary measure with a deprecation warning for multithreaded WMO w/o per file paths, to flush out any misuses? Let me know which you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, I hadn't thought through the workflow of just the -save-optimization-record without any explicit path arguments at all.

I agree these are edge cases but it seems more reasonable to keep this around as a shorthand, thanks for explaining.

Copy link
Contributor

@artemcm artemcm left a comment

Choose a reason for hiding this comment

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

Just the above comment about lifting up the various checks for single-treaded WMO into a computed property, and otherwise LGTM, thanks.

This infrastructure is needed for both primary file mode and multi-threaded
WMO optimization record fixes.
Validate that multi-threaded WMO with explicit paths requires one path per source file

rdar://164494085
Module-level entries should only apply to single-threaded WMO.
Add warning when both explicit -save-optimization-record-path and file map entries exist
@rjmansfield rjmansfield force-pushed the fix-opt-record-handling branch from 248e531 to ad91f4a Compare January 28, 2026 18:14
@rjmansfield
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@rjmansfield
Copy link
Contributor Author

@swift-ci please test

@rjmansfield rjmansfield merged commit d6af921 into swiftlang:main Jan 29, 2026
16 of 17 checks passed
@rjmansfield rjmansfield deleted the fix-opt-record-handling branch January 29, 2026 13:38
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