Skip to content

Commit 5d315ae

Browse files
author
Enrico Granata
committed
Add a getKindForRemoteTypeMetadata() API to the RemoteAST - LLDB plans to use this API to decide whether certain kinds of existential containers need a two-level type resolution (e.g. if an existential box points to a class, the true type that we want to resolve is the type that the class's ISA refers to, not the static type that the box refers to)
1 parent f040eaf commit 5d315ae

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

include/swift/Remote/MetadataReader.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <vector>
2626
#include <unordered_map>
27+
#include <utility>
2728

2829
namespace swift {
2930
namespace remote {
@@ -419,6 +420,24 @@ class MetadataReader {
419420
return swift::remote::decodeMangledType(Builder, Node);
420421
}
421422

423+
/// Given a remote pointer to metadata, attempt to discover its MetadataKind.
424+
std::pair<bool,MetadataKind>
425+
readKindFromMetadata(StoredPointer MetadataAddress) {
426+
auto Cached = MetadataCache.find(MetadataAddress);
427+
if (Cached != MetadataCache.end()) {
428+
if (auto Meta = Cached->second) {
429+
return {true,Cached->second->getKind()};
430+
} else {
431+
return {false,MetadataKind::Opaque};
432+
}
433+
}
434+
435+
auto Meta = readMetadata(MetadataAddress);
436+
if (!Meta) return {false,MetadataKind::Opaque};
437+
438+
return {true,Meta->getKind()};
439+
}
440+
422441
/// Given a remote pointer to metadata, attempt to turn it into a type.
423442
BuiltType readTypeFromMetadata(StoredPointer MetadataAddress) {
424443
auto Cached = TypeCache.find(MetadataAddress);

include/swift/RemoteAST/RemoteAST.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/Remote/Failure.h"
2323
#include "swift/Remote/MemoryReader.h"
2424
#include "swift/Basic/LLVM.h"
25+
#include "swift/ABI/MetadataValues.h"
2526
#include "llvm/ADT/Optional.h"
2627
#include "llvm/ADT/StringRef.h"
2728

@@ -169,6 +170,11 @@ class RemoteASTContext {
169170
/// resolve it to a specific type in the local AST.
170171
Result<Type> getTypeForRemoteTypeMetadata(remote::RemoteAddress address);
171172

173+
/// Given an address which is supposedly of type metadata, try to
174+
/// resolve it to a specific MetadataKind value for its backing type.
175+
Result<MetadataKind>
176+
getKindForRemoteTypeMetadata(remote::RemoteAddress address);
177+
172178
/// Given an address which is supposedly of a nominal type descriptor,
173179
/// try to resolve it to a specific nominal type declaration in the
174180
/// local AST.

lib/RemoteAST/RemoteAST.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,17 @@ class RemoteASTContextImpl {
537537
return Result<Type>::emplaceFailure(Failure::Unknown);
538538
}
539539

540+
Result<MetadataKind> getKindForRemoteTypeMetadata(RemoteAddress address) {
541+
std::pair<bool,MetadataKind> result;
542+
if (Is32) {
543+
result = Reader32->readKindFromMetadata(address.getAddressData());
544+
} else {
545+
result = Reader64->readKindFromMetadata(address.getAddressData());
546+
}
547+
if (result.first) return Result<MetadataKind>(result.second);
548+
return Result<MetadataKind>::emplaceFailure(Failure::Unknown);
549+
}
550+
540551
Result<NominalTypeDecl *>
541552
getDeclForRemoteNominalTypeDescriptor(RemoteAddress address) {
542553
NominalTypeDecl *result;

0 commit comments

Comments
 (0)