Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimum adjustments to make JuliaInterpreter work with v1.12 #631

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,14 @@ evaluate_call!(frame::Frame, call_expr::Expr; kwargs...) = evaluate_call!(finish
# The following come up only when evaluating toplevel code
function evaluate_methoddef(frame, node)
f = node.args[1]
if isa(f, Symbol)
mod = moduleof(frame)
if Base.isbindingresolved(mod, f) && isdefined(mod, f) # `isdefined` accesses the binding, making it impossible to create a new one
f = getfield(mod, f)
if f isa Symbol || f isa GlobalRef
mod = f isa Symbol ? moduleof(frame) : f.mod
name = f isa Symbol ? f : f.name
if Base.isbindingresolved(mod, name) && isdefined(mod, name) # `isdefined` accesses the binding, making it impossible to create a new one
f = getfield(mod, name)
else
f = Core.eval(moduleof(frame), Expr(:function, f)) # create a new function
f = Core.eval(mod, Expr(:function, name)) # create a new function
end
elseif isa(f, GlobalRef)
f = getfield(f.mod, f.name)
end
length(node.args) == 1 && return f
sig = @lookup(frame, node.args[2])::SimpleVector
Expand Down
24 changes: 16 additions & 8 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function lookup_stmt(stmts::Vector{Any}, @nospecialize arg)
arg = stmts[arg.id]
end
if isa(arg, QuoteNode)
arg = arg.value
return arg.value
end
return arg
end
Expand All @@ -24,16 +24,16 @@ function smallest_ref(stmts, arg, idmin)
end

function lookup_global_ref(a::GlobalRef)
if isdefined(a.mod, a.name) && isconst(a.mod, a.name)
r = getfield(a.mod, a.name)
return QuoteNode(r)
else
return a
if Base.isbindingresolved(a.mod, a.name) && isdefined(a.mod, a.name)
return QuoteNode(getfield(a.mod, a.name))
end
return a
end

function lookup_global_refs!(ex::Expr)
(ex.head === :isdefined || ex.head === :thunk || ex.head === :toplevel) && return nothing
if isexpr(ex, (:isdefined, :thunk, :toplevel, :method, :global, :const))
return nothing
end
for (i, a) in enumerate(ex.args)
ex.head === :(=) && i == 1 && continue # Don't look up globalrefs on the LHS of an assignment (issue #98)
if isa(a, GlobalRef)
Expand All @@ -57,7 +57,14 @@ function lookup_getproperties(code::Vector{Any}, @nospecialize a)
return lookup_global_ref(GlobalRef(arg2, arg3))
end

# TODO This isn't optimization really, but necessary to bypass llvmcall and foreigncall
# HACK This isn't optimization really, but necessary to bypass llvmcall and foreigncall
# TODO This "optimization" should be refactored into a "minimum compilation" necessary to
# execute `llvmcall` and `foreigncall` and pure optimizations on the lowered code representation.
# In particular, the optimization that replaces `GlobalRef` with `QuoteNode` is invalid and
# should be removed: This is because it is not possible to know when and where the binding
# will be resolved without executing the code.
# Since the current `build_compiled_[llvmcall|foreigncall]!` relies on this replacement,
# they also need to be reimplemented.

"""
optimize!(code::CodeInfo, mod::Module)
Expand All @@ -73,6 +80,7 @@ function optimize!(code::CodeInfo, scope)
evalmod = mod == Core.Compiler ? Core.Compiler : CompiledCalls
sparams = scope isa Method ? sparam_syms(scope) : Symbol[]
replace_coretypes!(code)

# TODO: because of builtins.jl, for CodeInfos like
# %1 = Core.apply_type
# %2 = (%1)(args...)
Expand Down
Loading