On Thursday, 28 August 2025 at 14:49:25 UTC, Kagamin wrote:
> If set allows deconstruction, you would match it against unnamed tuples
enum E : int {e0, e1, e2}
alias ESet = E.setof;
ESet es;
switch(es)
{
case (E.e0, E.e2): break;
case (E.e1, E.e2): break;
default: break;
}
LLVM IR for this Styx:
unit temp;
function main(): s32
{
enum E : s32 {e0, e1, e2}
alias ESet = bool[E];
var ESet es;
switch es do
{
on [E.e0, E.e2] do {}
on [E.e1, E.e2] do {}
else do {}
}
return 0;
}
is
; ModuleID = 'temp'
source_filename = "temp"
define i32 @main() {
entry:
%0 = alloca i32, align 4
%1 = alloca [2 x i32], align 4
%2 = alloca [2 x i32], align 4
store i32 0, ptr %0, align 4
%3 = load i32, ptr %0, align 4
switch i32 %3, label %4 [
i32 5, label %5
i32 6, label %6
]
4: ; preds = %entry
br label %7
5: ; preds = %entry
br label %7
6: ; preds = %entry
br label %7
7: ; preds = %4, %6, %5
ret i32 0
}
You should see the abstraction.
[E.e0, E.e2]
is i32 5
is 1 << 0 | 1 << 2
i.e 1 + 4
[E.e1, E.e2]
is i32 6
is 1 << 1 | 1 << 2
i.e 2 + 4
and that gets const folded.
I've nver get what people have against that kind of thing here. Still curious to me.