Skip to content

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

Merged
merged 1 commit into from
Aug 18, 2022

Conversation

augusto2112
Copy link
Contributor

@augusto2112 augusto2112 commented Aug 10, 2022

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.

@@ -772,7 +772,7 @@ class ReflectionContext
/// \return
Copy link
Contributor

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

@augusto2112 augusto2112 force-pushed the swift-meta-cache branch 2 times, most recently from 59a2201 to 3ec6462 Compare August 11, 2022 23:43
@augusto2112 augusto2112 changed the title Register and look up field descriptors using TypeInfoProvider Introduce ExternalTypeRefInfoProvider Aug 11, 2022
@augusto2112 augusto2112 requested a review from mikeash August 11, 2022 23:44
@augusto2112 augusto2112 marked this pull request as ready for review August 11, 2022 23:44
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112 augusto2112 requested a review from jckarter August 11, 2022 23:44
@@ -982,35 +991,46 @@ class TypeRefBuilder {
IntVariableReader OpaqueIntVariableReader;

public:
template<typename Runtime>
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@mikeash
Copy link
Contributor

mikeash commented Aug 12, 2022

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.

@augusto2112
Copy link
Contributor Author

augusto2112 commented Aug 12, 2022

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?

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.

@augusto2112
Copy link
Contributor Author

It would also be good to have tests to exercise the case when an external provider is given.

I'll try to come up with a way of testing this.

@augusto2112
Copy link
Contributor Author

swiftlang/llvm-project#5100

@swift-ci smoke test

@mikeash
Copy link
Contributor

mikeash commented Aug 12, 2022

@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,
Copy link
Contributor

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)))
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@augusto2112
Copy link
Contributor Author

swiftlang/llvm-project#5100

@swift-ci smoke test

@augusto2112
Copy link
Contributor Author

@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++ -*-===//
Copy link
Contributor

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)?

Copy link
Contributor

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

Copy link
Contributor Author

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.

@augusto2112
Copy link
Contributor Author

swiftlang/llvm-project#5100

@swift-ci smoke test

@augusto2112 augusto2112 changed the base branch from rebranch to main August 17, 2022 18:28
@augusto2112
Copy link
Contributor Author

swiftlang/llvm-project#5100

@swift-ci smoke test

@augusto2112
Copy link
Contributor Author

swiftlang/llvm-project#5100

@swift-ci smoke test Linux

Copy link
Contributor

@adrian-prantl adrian-prantl left a 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.
@augusto2112
Copy link
Contributor Author

swiftlang/llvm-project#5100

@swift-ci smoke test Linux

@augusto2112
Copy link
Contributor Author

swiftlang/llvm-project#5100

@swift-ci smoke test macOS

@augusto2112 augusto2112 merged commit 70d9f16 into swiftlang:main Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants