-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Emit type metadata for foreign types more often #76011
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ | |||||||||
#include "GenKeyPath.h" | ||||||||||
#include "swift/AST/ASTContext.h" | ||||||||||
#include "swift/AST/ASTMangler.h" | ||||||||||
#include "swift/AST/Decl.h" | ||||||||||
#include "swift/AST/DiagnosticsIRGen.h" | ||||||||||
#include "swift/AST/ExtInfo.h" | ||||||||||
#include "swift/AST/GenericEnvironment.h" | ||||||||||
|
@@ -26,6 +27,9 @@ | |||||||||
#include "swift/AST/Pattern.h" | ||||||||||
#include "swift/AST/SemanticAttrs.h" | ||||||||||
#include "swift/AST/SubstitutionMap.h" | ||||||||||
#include "swift/AST/Type.h" | ||||||||||
#include "swift/AST/TypeExpansionContext.h" | ||||||||||
#include "swift/AST/TypeVisitor.h" | ||||||||||
#include "swift/AST/Types.h" | ||||||||||
#include "swift/Basic/Assertions.h" | ||||||||||
#include "swift/Basic/ExternalUnion.h" | ||||||||||
|
@@ -2472,6 +2476,53 @@ static void emitDynamicSelfMetadata(IRGenSILFunction &IGF) { | |||||||||
IGF.setDynamicSelfMetadata(selfTy, isExact, value, selfKind); | ||||||||||
} | ||||||||||
|
||||||||||
/// C++ interop might refer to the type metadata in some scenarios. | ||||||||||
/// This function covers those cases and makes sure metadata is emitted | ||||||||||
/// for the foreign types. | ||||||||||
static void noteUseOfMetadataByCXXInterop(IRGenerator &IRGen, | ||||||||||
const SILFunction *f, | ||||||||||
const TypeExpansionContext &context) { | ||||||||||
auto type = f->getLoweredFunctionType(); | ||||||||||
|
||||||||||
// Notes the use of foreign types in generic arguments for C++ interop. | ||||||||||
auto processType = [&](CanType type) { | ||||||||||
struct Walker : TypeWalker { | ||||||||||
Walker(IRGenerator &IRGen) : IRGen(IRGen) {} | ||||||||||
|
||||||||||
Action walkToTypePre(Type ty) override { | ||||||||||
if (auto *BGT = ty->getAs<BoundGenericType>()) | ||||||||||
genericDepth++; | ||||||||||
else if (auto *nominal = ty->getAs<NominalType>()) | ||||||||||
noteUseOfTypeMetadata(nominal->getDecl()); | ||||||||||
return Action::Continue; | ||||||||||
} | ||||||||||
|
||||||||||
Action walkToTypePost(Type ty) override { | ||||||||||
if (auto *BGT = ty->getAs<BoundGenericType>()) | ||||||||||
genericDepth--; | ||||||||||
|
||||||||||
return Action::Continue; | ||||||||||
} | ||||||||||
|
||||||||||
void noteUseOfTypeMetadata(NominalTypeDecl *type) { | ||||||||||
if (genericDepth == 0) | ||||||||||
return; | ||||||||||
if (!IRGen.hasLazyMetadata(type) || !type->hasClangNode()) | ||||||||||
return; | ||||||||||
IRGen.noteUseOfTypeMetadata(type); | ||||||||||
} | ||||||||||
IRGenerator &IRGen; | ||||||||||
int genericDepth = 0; | ||||||||||
} walker{IRGen}; | ||||||||||
type.walk(walker); | ||||||||||
}; | ||||||||||
|
||||||||||
for (const auto ¶m : type->getParameters()) | ||||||||||
processType(param.getArgumentType(IRGen.SIL, type, context)); | ||||||||||
for (const auto &result : type->getResultsWithError()) | ||||||||||
processType(result.getReturnValueType(IRGen.SIL, type, context)); | ||||||||||
} | ||||||||||
|
||||||||||
/// Emit the definition for the given SIL constant. | ||||||||||
void IRGenModule::emitSILFunction(SILFunction *f) { | ||||||||||
if (f->isExternalDeclaration()) | ||||||||||
|
@@ -2487,6 +2538,12 @@ void IRGenModule::emitSILFunction(SILFunction *f) { | |||||||||
f->isAvailableExternally()) | ||||||||||
return; | ||||||||||
|
||||||||||
// Type metadata for foreign references is not yet supported on Windows. Bug #76168. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason that this is not supported on Windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that on Windows we end up requiring a metadata completion function for C++ foreign reference types. That logic just isn't implemented yet for C++ types. Lines 6636 to 6639 in bd313de
|
||||||||||
if (Context.LangOpts.EnableCXXInterop && | ||||||||||
f->getLinkage() == SILLinkage::Public && | ||||||||||
!Context.LangOpts.Target.isOSWindows()) | ||||||||||
noteUseOfMetadataByCXXInterop(IRGen, f, TypeExpansionContext(*f)); | ||||||||||
|
||||||||||
PrettyStackTraceSILFunction stackTrace("emitting IR", f); | ||||||||||
IRGenSILFunction(*this, f).emitSILFunction(); | ||||||||||
} | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.