authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-20 13:09:13-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-21 14:48:40-07:00
log2da62a710652571cefe81e958e86d9c9ef74c747
tree8efa5bbf70929b7cb411bb62b9c32a886ba877c3
parentf739ac9c21ad89c07eb04f3aa7fc439f69b4a2fe

Sema: restore master branch field reordering behavior

Let's try to reduce the explosive scope of this branch.

1 files changed, 22 insertions(+), 3 deletions(-)

src/Sema.zig+22-3
......@@ -34349,9 +34349,28 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3434934349 return a_align.compare(.gt, b_align);
3435034350 }
3435134351 };
34352 mem.sortUnstable(RuntimeOrder, runtime_order, AlignSortContext{
34353 .aligns = aligns,
34354 }, AlignSortContext.lessThan);
34352 if (struct_type.isTuple(ip) or !mod.backendSupportsFeature(.field_reordering)) {
34353 // TODO: don't handle tuples differently. This logic exists only because it
34354 // uncovers latent bugs if removed. Fix the latent bugs and remove this logic!
34355 // Likewise, implement field reordering support in all the backends!
34356 // This logic does not reorder fields; it only moves the omitted ones to the end
34357 // so that logic elsewhere does not need to special-case tuples.
34358 var i: usize = 0;
34359 var off: usize = 0;
34360 while (i + off < runtime_order.len) {
34361 if (runtime_order[i + off] == .omitted) {
34362 off += 1;
34363 continue;
34364 }
34365 runtime_order[i] = runtime_order[i + off];
34366 i += 1;
34367 }
34368 @memset(runtime_order[i..], .omitted);
34369 } else {
34370 mem.sortUnstable(RuntimeOrder, runtime_order, AlignSortContext{
34371 .aligns = aligns,
34372 }, AlignSortContext.lessThan);
34373 }
3435534374 }
3435634375
3435734376 // Calculate size, alignment, and field offsets.