Skip to content

Conversation

egorzhdan
Copy link
Contributor

  • Explanation: Some foreign reference types such as IUnknown or WebKit's RefCounted define retain/release operations as methods of the type.
    Previously Swift only supported retain/release operations as standalone functions.
    The syntax for member functions would be SWIFT_SHARED_REFERENCE(.doRetain, .doRelease).
  • Scope: This extends ClangImporter and IRGen to accept retain/release functions which are instance functions.
  • Issues: rdar://160696723
  • Original PRs: [cxx-interop] Allow retain/release operations to be methods #84343
  • Risk: Low, this is a purely additive change. It accepts syntax that would previously not compile.
  • Testing: Added a compiler test.
  • Reviewers: @Xazax-hun @fahadnayyar

Some foreign reference types such as IUnknown define retain/release operations as methods of the type.

Previously Swift only supported retain/release operations as standalone functions.

The syntax for member functions would be `SWIFT_SHARED_REFERENCE(.doRetain, .doRelease)`.

rdar://160696723
(cherry picked from commit e78ce61)
@egorzhdan egorzhdan requested a review from a team as a code owner September 23, 2025 13:54
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Sep 23, 2025
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

Comment on lines +7888 to +7897
if (name.starts_with(".")) {
// Look for a member of decl instead of a global.
StringRef memberName = name.drop_front(1);
if (memberName.empty())
return {};
auto declName = DeclName(ctx.getIdentifier(memberName));
auto allResults = evaluateOrDefault(
ctx.evaluator, ClangRecordMemberLookup({decl, declName}), {});
return SmallVector<ValueDecl *, 1>(allResults.begin(), allResults.end());
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we also need a spelling for static member functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, we are rejecting static member functions in https://github.com/swiftlang/swift/pull/84343/files#diff-d29df7eb941cda5dc4dc36df1f3220fe4468a9b58d4fa8ca251c76337f353589R2805. In future I think it would be reasonable to allow it, possibly with the same leading-dot spelling, once we figure out the correct behavior for static retain/release functions declared in a base type.

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

2 similar comments
@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan egorzhdan merged commit 14ade31 into swiftlang:release/6.2 Sep 25, 2025
5 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/6.2-retain-release-methods branch September 25, 2025 14:32
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.

3 participants