Skip to content

Commit 562c731

Browse files
authored
Merge pull request #64056 from augusto2112/type-info-prov-id-rebranch
Allow TypeInfoProviders to identify themselves
2 parents e256b56 + 1ea41ba commit 562c731

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

include/swift/Remote/TypeInfoProvider.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_REMOTE_TYPEINFOPROVIDER_H
1818
#define SWIFT_REMOTE_TYPEINFOPROVIDER_H
1919

20+
#include <stdint.h>
2021
namespace swift {
2122
namespace reflection {
2223
class TypeInfo;
@@ -25,13 +26,22 @@ namespace remote {
2526

2627
/// An abstract interface for providing external type layout information.
2728
struct TypeInfoProvider {
29+
using IdType = void *;
30+
2831
virtual ~TypeInfoProvider() = default;
2932

3033
/// Attempt to read type information about (Clang)imported types that are not
3134
/// represented in the metadata. LLDB can read this information from debug
3235
/// info, for example.
3336
virtual const reflection::TypeInfo *
3437
getTypeInfo(llvm::StringRef mangledName) = 0;
38+
39+
/// A key that can be used to identify the type info provider (for example,
40+
/// for caching purposes).
41+
virtual IdType getId() {
42+
// Default implementation is the instance's ID.
43+
return (void *) this;
44+
}
3545
};
3646

3747
} // namespace remote

include/swift/RemoteInspection/TypeLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ class ReferenceTypeInfo : public TypeInfo {
328328
class TypeConverter {
329329
TypeRefBuilder &Builder;
330330
std::vector<std::unique_ptr<const TypeInfo>> Pool;
331-
llvm::DenseMap<std::pair<const TypeRef *, remote::TypeInfoProvider *>,
331+
llvm::DenseMap<std::pair<const TypeRef *, remote::TypeInfoProvider::IdType>,
332332
const TypeInfo *> Cache;
333333
llvm::DenseSet<const TypeRef *> RecursionCheck;
334334
llvm::DenseMap<std::pair<unsigned, unsigned>,

stdlib/public/RemoteInspection/TypeLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,8 +2584,10 @@ TypeConverter::getTypeInfo(const TypeRef *TR,
25842584
return nullptr;
25852585
}
25862586

2587+
auto ExternalTypeInfoId =
2588+
ExternalTypeInfo ? ExternalTypeInfo->getId() : 0;
25872589
// See if we already computed the result
2588-
auto found = Cache.find({TR, ExternalTypeInfo});
2590+
auto found = Cache.find({TR, ExternalTypeInfoId});
25892591
if (found != Cache.end())
25902592
return found->second;
25912593

@@ -2598,7 +2600,7 @@ TypeConverter::getTypeInfo(const TypeRef *TR,
25982600

25992601
// Compute the result and cache it
26002602
auto *TI = LowerType(*this, ExternalTypeInfo).visit(TR);
2601-
Cache.insert({{TR, ExternalTypeInfo}, TI});
2603+
Cache.insert({{TR, ExternalTypeInfoId}, TI});
26022604

26032605
RecursionCheck.erase(TR);
26042606

0 commit comments

Comments
 (0)