diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-09-20 13:09:13 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-09-21 14:48:40 -0700 |
| commit | 2da62a710652571cefe81e958e86d9c9ef74c747 (patch) | |
| tree | 8efa5bbf70929b7cb411bb62b9c32a886ba877c3 /src/Sema.zig | |
| parent | f739ac9c21ad89c07eb04f3aa7fc439f69b4a2fe (diff) | |
| download | zig-2da62a710652571cefe81e958e86d9c9ef74c747.tar.gz zig-2da62a710652571cefe81e958e86d9c9ef74c747.zip | |
Sema: restore master branch field reordering behavior
Let's try to reduce the explosive scope of this branch.
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index e152822399..1e4f6dea28 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -34349,9 +34349,28 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { return a_align.compare(.gt, b_align); } }; - mem.sortUnstable(RuntimeOrder, runtime_order, AlignSortContext{ - .aligns = aligns, - }, AlignSortContext.lessThan); + if (struct_type.isTuple(ip) or !mod.backendSupportsFeature(.field_reordering)) { + // TODO: don't handle tuples differently. This logic exists only because it + // uncovers latent bugs if removed. Fix the latent bugs and remove this logic! + // Likewise, implement field reordering support in all the backends! + // This logic does not reorder fields; it only moves the omitted ones to the end + // so that logic elsewhere does not need to special-case tuples. + var i: usize = 0; + var off: usize = 0; + while (i + off < runtime_order.len) { + if (runtime_order[i + off] == .omitted) { + off += 1; + continue; + } + runtime_order[i] = runtime_order[i + off]; + i += 1; + } + @memset(runtime_order[i..], .omitted); + } else { + mem.sortUnstable(RuntimeOrder, runtime_order, AlignSortContext{ + .aligns = aligns, + }, AlignSortContext.lessThan); + } } // Calculate size, alignment, and field offsets. |
