-
Notifications
You must be signed in to change notification settings - Fork 200
Deduplicate push()
/extend()
helpers as a default impl on TaggedStructure
#994
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
base: master
Are you sure you want to change the base?
Conversation
quote!(unsafe impl Extends<#base<'_>> for #name<'_> {}) | ||
quote!(unsafe impl<'a> Extends<'a, #base<'a>> for #name<'a> {}) |
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.
Named lifetimes are back otherwise the trybuild
test no longer fails as expected.
/// their structure is layout-compatible [`BaseInStructure`] and [`BaseOutStructure`]. | ||
/// | ||
/// [1]: https://registry.khronos.org/vulkan/specs/latest/styleguide.html#extensions-interactions | ||
pub unsafe trait Extends<'a, B: AnyTaggedStructure<'a>>: AnyTaggedStructure<'a> {} |
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.
Note to self: play with these lifetimes to see if we can simplify any further before we commit.
…tructure` Having these functions generated for every root struct in our definitions file contributes to significant bloat, in part because of their massive documentation comments and not containing any generator-dynamic code or identifiers. Now that `trait Extends{Root}` was generalized into a single `trait Extends<Root>` with the root structure as generic argument, it becomes possible to build on top of that and define a default trait function on every Vulkan structure. These functions require the "pushed" type to derive `Extends<Self>`, hence limiting the function to be called without ever having to track if the root structure is being extended.
Alright, spent some time messing around with this. First: It seems like a lifetime parameter is needed on whatever trait Separately, I'm not sure the object safety achieved here is useful. IIRC (though I can't find the discussion) the motivation was to support stuff like If we remove the object safety constraint, then it's no longer necessary to have In short, I think the following diff, on top of this PR, plus a generator rerun, is a sweet spot:
|
I also experimented briefly with something like trait TaggedStructure {
type Abstract<'a>;
fn narrow<'a>(self) -> Self::Abstract<'a>
where Self: 'a;
} but that would require a |
Having these functions generated for every root struct in our definitions file contributes to significant bloat, in part because of their massive documentation comments and not containing any generator-dynamic code or identifiers.
Now that
trait Extends{Root}
was generalized into a singletrait Extends<Root>
with the root structure as generic argument, it becomes possible to build on top of that and define a default trait function on every Vulkan structure. These functions require the "pushed" type to deriveExtends<Self>
, hence limiting the function to be called without ever having to track if the root structure is being extended.