Skip to content

Account for whether artificial subclasses are skipped on type caching #68404

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
Sep 12, 2023

Conversation

augusto2112
Copy link
Contributor

MetadataReader caches types only with the metadata address as the key. However a type lookup can be requested skipping artificial subclasses or not. This makes the cached results incorrect if two requests for the same type, but skipping subclasses on one and not on the other, are made. Fix this by adding a second dimension to the cache key.

rdar://101519300

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

Copy link
Contributor

@mikeash mikeash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's any point to making skipArtificialSubclasses optional. Seems like we should probably just always do it. But that can be a task for another day.

@augusto2112
Copy link
Contributor Author

I wonder if there's any point to making skipArtificialSubclasses optional. Seems like we should probably just always do it. But that can be a task for another day.

Actually in LLDB there is at least one place where we want to not skip artificial subclasses, since we iterate over a type's superclasses ourselves, and if metadata reader silently skipped over them our results would be off.

I do agree that this should've probably be defaulted to true instead of false though.

@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

MetadataReader caches types only with the metadata address as the key.
However a type lookup can be requested skipping artificial subclasses or
not. This makes the cached results incorrect if two requests for the
same type, but skipping subclasses on one and not on the other, are made.
Fix this by adding a second dimension to the cache key.

rdar://101519300
@augusto2112 augusto2112 force-pushed the type-cache-artificial branch from 64f4854 to 9151305 Compare September 8, 2023 20:22
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

/// A cache of built types, keyed by the address of the type and whether the
/// request ignored articial superclasses or not.
std::unordered_map<std::pair<StoredPointer, bool>, BuiltType,
TypeCacheKeyHash>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: If we are using the LLVM libraries anyway, why not use a DenseMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can, I'll change this in a separate patch.

@augusto2112 augusto2112 merged commit 666c0cb into swiftlang:main Sep 12, 2023
@adrian-prantl
Copy link
Contributor

@augusto2112 You will probably also want to cherry-pick this to release/5.10

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