Skip to content

Commit 090f159

Browse files
committed
WIP
1 parent dafab23 commit 090f159

File tree

6 files changed

+43
-53
lines changed

6 files changed

+43
-53
lines changed

lib/Serialization/DeclTypeRecordNodes.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ PATTERN(VAR)
151151
OTHER(PARAMETERLIST, 210)
152152
// 211 is unused
153153
OTHER(FOREIGN_ERROR_CONVENTION, 212)
154-
OTHER(XREF_CLANG_TEMPLATE_INSTANTIATION, 213)
155154
OTHER(XREF_TYPE_PATH_PIECE, 214)
156155
OTHER(XREF_VALUE_PATH_PIECE, 215)
157156
OTHER(XREF_EXTENSION_PATH_PIECE, 216)
@@ -195,6 +194,8 @@ OTHER(XREF_OPAQUE_RETURN_TYPE_PATH_PIECE, 252)
195194
OTHER(CLANG_TYPE, 253)
196195

197196
OTHER(DERIVATIVE_FUNCTION_CONFIGURATION, 254)
197+
OTHER(XREF_CLANG_TEMPLATE_INSTANTIATION, 255)
198+
198199

199200
#undef RECORD
200201
#undef DECLTYPERECORDNODES_HAS_RECORD_VAL

lib/Serialization/Deserialization.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,7 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
13011301
importedFromClang, isStatic);
13021302

13031303
DeclBaseName name = getDeclBaseName(IID);
1304+
llvm::errs() << "YOYOYOOOOO " << name <<"\n";
13041305
pathTrace.addValue(name);
13051306
if (privateDiscriminator)
13061307
pathTrace.addValue(getIdentifier(privateDiscriminator));
@@ -1394,40 +1395,35 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
13941395
case XREF_CLANG_TEMPLATE_INSTANTIATION: {
13951396
auto &astContext = getContext();
13961397
auto clangModuleLoader = astContext.getClangModuleLoader();
1398+
auto clangImporter = static_cast<ClangImporter *>(clangModuleLoader);
13971399
auto &clangASTContext = clangModuleLoader->getClangASTContext();
13981400

1399-
IdentifierID templateId;
1400-
ArrayRef<uint64_t> argumentIds;
1401-
XRefClangTemplateInstantiationLayout::readRecord(scratch, templateId, argumentIds);
1402-
1403-
auto templateIdent = getIdentifier(templateId);
1404-
SmallVector<ValueDecl*, 4> templateDeclResults;
1405-
VectorDeclConsumer templateDeclConsumer(templateDeclResults);
1406-
clangModuleLoader->lookupValue(templateIdent, templateDeclConsumer);
1407-
assert(templateDeclResults.size() == 1);
1408-
auto *templateDecl = templateDeclResults[0];
1409-
auto *classTemplateDecl = const_cast<clang::ClassTemplateDecl *>(
1410-
dyn_cast<clang::ClassTemplateDecl>(templateDecl->getClangDecl()));
1411-
assert(classTemplateDecl);
1412-
1413-
SmallVector<ValueDecl*, 2> arguments;
1414-
VectorDeclConsumer argumentsConsumer(arguments);
1415-
unsigned counter = 0;
1416-
for (auto id : argumentIds) {
1417-
auto argIdent = getIdentifier(id);
1418-
clangModuleLoader->lookupValue(argIdent, argumentsConsumer);
1419-
assert(arguments.size() == ++counter);
1420-
}
1421-
SmallVector<clang::TemplateArgument, 2> templateArguments;
1422-
for (auto &decl : arguments) {
1423-
templateArguments.push_back(
1424-
clang::TemplateArgument(clangASTContext.getTagDeclType(
1425-
dyn_cast<clang::TagDecl>(decl->getClangDecl()))));
1426-
}
1427-
1428-
auto *instantiation = clangModuleLoader->instantiateCXXClassTemplate(
1429-
classTemplateDecl, templateArguments);
1430-
return instantiation;
1401+
ClangTypeID clangTypeId;
1402+
XRefClangTemplateInstantiationLayout::readRecord(scratch, clangTypeId);
1403+
1404+
const clang::Type *clangInstantiationType = nullptr;
1405+
auto loadedClangType = getClangType(clangTypeId);
1406+
if (!loadedClangType) {
1407+
return loadedClangType.takeError();
1408+
clangInstantiationType = loadedClangType.get();
1409+
}
1410+
1411+
auto decl = clangInstantiationType->getAsCXXRecordDecl();
1412+
decl->dump();
1413+
1414+
llvm_unreachable("only in a nominal or function");
1415+
return nullptr;
1416+
1417+
// clangInstantiationType
1418+
// clangModuleLoader->lookup(clangInstantiationType);
1419+
1420+
// auto *classTemplateDecl = const_cast<clang::ClassTemplateDecl *>(
1421+
// dyn_cast<clang::ClassTemplateDecl>(templateDecl->getClangDecl()));
1422+
// assert(classTemplateDecl);
1423+
1424+
// auto *instantiation = clangModuleLoader->instantiateCXXClassTemplate(
1425+
// classTemplateDecl, templateArguments);
1426+
// return instantiation;
14311427
}
14321428
default:
14331429
// Unknown xref kind.

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,8 +1716,7 @@ namespace decls_block {
17161716

17171717
using XRefClangTemplateInstantiationLayout = BCRecordLayout<
17181718
XREF_CLANG_TEMPLATE_INSTANTIATION,
1719-
IdentifierIDField, // template name
1720-
BCArray<IdentifierIDField> // template args
1719+
ClangTypeIDField
17211720
>;
17221721

17231722
using SILGenNameDeclAttrLayout = BCRecordLayout<

lib/Serialization/Serialization.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,19 +1885,12 @@ void Serializer::writeCrossReference(const Decl *D) {
18851885
if (D->hasClangNode()) {
18861886
if (auto ctsd = dyn_cast<clang::ClassTemplateSpecializationDecl>(
18871887
D->getClangDecl())) {
1888-
auto *clangModuleLoader = D->getASTContext().getClangModuleLoader();
18891888
abbrCode = DeclTypeAbbrCodes[XRefClangTemplateInstantiationLayout::Code];
1890-
SmallVector<IdentifierID, 4> arguments;
1891-
for (auto &param : ctsd->getTemplateArgs().asArray()) {
1892-
arguments.push_back(
1893-
addDeclBaseNameRef(clangModuleLoader->lookupIdentifier(
1894-
param.getAsType().getBaseTypeIdentifier())));
1895-
}
1889+
auto clangTypeID = addClangTypeRef(ctsd->getTypeForDecl());
1890+
18961891
XRefClangTemplateInstantiationLayout::emitRecord(
1897-
Out, ScratchRecord, abbrCode,
1898-
addDeclBaseNameRef(
1899-
clangModuleLoader->lookupIdentifier(ctsd->getDeclName().getAsIdentifierInfo())),
1900-
arguments);
1892+
Out, ScratchRecord, abbrCode, clangTypeID);
1893+
19011894
return;
19021895
}
19031896
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t.swiftinterface %S/Inputs/SwiftClassInstantiationInNamespaceModule.swift -I %S/Inputs -enable-cxx-interop
3-
// RUN: %FileCheck %s < %t.swiftinterface
2+
// RUN: %target-swiftxx-frontend -emit-module -o %t/SwiftClassTemplateInNamespaceModule.swiftmodule %S/Inputs/SwiftClassInstantiationInNamespaceModule.swift -I %S/Inputs -enable-library-evolution -swift-version 5
3+
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftClassTemplateInNamespaceModule -I %t/ -source-filename=x -enable-cxx-interop | %FileCheck %s
44

55
// CHECK: import ClassTemplateInNamespace
66
// CHECK: public func receiveShip(_ i: inout ClassTemplateInNamespace.Space.__CxxTemplateInstN5Space4ShipIbEE)
77
// CHECK: public func returnShip() -> ClassTemplateInNamespace.Space.__CxxTemplateInstN5Space4ShipIbEE
88
// CHECK: public func receiveShipWithEngine(_ i: inout ClassTemplateInNamespace.Space.__CxxTemplateInstN5Space4ShipIN6Engine8TurbojetEEE)
9-
// CHECK: public func returnShipWithEngine() -> ClassTemplateInNamespace.Space.__CxxTemplateInstN5Space4ShipIN6Engine8TurbojetEEE
9+
// CHECK: public func returnShipWithEngine() -> ClassTemplateInNamespace.Space.__CxxTemplateInstN5Space4ShipIN6Engine8TurbojetEEE
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t.swiftinterface %S/Inputs/SwiftClassInstantiationModule.swift -I %S/Inputs -enable-cxx-interop
3-
// RUN: %FileCheck %s < %t.swiftinterface
2+
// RUN: %target-swiftxx-frontend -emit-module -o %t/SwiftClassTemplateModule.swiftmodule %S/Inputs/SwiftClassInstantiationModule.swift -I %S/Inputs -enable-library-evolution -swift-version 5
3+
// RUN: %target-swift-ide-test -print-module -module-to-print=SwiftClassTemplateModule -I %t/ -source-filename=x -enable-cxx-interop | %FileCheck %s
4+
45

56
// CHECK: import ClassTemplateForSwiftModule
6-
// CHECK: func makeWrappedMagicNumber() -> __ObjC.__CxxTemplateInst12MagicWrapperI10IntWrapperE
7-
// CHECK: func readWrappedMagicNumber(_ i: inout __ObjC.__CxxTemplateInst12MagicWrapperI10IntWrapperE) -> Swift.CInt
7+
// CHECK: func makeWrappedMagicNumber() -> __CxxTemplateInst12MagicWrapperI10IntWrapperE
8+
// CHECK: func readWrappedMagicNumber(_ i: inout __CxxTemplateInst12MagicWrapperI10IntWrapperE) -> CInt

0 commit comments

Comments
 (0)