-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Introduce ExternalTypeRefInfoProvider #60497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#ifndef SWIFT_REFLECTION_TYPEREFBUILDER_H | ||
#define SWIFT_REFLECTION_TYPEREFBUILDER_H | ||
|
||
#include "swift/Remote/ExternalTypeRefCache.h" | ||
#include "swift/Remote/MetadataReader.h" | ||
#include "swift/Reflection/MetadataSourceBuilder.h" | ||
#include "swift/Reflection/Records.h" | ||
|
@@ -426,6 +427,8 @@ class TypeRefBuilder { | |
TypeConverter TC; | ||
MetadataSourceBuilder MSB; | ||
|
||
remote::ExternalTypeRefCache *ExternalTypeRefCache = nullptr; | ||
|
||
#define TYPEREF(Id, Parent) \ | ||
std::unordered_map<TypeRefID, const Id##TypeRef *, \ | ||
TypeRefID::Hash, TypeRefID::Equal> Id##TypeRefs; | ||
|
@@ -915,10 +918,17 @@ class TypeRefBuilder { | |
/// Parsing reflection metadata | ||
/// | ||
|
||
void addReflectionInfo(ReflectionInfo I) { | ||
/// Add the ReflectionInfo and return a unique ID for the reflection image | ||
/// added. Since we only add reflection infos, the ID can be its index. | ||
/// We return a uint32_t since it's extremely unlikely we'll run out of | ||
/// indexes. | ||
uint32_t addReflectionInfo(ReflectionInfo I) { | ||
ReflectionInfos.push_back(I); | ||
auto InfoID = ReflectionInfos.size() - 1; | ||
assert(InfoID <= UINT32_MAX && "ReflectionInfo ID overflow"); | ||
return InfoID; | ||
} | ||
|
||
const std::vector<ReflectionInfo> &getReflectionInfos() { | ||
return ReflectionInfos; | ||
} | ||
|
@@ -943,6 +953,9 @@ class TypeRefBuilder { | |
llvm::Optional<RemoteRef<FieldDescriptor>> | ||
findFieldDescriptorAtIndex(size_t Index, const std::string &MangledName); | ||
|
||
llvm::Optional<RemoteRef<FieldDescriptor>> | ||
getFieldDescriptorFromExternalCache(const std::string &MangledName); | ||
|
||
public: | ||
RemoteRef<char> readTypeRef(uint64_t remoteAddr); | ||
|
||
|
@@ -983,8 +996,9 @@ class TypeRefBuilder { | |
|
||
public: | ||
template<typename Runtime> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this is just a formatting change. Can we do that as a separate PR if so? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It got formatted because of the new |
||
TypeRefBuilder(remote::MetadataReader<Runtime, TypeRefBuilder> &reader) | ||
: TC(*this), | ||
TypeRefBuilder(remote::MetadataReader<Runtime, TypeRefBuilder> &reader, | ||
remote::ExternalTypeRefCache *externalCache = nullptr) | ||
: TC(*this), ExternalTypeRefCache(externalCache), | ||
PointerSize(sizeof(typename Runtime::StoredPointer)), | ||
TypeRefDemangler( | ||
[this, &reader](RemoteRef<char> string, bool useOpaqueTypeSymbolicReferences) -> Demangle::Node * { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===--- ExternalTypeRefCache.h - Abstract access to external caches of | ||
//typeref ------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2022 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
/// @file | ||
/// This file declares an abstract interface for external caches of | ||
/// typeref information. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_REMOTE_EXTERNALTYPEREFCACHE_H | ||
#define SWIFT_REMOTE_EXTERNALTYPEREFCACHE_H | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/ADT/Optional.h" | ||
|
||
#include <string> | ||
|
||
namespace swift { | ||
namespace reflection { | ||
|
||
template <typename T> | ||
class ReflectionSection; | ||
class FieldDescriptorIterator; | ||
using FieldSection = ReflectionSection<FieldDescriptorIterator>; | ||
} | ||
|
||
namespace remote { | ||
/// A struct with the information required to locate a specific field | ||
/// descriptor. | ||
struct FieldDescriptorLocator { | ||
/// The reflection info ID the field descriptor belongs to. | ||
uint64_t InfoID; | ||
|
||
/// The offset of the field descriptor in the FieldSection buffer. | ||
uint64_t Offset; | ||
}; | ||
|
||
/// An abstract interface for providing external type layout information. | ||
struct ExternalTypeRefCache { | ||
virtual ~ExternalTypeRefCache() = default; | ||
|
||
/// Cache the field descriptors of a reflection info with a given id with | ||
/// their corresponding mangled names. The amount of field descriptors and | ||
/// mangled names must be the same. If a field descriptor does not have a | ||
/// mangled name a corresponding empty string must be in the mangled_names | ||
/// array. | ||
virtual void | ||
cacheFieldDescriptors(uint64_t InfoID, | ||
const swift::reflection::FieldSection &FieldDescriptors, | ||
llvm::ArrayRef<std::string> MangledNames) = 0; | ||
|
||
/// Retrieve a pair representing the reflection info id and the offset of a | ||
/// field descriptor in the field section buffer, if available. | ||
virtual llvm::Optional<FieldDescriptorLocator> | ||
getFieldDescriptorLocator(const std::string &Name) = 0; | ||
|
||
/// Returns whether the reflection info with the corresponding ID has been | ||
/// cached already. | ||
virtual bool isReflectionInfoCached(uint64_t InfoID) = 0; | ||
}; | ||
|
||
} // namespace remote | ||
} // namespace swift | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment is now out of date