-
Notifications
You must be signed in to change notification settings - Fork 190
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
Rewrite chains to support immutable p_next
input structures
#970
Comments
Assigning the |
I think our current interface is safer and more readable than the C++-style one. |
It may have gotten lost in this long read: the point is to get rid of |
Right, I'm saying I think the ergonomics of our pointer chain helpers justify the use of
I'm not sure what you mean by this. |
And that sits wrong with me. Having I don't have a concrete use-case around other than the proposed sample, where
This is what I mean, if we introduce the Either way, perhaps we should add this caveat to the |
It seems normal to me to have something that's mutable while you set it up and then passed elsewhere immutably to be consumed.
I don't have a strong argument against supporting both patterns if you really want, except that it might cause minor confusion about best practices downstream. Also probably a post-#953 thing, in the interest of avoiding large amounts of new redundant code.
Yeah, that would be useful. |
And we haven't done anything about "unborrowing" them yet, but that's another beast.
👍
I proposed in #879 (comment) to take a more piecemeal, incremental approach. That PR crams in way too much. Wdyt about the proposal? You mentioned two points against traitifying, that equally apply to #953? Pending that I can orchestrate how to land #909 relative to it. |
Vulkan specifically defines a
VkBaseInStructure
with a constantpNext
pointer for read-only inputs to APIs likeinfo
invkGetPhysicalDeviceImageFormatProperties2()
(in contrast to the writableproperties
as outputs).We do not currently make use of this distinction between
VkBaseOutStructure
, requiring callers to unconditionally declare their "read-only" input structures asmut
when using.push_next(&mut T)
because of the way we build up a pointer chain.While this might not directly be a problem, it would have been nice to have a way to construct chains "more linearly" (like in C++) while keeping these structs defined as constants locally, to signify their
Example
Unfortunately
external_image_format_info
anddrm_format_modifier_info
in this example are only definedmut
because of.push_next(&mut T)
. The second call to.push_next()
has to mutateexternal_image_format_info.p_next = drm_format_modifier_info.p_next;
to insert it in the chain.Not to mention, by default this means structs are inserted in the chain in reverse order, i.e. the last struct to go ends up being the first struct in the chain. This is usually not a problem in practice.
Unfortunately I do not immediately have a solution to this "problem" (that isn't introducing multiple wrapper structs and macros to abstract chains...) aside from defining a
.next()
directly on these "extending structures, so that you would instead write:This is much closer to what one would write in C++, making sample/code translation easier. Noting that
next()
here is a builder function that overwritesp_next
- and probably needs an assert in case!self.p_next.is_null()
?However, it easily breaks our predicate of guarding
push_next()
to only take extending structs, and only implementing it on the root struct viatrait ExtendsT
. Moreover, we'd have to disambiguate where a struct extends multiple root structs, such as:Besides not being able to create an OR trait bound on this hypothetical
fn next<T: ExtendsX | ExtendsY | ExtendsZ>
, users could mix up pointer chains from different "incompatible" hierarchies at places.Perhaps that validation is not something that is very important for Ash. It's definitely a nicety for callers and why I'd like to keep it, but not something that's in place to prevent UB.
The text was updated successfully, but these errors were encountered: