Skip to content

[cxx-interop] Relax a SILVerifier assertion for immortal reference types #81614

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
May 21, 2025

Conversation

egorzhdan
Copy link
Contributor

Immortal C++ foreign reference types get TrivialTypeLowering instead of ReferenceTypeLowering, since they do not have retain/release lifetime operations. This was tripping up an assertion in SILVerifier.

rdar://147251759 / resolves #80065

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label May 19, 2025
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan requested a review from nate-chandler May 19, 2025 17:28
@egorzhdan egorzhdan force-pushed the egorzhdan/silverifier-trivial-frt branch from a78d8ba to 2b3263f Compare May 19, 2025 17:36
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan changed the title [cxx-interop] Relax a SILVerifier assertion [cxx-interop] Relax a SILVerifier assertion for immortal reference types May 19, 2025
@@ -1059,7 +1059,13 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {

auto objectTy = value->getType().unwrapOptionalType();

require(objectTy.isReferenceCounted(F.getModule()),
// C++ foreign reference types are represented as trivially lowered types
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
// C++ foreign reference types are represented as trivially lowered types
// Immortal C++ foreign reference types are represented as trivially lowered types

(because this isn't true for SWIFT_SHARED_REFERENCE types, right?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixed.

require(objectTy.isReferenceCounted(F.getModule()),
// C++ foreign reference types are represented as trivially lowered types
// since they do not require retain/release calls.
bool isImmortalFRT = objectTy.isForeignReferenceType() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this also true for SWIFT_UNSAFE_REFERENCEs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeap! From the compiler point of view, they're the same thing, except if strictly safe mode is enabled – both SWIFT_UNSAFE_REFERENCE and SWIFT_IMMORTAL_REFERENCE macros expand into retain:immortal and release:immortal.

Immortal C++ foreign reference types get TrivialTypeLowering instead of ReferenceTypeLowering, since they do not have retain/release lifetime operations. This was tripping up an assertion in SILVerifier.

rdar://147251759 / resolves #80065
@egorzhdan egorzhdan force-pushed the egorzhdan/silverifier-trivial-frt branch from 2b3263f to 2e3df1c Compare May 20, 2025 13:01
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan merged commit 5583f93 into main May 21, 2025
5 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/silverifier-trivial-frt branch May 21, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cxx-interop] SIL verifier crash in Unmanaged.passUnretained() on SWIFT_UNSAFE_REFERENCE type
3 participants