Skip to content

Commit d4a0012

Browse files
committed
void
1 parent 6fb29e0 commit d4a0012

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

src/Lean/Compiler/IR/Basic.lean

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ instance : ToString JoinPointId := ⟨fun a => "block_" ++ toString a.idx⟩
5454
5555
- `tobject` an `object` or a `tagged` pointer
5656
57+
- `void` is used to identify uses of the state token from `BaseIO` which do no longer need
58+
to be passed around etc. at this point in the pipeline.
59+
5760
- `struct` and `union` are used to return small values (e.g., `Option`, `Prod`, `Except`)
5861
on the stack.
5962
@@ -80,7 +83,7 @@ inductive IRType where
8083
| struct (leanTypeName : Option Name) (types : Array IRType) : IRType
8184
| union (leanTypeName : Name) (types : Array IRType) : IRType
8285
-- TODO: Move this upwards after a stage0 update.
83-
| tagged
86+
| tagged | void
8487
deriving Inhabited, BEq, Repr
8588

8689
namespace IRType
@@ -99,6 +102,7 @@ def isObj : IRType → Bool
99102
| object => true
100103
| tagged => true
101104
| tobject => true
105+
| void => true
102106
| _ => false
103107

104108
def isPossibleRef : IRType → Bool
@@ -115,7 +119,7 @@ def isErased : IRType → Bool
115119

116120
def boxed : IRType → IRType
117121
| object | float | float32 => object
118-
| tagged | uint8 | uint16 => tagged
122+
| void | tagged | uint8 | uint16 => tagged
119123
| _ => tobject
120124

121125
end IRType

src/Lean/Compiler/IR/EmitC.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def toCType : IRType → String
6969
| IRType.tagged => "lean_object*"
7070
| IRType.tobject => "lean_object*"
7171
| IRType.erased => "lean_object*"
72+
| IRType.void => "lean_object*"
7273
| IRType.struct _ _ => panic! "not implemented yet"
7374
| IRType.union _ _ => panic! "not implemented yet"
7475

src/Lean/Compiler/IR/EmitLLVM.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ def toLLVMType (t : IRType) : M llvmctx (LLVM.LLVMType llvmctx) := do
329329
| IRType.tagged => do LLVM.pointerType (← LLVM.i8Type llvmctx)
330330
| IRType.tobject => do LLVM.pointerType (← LLVM.i8Type llvmctx)
331331
| IRType.erased => do LLVM.pointerType (← LLVM.i8Type llvmctx)
332+
| .void => do LLVM.pointerType (← LLVM.i8Type llvmctx)
332333
| IRType.struct _ _ => panic! "not implemented yet"
333334
| IRType.union _ _ => panic! "not implemented yet"
334335

src/Lean/Compiler/IR/Format.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private partial def formatIRType : IRType → Format
6666
| IRType.uint64 => "u64"
6767
| IRType.usize => "usize"
6868
| IRType.erased => "◾"
69+
| IRType.void => "void"
6970
| IRType.object => "obj"
7071
| IRType.tagged => "tagged"
7172
| IRType.tobject => "tobj"

src/Lean/Compiler/IR/ToIR.lean

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def lowerArg (a : LCNF.Arg) : M Arg := do
8989
inductive TranslatedProj where
9090
| expr (e : Expr)
9191
| erased
92+
| void
9293
deriving Inhabited
9394

9495
def lowerProj (base : VarId) (ctorInfo : CtorInfo) (field : CtorFieldInfo)
@@ -98,6 +99,7 @@ def lowerProj (base : VarId) (ctorInfo : CtorInfo) (field : CtorFieldInfo)
9899
| .usize i => ⟨.expr (.uproj i base), .usize⟩
99100
| .scalar _ offset irType => ⟨.expr (.sproj (ctorInfo.size + ctorInfo.usize) offset base), irType⟩
100101
| .erased => ⟨.erased, .erased⟩
102+
| .void => ⟨.void, .void⟩
101103

102104
def lowerParam (p : LCNF.Param) : M Param := do
103105
let x ← bindVar p.fvarId
@@ -148,6 +150,7 @@ partial def lowerLet (decl : LCNF.LetDecl) (k : LCNF.Code) : M FnBody := do
148150
| .erased =>
149151
bindErased decl.fvarId
150152
lowerCode k
153+
| .void => unreachable!
151154
| .erased =>
152155
bindErased decl.fvarId
153156
lowerCode k
@@ -178,7 +181,7 @@ partial def lowerLet (decl : LCNF.LetDecl) (k : LCNF.Code) : M FnBody := do
178181
match fields[i] with
179182
| .object .. =>
180183
result := result.push irArgs[i]!
181-
| .usize .. | .scalar .. | .erased => pure ()
184+
| .usize .. | .scalar .. | .erased | .void => pure ()
182185
pure result
183186
let objVar ← bindVar decl.fvarId
184187
let rec lowerNonObjectFields (_ : Unit) : M FnBody :=
@@ -192,7 +195,7 @@ partial def lowerLet (decl : LCNF.LetDecl) (k : LCNF.Code) : M FnBody := do
192195
| .scalar _ offset argType =>
193196
let k ← loop (i + 1)
194197
return .sset objVar (ctorInfo.size + ctorInfo.usize) offset varId argType k
195-
| .object .. | .erased => loop (i + 1)
198+
| .object .. | .erased | .void => loop (i + 1)
196199
| some .erased => loop (i + 1)
197200
| none => lowerCode k
198201
loop 0
@@ -270,6 +273,12 @@ partial def lowerAlt (discr : VarId) (a : LCNF.Alt) : M Alt := do
270273
| .erased =>
271274
bindErased param.fvarId
272275
loop (i + 1)
276+
| .void =>
277+
let info ← getCtorLayout ``PUnit.unit
278+
return .vdecl (← bindVar param.fvarId)
279+
.void
280+
(.ctor info.ctorInfo #[])
281+
(← loop (i + 1))
273282
| none, none => lowerCode code
274283
| _, _ => panic! "mismatched fields and params"
275284
loop 0

src/Lean/Compiler/IR/ToIRType.lean

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ where fillCache : CoreM IRType := do
5454
-- `Int` is specified as an inductive type with two constructors that have relevant arguments,
5555
-- but it has the same runtime representation as `Nat` and thus needs to be special-cased here.
5656
| ``Int => return .tobject
57-
| ``lcRealWorld => return .tagged
57+
| ``lcRealWorld => return .void
5858
| _ =>
5959
let env ← Lean.getEnv
6060
let some (.inductInfo inductiveVal) := env.find? name | return .tobject
@@ -110,12 +110,14 @@ inductive CtorFieldInfo where
110110
| object (i : Nat) (type : IRType)
111111
| usize (i : Nat)
112112
| scalar (sz : Nat) (offset : Nat) (type : IRType)
113+
| void
113114
deriving Inhabited
114115

115116
namespace CtorFieldInfo
116117

117118
def format : CtorFieldInfo → Format
118119
| erased => "◾"
120+
| void => "void"
119121
| object i type => f!"obj@{i}:{type}"
120122
| usize i => f!"usize@{i}"
121123
| scalar sz offset type => f!"scalar#{sz}@{offset}:{type}"
@@ -160,6 +162,7 @@ where fillCache := do
160162
pure <| .object i irFieldType
161163
| .usize => pure <| .usize 0
162164
| .erased => .pure <| .erased
165+
| .void => .pure <| .void
163166
| .uint8 =>
164167
has1BScalar := true
165168
.pure <| .scalar 1 0 .uint8
@@ -186,7 +189,7 @@ where fillCache := do
186189
| .usize _ => do
187190
let i ← modifyGet fun nextIdx => (nextIdx, nextIdx + 1)
188191
return .usize i
189-
| .object .. | .scalar .. | .erased => return field
192+
| .object .. | .scalar .. | .erased | .void => return field
190193
let numUSize := nextIdx - numObjs
191194
let adjustScalarsForSize (fields : Array CtorFieldInfo) (size : Nat) (nextOffset : Nat)
192195
: Array CtorFieldInfo × Nat :=
@@ -198,7 +201,7 @@ where fillCache := do
198201
return .scalar sz offset type
199202
else
200203
return field
201-
| .object .. | .usize _ | .erased => return field
204+
| .object .. | .usize _ | .erased | .void => return field
202205
let mut nextOffset := 0
203206
if has8BScalar then
204207
⟨fields, nextOffset⟩ := adjustScalarsForSize fields 8 nextOffset

0 commit comments

Comments
 (0)