@fieldParentPtr
violates type based aliasing guarantees
#1644
Milestone
@fieldParentPtr
violates type based aliasing guarantees
#1644
(Depends on the answer to #1643, but I had it all typed out already so why not just post it.)
I believe that @fieldParentPtr , which has been more actively discussed recently on the topic of interface design, violates the basic assumptions of type based (non-)aliasing guarantees ("strict aliasing") (which I believe are still planned, but maybe not? see #1643 ).
Minimal example code:
From how I understand it, passing a value
t
of type*T
may modify any values
of distinct typeS
, as long as the compiler cannot prove thatt
ands
are not related via struct composition. This would have to be proven transitively across structs and functions, thereby also ".o"/"language" boundaries. (I think that would only make it reasonable for non-public/-exported types, although in that scope I would expect inlining and local dependency analysis to do a better job regardless.)Now that I look at it again, even dependencies between structs with pointer fields become kind of hairy. And any opaque type could potentially hide any number of types as fields as well... right? Maybe I just overestimated the applicability of strict aliasing (or underestimated its complexity).
Regardless, without
@fieldParentPtr
(aka "in the C world"), at least "primitive types" (non-composites) were relatively "safe" to optimize based on this. Now I'm having trouble coming up with any example where strict aliasing would be safe plainly based on function signature (without scope / lifetime information beyond that).The text was updated successfully, but these errors were encountered: