Skip to content

Commit bdd6335

Browse files
committed
sq
1 parent 8072504 commit bdd6335

File tree

7 files changed

+118
-10
lines changed

7 files changed

+118
-10
lines changed

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void swift::conformToCxxIteratorIfNeeded(
449449
auto underlyingCategoryDecl = unwrapUnderlyingTypeDecl(iteratorCategory);
450450
if (!underlyingCategoryDecl)
451451
return;
452-
452+
453453
auto isIteratorTagDecl = [&](const clang::CXXRecordDecl *base,
454454
StringRef tag) {
455455
return base->isInStdNamespace() && base->getIdentifier() &&
@@ -484,6 +484,10 @@ void swift::conformToCxxIteratorIfNeeded(
484484

485485
if (!isInputIterator)
486486
return;
487+
if (clangDecl->getIdentifier() &&
488+
clangDecl->getName() == "__normal_iterator") {
489+
llvm::errs() << "//// conforming __normal_iterator to UnsafeCxxIter: is input iterator\n";
490+
}
487491

488492
bool isContiguousIterator = false;
489493
// In C++20, `std::contiguous_iterator_tag` is specified as a type called
@@ -505,17 +509,32 @@ void swift::conformToCxxIteratorIfNeeded(
505509
});
506510
}
507511
}
512+
513+
if (clangDecl->getIdentifier() &&
514+
clangDecl->getName() == "__normal_iterator") {
515+
llvm::errs() << "//// conforming __normal_iterator to UnsafeCxxIter: checking pointee\n";
516+
}
508517

509518
// Check if present: `var pointee: Pointee { get }`
510519
auto pointeeId = ctx.getIdentifier("pointee");
511520
auto pointee = lookupDirectSingleWithoutExtensions<VarDecl>(decl, pointeeId);
512521
if (!pointee || pointee->isGetterMutating() || pointee->getTypeInContext()->hasError())
513522
return;
523+
524+
if (clangDecl->getIdentifier() &&
525+
clangDecl->getName() == "__normal_iterator") {
526+
llvm::errs() << "//// conforming __normal_iterator to UnsafeCxxIter: checking pointee settable\n";
527+
}
514528

515529
// Check if `var pointee: Pointee` is settable. This is required for the
516530
// conformance to UnsafeCxxMutableInputIterator but is not necessary for
517531
// UnsafeCxxInputIterator.
518532
bool pointeeSettable = pointee->isSettable(nullptr);
533+
534+
if (clangDecl->getIdentifier() &&
535+
clangDecl->getName() == "__normal_iterator") {
536+
llvm::errs() << "//// conforming __normal_iterator to UnsafeCxxIter: checking successor\n";
537+
}
519538

520539
// Check if present: `func successor() -> Self`
521540
auto successorId = ctx.getIdentifier("successor");
@@ -526,6 +545,11 @@ void swift::conformToCxxIteratorIfNeeded(
526545
auto successorTy = successor->getResultInterfaceType();
527546
if (!successorTy || successorTy->getAnyNominal() != decl)
528547
return;
548+
549+
if (clangDecl->getIdentifier() &&
550+
clangDecl->getName() == "__normal_iterator") {
551+
llvm::errs() << "//// conforming __normal_iterator to UnsafeCxxIter: checking ==\n";
552+
}
529553

530554
// Check if present: `func ==`
531555
auto equalEqual = getEqualEqualOperator(decl);
@@ -551,6 +575,11 @@ void swift::conformToCxxIteratorIfNeeded(
551575
}
552576
if (!equalEqual)
553577
return;
578+
579+
if (clangDecl->getIdentifier() &&
580+
clangDecl->getName() == "__normal_iterator") {
581+
llvm::errs() << "//// conforming __normal_iterator to UnsafeCxxIter: done for input\n";
582+
}
554583

555584
impl.addSynthesizedTypealias(decl, ctx.getIdentifier("Pointee"),
556585
pointee->getTypeInContext());
@@ -566,6 +595,10 @@ void swift::conformToCxxIteratorIfNeeded(
566595
return;
567596

568597
// Try to conform to UnsafeCxxRandomAccessIterator if possible.
598+
if (clangDecl->getIdentifier() &&
599+
clangDecl->getName() == "__normal_iterator") {
600+
llvm::errs() << "//// conforming __normal_iterator to UnsafeCxxIter: trying rac\n";
601+
}
569602

570603
// Check if present: `func -`
571604
auto minus = getMinusOperator(decl);
@@ -1084,8 +1117,11 @@ void swift::conformToCxxVectorIfNeeded(ClangImporter::Implementation &impl,
10841117
auto rawIteratorTy = iterType->getUnderlyingType();
10851118

10861119
// Check if RawIterator conforms to UnsafeCxxRandomAccessIterator.
1087-
if (!checkConformance(rawIteratorTy, cxxRandomAccessIteratorProto))
1120+
if (!checkConformance(rawIteratorTy, cxxRandomAccessIteratorProto)) {
1121+
llvm::errs() << "!!! !!! !!! RawIterator does not conform:\n";
1122+
rawIteratorTy->getAnyNominal()->dump(llvm::errs());
10881123
return;
1124+
}
10891125

10901126
impl.addSynthesizedTypealias(decl, ctx.Id_Element,
10911127
valueType->getUnderlyingType());

lib/ClangImporter/ClangImporter.cpp

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7620,18 +7620,61 @@ static bool hasCopyTypeOperations(const clang::CXXRecordDecl *decl) {
76207620
decl->getName() == "_Optional_construct_base")
76217621
return true;
76227622

7623+
if (decl->getIdentifier() &&
7624+
decl->getName() == "__normal_iterator") {
7625+
llvm::errs() << "!!! === __normal_iterator ctors: ===\n\n";
7626+
bool sawCopyCtor = false;
7627+
for (auto c : decl->ctors()) {
7628+
c->dump(llvm::errs());
7629+
llvm::errs() << "\n";
7630+
llvm::errs() << "isCopyCtor = " << c->isCopyConstructor() << "\n";
7631+
llvm::errs() << "isDeleted = " << c->isDeleted() << "\n";
7632+
llvm::errs() << "access = " << c->getAccess() << "\n";
7633+
llvm::errs() << "\n\n";
7634+
if (c->isCopyConstructor())
7635+
sawCopyCtor = true;
7636+
}
7637+
7638+
for (auto member : decl->decls()) {
7639+
if (auto memberTemplate = dyn_cast<clang::FunctionTemplateDecl>(member))
7640+
if (auto c = dyn_cast<clang::CXXConstructorDecl>(
7641+
memberTemplate->getTemplatedDecl())) {
7642+
llvm::errs() << "TEMPLATED ctor:\n";
7643+
c->dump(llvm::errs());
7644+
llvm::errs() << "isCopyCtor = " << c->isCopyConstructor() << "\n";
7645+
llvm::errs() << "isDeleted = " << c->isDeleted() << "\n";
7646+
llvm::errs() << "access = " << c->getAccess() << "\n";
7647+
llvm::errs() << "\n";
7648+
if (c->isCopyConstructor())
7649+
sawCopyCtor = true;
7650+
}
7651+
}
7652+
7653+
if (!sawCopyCtor) {
7654+
decl->dump();
7655+
llvm::errs() << "decl->needsImplicitCopyConstructor() =" << decl->needsImplicitCopyConstructor() << "\n";
7656+
llvm::errs() << "decl->isTriviallyCopyable() =" << decl->isTriviallyCopyable() << "\n";
7657+
}
7658+
}
7659+
76237660
// If we have no way of copying the type we can't import the class
76247661
// at all because we cannot express the correct semantics as a swift
76257662
// struct.
7626-
if (llvm::any_of(decl->ctors(), [](clang::CXXConstructorDecl *ctor) {
7627-
return ctor->isCopyConstructor() &&
7628-
(ctor->isDeleted() || ctor->getAccess() != clang::AS_public);
7629-
}))
7630-
return false;
7663+
for (auto member : decl->decls()) {
7664+
clang::CXXConstructorDecl *ctor =
7665+
dyn_cast<clang::CXXConstructorDecl>(member);
7666+
// The copy constructor might be templated.
7667+
if (auto memberTemplate = dyn_cast<clang::FunctionTemplateDecl>(member))
7668+
ctor = dyn_cast<clang::CXXConstructorDecl>(
7669+
memberTemplate->getTemplatedDecl());
7670+
if (!ctor)
7671+
continue;
76317672

7632-
return llvm::any_of(decl->ctors(), [](clang::CXXConstructorDecl *ctor) {
7633-
return ctor->isCopyConstructor();
7634-
});
7673+
if (ctor->isCopyConstructor() && !ctor->isDeleted() &&
7674+
ctor->getAccess() == clang::AccessSpecifier::AS_public)
7675+
return true;
7676+
}
7677+
return false;
76357678
}
76367679

76377680
static bool hasMoveTypeOperations(const clang::CXXRecordDecl *decl) {

lib/ClangImporter/ImportDecl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,10 @@ namespace {
25462546
}
25472547
}
25482548

2549+
if (decl->getIdentifier() &&
2550+
decl->getName() == "__normal_iterator") {
2551+
llvm::errs() << "//// IMPORTED __normal_iterator\n";
2552+
}
25492553
result->setMemberLoader(&Impl, 0);
25502554
return result;
25512555
}
@@ -2726,6 +2730,8 @@ namespace {
27262730
}
27272731

27282732
Decl *VisitCXXRecordDecl(const clang::CXXRecordDecl *decl) {
2733+
if (decl->isDependentContext())
2734+
return nullptr;
27292735
// This can be called from lldb without C++ interop being enabled: There
27302736
// may be C++ declarations in imported modules, but the interface for
27312737
// those modules may be a pure C or Objective-C interface.
@@ -2853,6 +2859,13 @@ namespace {
28532859
const_cast<clang::CXXRecordDecl *>(decl));
28542860
clangSema.DefineImplicitDestructor(clang::SourceLocation(), dtor);
28552861
}
2862+
} else {
2863+
llvm::errs() << "??? skipping generation for:\n";
2864+
llvm::errs() << "??? !decl->isBeingDefined(): " << !decl->isBeingDefined() << "\n";
2865+
llvm::errs() << "??? !decl->isDependentContext(): " << !decl->isDependentContext() << "\n";
2866+
llvm::errs() << "??? areRecordFieldsComplete(decl): " << areRecordFieldsComplete(decl) << "\n";
2867+
decl->dump(llvm::errs());
2868+
llvm::errs() << "\n??? =================\n";
28562869
}
28572870

28582871
// It is import that we bail on an unimportable record *before* we import
@@ -2881,6 +2894,7 @@ namespace {
28812894
auto result = VisitRecordDecl(decl);
28822895
if (!result)
28832896
return nullptr;
2897+
Impl.ImportedDecls[{decl, getVersion()}] = result;
28842898

28852899
if (decl->hasAttr<clang::TrivialABIAttr>()) {
28862900
// We cannot yet represent trivial_abi C++ records in Swift.
@@ -2932,6 +2946,12 @@ namespace {
29322946

29332947
if (auto *ntd = dyn_cast<NominalTypeDecl>(result))
29342948
addExplicitProtocolConformances(ntd, decl);
2949+
2950+
if (decl->getIdentifier() && decl->isInStdNamespace() &&
2951+
decl->getName() == "vector") {
2952+
llvm::errs() << "//// IMPORTED vector\n";
2953+
decl->dump(llvm::errs());
2954+
}
29352955

29362956
return result;
29372957
}
@@ -3978,6 +3998,7 @@ namespace {
39783998
}
39793999

39804000
Decl *VisitCXXMethodDecl(const clang::CXXMethodDecl *decl) {
4001+
if (decl->isDependentContext()) return nullptr;
39814002
// The static `operator ()` introduced in C++ 23 is still callable as an
39824003
// instance operator in C++, and we want to preserve the ability to call
39834004
// it as an instance method in Swift as well for source compatibility.

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4334,6 +4334,11 @@ bool MissingMemberFailure::diagnoseAsError() {
43344334
emitDiagnostic(diagnostic, baseType, getName())
43354335
.highlight(getSourceRange())
43364336
.highlight(nameLoc.getSourceRange());
4337+
if (getName().isSimpleName("VectorOfU32")) {
4338+
llvm::errs() << "!!!! dumping type:\n";
4339+
baseType->getAnyNominal()->dump(llvm::errs());
4340+
}
4341+
43374342
const auto &ctx = getSolution().getDC()->getASTContext();
43384343
if (!ctx.LangOpts.DisableExperimentalClangImporterDiagnostics) {
43394344
ctx.getClangModuleLoader()->diagnoseMemberValue(getName().getFullName(),

test/Interop/Cxx/symbolic-imports/indexing-emit-symbolic-module-interface-used-decls.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -c -index-system-modules -index-store-path %t/store -enable-experimental-cxx-interop 2>&1
55
// RUN: cat %t/store/interfaces/CxxModule* | %FileCheck --check-prefix=CHECK %s
66

7+
// UNSUPPORTED: OS=linux-gnu
78
//--- Inputs/module.modulemap
89
module CxxModule {
910
header "header.h"

test/Interop/Cxx/symbolic-imports/indexing-emit-symbolic-module-interface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: split-file %s %t
33

4+
// UNSUPPORTED: OS=linux-gnu
45
// Verify that symbolic interfaces are emitted.
56
//
67
// RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -c -index-system-modules -index-store-path %t/store -enable-experimental-cxx-interop -Rindexing-system-module 2>%t/remarks

test/Interop/Cxx/symbolic-imports/print-symbolic-module-interface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: split-file %s %t
33
// RUN: %target-swift-ide-test -print-module -module-to-print=CxxModule -I %t/Inputs -source-filename=x -enable-experimental-cxx-interop -enable-experimental-feature ImportSymbolicCXXDecls | %FileCheck %s
44

5+
// UNSUPPORTED: OS=linux-gnu
56
// REQUIRES: asserts
67

78
//--- Inputs/module.modulemap

0 commit comments

Comments
 (0)