@@ -61,16 +61,13 @@ printCValueTypeStorageStruct(raw_ostream &os, const NominalTypeDecl *typeDecl,
61
61
}
62
62
63
63
void printCTypeMetadataTypeFunction (raw_ostream &os,
64
- const NominalTypeDecl *typeDecl) {
64
+ const NominalTypeDecl *typeDecl,
65
+ StringRef typeMetadataFuncName) {
65
66
os << " // Type metadata accessor for " << typeDecl->getNameStr () << " \n " ;
66
- auto entity = irgen::LinkEntity::forTypeMetadataAccessFunction (
67
- typeDecl->getDeclaredType ()->getCanonicalType ());
68
67
os << " SWIFT_EXTERN " ;
69
68
ClangSyntaxPrinter printer (os);
70
69
printer.printSwiftImplQualifier ();
71
- os << " MetadataResponseTy " ;
72
- entity.mangle (os);
73
- os << ' (' ;
70
+ os << " MetadataResponseTy " << typeMetadataFuncName << ' (' ;
74
71
printer.printSwiftImplQualifier ();
75
72
os << " MetadataRequestTy)" ;
76
73
os << " SWIFT_NOEXCEPT SWIFT_CALL;\n\n " ;
@@ -90,6 +87,10 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
90
87
91
88
ClangSyntaxPrinter printer (os);
92
89
90
+ auto typeMetadataFunc = irgen::LinkEntity::forTypeMetadataAccessFunction (
91
+ SD->getDeclaredType ()->getCanonicalType ());
92
+ std::string typeMetadataFuncName = typeMetadataFunc.mangleAsString ();
93
+
93
94
// Print out a forward declaration of the "hidden" _impl class.
94
95
printer.printNamespace (cxx_synthesis::getCxxImplNamespaceName (),
95
96
[&](raw_ostream &os) {
@@ -99,13 +100,41 @@ void ClangValueTypePrinter::printStructDecl(const StructDecl *SD) {
99
100
100
101
// Print out special functions, like functions that
101
102
// access type metadata.
102
- printCTypeMetadataTypeFunction (os, SD);
103
+ printCTypeMetadataTypeFunction (os, SD,
104
+ typeMetadataFuncName);
103
105
});
104
106
105
107
// Print out the C++ class itself.
106
108
os << " class " ;
107
109
ClangSyntaxPrinter (os).printBaseName (SD);
108
110
os << " final {\n " ;
111
+ os << " public:\n " ;
112
+
113
+ // Print out the destructor.
114
+ os << " inline ~" ;
115
+ printer.printBaseName (SD);
116
+ os << " () {\n " ;
117
+ os << " auto metadata = " << cxx_synthesis::getCxxImplNamespaceName ()
118
+ << " ::" << typeMetadataFuncName << " (0);\n " ;
119
+ os << " auto *vwTable = "
120
+ " *(reinterpret_cast<swift::_impl::ValueWitnessTable **>(metadata._0) - "
121
+ " 1);\n " ;
122
+ os << " vwTable->destroy(_getOpaquePointer(), metadata._0);\n " ;
123
+ os << " }\n " ;
124
+
125
+ os << " inline " ;
126
+ printer.printBaseName (SD);
127
+ os << " (const " ;
128
+ printer.printBaseName (SD);
129
+ os << " &) = default;\n " ;
130
+
131
+ // FIXME: the move constructor should be hidden somehow.
132
+ os << " inline " ;
133
+ printer.printBaseName (SD);
134
+ os << " (" ;
135
+ printer.printBaseName (SD);
136
+ os << " &&) = default;\n " ;
137
+
109
138
// FIXME: Print the other members of the struct.
110
139
os << " private:\n " ;
111
140
0 commit comments