Open Manishearth opened 10 months ago
Do they have the same ABI?
No.
is it safe to transmute between Generic\
and Generic<Wrapper\ >?
I think that s the intention; I don't know if it actually follows from anything we document. I also don't know what -Zrandomize-layout
does here.
Probably worth documenting somewhere.
I suspect -Zrandomize-layout
doesn't respect this, but that's fine, it's not a perfect representation of the rules.
That would make randomize-layout unsound though, which is clearly a bug. So I don't think it's "fine".
I don't think we promise that Generic<T>
and Generic<Wrapper<T>>
are the same. In general we can't do this, because of associated types. Maybe we can carve out some subset of cases for which it is okay, but I don't think that -Zrandomize-layout
is doing anything unsound currently.
The question (as I understood it) was for this specific type, which doesn't use associated types. Obviously there are limits to this.
We definitely don't promise this, and randomize-layout
may be laying them out differently. I don't think this is particularly desirable, but repr(Rust) structs have basically no layout guarantees.
That would make randomize-layout unsound though, which is clearly a bug. So I don't think it's "fine".
Oh sure I meant that I wouldn't be surprised and I wouldn't treat it as a strong expectation of what the semantics should be.
Do they have the same ABI?
No.
I read through the linked document and could not find anything that states that the answer is no. What am I missing?
The answer is always "no" except when the linked document states otherwise. So the fact that none of the cases there says they are compatible implies that they are not compatible.
The answer is always "no" except when the linked document states otherwise. So the fact that none of the cases there says they are compatible implies that they are not compatible.
The document does not seem to discuss ABI compatibility of structs at all. Does that mean that two different structs are never ABI compatible?
It mentions repr(transparent). But structs without that attribute are indeed not ABI compatible with anything else.
Context: https://github.com/hyperium/hyper/issues/3500
repr(transparent)
makes types have the same representation/ABI. Does it have the same effect on generic types containing it?For example, in the following case:
is it safe to transmute between
Generic<T>
andGeneric<Wrapper<T>>
? Do they have the same ABI? I'm thinking about things like-Zrandomize-layout
.