Skip to content

Conversation

@kovdan01
Copy link
Contributor

@kovdan01 kovdan01 commented Oct 16, 2025

Calling cloneRecursively from SpecializationInfo.cloneClosures requires the callee having ownership info. Otherwise, the cloner uses recordFoldedValue instead of recordClonedInstruction, and postProcess hook is not called, which leads to an assertion failure in BridgedClonerImpl::cloneInst.

…back

Calling `cloneRecursively` from `SpecializationInfo.cloneClosures`
requires the pullback having ownership info. Otherwise, the cloner
uses `recordFoldedValue` instead of `recordClonedInstruction`, and
`postProcess` hook is not called, which leads to an assertion
failure in `BridgedClonerImpl::cloneInst`.

TODO: investigate why the assertion fails only on Linux. See:

* swiftlang#84800 (comment)
* swiftlang#84955
@kovdan01 kovdan01 requested review from asl and xedin October 16, 2025 14:57
@kovdan01
Copy link
Contributor Author

Tagging @JaapWijnen

@kovdan01 kovdan01 marked this pull request as ready for review October 16, 2025 14:57
@kovdan01 kovdan01 requested a review from eeckstein as a code owner October 16, 2025 14:57
@kovdan01
Copy link
Contributor Author

@swift-ci please smoke test

// TODO: investigate why the assertion fails only on Linux. See
// * https://github.com/swiftlang/swift/pull/84800#issuecomment-3398200989
// * https://github.com/swiftlang/swift/issues/84955
partialApply.referencedFunction?.hasOwnership == true
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put this check into isCalleeSpecializable, because we need to check it also in the regular closure specialization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you put this check into isCalleeSpecializable, because we need to check it also in the regular closure specialization

Applied the suggestion in 93169c1, thanks.

// uses `recordFoldedValue` instead of `recordClonedInstruction`, and
// `postProcess` hook is not called, which leads to an assertion
// failure in `BridgedClonerImpl::cloneInst`.
// TODO: investigate why the assertion fails only on Linux. See
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the TODO. It's definitely not working to specialize a non OSSA callee. We just might get lucky on macos

Copy link
Contributor Author

@kovdan01 kovdan01 Oct 16, 2025

Choose a reason for hiding this comment

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

You can remove the TODO. It's definitely not working to specialize a non OSSA callee. We just might get lucky on macos

@eeckstein Do I get you point correct that such a mismatch in ownership between the function containing apply site and the callee is actually a valid behavior? So, we do not need to investigate why the mismatch occurs, but we just need to use this additional check introduced in this PR - is this correct?

If so, I should probably also close the issue #84955 should probably be closed, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do I get you point correct that such a mismatch in ownership between the function containing apply site and the callee is actually a valid behavior?

Yes, currently. This is because the OwnershipModelEliminator is a function pass. And functions are processed bottom-up the call tree. Therefore it can happen that one function is still in OSSA while the other isn't anymore.

This is of course not ideal and I'm going to change the OwnershipModelEliminator to be a module pass (eeckstein@878f3ab on my private branch)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can remove the TODO. It's definitely not working to specialize a non OSSA callee. We just might get lucky on macos

@eeckstein Removed the TODO in 93169c1, thanks for suggestion

@kovdan01 kovdan01 changed the title [AutoDiff] Run closure spec only if ownership info is present in pullback Run closure specialization only if ownership info is present in callee Oct 16, 2025
@kovdan01
Copy link
Contributor Author

@eeckstein I've also changed the PR description and title so it's no longer AutoDiff-specific

@kovdan01 kovdan01 requested a review from eeckstein October 16, 2025 17:42
@kovdan01
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

lgtm

@kovdan01 kovdan01 enabled auto-merge (squash) October 16, 2025 18:12
@asl
Copy link
Contributor

asl commented Oct 16, 2025

@swift-ci smoke test macos platform

2 similar comments
@kovdan01
Copy link
Contributor Author

@swift-ci smoke test macos platform

@xedin
Copy link
Contributor

xedin commented Oct 17, 2025

@swift-ci smoke test macos platform

@kovdan01 kovdan01 merged commit 75f8041 into swiftlang:main Oct 17, 2025
3 checks passed
dendiz pushed a commit to dendiz/swift that referenced this pull request Oct 21, 2025
swiftlang#84956)

Calling `cloneRecursively` from `SpecializationInfo.cloneClosures`
requires the callee having ownership info. Otherwise, the cloner uses
`recordFoldedValue` instead of `recordClonedInstruction`, and
`postProcess` hook is not called, which leads to an assertion failure in
`BridgedClonerImpl::cloneInst`.
speednoisemovement pushed a commit to speednoisemovement/swift that referenced this pull request Oct 29, 2025
swiftlang#84956)

Calling `cloneRecursively` from `SpecializationInfo.cloneClosures`
requires the callee having ownership info. Otherwise, the cloner uses
`recordFoldedValue` instead of `recordClonedInstruction`, and
`postProcess` hook is not called, which leads to an assertion failure in
`BridgedClonerImpl::cloneInst`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants