Skip to content

Commit

Permalink
Run on 1.9+ (#93)
Browse files Browse the repository at this point in the history
* run on nightly

* backing_error
  • Loading branch information
mcabbott committed Dec 27, 2022
1 parent 55d2871 commit 2e571fe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/extra_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,6 @@ function ChainRulesCore.rrule(::DiffractorRuleConfig, ::Type{InplaceableThunk},
end

Base.real(z::NoTangent) = z # TODO should be in CRC, https://github.com/JuliaDiff/ChainRulesCore.jl/pull/581

# Avoid https://github.com/JuliaDiff/ChainRulesCore.jl/pull/495
ChainRulesCore._backing_error(P::Type{<:Base.Pairs}, G::Type{<:NamedTuple}, E::Type{<:AbstractDict}) = nothing
16 changes: 14 additions & 2 deletions src/stage1/compiler_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ function Base.setindex!(ir::Core.Compiler.IRCode, ni::NewInstruction, i::Int)
stmt = ir.stmts[i]
stmt.inst = ni.stmt
stmt.type = ni.type
stmt.flag = ni.flag
stmt.flag = something(ni.flag, 0) # fixes 1.9?
stmt.line = something(ni.line, 0)
ni
end

function Base.push!(ir::IRCode, ni::NewInstruction)
# TODO: This should be a check in insert_node!
@assert length(ir.new_nodes.stmts) == 0
ir[Core.Compiler.add!(ir.stmts)] = ni
@static if isdefined(Core.Compiler, :add!)
# Julia 1.7 & 1.8
ir[Core.Compiler.add!(ir.stmts)] = ni
else
# Re-named in https://github.com/JuliaLang/julia/pull/47051
ir[Core.Compiler.add_new_idx!(ir.stmts)] = ni
end
ir
end

Expand All @@ -47,3 +53,9 @@ end

Base.lastindex(x::Core.Compiler.InstructionStream) =
Core.Compiler.length(x)

# Solves an error after https://github.com/JuliaLang/julia/pull/46961
# as does https://github.com/FluxML/IRTools.jl/pull/101
if isdefined(Core.Compiler, :CallInfo)
Base.convert(::Type{Core.Compiler.CallInfo}, ::Nothing) = Core.Compiler.NoCallInfo()
end
5 changes: 4 additions & 1 deletion src/stage1/hacks.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Updated copy of the same code in Base, but with bugs fixed
using Core.Compiler: count_added_node!, add!, NewSSAValue, add_pending!,
using Core.Compiler: count_added_node!, NewSSAValue, add_pending!,
StmtRange, BasicBlock

# Re-named in https://github.com/JuliaLang/julia/pull/47051
const add! = VERSION < v"1.9-" ? Core.Compiler.add! : Core.Compiler.add_inst!

Base.length(c::Core.Compiler.NewNodeStream) = Core.Compiler.length(c)
Base.setindex!(i::Instruction, args...) = Core.Compiler.setindex!(i, args...)
Core.Compiler.BasicBlock(x::UnitRange) =
Expand Down
2 changes: 1 addition & 1 deletion src/tangent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function StructArrays.staticschema(::Type{<:TaylorBundle{N, B}}) where {N, B}
Tuple{B, Vararg{Any, N}}
end

function StructArrays.component(m::TaylorBundle{N, B}, i::Int) where {N, B, T}
function StructArrays.component(m::TaylorBundle{N, B}, i::Int) where {N, B}
i == 1 && return m.primal
return m.coeffs[i - 1]
end
Expand Down

0 comments on commit 2e571fe

Please sign in to comment.