Add new direct delegation mode and use it in preset inheritance#111
Merged
soareschen merged 6 commits intomainfrom Jun 16, 2025
Merged
Add new direct delegation mode and use it in preset inheritance#111soareschen merged 6 commits intomainfrom
soareschen merged 6 commits intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new direct delegation for
delegate_components!and presets to work more efficiently. The direct delegation mode works by delegating to the target's delegate of the same key, instead of the target itself.Direct delegation can bring significant performance improvements, especially for presets and async functions, as it reduces the number of indirection calls generated from the generic code, thereby reducing the compile time.
New
->Delegation SyntaxA new delegation syntax
->is now supported, and can be used in place of:for direct delegation indelegate_components!.Consider the following example:
The macro will generate the following code:
As we can see, when direct delegation
->is used withBarComponnent, the macro will delegate to<BarProvider as DelegateComponents<BarComponent>>::Delegateinstead ofBarProvider. This requires thatBarProvideritself to also contain a delegation entry forBarComponent, as compared to implementing the provider trait directly.Direct Delegation in Preset Inheritance
The direct delegation mode is now used in preset inheritance. Since we know that the parent preset always contains the component maps instead of implementing the provider traits directly, the direct delegation mode would always work and thus can be used safely.
The use of direct delegation with presets significantly improves the compile time, especially when many nested levels of presets are used, such as in Hypershell.
Direct Delegation in
#[cgp_context]When preset inheritance is used in
#[cgp_context], the direct delegation mode is also used. This result in the context implementation having zero overhead when using presets, as compared to defining the component mappings directly.