lean4-htt/tests/lean/run/4278.lean
Cameron Zwarich 2e627d3692 feat: move constructor layout to Lean and add a few optimizations
This PR moves the constructor layout code from C++ to Lean. When
writing the new compiler, we just reused the existing C++ code,
even though it was a bit inconvenient, because we wanted to
ensure that constructor layout always matched the existing
compiler.

This fixes #2589 by handling struct field types just like any
other type being lowered, and thus applying the trivial structure
optimization in the process. Originally, I wanted to port the
code to Lean without any functional changes, but I found that
it took less code to just implement it "correctly" and get this
fix as a consequence than to emulate the bugs of the existing
C++ implementation.
2025-06-30 15:39:58 +02:00

23 lines
574 B
Text

-- Type has trivial structure, so `u64` representation is expected.
structure Unboxed where val : UInt64
structure S where
unboxed : Unboxed
unused : Bool
/--
trace: [Compiler.IR] [result]
def get_unboxed (x_1 : obj) : u64 :=
let x_2 : u64 := sproj[0, 0] x_1;
dec x_1;
ret x_2
def get_unboxed._boxed (x_1 : obj) : obj :=
let x_2 : u64 := get_unboxed x_1;
let x_3 : obj := box x_2;
ret x_3
-/
#guard_msgs in
set_option trace.compiler.ir.result true in
@[export get_unboxed]
def get_unboxed (s : S) : UInt64 := s.unboxed.val