Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

pschuh
Copy link
Contributor

@pschuh pschuh commented Aug 14, 2019

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

@jrose-apple
Copy link
Contributor

Hmm. I'm sad that we need cxx_virtual_method at all because it does not bode well for adding other importers in the future. I'll take a closer look soon.

@jrose-apple jrose-apple requested a review from jckarter August 15, 2019 01:03
@pschuh
Copy link
Contributor Author

pschuh commented Aug 15, 2019

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.

@jrose-apple
Copy link
Contributor

I guess if we have a C++ abstraction pattern we can have a cxx_virtual_method instruction.

@Azoy
Copy link
Contributor

Azoy commented Aug 15, 2019

I'm just a simple bystander, but could you add some SILGen tests as well?

@pschuh pschuh force-pushed the cpp-9 branch 2 times, most recently from 7b846ff to c468172 Compare August 15, 2019 21:16
include/swift/SIL/SILInstruction.h Outdated Show resolved Hide resolved
: public UnaryInstructionBase<SILInstructionKind::CXXVirtualMethodInst,
MultipleValueInstruction>,
public MultipleValueInstructionTrailingObjects<CXXVirtualMethodInst,
CXXVirtualMethodResult> {
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

@rjmccall or @jckarter should probably verify this rather than me.

lib/IRGen/IRGenSIL.cpp Outdated Show resolved Hide resolved
lib/IRGen/Signature.h Outdated Show resolved Hide resolved
lib/SIL/SILPrinter.cpp Show resolved Hide resolved
lib/SIL/ValueOwnership.cpp Outdated Show resolved Hide resolved
SGF.B.createObjCMethod(Loc, borrowedSelf->getValue(), *constant,
SILType::getPrimitiveObjectType(methodTy));
} else {
// TODO: Update borrowedSelf with the updated self-pointer...
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems important…

Copy link
Contributor

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.

Copy link
Contributor

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.

lib/Serialization/SerializeSIL.cpp Show resolved Hide resolved
test/ClangImporter/cxx_interop_sil.swift Show resolved Hide resolved
Copy link
Contributor

@gottesmm gottesmm left a 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.

test/ClangImporter/cxx_interop_sil.swift Show resolved Hide resolved
lib/Serialization/SerializeSIL.cpp Outdated Show resolved Hide resolved
include/swift/SIL/SILInstruction.h Outdated Show resolved Hide resolved
: UnaryInstructionBase(DebugLoc, Operand),
MultipleValueInstructionTrailingObjects(
this, {Ty, Operand->getType()},
{ValueOwnershipKind::Unowned, ValueOwnershipKind::Any}),
Copy link
Contributor

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.

lib/SIL/ValueOwnership.cpp Outdated Show resolved Hide resolved
SGF.B.createObjCMethod(Loc, borrowedSelf->getValue(), *constant,
SILType::getPrimitiveObjectType(methodTy));
} else {
// TODO: Update borrowedSelf with the updated self-pointer...
Copy link
Contributor

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.

@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

@shahmishal shahmishal closed this Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants