-
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
Conversation
@@ -772,7 +772,7 @@ class ReflectionContext | |||
/// \return |
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
59a2201
to
3ec6462
Compare
@swift-ci smoke test |
@@ -982,35 +991,46 @@ class TypeRefBuilder { | |||
IntVariableReader OpaqueIntVariableReader; | |||
|
|||
public: | |||
template<typename Runtime> |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
It got formatted because of the new remote::ExternalTypeRefInfoProvider *provider = nullptr
parameter, but I guess it formatted the whole constructor 😅 I'll remove the non-related parts.
Neat idea. Would it make sense to roll this logic into Remote Mirror rather than having it provided externally, or is it going to be very specific to LLDB in some way? It would also be good to have tests to exercise the case when an external provider is given. |
Could you explain what you're envisioning when you suggest rolling this logic into Remote Mirror? If it could benefit the runtime besides LLDB I'd be happy to do it. To give more context, LLDB's use case for this is to cache a map of mangled names to field descriptor locators (the field descriptor and the offset in the typeref buffer), and then provide them back in future runs. You can check the lldb patch here: swiftlang/llvm-project#5100. The interesting file to look at is SwiftMetadataCache.h and SwiftMetadataCache.cpp. If you see a way this could benefit the runtime as well we could change the approach. |
3ec6462
to
4837a8e
Compare
I'll try to come up with a way of testing this. |
@swift-ci smoke test |
@augusto2112 and I discussed this some offline. Persistent caching wouldn't fit well on the Swift side. It might be feasible to put most of the caching here, with a get/set function that the client could use to persist it across runs. Then clients other than LLDB could use it pretty easily if they needed it. However, we don't have such a need yet, so we'll just keep that as a future possibility. |
return *FD; | ||
if ((!ExternalProvider || | ||
ExternalProvider->shouldParseReflectionInfoWithId(i))) | ||
if (llvm::is_contained(ReflectionInfos[i].PotentialModuleNames, |
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.
I think this could use another comment explaining the algorithm and the contract with ExternalProvider here. I'm not sure it's obvious to the reader that !shouldParseReflectionInfoWithId(i) means we already parsed it.
if (auto FD = findFieldDescriptorAtIndex(i, *MangledName)) | ||
return *FD; | ||
if ((!ExternalProvider || | ||
ExternalProvider->shouldParseReflectionInfoWithId(i))) |
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.
would
if (ExternalProvider && !ExternalProvider->shouldParseReflectionInfoWithId(i)))
continuel
be easier to read?
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.
"shouldParse" doesn't explain why. Should we name it "didCacheReflectionInfo(i)" or simething more descriptive?
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.
I named the ExternalProvider in a deliberately not specific way just in case someone else wanted to implement the interface with a different strategy. I can change it to be more concrete though.
|
||
/// Returns whether looking for a mangled name in reflection info with a given | ||
/// id could possibly return information that couldn't be provided by the | ||
/// external provider. |
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.
What would be an example?
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.
If we have all of the field descriptors for that ReflectionInfo on the cache, and getFieldDescriptorLocator
didn't find anything, then the field descriptor we're looking for must not be in that ReflectionInfo.
4837a8e
to
6e1e053
Compare
@swift-ci smoke test |
@adrian-prantl made the new interface closer to how it's actually implemented, which should make the logic easier to understand. |
@@ -0,0 +1,74 @@ | |||
//===--- ExternalTypeRefCacheProvider.h - Abstract access to external caches of | |||
//typeref ------*- C++ -*-===// |
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.
The ExternalTypeInfoProvider
is called so because it provides typeinfo records from the outside. Here, I think ExternalTypeRefCache
alone would suffice (without the `provider)?
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.
Thinking about it ... do we even need the External
in the type name? I.e.: we could pass around a TypeRefCache *ExternalTypeRefCache
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.
I agree with removing "provider", I do think "external" in the type name makes it more obvious what it is, versus as the variable name.
6e1e053
to
c9f2dc7
Compare
@swift-ci smoke test |
@swift-ci smoke test |
@swift-ci smoke test Linux |
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.
LGTM with inline comments addressed
LLDB would like to cache typeref information to accelerate finding type information. This patch adds an optional interface that allows of typeref to register and provider field descriptor information for faster lookups.
c9f2dc7
to
63a2c76
Compare
@swift-ci smoke test Linux |
@swift-ci smoke test macOS |
Introduce ExternalTypeRefInfoProvider
LLDB would like to cache typeref information to accelerate finding type
information. This patch adds an optional interface that allows of
typeref to register and provider field descriptor information for faster
lookups.