@@ -86,6 +86,7 @@ mutable struct Frame
8686 edges:: Vector{Any}
8787 stmts:: Vector{Vector{Variable}}
8888 rettype:: AType
89+ outer:: Bool
8990end
9091
9192getblock (fr:: Frame , b, follow) =
@@ -95,7 +96,7 @@ getblock(fr::Frame, b, follow) =
9596# TODO clear up inlined edges
9697uninline! (fr:: Frame , b, follow) = deleteat! (fr. inlined[b], follow+ 1 : length (fr. inlined[b]))
9798
98- Frame (ir:: IR ) = Frame (ir, [IR[] for _ = 1 : length (blocks (ir))], [], keys .(blocks (ir)), Union{})
99+ Frame (ir:: IR ; outer = false ) = Frame (ir, [IR[] for _ = 1 : length (blocks (ir))], [], keys .(blocks (ir)), Union{}, outer )
99100
100101function frame (ir:: IR , args... )
101102 prepare_ir! (ir)
@@ -200,7 +201,7 @@ function step!(inf::Inference)
200201 error (" Unrecognised expression $(st. expr) " )
201202 end
202203 elseif (brs = openbranches (block); length (brs) == 1 && ! isreturn (brs[1 ])
203- && ! (brs[1 ]. block == length (frame. ir. blocks)))
204+ && ! (frame . outer && brs[1 ]. block == length (frame. ir. blocks)))
204205 inferbranch! (inf, frame, b, f, brs[1 ])
205206 else
206207 for br in brs
@@ -249,3 +250,19 @@ function return_type(ir::IR, args...)
249250 infer! (inf)
250251 return fr. rettype
251252end
253+
254+ function inlineable (ir:: IR , inf:: Inference )
255+ for (v, st) in ir
256+ Ts = exprtype .((ir,), st. expr. args)
257+ haskey (inf. frames, Ts) && return (v, Ts)
258+ end
259+ end
260+
261+ function inlineall (ir:: IR , inf:: Inference )
262+ while (next = inlineable (ir, inf)) != nothing
263+ v, Ts = next
264+ subir = inf. frames[Ts]. ir
265+ ir = inline (ir, v, subir)
266+ end
267+ return ir
268+ end
0 commit comments