Skip to content

Commit ad86d9a

Browse files
committed
Minor type stability improvements (JuliaLang/JuliaLowering.jl#73)
Fixing several type instabilities that I noticed while reviewing the code. Probably does not have much impact on compilation/runtime performance.
1 parent d1a99cf commit ad86d9a

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

JuliaLowering/src/eval.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,25 @@ function _to_lowered_expr(ex::SyntaxTree, stmt_offset::Int)
287287
elseif k == K"method"
288288
cs = map(e->_to_lowered_expr(e, stmt_offset), children(ex))
289289
# Ad-hoc unwrapping to satisfy `Expr(:method)` expectations
290-
c1 = cs[1] isa QuoteNode ? cs[1].value : cs[1]
290+
cs1 = cs[1]
291+
c1 = cs1 isa QuoteNode ? cs1.value : cs1
291292
Expr(:method, c1, cs[2:end]...)
292293
elseif k == K"newvar"
293294
Core.NewvarNode(_to_lowered_expr(ex[1], stmt_offset))
294295
elseif k == K"opaque_closure_method"
295296
args = map(e->_to_lowered_expr(e, stmt_offset), children(ex))
296297
# opaque_closure_method has special non-evaluated semantics for the
297298
# `functionloc` line number node so we need to undo a level of quoting
298-
@assert args[4] isa QuoteNode
299-
args[4] = args[4].value
299+
arg4 = args[4]
300+
@assert arg4 isa QuoteNode
301+
args[4] = arg4.value
300302
Expr(:opaque_closure_method, args...)
301303
elseif k == K"meta"
302304
args = Any[_to_lowered_expr(e, stmt_offset) for e in children(ex)]
303305
# Unpack K"Symbol" QuoteNode as `Expr(:meta)` requires an identifier here.
304-
args[1] = args[1].value
306+
arg1 = args[1]
307+
@assert arg1 isa QuoteNode
308+
args[1] = arg1.value
305309
Expr(:meta, args...)
306310
elseif k == K"static_eval"
307311
@assert numchildren(ex) == 1
@@ -339,7 +343,11 @@ function _to_lowered_expr(ex::SyntaxTree, stmt_offset::Int)
339343
if isnothing(head)
340344
throw(LoweringError(ex, "Unhandled form for kind $k"))
341345
end
342-
Expr(head, map(e->_to_lowered_expr(e, stmt_offset), children(ex))...)
346+
ret = Expr(head)
347+
for e in children(ex)
348+
push!(ret.args, _to_lowered_expr(e, stmt_offset))
349+
end
350+
return ret
343351
end
344352
end
345353

JuliaLowering/src/macro_expansion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function expand_macro(ctx, ex)
216216
# We use a specific well defined world age for the next checks and macro
217217
# expansion invocations. This avoids inconsistencies if the latest world
218218
# age changes concurrently.
219-
#
219+
#
220220
# TODO: Allow this to be passed in
221221
if hasmethod(macfunc, Tuple{typeof(mctx), typeof.(raw_args)...}; world=ctx.macro_world)
222222
macro_args = prepare_macro_args(ctx, mctx, raw_args)

JuliaLowering/src/runtime.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ function eval_closure_type(mod::Module, closure_type_name::Symbol, field_names,
195195
end
196196

197197
# Interpolate captured local variables into the CodeInfo for a global method
198-
function replace_captured_locals!(codeinfo, locals)
198+
function replace_captured_locals!(codeinfo::Core.CodeInfo, locals::Core.SimpleVector)
199199
for (i, ex) in enumerate(codeinfo.code)
200200
if Meta.isexpr(ex, :captured_local)
201-
codeinfo.code[i] = locals[ex.args[1]]
201+
codeinfo.code[i] = locals[ex.args[1]::Int]
202202
end
203203
end
204204
codeinfo

0 commit comments

Comments
 (0)