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

overdubbed method doesn't infer #13

Closed
maleadt opened this issue Nov 14, 2017 · 4 comments
Closed

overdubbed method doesn't infer #13

maleadt opened this issue Nov 14, 2017 · 4 comments

Comments

@maleadt
Copy link
Contributor

maleadt commented Nov 14, 2017

For lack of better title (I haven't looked into the issue, only reduced it).

Repro:

foo(ptr::Ptr{T}, i) where {T} = Base.unsafe_load(ptr, i)::T
# removing ::T or i arg fixes this one


code_warntype(foo, Tuple{Ptr{Float32}, Int})


using Cassette

Cassette.@context Ctx
const ctx = Ctx(foo)

code_warntype(Cassette.Overdub(Cassette.Execute(), foo, Cassette.Settings(ctx)),
              Tuple{Ptr{Float32}, Int})

Original IR:

Variables:
  ptr::Ptr{Float32}
  i::Int64

Body:
  begin
      return (Base.pointerref)(ptr::Ptr{Float32}, i::Int64, 1)::Float32
  end::Float32

Overdubbed IR:

Variables:
  o<optimized out>
  x1::Ptr{Float32}
  x2::Int64
  #temp#@_6::Int64
  #temp#@_10::Any

Body:
  begin
      #temp#@_6::Int64 = (typeassert)(x2::Int64, Int64)::Int64
      goto 39
      39: 
      goto 43
      43: 
      #temp#@_10::Any = (Base.pointerref)(x1::Ptr{Float32}, #temp#@_6::Int64, 1)::Any
      goto 66
      66: 
      goto 70
      70: 
      return ($(QuoteNode(Cassette.Overdub{Cassette.Intercept,typeof(typeassert),Cassette.Settings{Ctx{0xb88cf540947f2ecf},Void,0x0000000000005b28,false}}(Cassette.Intercept(), typeassert, Cassette.Settings{Ctx{0xb88cf540947f2ecf},Void,0x0000000000005b28,false}(Ctx{13298273457436307151}(), nothing, Cassette.World{0x0000000000005b28}(), Val{false}())))))(#temp#@_10::Any, Float32)::Any
  end::Any
@vtjnash
Copy link

vtjnash commented Nov 14, 2017

Yes, I think it remains to be seen how we can make it possible for inference to avoid triggering the limit trigger rules.

@maleadt
Copy link
Contributor Author

maleadt commented Nov 17, 2017

Which inference limit/rule is this running into? Can it be resolved with custom InferenceParams?

@maleadt
Copy link
Contributor Author

maleadt commented Jan 5, 2018

With the inference spoofing heuristics from JuliaLang/julia#24852 / #25 this gets quite a bit further (the final Overdub call wrapping the typeassert is gone), but still fails to infer pointerref. I reduced it a little more:

code_warntype(unsafe_load, Tuple{Ptr{Float32}})


using Cassette
Cassette.@context Ctx

code_warntype(Cassette.overdub(Ctx, unsafe_load), Tuple{Ptr{Float32}})

Original IR:

Variables:
  p::Ptr{Float32}

Body:
  begin
      # meta: location pointer.jl unsafe_load 105
      SSAValue(2) = (Base.pointerref)(p::Ptr{Float32}, 1, 1)::Float32
      # meta: pop location
      return SSAValue(2)
  end::Float32

Overdubbed:

Variables:
  o<optimized out>
  x1::Ptr{Float32}

Body:
  begin
      # stripped the meta nodes and useless goto's
      SSAValue(202) = (typeassert)(1, Int64)::Int64
      SSAValue(332) = (pointerref)(x1::Ptr{Float32}, SSAValue(202), 1)::Any
      return SSAValue(332)
  end::Any

@jrevels
Copy link
Collaborator

jrevels commented May 10, 2018

closed by #41

julia> using Cassette

julia> Cassette.@context Ctx

julia> ctx = Ctx()
Ctx{Cassette.Unused,0x0000000000006ba5,Cassette.Unused,Nothing}(Cassette.Unused(), Val{0x0000000000006ba5}(), Cassette.Unused(), nothing)

julia> foo(ptr::Ptr{T}, i) where {T} = Base.unsafe_load(ptr, i)::T
foo (generic function with 1 method)

julia> x = rand(Float32,1);

julia> ptr = pointer(x);

julia> ctx = Ctx();^C

julia> @code_warntype Cassette.overdub_execute(ctx, foo, ptr, 1)
Variables:
  ctx<optimized out>
  args::Tuple{typeof(foo),Ptr{Float32},Int64}
  output<optimized out>

Body:
  begin
      Core.SSAValue(17) = (Core.getfield)(args::Tuple{typeof(foo),Ptr{Float32},Int64}, 2)::Ptr{Float32}
      Core.SSAValue(18) = (Core.getfield)(args::Tuple{typeof(foo),Ptr{Float32},Int64}, 3)::Int64
      Core.SSAValue(35) = (Base.pointerref)(Core.SSAValue(17), Core.SSAValue(18), 1)::Float32
      return Core.SSAValue(35)
  end::Float32

@jrevels jrevels closed this as completed May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants