Skip to content

Commit 9c5e5ef

Browse files
authored
Merge pull request swiftlang#40053 from augusto2112/is-in-existential-container
Implement IsValueInlinedInExistentialContainer
2 parents 8f062ad + 1336d2b commit 9c5e5ef

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

include/swift/Remote/MetadataReader.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,28 @@ class MetadataReader {
690690
RemoteAddress(StartOfValue));
691691
}
692692

693+
/// Given a known-opaque existential, discover if its value is inlined in
694+
/// the existential container.
695+
llvm::Optional<bool>
696+
isValueInlinedInExistentialContainer(RemoteAddress ExistentialAddress) {
697+
// OpaqueExistentialContainer is the layout of an opaque existential.
698+
// `Type` is the pointer to the metadata.
699+
TargetOpaqueExistentialContainer<Runtime> Container;
700+
if (!Reader->readBytes(RemoteAddress(ExistentialAddress),
701+
(uint8_t *)&Container, sizeof(Container)))
702+
return None;
703+
auto MetadataAddress = static_cast<StoredPointer>(Container.Type);
704+
auto Metadata = readMetadata(MetadataAddress);
705+
if (!Metadata)
706+
return None;
707+
708+
auto VWT = readValueWitnessTable(MetadataAddress);
709+
if (!VWT)
710+
return None;
711+
712+
return VWT->isValueInline();
713+
}
714+
693715
/// Read a protocol from a reference to said protocol.
694716
template<typename Resolver>
695717
typename Resolver::Result readProtocol(

0 commit comments

Comments
 (0)