pre-RFC: #[phantomgeneric(..)] attribute


Given the general way that the unsafe code guidelines have been going with respect to guaranteeing anything about the layout of types,I’ve decided to create an RFC for guaranteeing the layout of types with phantom generic (type/const) parameters with an attribute.

I welcome criticisms as to structure,examples given,grammar,etc.


Do you need full “regardless”? Would a weaker rule like “the monomorphized types are layout compatible when their generic arguments are layout compatible” be sufficient?

That’s sortof a middle ground to the “deterministic but undefined” rule: deterministic inside a type constructor, but not between then.

(That way (i32,u32) and (i32,f32) would be compatible – layout compatible things passed to the same Tuple2 type constructor – but they wouldn’t be compatible with struct Foo(f32,u32);.)


The idea is that for this datatype:

struct Wrapper<T,C>{

Arc<Wrapper<T,SomeType>> is layout compatible with Arc<Wrapper<T,SomeOtherType>>.

The attribute is intended to specify phantom generic parameters,allowing those generic parameters to change while guaranteeing that the memory layout is the same.

Whether (i32,u32) and (i32,f32) are compatible is outside the scope of this attribute.


The reason is that the generic parameters are not instantiated as values,they are required to be phantom generic parameters, which are used entirely at compile-time, without any runtime component.