zig icon indicating copy to clipboard operation
zig copied to clipboard

Sema: copy pointer alignment to union field pointers

Open mlugg opened this issue 2 years ago • 1 comments

Resolves: #15878

mlugg avatar Jun 10 '23 00:06 mlugg

Hm, this isn't quite right for tagged unions in some cases. The current layout of tagged unions is such that the larger of the tag and payload comes first. This has a weird consequence: if we have an *align(128) U, then &ptr.field is align(128) only if the payload is larger than the tag (since then the payload comes first so inherits the alignment, even if it's larger than the payload's natural alignment). I don't think it's desirable to have the type of a field pointer depend on language semantics like this, so we have a few choices here:

  • Make &u.field for tagged unions cap the alignment at the union's natural alignment, regardless of whether it's actually more-aligned. This is probably the simplest option.
  • Change the backends so the payload comes first, regardless of its size. This would be more work, and might make tagged unions bigger in memory in some cases, but would have less surprising semantics at the language level.

mlugg avatar Jun 11 '23 09:06 mlugg

This merge has been reverted in 43c98dc11567eeb38be041c7dad179c53156f3df while the large variety of random failures that occur with the build system on my local configuration in response to this change are investigated.

jacobly0 avatar Jun 29 '23 04:06 jacobly0

The previous revert has been unreverted in 2282c278850e29af81e463d55c81fa08855823f8 due to finally diagnosing the issue as being related to linux kernel 6.4.0 and not this PR.

jacobly0 avatar Jul 01 '23 03:07 jacobly0