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

Interp2 #365

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open

Interp2 #365

wants to merge 35 commits into from

Conversation

wsmoses
Copy link
Member

@wsmoses wsmoses commented Dec 11, 2024

No description provided.

@@ -779,6 +779,11 @@ function compile(f, args; client=nothing, optimize=true, sync=false)
return register_thunk(fname, body)
end

# Compiling within a compile should return simply the original function
Reactant.@reactant_override function Reactant.Compiler.compile(f, args; client=nothing, optimize=true, sync=false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Reactant.@reactant_override function Reactant.Compiler.compile(f, args; client=nothing, optimize=true, sync=false)
Reactant.@reactant_override function Reactant.Compiler.compile(
f, args; client=nothing, optimize=true, sync=false
)

Comment on lines +47 to 58
arginfo2 = ArgInfo(
fargs isa Nothing ? nothing :
fargs[2:end],
argtypes[2:end],
)
return abstract_call(
interp,
arginfo2::ArgInfo,
si,
sv,
max_methods,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
arginfo2 = ArgInfo(
fargs isa Nothing ? nothing :
fargs[2:end],
argtypes[2:end],
)
return abstract_call(
interp,
arginfo2::ArgInfo,
si,
sv,
max_methods,
)
arginfo2 = ArgInfo(fargs isa Nothing ? nothing : fargs[2:end], argtypes[2:end])
return abstract_call(interp, arginfo2::ArgInfo, si, sv, max_methods)

end
end
if Meta.isexpr(inst, :invoke)
# return false, Expr(:call, inst.args[2:end]...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
# return false, Expr(:call, inst.args[2:end]...)
# return false, Expr(:call, inst.args[2:end]...)

Comment on lines +89 to +99
function make_oc(@nospecialize(sig::Type), @nospecialize(rt::Type), @nospecialize(rt2::Type), method::Core.Method)
Base.llvmcall(("""
declare {} addrspace(10)* @jl_new_opaque_closure_jlcall({} addrspace(10)*, {} addrspace(10)**, i32);

declare {} addrspace(10)* @julia.call(...)

define {} addrspace(10)* @f({} addrspace(10)* %a0, {} addrspace(10)* %a1, {} addrspace(10)* %a2, {} addrspace(10)* %a3) {
%res = call {} addrspace(10)* (...) @julia.call({} addrspace(10)* ({} addrspace(10)*, {} addrspace(10)**, i32)* @jl_new_opaque_closure_jlcall, {} addrspace(10)* %a0, {} addrspace(10)* %a1, {} addrspace(10)* %a2, {} addrspace(10)* %a3)
ret {} addrspace(10)* %res
}
""", "f"), Any, Tuple{Any, Any, Any, Any}, sig, rt, rt2, method)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function make_oc(@nospecialize(sig::Type), @nospecialize(rt::Type), @nospecialize(rt2::Type), method::Core.Method)
Base.llvmcall(("""
declare {} addrspace(10)* @jl_new_opaque_closure_jlcall({} addrspace(10)*, {} addrspace(10)**, i32);
declare {} addrspace(10)* @julia.call(...)
define {} addrspace(10)* @f({} addrspace(10)* %a0, {} addrspace(10)* %a1, {} addrspace(10)* %a2, {} addrspace(10)* %a3) {
%res = call {} addrspace(10)* (...) @julia.call({} addrspace(10)* ({} addrspace(10)*, {} addrspace(10)**, i32)* @jl_new_opaque_closure_jlcall, {} addrspace(10)* %a0, {} addrspace(10)* %a1, {} addrspace(10)* %a2, {} addrspace(10)* %a3)
ret {} addrspace(10)* %res
}
""", "f"), Any, Tuple{Any, Any, Any, Any}, sig, rt, rt2, method)
function make_oc(
@nospecialize(sig::Type),
@nospecialize(rt::Type),
@nospecialize(rt2::Type),
method::Core.Method,
)
return Base.llvmcall(
(
"""
declare {} addrspace(10)* @jl_new_opaque_closure_jlcall({} addrspace(10)*, {} addrspace(10)**, i32);
declare {} addrspace(10)* @julia.call(...)
define {} addrspace(10)* @f({} addrspace(10)* %a0, {} addrspace(10)* %a1, {} addrspace(10)* %a2, {} addrspace(10)* %a3) {
%res = call {} addrspace(10)* (...) @julia.call({} addrspace(10)* ({} addrspace(10)*, {} addrspace(10)**, i32)* @jl_new_opaque_closure_jlcall, {} addrspace(10)* %a0, {} addrspace(10)* %a1, {} addrspace(10)* %a2, {} addrspace(10)* %a3)
ret {} addrspace(10)* %res
}
""",
"f",
),
Any,
Tuple{Any,Any,Any,Any},
sig,
rt,
rt2,
method,
)

@nospecialize
args = redub_arguments

ccall(:jl_, Any, (Any,), "world="*string(world))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ccall(:jl_, Any, (Any,), "world="*string(world))
ccall(:jl_, Any, (Any,), "world=" * string(world))

end

if lookup_result === nothing || lookup_result === missing
ccall(:jl_, Any, (Any,), "no rlookup_result"*string(lookup_result))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ccall(:jl_, Any, (Any,), "no rlookup_result"*string(lookup_result))
ccall(:jl_, Any, (Any,), "no rlookup_result" * string(lookup_result))

Comment on lines +152 to +153
ccall(:jl_, Any, (Any,), "no matches "*string(lookup_result))
ccall(:jl_, Any, (Any,), "no matches2 "*string(matches))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ccall(:jl_, Any, (Any,), "no matches "*string(lookup_result))
ccall(:jl_, Any, (Any,), "no matches2 "*string(matches))
ccall(:jl_, Any, (Any,), "no matches " * string(lookup_result))
ccall(:jl_, Any, (Any,), "no matches2 " * string(matches))


result = Core.Compiler.InferenceResult(mi, Core.Compiler.typeinf_lattice(interp))
frame = Core.Compiler.InferenceState(result, :local, interp) #=cache_mode=#
ccall(:jl_, Any, (Any,), "frame="*string(frame))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ccall(:jl_, Any, (Any,), "frame="*string(frame))
ccall(:jl_, Any, (Any,), "frame=" * string(frame))

Core.Compiler.ipo_dataflow_analysis!(interp, ir, caller)
end


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change


src = Core.Compiler.ir_to_codeinf!(opt)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

meth.nargs = method.nargs
meth.file = Symbol("")
meth.line = 0 # source
ccall(:jl_method_set_source, Cvoid, (Ref{Core.Method}, Ref{Core.Compiler.CodeInfo}), meth, src)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ccall(:jl_method_set_source, Cvoid, (Ref{Core.Method}, Ref{Core.Compiler.CodeInfo}), meth, src)
ccall(
:jl_method_set_source,
Cvoid,
(Ref{Core.Method}, Ref{Core.Compiler.CodeInfo}),
meth,
src,
)

meth.line = 0 # source
ccall(:jl_method_set_source, Cvoid, (Ref{Core.Method}, Ref{Core.Compiler.CodeInfo}), meth, src)

nmi = ccall(:jl_specializations_get_linfo, Ref{Core.MethodInstance}, (Any, Any, Any), meth, sig, Core.svec())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
nmi = ccall(:jl_specializations_get_linfo, Ref{Core.MethodInstance}, (Any, Any, Any), meth, sig, Core.svec())
nmi = ccall(
:jl_specializations_get_linfo,
Ref{Core.MethodInstance},
(Any, Any, Any),
meth,
sig,
Core.svec(),
)

Comment on lines +361 to +364
nmi::Core.MethodInstance, rt, #=@nospecialize(inferred_const)=#C_NULL,
#=@nospecialize(inferred)=#src, #=const_flags=#Int32(0), lookup_result.valid_worlds.min_world, lookup_result.valid_worlds.max_world,
#=ipo_effects::UInt32=#UInt32(0), #=effects::UInt32=#UInt32(0), #=@nospecialize(argescapes#=::Union{Nothing,Vector{ArgEscapeInfo}}=#)=#nothing,
#=src.relocatability=#UInt8(0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
nmi::Core.MethodInstance, rt, #=@nospecialize(inferred_const)=#C_NULL,
#=@nospecialize(inferred)=#src, #=const_flags=#Int32(0), lookup_result.valid_worlds.min_world, lookup_result.valid_worlds.max_world,
#=ipo_effects::UInt32=#UInt32(0), #=effects::UInt32=#UInt32(0), #=@nospecialize(argescapes#=::Union{Nothing,Vector{ArgEscapeInfo}}=#)=#nothing,
#=src.relocatability=#UInt8(0))
nmi::Core.MethodInstance,
rt,
C_NULL, #=@nospecialize(inferred_const)=#
src,
Int32(0),
lookup_result.valid_worlds.min_world,
lookup_result.valid_worlds.max_world, #=const_flags=#
UInt32(0),
UInt32(0),
nothing, #=@nospecialize(argescapes#=::Union{Nothing,Vector{ArgEscapeInfo}}=#)=#
UInt8(0),
) #=src.relocatability=#


# oc = Core.OpaqueClosure(sig, rt, rt, method, C_NULL, 0, true) #

ocargs = Any[Tuple{typeof(Reactant.apply), sig.parameters...}, rt, rt, meth]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
ocargs = Any[Tuple{typeof(Reactant.apply), sig.parameters...}, rt, rt, meth]
ocargs = Any[Tuple{typeof(Reactant.apply),sig.parameters...}, rt, rt, meth]

@show meth.nargs
@show length(ocargs[1].parameters)
flush(stdout)
oc = ccall(:jl_new_opaque_closure_jlcall, Any, (Ptr{Cvoid}, Ptr{Any}, Int32), C_NULL, ocargs, Int32(4))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
oc = ccall(:jl_new_opaque_closure_jlcall, Any, (Ptr{Cvoid}, Ptr{Any}, Int32), C_NULL, ocargs, Int32(4))
oc = ccall(
:jl_new_opaque_closure_jlcall,
Any,
(Ptr{Cvoid}, Ptr{Any}, Int32),
C_NULL,
ocargs,
Int32(4),
)

Comment on lines +382 to +389
push!(
overdubbed_code,
Expr(
:(call),
oc,
fn_args...
),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
push!(
overdubbed_code,
Expr(
:(call),
oc,
fn_args...
),
)
push!(overdubbed_code, Expr(:(call), oc, fn_args...))

Comment on lines +393 to +396
push!(
overdubbed_code,
Core.ReturnNode(Core.SSAValue(length(overdubbed_code)))
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
push!(
overdubbed_code,
Core.ReturnNode(Core.SSAValue(length(overdubbed_code)))
)
push!(overdubbed_code, Core.ReturnNode(Core.SSAValue(length(overdubbed_code))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants