fix: call lowerEnumToScalarType? with ConstructorVal.induct (#9134)

This PR changes ToIR to call `lowerEnumToScalarType?` with
`ConstructorVal.induct` rather than the name of the constructor itself.
This was an oversight in some refactoring of code in the new compiler
before landing it. It should not affect runtime of compiled code (due to
the extra tagging/untagging being optimized by LLVM), but it does make
IR for the interpreter slightly more efficient.
This commit is contained in:
Cameron Zwarich 2025-07-01 13:00:34 -07:00 committed by GitHub
parent d31dfe92de
commit dbcf5b9d9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 13 deletions

View file

@ -208,7 +208,7 @@ partial def lowerLet (decl : LCNF.LetDecl) (k : LCNF.Code) : M FnBody := do
return code
else
mkExpr (.fap name irArgs)
else if let some scalarType ← lowerEnumToScalarType? ctorVal.name then
else if let some scalarType ← lowerEnumToScalarType? ctorVal.induct then
assert! args.isEmpty
let var ← bindVar decl.fvarId
return .vdecl var scalarType (.lit (.num ctorVal.cidx)) (← lowerCode k)

View file

@ -2,13 +2,11 @@
def MyOption.isSomeWithInstance._at_.isSomeWithInstanceNat.spec_0 (x_1 : @& obj) : u8 :=
case x_1 : obj of
MyOption.none →
let x_2 : obj := ctor_0[Bool.false];
let x_3 : u8 := unbox x_2;
ret x_3
let x_2 : u8 := 0;
ret x_2
MyOption.some →
let x_4 : obj := ctor_1[Bool.true];
let x_5 : u8 := unbox x_4;
ret x_5
let x_3 : u8 := 1;
ret x_3
def isSomeWithInstanceNat (x_1 : @& obj) : u8 :=
let x_2 : usize := 0;
let x_3 : obj := Array.uget ◾ x_1 x_2 ◾;

View file

@ -175,13 +175,11 @@
def g (x_1 : @& obj) : u8 :=
case x_1 : obj of
Exp.a3._impl →
let x_2 : obj := ctor_1[Bool.true];
let x_3 : u8 := unbox x_2;
ret x_3
let x_2 : u8 := 1;
ret x_2
default →
let x_4 : obj := ctor_0[Bool.false];
let x_5 : u8 := unbox x_4;
ret x_5
let x_3 : u8 := 0;
ret x_3
def g._boxed (x_1 : obj) : obj :=
let x_2 : u8 := g x_1;
dec x_1;