Skip to content

Commit e3641c1

Browse files
committed
Cleanup
1 parent b5ecc40 commit e3641c1

File tree

10 files changed

+37
-91
lines changed

10 files changed

+37
-91
lines changed

include/swift/AST/ClangModuleLoader.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,17 @@ class ClangModuleLoader : public ModuleLoader {
176176
lookupRelatedEntity(StringRef clangName, ClangTypeKind kind,
177177
StringRef relatedEntityKind,
178178
llvm::function_ref<void(TypeDecl *)> receiver) = 0;
179-
/// Instantiate and import class template.
179+
180+
/// Instantiate and import class template using given arguments.
181+
///
182+
/// This method will find the clang::ClassTemplateSpecialization decl if
183+
/// it already exists, or it will create one. Then it will import this
184+
/// decl the same way as we import typedeffed class templates - using
185+
/// the hidden struct prefixed with `__CxxTemplateInst`.
180186
virtual StructDecl *
181187
instantiateCXXClassTemplate(clang::ClassTemplateDecl *decl,
182188
ArrayRef<clang::TemplateArgument> arguments) = 0;
183189

184-
/// Lookup identifier for an already imported decl.
185-
virtual Identifier
186-
lookupIdentifier(const clang::IdentifierInfo* declName) = 0;
187-
188190
/// Try to parse the string as a Clang function type.
189191
///
190192
/// Returns null if there was a parsing failure.

include/swift/AST/Decl.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,17 +3392,21 @@ class EnumDecl final : public NominalTypeDecl {
33923392
/// to get the declared type ("Complex" in the above example).
33933393
class StructDecl final : public NominalTypeDecl {
33943394
SourceLoc StructLoc;
3395-
Type TemplateInstantiationType;
3395+
// We import C++ class template instantiations as non-generic structs
3396+
// with a name prefixed with `__CxxTemplateInst`. However for proper
3397+
// serialization we need to have an access to the bound generic type
3398+
// that would have produced this instantiation. This field contains
3399+
// such type.
3400+
//
3401+
// The field is set during the typechecking at the time when we
3402+
// instantiate the C++ class template.
3403+
Type TemplateInstantiationType = Type();
33963404

33973405
public:
33983406
StructDecl(SourceLoc StructLoc, Identifier Name, SourceLoc NameLoc,
33993407
ArrayRef<TypeLoc> Inherited,
34003408
GenericParamList *GenericParams, DeclContext *DC);
34013409

3402-
StructDecl(SourceLoc StructLoc, Identifier Name, SourceLoc NameLoc,
3403-
ArrayRef<TypeLoc> Inherited,
3404-
GenericParamList *GenericParams, DeclContext *DC, Type templateInstantiationType);
3405-
34063410
SourceLoc getStartLoc() const { return StructLoc; }
34073411
SourceRange getSourceRange() const {
34083412
return SourceRange(StructLoc, getBraces().End);

include/swift/ClangImporter/ClangImporter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ class ClangImporter final : public ClangModuleLoader {
244244
instantiateCXXClassTemplate(clang::ClassTemplateDecl *decl,
245245
ArrayRef<clang::TemplateArgument> arguments) override;
246246

247-
Identifier
248-
lookupIdentifier(const clang::IdentifierInfo* declName) override;
249-
250247
/// Just like Decl::getClangNode() except we look through to the 'Code'
251248
/// enum of an error wrapper struct.
252249
ClangNode getEffectiveClangNode(const Decl *decl) const;

lib/AST/Decl.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,21 +3974,15 @@ void EnumDecl::setRawType(Type rawType) {
39743974

39753975
StructDecl::StructDecl(SourceLoc StructLoc, Identifier Name, SourceLoc NameLoc,
39763976
ArrayRef<TypeLoc> Inherited,
3977-
GenericParamList *GenericParams, DeclContext *Parent, Type TemplateInstantiationType)
3977+
GenericParamList *GenericParams, DeclContext *Parent)
39783978
: NominalTypeDecl(DeclKind::Struct, Parent, Name, NameLoc, Inherited,
39793979
GenericParams),
3980-
StructLoc(StructLoc), TemplateInstantiationType(TemplateInstantiationType)
3980+
StructLoc(StructLoc)
39813981
{
39823982
Bits.StructDecl.HasUnreferenceableStorage = false;
39833983
Bits.StructDecl.IsCxxNonTrivial = false;
39843984
}
39853985

3986-
StructDecl::StructDecl(SourceLoc StructLoc, Identifier Name, SourceLoc NameLoc,
3987-
ArrayRef<TypeLoc> Inherited,
3988-
GenericParamList *GenericParams, DeclContext *Parent)
3989-
: StructDecl(StructLoc, Name, NameLoc, Inherited, GenericParams, Parent, Type())
3990-
{}
3991-
39923986
bool NominalTypeDecl::hasMemberwiseInitializer() const {
39933987
// Currently only structs can have memberwise initializers.
39943988
auto *sd = dyn_cast<StructDecl>(this);

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4172,8 +4172,3 @@ ClangImporter::instantiateCXXClassTemplate(
41724172
return dyn_cast_or_null<StructDecl>(
41734173
Impl.importDecl(ctsd, Impl.CurrentVersion));
41744174
}
4175-
4176-
Identifier
4177-
ClangImporter::lookupIdentifier(const clang::IdentifierInfo* declName) {
4178-
return Impl.importIdentifier(declName);
4179-
}

lib/ClangImporter/Serializability.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "ImporterImpl.h"
2525
#include "swift/ClangImporter/SwiftAbstractBasicWriter.h"
26-
#include "clang/AST/DeclTemplate.h"
2726

2827
using namespace swift;
2928

@@ -73,12 +72,9 @@ class SerializationPathFinder {
7372
// easier to just avoid doing so and fall into the external-path code.
7473
if (!isa<TypeAliasDecl>(swiftDecl)) {
7574
// Only accept this declaration if it round-trips.
76-
if (auto swiftClangDecl = swiftDecl->getClangDecl()) {
77-
if (!isa<clang::ClassTemplateSpecializationDecl>(swiftClangDecl)) {
75+
if (auto swiftClangDecl = swiftDecl->getClangDecl())
7876
if (isSameDecl(decl, swiftClangDecl))
7977
return swiftDecl;
80-
}
81-
}
8278
}
8379
}
8480

@@ -106,7 +102,7 @@ class SerializationPathFinder {
106102
bool findExternalPath(const clang::TagDecl *decl, ExternalPath &path) {
107103
// We can't handle class template specializations right now.
108104
if (isa<clang::ClassTemplateSpecializationDecl>(decl))
109-
decl->dump();
105+
return false;
110106

111107
// Named tags are straightforward.
112108
if (auto name = decl->getIdentifier()) {

lib/Serialization/DeclTypeRecordNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ PATTERN(VAR)
151151
OTHER(PARAMETERLIST, 210)
152152
// 211 is unused
153153
OTHER(FOREIGN_ERROR_CONVENTION, 212)
154+
// 213 is unused
154155
OTHER(XREF_TYPE_PATH_PIECE, 214)
155156
OTHER(XREF_VALUE_PATH_PIECE, 215)
156157
OTHER(XREF_EXTENSION_PATH_PIECE, 216)
@@ -194,7 +195,6 @@ OTHER(XREF_OPAQUE_RETURN_TYPE_PATH_PIECE, 252)
194195
OTHER(CLANG_TYPE, 253)
195196

196197
OTHER(DERIVATIVE_FUNCTION_CONFIGURATION, 254)
197-
OTHER(XREF_CLANG_TEMPLATE_INSTANTIATION, 255)
198198

199199

200200
#undef RECORD

lib/Serialization/Deserialization.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,39 +1391,6 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
13911391
case XREF_INITIALIZER_PATH_PIECE:
13921392
llvm_unreachable("only in a nominal or function");
13931393

1394-
case XREF_CLANG_TEMPLATE_INSTANTIATION: {
1395-
auto &astContext = getContext();
1396-
auto clangModuleLoader = astContext.getClangModuleLoader();
1397-
auto clangImporter = static_cast<ClangImporter *>(clangModuleLoader);
1398-
auto &clangASTContext = clangModuleLoader->getClangASTContext();
1399-
1400-
ClangTypeID clangTypeId;
1401-
XRefClangTemplateInstantiationLayout::readRecord(scratch, clangTypeId);
1402-
1403-
const clang::Type *clangInstantiationType = nullptr;
1404-
auto loadedClangType = getClangType(clangTypeId);
1405-
if (!loadedClangType) {
1406-
return loadedClangType.takeError();
1407-
clangInstantiationType = loadedClangType.get();
1408-
}
1409-
1410-
auto decl = clangInstantiationType->getAsCXXRecordDecl();
1411-
decl->dump();
1412-
1413-
llvm_unreachable("only in a nominal or function");
1414-
return nullptr;
1415-
1416-
// clangInstantiationType
1417-
// clangModuleLoader->lookup(clangInstantiationType);
1418-
1419-
// auto *classTemplateDecl = const_cast<clang::ClassTemplateDecl *>(
1420-
// dyn_cast<clang::ClassTemplateDecl>(templateDecl->getClangDecl()));
1421-
// assert(classTemplateDecl);
1422-
1423-
// auto *instantiation = clangModuleLoader->instantiateCXXClassTemplate(
1424-
// classTemplateDecl, templateArguments);
1425-
// return instantiation;
1426-
}
14271394
default:
14281395
// Unknown xref kind.
14291396
pathTrace.addUnknown(recordID);

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 591; // XRefClangTemplateInstantiation added
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 590; // differentiable_function_extract explicit extractee type
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///
@@ -1714,11 +1714,6 @@ namespace decls_block {
17141714
BCVBR<5> // index
17151715
>;
17161716

1717-
using XRefClangTemplateInstantiationLayout = BCRecordLayout<
1718-
XREF_CLANG_TEMPLATE_INSTANTIATION,
1719-
ClangTypeIDField
1720-
>;
1721-
17221717
using SILGenNameDeclAttrLayout = BCRecordLayout<
17231718
SILGenName_DECL_ATTR,
17241719
BCFixed<1>, // implicit flag

lib/Serialization/Serialization.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "Serialization.h"
14-
#include "ModuleFormat.h"
1514
#include "SILFormat.h"
1615
#include "swift/AST/ASTContext.h"
1716
#include "swift/AST/ASTMangler.h"
@@ -76,20 +75,6 @@ using swift::version::Version;
7675
using llvm::BCBlockRAII;
7776

7877

79-
static Type getResultInterfaceTypeForSerialization(Type t) {
80-
if (!t)
81-
return t;
82-
if (auto nominalDecl = t->getAnyNominal()) {
83-
if (auto structDecl = dyn_cast<StructDecl>(nominalDecl)) {
84-
if (auto templateInstantiationType =
85-
structDecl->getTemplateInstantiationType()) {
86-
return templateInstantiationType;
87-
}
88-
}
89-
}
90-
return t;
91-
}
92-
9378
ASTContext &SerializerBase::getASTContext() {
9479
return M->getASTContext();
9580
}
@@ -643,14 +628,25 @@ DeclID Serializer::addDeclRef(const Decl *D, bool allowTypeAliasXRef) {
643628
}
644629

645630
serialization::TypeID Serializer::addTypeRef(Type ty) {
646-
auto tyToSerialize = getResultInterfaceTypeForSerialization(ty);
631+
Type typeToSerialize = ty;
632+
if (ty) {
633+
if (auto nominalDecl = ty->getAnyNominal()) {
634+
if (auto structDecl = dyn_cast<StructDecl>(nominalDecl)) {
635+
if (auto templateInstantiationType =
636+
structDecl->getTemplateInstantiationType()) {
637+
typeToSerialize = templateInstantiationType;
638+
}
639+
}
640+
}
641+
}
642+
647643
#ifndef NDEBUG
648-
PrettyStackTraceType trace(M->getASTContext(), "serializing", tyToSerialize);
644+
PrettyStackTraceType trace(M->getASTContext(), "serializing", typeToSerialize);
649645
assert(M->getASTContext().LangOpts.AllowModuleWithCompilerErrors ||
650-
!tyToSerialize || !ty->hasError() && "serializing type with an error");
646+
!typeToSerialize || !typeToSerialize->hasError() && "serializing type with an error");
651647
#endif
652648

653-
return TypesToSerialize.addRef(tyToSerialize);
649+
return TypesToSerialize.addRef(typeToSerialize);
654650
}
655651

656652
serialization::ClangTypeID Serializer::addClangTypeRef(const clang::Type *ty) {

0 commit comments

Comments
 (0)