@@ -145,92 +145,23 @@ static malloc_type_summary_t
145145computeMallocTypeSummary (const HeapMetadata *heapMetadata) {
146146 assert (isHeapMetadataKind (heapMetadata->getKind ()));
147147 auto *classMetadata = heapMetadata->getClassObject ();
148- auto *typeDesc = heapMetadata->getTypeContextDescriptor ();
149-
150- // Pruned metadata or unclassified
151- if (!classMetadata || !typeDesc)
152- return {.type_kind = MALLOC_TYPE_KIND_SWIFT};
153148
154149 // Objc
155- if (classMetadata->isPureObjC ())
150+ if (classMetadata && classMetadata ->isPureObjC ())
156151 return {.type_kind = MALLOC_TYPE_KIND_OBJC};
157152
158- malloc_type_summary_t summary = {.type_kind = MALLOC_TYPE_KIND_SWIFT};
159- summary.layout_semantics .reference_count =
160- (classMetadata->getFlags () & ClassFlags::UsesSwiftRefcounting);
161-
162- auto *fieldDesc = typeDesc->Fields .get ();
163- if (!fieldDesc)
164- return summary;
165-
166- bool isGenericData = true ;
167- for (auto &field : *fieldDesc) {
168- if (field.isIndirectCase ()) {
169- isGenericData = false ;
170- if (field.isVar ())
171- summary.layout_semantics .data_pointer = true ;
172- else
173- summary.layout_semantics .immutable_pointer = true ;
174- }
175- }
176- summary.layout_semantics .generic_data = isGenericData;
177-
178- return summary;
179-
180- // FIXME: these are all the things we are potentially interested in
181- // typedef struct {
182- // bool data_pointer : 1;
183- // bool struct_pointer : 1;
184- // bool immutable_pointer : 1;
185- // bool anonymous_pointer : 1;
186- // bool reference_count : 1;
187- // bool resource_handle : 1;
188- // bool spatial_bounds : 1;
189- // bool tainted_data : 1;
190- // bool generic_data : 1;
191- // uint16_t unused : 7;
192- // } malloc_type_layout_semantics_t;
193- }
194-
195- struct MallocTypeCacheEntry {
196- // union malloc_type_descriptor_t {
197- // struct {
198- // uint32_t hash;
199- // malloc_type_summary_t summary;
200- // };
201- // malloc_type_id_t type_id;
202- // };
203- malloc_type_descriptor_t desc;
204-
205- friend llvm::hash_code hash_value (const MallocTypeCacheEntry &entry) {
206- return hash_value (entry.desc .hash );
207- }
208- bool matchesKey (uint32_t key) const { return desc.hash == key; }
209- };
210- static ConcurrentReadableHashMap<MallocTypeCacheEntry> MallocTypes;
153+ return {.type_kind = MALLOC_TYPE_KIND_SWIFT};
154+ }
211155
212156static malloc_type_id_t getMallocTypeId (const HeapMetadata *heapMetadata) {
213157 uint64_t metadataPtrBits = reinterpret_cast <uint64_t >(heapMetadata);
214- uint32_t key = (metadataPtrBits >> 32 ) ^ (metadataPtrBits >> 0 );
215-
216- {
217- auto snapshot = MallocTypes.snapshot ();
218- if (auto *entry = snapshot.find (key))
219- return entry->desc .type_id ;
220- }
158+ uint32_t hash = (metadataPtrBits >> 32 ) ^ (metadataPtrBits >> 0 );
221159
222160 malloc_type_descriptor_t desc = {
223- .hash = key ,
161+ .hash = hash ,
224162 .summary = computeMallocTypeSummary (heapMetadata)
225163 };
226164
227- MallocTypes.getOrInsert (
228- key, [desc](MallocTypeCacheEntry *entry, bool created) {
229- if (created)
230- entry->desc = desc;
231- return true ;
232- });
233-
234165 return desc.type_id ;
235166}
236167#endif // SWIFT_STDLIB_HAS_MALLOC_TYPE
0 commit comments