-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Add cxx_virtual_method instruction. #26658
Conversation
Hmm. I'm sad that we need |
Hi @jrose-apple, the context for needing cxx_virtual_method is here: https://forums.swift.org/t/c-interop-virtual-function-calls/27567/3 in case you missed it. |
I guess if we have a C++ abstraction pattern we can have a |
I'm just a simple bystander, but could you add some SILGen tests as well? |
7b846ff
to
c468172
Compare
: public UnaryInstructionBase<SILInstructionKind::CXXVirtualMethodInst, | ||
MultipleValueInstruction>, | ||
public MultipleValueInstructionTrailingObjects<CXXVirtualMethodInst, | ||
CXXVirtualMethodResult> { |
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.
I wonder if there's a better way to have exactly two results than this. My SIL isn't strong enough. @gottesmm?
expansion.ForeignInfo.ClangInfo = | ||
&clang::CodeGen::arrangeCXXMethodDeclaration(IGM.getClangCGM(), decl); | ||
llvm::FunctionType *Ty = clang::CodeGen::getFunctionType( | ||
IGM.getClangCGM(), *expansion.ForeignInfo.ClangInfo); |
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.
SGF.B.createObjCMethod(Loc, borrowedSelf->getValue(), *constant, | ||
SILType::getPrimitiveObjectType(methodTy)); | ||
} else { | ||
// TODO: Update borrowedSelf with the updated self-pointer... |
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 seems important…
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.
When you do get to it, we'll need some way to indicate that the adjusted "this" pointer depends on the lifetime of the original object. I'm not sure if there's a way to do that other than the mark_dependence
instruction, but there ought to be.
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.
My suggestion (going back to what I was saying above) is that the method should take self either forwarding or guaranteed.
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.
Before you land this, I want to take another look through. But some initial comments.
lib/SIL/SILInstructions.cpp
Outdated
: UnaryInstructionBase(DebugLoc, Operand), | ||
MultipleValueInstructionTrailingObjects( | ||
this, {Ty, Operand->getType()}, | ||
{ValueOwnershipKind::Unowned, ValueOwnershipKind::Any}), |
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 the wrong semantics. The right semantics IMO are that this should be either forwarding or guaranteed.
SGF.B.createObjCMethod(Loc, borrowedSelf->getValue(), *constant, | ||
SILType::getPrimitiveObjectType(methodTy)); | ||
} else { | ||
// TODO: Update borrowedSelf with the updated self-pointer... |
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.
My suggestion (going back to what I was saying above) is that the method should take self either forwarding or guaranteed.
This also contains the code to trigger forming cxx_virtual_method instructions but the this pointer adjustment is not hooked up yet.
Companion pr: apple/swift-clang#349