JuliaDiff / JuliaDiff/Diffractor.jl

forward_diff_no_inf can't handle throw_undef_if_not

Open
#161 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
453
Forks
33
PR merge metrics
No merged PRs in 30d

Description

Ran into this while trying to reproduce another bug.
The following code errors:

using Diffractor
# this is needed as transform! is *always* called on Arguments regardless of what visit_custom says
identity_transform!(ir, ssa::Core.SSAValue, order) = ir[ssa]
function identity_transform!(ir, arg::Core.Argument, order)
    return Core.Compiler.insert_node!(ir, Core.SSAValue(1), Core.Compiler.NewInstruction(Expr(:call, Diffractor.ZeroBundle{1}, arg), Any))
end

function phi_run(x::Float64, b1::Bool, b2::Bool)
    if b1
        a = 0.
    elseif b2
        a = z
    end
    return x - a
end

input_ir = first(only(Base.code_ircode(phi_run, Tuple{Float64, Bool, Bool})))
Diffractor.forward_diff_no_inf!(copy(input_ir), Core.SSAValue.(1:length(input_ir.stmts)) .=> 1; transform! = identity_transform!)

I think the fix is easy, add the case to forward_visit about what to do for this kind of node.
Which i think is return nothing

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the implementation of forward_diff_no_inf! and inspect forward_visit for the IR node produced by throw_undef_if_not. Reproduce the provided phi_run example with the identity_transform! callback; done means the call completes without the current error and the relevant node is handled consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.