Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
221a57b
add basics for unboxed unions/structs
Rob23oba Dec 31, 2025
8e56894
basic changes to make unboxed work with the interpreter
Rob23oba Jan 1, 2026
7723f50
cleanup with new boolean check functions
Rob23oba Jan 1, 2026
0ac01c6
handle reboxing
Rob23oba Jan 1, 2026
e6ec3f3
fix rc pass
Rob23oba Jan 1, 2026
da256b9
fix invalid reuse and memory leak, add box_params pass
Rob23oba Jan 1, 2026
57f8013
adjust c code emitter + some fixes
Rob23oba Jan 2, 2026
1b1c5b9
more compact formatting
Rob23oba Jan 2, 2026
1daf70b
some fixes for rc, fix ctor with erased params, handle "bad" reshapes
Rob23oba Jan 2, 2026
4e2e59f
commit windows build optimization
Rob23oba Jan 2, 2026
43b1b4d
fix interpreter
Rob23oba Jan 2, 2026
bbb841f
fix rc for box instruction + minor flaw in unbox_params
Rob23oba Jan 2, 2026
5c320a5
oopie
Rob23oba Jan 2, 2026
00a4298
oopie v2
Rob23oba Jan 2, 2026
e17e69f
handle reshape from erased field
Rob23oba Jan 2, 2026
a85756f
fix tests
Rob23oba Jan 2, 2026
a2ef519
oopie v3
Rob23oba Jan 2, 2026
7d9cc32
big reshape oopie
Rob23oba Jan 2, 2026
34d70f0
add import unbox attributes
Rob23oba Jan 2, 2026
e69e21d
disable unboxing on init decls
Rob23oba Jan 2, 2026
d470e42
oopie
Rob23oba Jan 2, 2026
c54088d
oopieS
Rob23oba Jan 2, 2026
4a62f78
come on
Rob23oba Jan 3, 2026
bd36228
also don't unbox IO Unit init fns
Rob23oba Jan 3, 2026
dd1e81f
use different approach
Rob23oba Jan 3, 2026
ece80f1
fix
Rob23oba Jan 3, 2026
1c34133
right, boxed versions take a parameter
Rob23oba Jan 3, 2026
c871947
fix calling convention mismatch in reshaping function
Jan 4, 2026
f473deb
fix test
Rob23oba Jan 4, 2026
429fefd
fix borrowing with let a := box b
Rob23oba Jan 4, 2026
fdbe96d
fix borrowing for let a := unbox b
Rob23oba Jan 4, 2026
df74ffd
handle sproj/uproj/sset/uset on structs correctly
Rob23oba Jan 4, 2026
7d56eb6
reduce amount of lines in big_do.lean to prevent stack overflow
Rob23oba Jan 4, 2026
89fcf62
fix tests + oopie
Rob23oba Jan 4, 2026
cfbdacf
disable test link_lake.lean
Rob23oba Jan 4, 2026
f32af45
Merge remote-tracking branch 'upstream/nightly-with-mathlib' into com…
Rob23oba Jan 4, 2026
2aab948
fix struct constants in the interpreter
Rob23oba Jan 4, 2026
0be87d6
also add _boxed declarations for struct `init` decls
Rob23oba Jan 5, 2026
b4e1ebc
add compiled-only struct_rc pass
Rob23oba Jan 6, 2026
84c45cb
cleanup, add docs, add tests
Rob23oba Jan 6, 2026
80f73b8
restore tests
Rob23oba Jan 4, 2026
6d9efe1
Merge branch 'nightly-with-mathlib' of https://github.com/leanprover/…
Rob23oba Jan 6, 2026
f1ff892
Merge branch 'master' of https://github.com/leanprover/lean4 into com…
Rob23oba Jan 6, 2026
14cabe0
fix uset/uproj and fix test
Rob23oba Jan 6, 2026
34e2c0f
fix memcpy calls
Rob23oba Jan 6, 2026
c99e6eb
fix test
Rob23oba Jan 6, 2026
b2a4183
Merge remote-tracking branch 'upstream/master' into HEAD
Rob23oba Jan 9, 2026
90e757e
fix struct rc pass
Rob23oba Jan 10, 2026
5be7b6a
spread structure args
Rob23oba Jan 10, 2026
a9d13a0
update stage0
Rob23oba Jan 10, 2026
c0180fe
special case for Option
Rob23oba Jan 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Init/Prelude.lean
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ structure PProd (α : Sort u) (β : Sort v) where
/-- The second element of a pair. -/
snd : β

attribute [unbox] PProd

/--
A product type in which both `α` and `β` are in the same universe.

Expand All @@ -546,6 +548,8 @@ structure MProd (α β : Type u) where
/-- The second element of a pair. -/
snd : β

attribute [unbox] MProd

/--
`And a b`, or `a ∧ b`, is the conjunction of propositions. It can be
constructed and destructed like a pair: if `ha : a` and `hb : b` then
Expand Down
1 change: 1 addition & 0 deletions src/Init/System/ST.lean
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ instance {σ : Type} : MonadAttach (ST σ) where
CanReturn x a := ∃ s s', x s = ⟨a, s'⟩
attach x s := match h : x s with | ⟨a, s'⟩ => ⟨⟨a, s, s', h⟩, s'⟩

@[unbox]
inductive EST.Out (ε : Type) (σ : Type) (α : Type) where
| ok : α → Void σ → EST.Out ε σ α
| error : ε → Void σ → EST.Out ε σ α
Expand Down
16 changes: 12 additions & 4 deletions src/Lean/Compiler/IR.lean
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,22 @@ def compile (decls : Array Decl) : CompilerM (Array Decl) := do
let mut decls := decls
decls := decls.map Decl.pushProj
logDecls `push_proj decls
decls := prepareBoxParams (← getEnv) decls
logDecls `box_params decls
decls ← explicitBoxing decls
logDecls `boxing decls
if compiler.reuse.get (← getOptions) then
decls := decls.map (Decl.insertResetReuse (← getEnv))
logDecls `reset_reuse decls
decls := decls.map Decl.elimDead
logDecls `elim_dead decls
decls := decls.map Decl.simpCase
logDecls `simp_case decls
decls := decls.map Decl.normalizeIds
decls := decls.map Decl.elimDead
logDecls `elim_dead decls
decls ← inferBorrow decls
logDecls `borrow decls
decls ← explicitBoxing decls
logDecls `boxing decls
decls := ExplicitBoxing.addBoxedVersions (← getEnv) decls
logDecls `boxed_versions decls
decls ← explicitRC decls
logDecls `rc decls
if compiler.reuse.get (← getOptions) then
Expand All @@ -70,6 +74,10 @@ def compile (decls : Array Decl) : CompilerM (Array Decl) := do
decls ← updateSorryDep decls
logDecls `result decls
checkDecls decls
if (← getOptions).getBool (tracePrefixOptionName ++ `struct_rc) ||
(← getOptions).getBool tracePrefixOptionName then
let decls2 := decls.map StructRC.visitDecl
log (LogEntry.step `struct_rc decls2)
decls ← toposortDecls decls
addDecls decls
inferMeta decls
Expand Down
284 changes: 195 additions & 89 deletions src/Lean/Compiler/IR/Basic.lean

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/Lean/Compiler/IR/Borrow.lean
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def ownArgsIfParam (xs : Array Arg) : M Unit := do
| .var x => if ctx.paramSet.contains x.idx then ownVar x
| .erased => pure ()

def collectExpr (z : VarId) (e : Expr) : M Unit := do
def collectExpr (z : VarId) (t : IRType) (e : Expr) : M Unit := do
match e with
| .reset _ x =>
ownVar z
Expand All @@ -243,9 +243,10 @@ def collectExpr (z : VarId) (e : Expr) : M Unit := do
| .ctor _ xs =>
ownVar z
ownArgsIfParam xs
| .proj _ x =>
| .proj _ _ x | .unbox x =>
if (← isOwned x) then ownVar z
if (← isOwned z) then ownVar x
if (← isOwned z) then
unless t.isScalar do ownVar x
| .fap g xs =>
let ps ← getParamInfo (.decl g)
ownVar z
Expand All @@ -257,7 +258,10 @@ def collectExpr (z : VarId) (e : Expr) : M Unit := do
| .pap _ xs =>
ownVar z
ownArgs xs
| _ => pure ()
| .box _ x =>
ownVar z
ownVar x
| .lit _ | .isShared _ | .sproj .. | .uproj .. => pure ()

def preserveTailCall (x : VarId) (v : Expr) (b : FnBody) : M Unit := do
let ctx ← read
Expand All @@ -279,9 +283,9 @@ partial def collectFnBody (b : FnBody) : M Unit := do
let ctx ← read
updateParamMap (.jp ctx.currFn j)
collectFnBody b
| .vdecl x _ v b =>
| .vdecl x t v b =>
collectFnBody b
collectExpr x v
collectExpr x t v
preserveTailCall x v b
| .jmp j ys =>
let ctx ← read
Expand Down
Loading
Loading