lang: Reserve the optional never tag

cfcb131ad26617f16904c557d80b3a30e9a14b5fd2ac9e3b8ba932d4b702ad31
Give optional never values space for the tag so their generated RIL
passes bounds verification.

Assisted-by: Codex:gpt-6
Alexis Sellier committed ago 1 parent 63b7f23e
lib/std/lang/resolver.rad +2 -2
1794 1794
    if isNullableType(inner) {
1795 1795
        return getTypeLayout(self, inner);
1796 1796
    }
1797 1797
    let innerLayout = getTypeLayout(self, inner);
1798 1798
    let tagSize: u32 = 1;
1799 -
    let valOffset = mem::alignUp(tagSize, innerLayout.alignment);
1800 1799
    let alignment = max(innerLayout.alignment, 1);
1800 +
    let valOffset = mem::alignUp(tagSize, alignment);
1801 1801
1802 1802
    return Layout {
1803 1803
        size: mem::alignUp(valOffset + innerLayout.size, alignment),
1804 1804
        alignment,
1805 1805
    };
1806 1806
}
1807 1807
1808 1808
/// Get the payload offset within an optional aggregate.
1809 1809
export fn getOptionalValOffset(self: &Resolver, inner: Type) -> u32 {
1810 1810
    let innerLayout = getTypeLayout(self, inner);
1811 -
    return mem::alignUp(1, innerLayout.alignment);
1811 +
    return mem::alignUp(1, max(innerLayout.alignment, 1));
1812 1812
}
1813 1813
1814 1814
/// Check if a type is optional.
1815 1815
export fn isOptionalType(ty: Type) -> bool {
1816 1816
    match ty {
test/verify/expected +0 -1
68 68
prog.vm Type
69 69
range.arithmetic Type
70 70
record.scalar Class
71 71
ref.local.slice.release Type
72 72
ref.mut.ptr Type
73 -
return.never.catch Bounds
74 73
slice.alloc.loop Type
75 74
slice.alloc.trait Type
76 75
slice.append.errors Type
77 76
slice.append.failure Type
78 77
slice.append.limit Type