Skip to content

Commit 79ce9c6

Browse files
committed
feat: consistent type ABI regardless of transparency
1 parent ac0b829 commit 79ce9c6

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/Lean/Compiler/LCNF/Types.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,12 @@ where
166166
| .proj ``Subtype 0 (.const ``IO.RealWorld.nonemptyType []) =>
167167
return mkConst ``lcRealWorld
168168
| _ => return mkConst ``lcAny
169+
169170
whnfEta (type : Expr) : MetaM Expr := do
170-
let type ← whnf type
171+
-- We increase transparency here to unfold type aliases of functions that are declared as
172+
-- `irreducible`, such that they end up being represented as C functions.
173+
let type ← withTransparency .all do
174+
whnf type
171175
let type' := type.eta
172176
if type' != type then
173177
whnfEta type'

stage0/src/stdlib_flags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "util/options.h"
22

3+
// please update stage0 good sir
4+
35
namespace lean {
46
options get_default_options() {
57
options opts;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/-!
2+
This test ensures that the code generator sees the same type representation regardless of
3+
transparency setting in the elaborator. If this test ever breaks you should ensure that the IR
4+
between A and B is in sync.
5+
-/
6+
7+
namespace A
8+
9+
@[irreducible] def Function (α β : Type) := α → β
10+
11+
namespace Function
12+
13+
attribute [local semireducible] Function
14+
15+
@[inline]
16+
def id : Function α α := fun x => x
17+
18+
end Function
19+
20+
/--
21+
trace: [Compiler.IR] [result]
22+
def A.foo (x_1 : @& tobj) : tobj :=
23+
inc x_1;
24+
ret x_1
25+
def A.foo._boxed (x_1 : tobj) : tobj :=
26+
let x_2 : tobj := A.foo x_1;
27+
dec x_1;
28+
ret x_2
29+
-/
30+
#guard_msgs in
31+
set_option trace.compiler.ir.result true in
32+
def foo : Function Nat Nat := Function.id
33+
34+
end A
35+
36+
namespace B
37+
38+
def Function (α β : Type) := α → β
39+
40+
namespace Function
41+
42+
@[inline]
43+
def id : Function α α := fun x => x
44+
45+
end Function
46+
47+
/--
48+
trace: [Compiler.IR] [result]
49+
def B.foo (x_1 : @& tobj) : tobj :=
50+
inc x_1;
51+
ret x_1
52+
def B.foo._boxed (x_1 : tobj) : tobj :=
53+
let x_2 : tobj := B.foo x_1;
54+
dec x_1;
55+
ret x_2
56+
-/
57+
#guard_msgs in
58+
set_option trace.compiler.ir.result true in
59+
def foo : Function Nat Nat := Function.id
60+
61+
end B

0 commit comments

Comments
 (0)