Skip to content

Computing the end line can error #31

@KristofferC

Description

@KristofferC
julia> using JuliaInterpreter, Zygote, CodeTracking

julia> l, back = Zygote.forward(x -> sum(x), ones(10,10,10))
(1000.0, getfield(Zygote, Symbol("##71#72")){typeof((getfield(Main, Symbol("##5#6"))()))}((getfield(Main, Symbol("##5#6"))())))

julia> frame = JuliaInterpreter.enter_call(back, 1f0);

julia> frame, pc = JuliaInterpreter.debug_command(frame, :si);

julia> frame, pc = JuliaInterpreter.debug_command(frame, :si);

julia> frame, pc = JuliaInterpreter.debug_command(frame, :si);

julia> m = frame.framecode.scope; # showing this will crash Julia due to https://github.com/FluxML/Zygote.jl/issues/134

julia> m.name
:Pullback

julia> CodeTracking.definition(String, m)
ERROR: Base.Meta.ParseError("unexpected \"end\"")
Stacktrace:
 [1] #parse#1(::Bool, ::Bool, ::Bool, ::Function, ::String, ::Int64) at .\meta.jl:129
 [2] parse(::String, ::Int64) at .\meta.jl:121
 [3] definition(::Type{String}, ::Method) at C:\Users\Kristoffer\Debugging\Debugger\dev\CodeTracking\src\CodeTracking.jl:209
 [4] top-level scope at none:0

src is at this point equal to

ignore(T) = all(T -> T <: Type, T.parameters)

@generated function _forward(ctx::Context, f, args...)
  T = Tuple{f,args...}
  ignore(T) && return :(f(args...), Pullback{$T}(()))
  g = try _lookup_grad(T) catch e e end
  !(g isa Tuple) && return :(f(args...), Pullback{$T}((f,)))
  meta, forw, _ = g
  argnames!(meta, Symbol("#self#"), :ctx, :f, :args)
  forw = varargs!(meta, forw, 3)
  forw = slots!(pis!(inlineable!(forw)))
  return IRTools.update!(meta, forw)
end

@generated function (j::Pullback{T})(Δ) where T
  ignore(T) && return :nothing
  g = try _lookup_grad(T)
  catch e
    rethrow(CompileError(T,e))
  end
  if g == nothing
    Δ == Nothing && return :nothing
    return :(error("Non-differentiable function $(j.t[1])"))
  end
  meta, _, back = g
  resize!(back.argtypes, 2)
  argnames!(meta, Symbol("#self#"), )
  back = slots!(inlineable!(back))
  return IRTools.update!(meta, back)
end

with istart = 477 and then:

julia> print(s[477:end])
end

@generated function (j::Pullback{T})(Δ) where T
  ignore(T) && return :nothing
  g = try _
...

starts with an end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions