Stream: t-lang/wg-unsafe-code-guidelines

Topic: Size >= Alignment for non-ZSTs


gnzlbg (Jul 02 2019 at 17:22, on Zulip):

We don't have any general layout rules that hold for all types. But AFAICT for all non-ZSTs, Size >= Alignment.

gnzlbg (Jul 02 2019 at 17:23, on Zulip):

Shall we document this somewhere ?

gnzlbg (Jul 02 2019 at 17:23, on Zulip):

We should also probably document for each of the possible ZSTs that their alignment >= size.

rkruppe (Jul 02 2019 at 17:27, on Zulip):

The formulation that doesn't need special casing for ZSTs is that "size has to be a multiple of alignment". Which is currently true but trying to document it riles up the "size vs stride" discussion again...

gnzlbg (Jul 02 2019 at 17:45, on Zulip):

@rkruppe that sounds good - we can add a note, explaining some of the straightforward consequences of that.

gnzlbg (Jul 02 2019 at 17:45, on Zulip):

I'm not sure where, but the beginning of the layout section might be appropriate

gnzlbg (Jul 02 2019 at 17:46, on Zulip):

or the glossary

gnzlbg (Jul 02 2019 at 17:46, on Zulip):

we can define size and alignment there

RalfJ (Jul 02 2019 at 18:06, on Zulip):

as long as we keep the reading from the array section, that we might want to change this to support stride>size types

RalfJ (Jul 02 2019 at 18:06, on Zulip):

until the lang team tells us "no"^^

RalfJ (Jul 02 2019 at 18:06, on Zulip):

this is one of the things I think Rust should have done pre-1.0 :/

rkruppe (Jul 02 2019 at 18:10, on Zulip):

I can't really imagine us ever actually doing this change now that we're years past 1.0, but long sigh yeah, in the terminology of the array chapter, it's "stride is a multiple of alignment"

RalfJ (Jul 02 2019 at 18:24, on Zulip):

well if I am the only one who thinks it is worthwhile to keep that option open, I am fine being outvoted

RalfJ (Jul 02 2019 at 18:24, on Zulip):

it's not like this is so close to my heart. we are not talking about union semantics after all. :P

gnzlbg (Jul 02 2019 at 18:51, on Zulip):

I would prefer to have a stride, and I'll also would prefer to somehow be able to reuse trailing padding.

gnzlbg (Jul 02 2019 at 18:52, on Zulip):

I don't know what Swift does here

Nicole Mazzuca (Jul 07 2019 at 06:34, on Zulip):

given the existence of unsafe code that assumes that stride = size, it's unlikely that we'd ever have the ability to change it

Last update: Nov 19 2019 at 19:05UTC