Skip to content
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

Key context improvements #4095

Merged

Conversation

chandlerc
Copy link
Contributor

@chandlerc chandlerc commented Jun 30, 2024

This injects a customization point for hashtable-specific equality testing that the key context uses by default. While this is rarely needed, there are LLVM types where it is necessary and it seems a good general tool to have to avoid unnecessary complexity from custom key contexts when a simple customization of equality is all that is required.

This also adds a CRTP mixin for implementing a common pattern of key contexts where the context provides translation of some key types into another type, potentially using state. Rather than having to implement the entire key context API, code can derive from this template and simply provide a set of overloads for the types it wants to translate. Any key types used which can be passed to one of those overloads will get translated before following the same logic as the default key context. While this updates the only usage so far of this pattern, a subsequent PR will add several more users making the pattern worth abstracting here.

Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

Looks like a nice API improvement.

common/hashtable_key_context.h Show resolved Hide resolved
common/hashtable_key_context.h Show resolved Hide resolved
This injects a customization point for hashtable-specific equality
testing that the key context uses by default. While this is rarely
needed, there are LLVM types where it is necessary and it seems a good
general tool to have to avoid unnecessary complexity from custom key
contexts when a simple customization of equality is all that is
required.

This also adds a CRTP mixin for implementing a common pattern of key
contexts where the context provides translation of some key types into
another type, potentially using state. Rather than having to implement
the entire key context API, code can derive from this template and
simply provide a set of overloads for the types it wants to translate.
Any key types used which can be passed to one of those overloads will
get translated before following the same logic as the default key
context. While this updates the only usage so far of this pattern,
a subsequent PR will add several more users making the pattern worth
abstracting here.
@chandlerc chandlerc force-pushed the key-context-improvements branch from 93db09f to 74f2a1a Compare July 2, 2024 21:11
@chandlerc chandlerc enabled auto-merge July 2, 2024 21:12
@chandlerc chandlerc added this pull request to the merge queue Jul 2, 2024
Merged via the queue into carbon-language:trunk with commit a8748f3 Jul 2, 2024
7 checks passed
@chandlerc chandlerc deleted the key-context-improvements branch July 2, 2024 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants