-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Cxx-Interop] Enable Record Friend functions #59801
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
Conversation
@swift-ci please smoke test |
lib/ClangImporter/ImportDecl.cpp
Outdated
if (auto friendDecl = dyn_cast<clang::FriendDecl>(m)) { | ||
auto d = VisitFriendDecl(friendDecl); | ||
|
||
// Check if the friend decl was converted into a FuncDecl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably remove this comment and add doc-string to VisitFriendDecl
saying that this function returns the Swift imported version of the "friend" (nested) decl found inside this clang::FriendDecl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!
- Please run clang-format on all of the changed code fragments (cmd+opt+L in your setup).
- Please remove the empty-line changes.
- Can you please add a few tests to check that e.g.
friend bool operator==
gets imported? You could add a couple of friend operator declarations tomember-inline.h
and a couple of extra checks inmember-inline-module-interface.swift
&member-inline.swift
.
lib/ClangImporter/ImportDecl.cpp
Outdated
@@ -2116,6 +2116,16 @@ namespace { | |||
continue; | |||
} | |||
|
|||
if (auto friendDecl = dyn_cast<clang::FriendDecl>(m)) { | |||
if (auto d = VisitFriendDecl(friendDecl)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done automatically on line 2147:
Decl *member = Impl.importDecl(nd, getActiveSwiftVersion());
Is there some reason that doesn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be! Testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FriendDecl
is not a NamedDecl
so it does not get to that line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about my above suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should work, would have to add to result->addMember
later on. But offline sounds like maybe we should make this global
lib/ClangImporter/ImportDecl.cpp
Outdated
@@ -3044,6 +3054,16 @@ namespace { | |||
result->setIsObjC(false); | |||
result->setIsDynamic(false); | |||
|
|||
bool isFromFriend = Impl.cxxFriends.contains(decl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put this in the importFunctionDecl
method? Can we just look at the decl context instead of Impl.cxxFriends
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant look at declContext
because the passed in decl is clang::FunctionDecl
and its context is not clang::FriendDecl
but rather TranslationUnit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aptly named clang::FunctionDecl:: isThisDeclarationInstantiatedFromAFriendDefinition
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whhhahaaaattttt 🤯
test/Interop/Cxx/operators/member-inline-module-interface.swift
Outdated
Show resolved
Hide resolved
test/Interop/Cxx/operators/member-inline-module-interface.swift
Outdated
Show resolved
Hide resolved
@@ -2116,6 +2116,16 @@ namespace { | |||
continue; | |||
} | |||
|
|||
if (auto friendDecl = dyn_cast<clang::FriendDecl>(m)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (auto friendDecl = dyn_cast<clang::FriendDecl>(m)) { | |
if (auto friendDecl = dyn_cast<clang::FriendDecl>(m)) { | |
m = friendDecl->getFriend(); |
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Much simpler. We might have to add another special case to the module printer to get the IDE tests working (that can be a follow up PR).
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please smoke test linux |
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Records may have friend functions (like operators) which do not get imported at all at the moment.
This is because friends are nested inside of a
clang::FriendDecl
rather than being a normalclang::Function
for example.Although the
clang::FriendDecl
may live inside aCXXRecord
context, the "friend" (nested decl -- such asclang::FunctionDecl
) live inside of aTranslationUnit
context.This PR adds the ability to import Friend Functions that live inside of Records. Can be expanded later to include other decl types and those that live outside of records as well.Looking to get some feedback on better ways of informing the compiler later on that this record (clang::FunctionDecl
) came from aclang::FriendDecl
(since its been "unwrapped" already the compiler no longer knows that it came from aclang::FriendDecl
, all it knows is that itsclang::FunctionDecl
) This is made difficult by the fact thatgetDeclContext()
returnsTranslationUnit
on theclang::FunctionDecl
, notclang::FriendDecl
Still needs:
Issue identified: #59492 (comment)