Skip to content

[cxx-interop] Re-enable round tripping for debug types. #62821

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 14 additions & 45 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3033,53 +3033,22 @@ ClangNode ClangImporter::getEffectiveClangNode(const Decl *decl) const {
void ClangImporter::lookupTypeDecl(
StringRef rawName, ClangTypeKind kind,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should either remove ClangTypeKind from the API for factor it in to the lookup if it's necessary.

llvm::function_ref<void(TypeDecl *)> receiver) {
clang::DeclarationName clangName(
&Impl.Instance->getASTContext().Idents.get(rawName));

SmallVector<clang::Sema::LookupNameKind, 1> lookupKinds;
switch (kind) {
case ClangTypeKind::Typedef:
lookupKinds.push_back(clang::Sema::LookupOrdinaryName);
break;
case ClangTypeKind::Tag:
lookupKinds.push_back(clang::Sema::LookupTagName);
lookupKinds.push_back(clang::Sema::LookupNamespaceName);
break;
case ClangTypeKind::ObjCProtocol:
lookupKinds.push_back(clang::Sema::LookupObjCProtocolName);
break;
}

// Perform name lookup into the global scope.
auto &sema = Impl.Instance->getSema();
auto &ctx = Impl.SwiftContext;
auto name = DeclName(ctx.getIdentifier(rawName));
bool foundViaClang = false;

for (auto lookupKind : lookupKinds) {
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
lookupKind);
if (!Impl.DisableSourceImport &&
sema.LookupName(lookupResult, /*Scope=*/ sema.TUScope)) {
for (auto clangDecl : lookupResult) {
if (!isa<clang::TypeDecl>(clangDecl) &&
!isa<clang::NamespaceDecl>(clangDecl) &&
!isa<clang::ObjCContainerDecl>(clangDecl) &&
!isa<clang::ObjCCompatibleAliasDecl>(clangDecl)) {
continue;
}
Decl *imported = Impl.importDecl(clangDecl, Impl.CurrentVersion);

// Namespaces are imported as extensions for enums.
if (auto ext = dyn_cast_or_null<ExtensionDecl>(imported)) {
imported = ext->getExtendedNominal();
}
if (auto *importedType = dyn_cast_or_null<TypeDecl>(imported)) {
foundViaClang = true;
receiver(importedType);
}
}
auto consumer = makeDeclConsumer(
[&foundViaClang, receiver](Decl *found, DeclVisibilityKind) {
// Namespaces are imported as extensions for enums.
if (auto ext = dyn_cast_or_null<ExtensionDecl>(found)) {
found = ext->getExtendedNominal();
}
}

if (auto *importedType = dyn_cast_or_null<TypeDecl>(found)) {
foundViaClang = true;
receiver(importedType);
}
});

ctx.getClangModuleLoader()->lookupValue(name, consumer);
// If Clang couldn't find the type, query the DWARFImporterDelegate.
if (!foundViaClang)
Impl.lookupTypeDeclDWARF(rawName, kind, receiver);
Expand Down
4 changes: 1 addition & 3 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
Mangle::ASTMangler Mangler;
std::string Result = Mangler.mangleTypeForDebugger(Ty, Sig);

// TODO(https://github.com/apple/swift/issues/57699): We currently cannot round trip some C++ types.
if (!Opts.DisableRoundTripDebugTypes &&
!Ty->getASTContext().LangOpts.EnableCXXInterop) {
if (!Opts.DisableRoundTripDebugTypes) {
// Make sure we can reconstruct mangled types for the debugger.
auto &Ctx = Ty->getASTContext();
Type Reconstructed = Demangle::getTypeForMangling(Ctx, Result);
Expand Down