Skip to content

Commit 9c8223e

Browse files
committed
perf: infer better IR types to reduce refcounting
1 parent 72ddc47 commit 9c8223e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Lean/Compiler/IR/Boxing.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ def tryCorrectVDeclType (ty : IRType) (e : Expr) : M IRType :=
280280
match e with
281281
| .fap f _ => do
282282
let decl ← getDecl f
283-
return decl.resultType
283+
match decl.name with
284+
| ``String.Pos.next | ``Array.size => dbg_trace "strrrrike"; return .tagged
285+
| _ => return decl.resultType
284286
| .pap .. => return .object
285287
| .uproj .. => return .usize
286288
| .ctor .. | .reuse .. | .ap .. | .lit .. | .sproj .. | .proj .. | .reset .. =>

tests/lean/run/unbox_sizes.lean

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/--
2+
trace: [Compiler.IR] [result]
3+
def test (x_1 : @& obj) : tobj :=
4+
let x_2 : tagged := Array.size ◾ x_1;
5+
let x_3 : tobj := Nat.add x_2 x_2;
6+
ret x_3
7+
def test._boxed (x_1 : obj) : tobj :=
8+
let x_2 : tobj := test x_1;
9+
dec x_1;
10+
ret x_2
11+
---
12+
info: strrrrike
13+
-/
14+
#guard_msgs in
15+
set_option trace.compiler.ir.result true in
16+
def test (xs : Array Int) :=
17+
let size := xs.size
18+
size + size

0 commit comments

Comments
 (0)