Skip to content

Instantly share code, notes, and snippets.

@blegat
Last active October 5, 2018 16:24
Show Gist options
  • Save blegat/c2109508c3ebad65b94de4ea1b565510 to your computer and use it in GitHub Desktop.
Save blegat/c2109508c3ebad65b94de4ea1b565510 to your computer and use it in GitHub Desktop.
iterate_inferred_nothing
using Polyhedra
h = HyperPlane([0, 1], 1) ∩ HyperPlane([0, 1], -1)
code = Any[
Expr(:(=), Core.SlotNumber(1), 0),
Expr(:call, GlobalRef(Main, :hyperplanes), GlobalRef(Main, :h)),
Expr(:(=), Core.SlotNumber(2), Expr(:call, Base.iterate, Base.SSAValue(2))),
Expr(:call, Core.:(===), Core.SlotNumber(2), nothing),
Expr(:call, Base.not_int, Base.SSAValue(4)),
Expr(:gotoifnot, Base.SSAValue(5), 16),
Core.SlotNumber(2),
Expr(:(=), Core.SlotNumber(3), Expr(:call, Core.getfield, Base.SSAValue(7), 1)),
Expr(:call, Core.getfield, Base.SSAValue(7), 2),
Expr(:(=), Core.SlotNumber(1), Expr(:call, Main.:(+), Core.SlotNumber(1), 1)),
Expr(:(=), Core.SlotNumber(2), Expr(:call, Base.iterate, Base.SSAValue(2), Base.SSAValue(9))),
Expr(:call, Core.:(===), Core.SlotNumber(2), nothing),
Expr(:call, Base.not_int, Base.SSAValue(12)),
Expr(:gotoifnot, Base.SSAValue(13), 16),
Base.GotoNode(7),
Expr(:call, Main.println, Core.SlotNumber(1)),
Expr(:return, Base.SSAValue(16))]
linetable = Any[Core.LineInfoNode(Main, Symbol("top-level scope"), Symbol("/home/blegat/.julia/dev/Polyhedra/ko.jl"), 4, 0),
Core.LineInfoNode(Main, Symbol("top-level scope"), Symbol("/home/blegat/.julia/dev/Polyhedra/ko.jl"), 5, 0),
Core.LineInfoNode(Main, Symbol("top-level scope"), Symbol("/home/blegat/.julia/dev/Polyhedra/ko.jl"), 6, 0),
Core.LineInfoNode(Main, Symbol("top-level scope"), Symbol("/home/blegat/.julia/dev/Polyhedra/ko.jl"), 8, 0)]
info = ccall(:jl_new_code_info_uninit, Ref{Base.CodeInfo}, ())
info.code = code
info.codelocs=Int32[1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4]
info.method_for_inference_limit_heuristics=nothing
info.ssavaluetypes=17
info.linetable=linetable
info.ssaflags=UInt8[]
info.slotflags=UInt8[0x00, 0x00, 0x10]
info.slotnames=Any[:i, Symbol("#temp#"), :a]
info.inferred=false
info.inlineable=false
info.propagate_inbounds=false
info.pure=false
method = ccall(:jl_new_method_instance_uninit, Ref{Base.MethodInstance}, ())
method.def = Main
method.specTypes = Tuple{}
method.rettype = Any
method.sparam_vals = Core.svec()
method.inferred = info
Core.Compiler.typeinf_ext(method, UInt(0))
@blegat
Copy link
Author

blegat commented Oct 5, 2018

It currently returns the correct code:

svec(Toplevel MethodInstance thunk, CodeInfo(
5 1%1  = (Main.hyperplanes)(Main.h)::Any                                                                                                                                               │
  │   %2  = (iterate)(%1)::Any                                                                                                                                                            │
  │   %3  = (===)(%2, nothing)::Bool                                                                                                                                                      │
  │   %4  = (not_int)(%3)::Bool                                                                                                                                                           │
  └──       goto #4 if not %4                                                                                                                                                             │
  2%6  = φ (#1 => 0, #3 => %10)::Any                                                                                                                                                   │%7  = φ (#1 => %2, #3 => %11)::Any                                                                                                                                                  │
  │         (getfield)(%7, 1)::Any                                                                                                                                                        │
  │   %9  = (getfield)(%7, 2)::Any6%10 = (+)(%6, 1)::Any                                                                                                                                                               │
  │   %11 = (iterate)(%1, %9)::Any                                                                                                                                                        │
  │   %12 = (===)(%11, nothing)::Bool                                                                                                                                                     │
  │   %13 = (not_int)(%12)::Bool                                                                                                                                                          │
  └──       goto #4 if not %13                                                                                                                                                            │
  3 ─       goto #2                                                                                                                                                                       │
8 4%16 = φ (#2 => %10, #1 => 0)::Any                                                                                                                                                   │%17 = (println)(%16)::Any                                                                                                                                                           │
  └──       return %17                                                                                                                                                                    │
))

although it seems to be exactly what gdb was printing. Any idea where the difference could lie ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment