Skip to content

[AutoDiff] Use LinkEntity::SecondaryPointer for diff witness #82412

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

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

kovdan01
Copy link
Contributor

If LinkEntity::isTypeKind() is true, IRGenModule::getAddrOfLLVMVariable assumes that we can safely call LinkEntity::getType(), which does reinterpret_cast of LinkEntity::Pointer to TypeBase *. However, for SIL differentiability witness, the pointer has SILDifferentiabilityWitness * type, which is not derived from TypeBase. So, such a cast is not allowed.

Just as with ProtocolWitnessTableLazyAccessFunction and ProtocolWitnessTableLazyCacheVariable link entity kinds (which are also type kinds), we should use SecondaryPointer instead of Pointer for storing payload here, while setting Pointer to nullptr.

If `LinkEntity::isTypeKind()` is true, `IRGenModule::getAddrOfLLVMVariable`
assumes that we can safely call `LinkEntity::getType()`, which does
`reinterpret_cast` of `LinkEntity::Pointer` to `TypeBase *`. However, for SIL
differentiability witness, the pointer has `SILDifferentiabilityWitness *`
type, which is not derived from `TypeBase`. So, such a cast is not allowed.

Just as with `ProtocolWitnessTableLazyAccessFunction` and
`ProtocolWitnessTableLazyCacheVariable` link entity kinds (which are
also type kinds), we should use `SecondaryPointer` instead of `Pointer` for
storing payload here, while setting `Pointer` to `nullptr`.
@kovdan01 kovdan01 marked this pull request as ready for review June 23, 2025 14:44
@kovdan01 kovdan01 requested a review from rjmccall as a code owner June 23, 2025 14:44
@kovdan01
Copy link
Contributor Author

@swift-ci please test

@kovdan01
Copy link
Contributor Author

Tagging @JaapWijnen

@asl asl added the AutoDiff label Jun 23, 2025
Copy link
Contributor

@asl asl left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me

@asl asl requested review from compnerd and rxwei June 23, 2025 15:56
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Thanks!

@asl
Copy link
Contributor

asl commented Jun 23, 2025

This kind of problem seems to be easily spotted by ASAN. Likely we'd need to use buildbot_incremental_asan_ubsan preset more :)

@asl asl enabled auto-merge (squash) June 23, 2025 20:54
@asl asl merged commit 644f364 into swiftlang:main Jun 23, 2025
4 of 5 checks passed
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.

3 participants