Skip to content

Commit 6031ed7

Browse files
authored
More 1.12 compat (#635)
Fixes most of the semantic issues on 1.12 - there's still some test failures related to source locations, but should be usable for day-to-day things at least.
1 parent 96ed09c commit 6031ed7

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

bin/generate_builtins.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const ALWAYS_PRESENT = Core.Builtin[
1313
]
1414
# Builtins present from 1.6, not builtins (potentially still normal functions) anymore
1515
const RECENTLY_REMOVED = GlobalRef.(Ref(Core), [
16-
:arrayref, :arrayset, :arrayset, :const_arrayref, :memoryref,
16+
:arrayref, :arrayset, :arrayset, :const_arrayref, :memoryref, :set_binding_type!
1717
])
1818
const kwinvoke = Core.kwfunc(Core.invoke)
1919

@@ -274,6 +274,9 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
274274
maxarg = 6
275275
elseif name === :arraysize
276276
maxarg = 2
277+
elseif name === :set_binding_type!
278+
minarg = 2
279+
maxarg = 3
277280
end
278281
_scopedname = "$mod.$name"
279282
fcall = generate_fcall_nargs(_scopedname, minarg, maxarg)

src/builtins.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
220220
else
221221
return Some{Any}(Core.memoryrefswap!(getargs(args, frame)...))
222222
end
223-
elseif @static isdefined(Core, :set_binding_type!) && f === Core.set_binding_type!
224-
return Some{Any}(Core.set_binding_type!(getargs(args, frame)...))
225223
elseif f === Core.sizeof
226224
if nargs == 1
227225
return Some{Any}(Core.sizeof(@lookup(frame, args[2])))
@@ -482,6 +480,14 @@ function maybe_evaluate_builtin(frame, call_expr, expand::Bool)
482480
else
483481
return Some{Any}(Core.memoryref(getargs(args, frame)...))
484482
end
483+
elseif @static (isdefined(Core, :set_binding_type!) && Core.set_binding_type! isa Core.Builtin) && f === Core.set_binding_type!
484+
if nargs == 2
485+
return Some{Any}(Core.set_binding_type!(@lookup(frame, args[2]), @lookup(frame, args[3])))
486+
elseif nargs == 3
487+
return Some{Any}(Core.set_binding_type!(@lookup(frame, args[2]), @lookup(frame, args[3]), @lookup(frame, args[4])))
488+
else
489+
return Some{Any}(Core.set_binding_type!(getargs(args, frame)...))
490+
end
485491
elseif f === Core.Intrinsics.llvmcall
486492
return Some{Any}(Core.Intrinsics.llvmcall(getargs(args, frame)...))
487493
end

src/interpret.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,13 @@ function step_expr!(@nospecialize(recurse), frame, @nospecialize(node), istoplev
538538
error("this should have been handled by split_expressions")
539539
elseif node.head === :using || node.head === :import || node.head === :export
540540
Core.eval(moduleof(frame), node)
541-
elseif node.head === :const
541+
elseif node.head === :const || node.head === :globaldecl
542542
g = node.args[1]
543-
if isa(g, GlobalRef)
544-
mod, name = g.mod, g.name
543+
if length(node.args) == 2
544+
Core.eval(moduleof(frame), Expr(:block, Expr(node.head, g, @lookup(frame, node.args[2])), nothing))
545545
else
546-
mod, name = moduleof(frame), g::Symbol
546+
Core.eval(moduleof(frame), Expr(:block, Expr(node.head, g), nothing))
547547
end
548-
Core.eval(mod, Expr(:const, name))
549548
elseif node.head === :thunk
550549
newframe = Frame(moduleof(frame), node.args[1]::CodeInfo)
551550
if isa(recurse, Compiled)

src/optimize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ function smallest_ref(stmts, arg, idmin)
2424
end
2525

2626
function lookup_global_ref(a::GlobalRef)
27-
if Base.isbindingresolved(a.mod, a.name) && isdefined(a.mod, a.name)
27+
if Base.isbindingresolved(a.mod, a.name) && isdefined(a.mod, a.name) && isconst(a.mod, a.name)
2828
return QuoteNode(getfield(a.mod, a.name))
2929
end
3030
return a
3131
end
3232

3333
function lookup_global_refs!(ex::Expr)
34-
if isexpr(ex, (:isdefined, :thunk, :toplevel, :method, :global, :const))
34+
if isexpr(ex, (:isdefined, :thunk, :toplevel, :method, :global, :const, :globaldecl))
3535
return nothing
3636
end
3737
for (i, a) in enumerate(ex.args)

0 commit comments

Comments
 (0)