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

add ability to evaluate ssavalues and locals #395

Merged
merged 3 commits into from
May 23, 2020
Merged

Conversation

KristofferC
Copy link
Member

1|debug>
In sin(x) at special/trig.jl:30
  3  │          Core.NewvarNode(:(n))
  4  │          absx = (abs)(x)
  5  │    %5  = absx
  6  │    %6  = ($(Expr(:static_parameter, 1)))(π)
> 7  │    %7  = (/)(%6, 4)
  8  │    %8  = (<)(%5, %7)
  9  └───       goto #6 if not %8
 10  2 ── %10 = absx
 11  │    %11 = (eps)($(Expr(:static_parameter, 1)))

About to run: (/)(3.141592653589793, 4)
1|julia> var"%5", var"%6"
(2.0, 3.141592653589793)

Expr(:block, map(x->Expr(:(=), x...), [(v.name, maybe_quote(v.value isa Core.Box ? v.value.contents : v.value)) for v in vars])...),
Expr(:block, map(x->Expr(:(=), x...), [(v.name, maybe_quote(v.value isa Core.Box ? v.value.contents : v.value)) for v in vars])...,
map(x->Expr(:(=), x...), [(Symbol("%$i"), data.ssavalues[i]) for i in defined_ssa])...,
map(x->Expr(:(=), x...), [(Symbol("@_$i"), data.locals[i].value) for i in defined_locals])...),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this makes slots available by their number but not their name, right?

julia> function summer(A)
           s = zero(eltype(A))
           for i in eachindex(A)
               s += A[i]
           end
           return s
       end
summer (generic function with 1 method)

julia> src = Base.uncompressed_ast(@which summer([1,2,3]))
CodeInfo(
    @ REPL[10]:2 within `summer'
1 ─ %1  = Main.eltype(A)
│         s = Main.zero(%1)
│   @ REPL[10]:3 within `summer'
│   %3  = Main.eachindex(A)
│         @_4 = Base.iterate(%3)
│   %5  = @_4 === nothing
│   %6  = Base.not_int(%5)
└──       goto #4 if not %6
2 ┄ %8  = @_4
│         i = Core.getfield(%8, 1)
│   %10 = Core.getfield(%8, 2)
│   @ REPL[10]:4 within `summer'%11 = s
│   %12 = Base.getindex(A, i)
│         s = %11 + %12@_4 = Base.iterate(%3, %10)
│   %15 = @_4 === nothing%16 = Base.not_int(%15)
└──       goto #4 if not %16
3 ─       goto #2
    @ REPL[10]:6 within `summer'
4 ┄       return s
)

julia> src.slotnames
5-element Array{Symbol,1}:
 Symbol("#self#")
 :A
 :s
 Symbol("")
 :i

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for their name you just evaluate with the local variable name, right? I was a bit unsure if I should include this but it seems easy enough and when you see e.g. @_4 = Base.iterate(%3, %10) in the lowered code, perhaps you just want to look at what @_4 contains.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, duh, you're saying this gets covered the other branch. Carry on 😄

@codecov-commenter
Copy link

codecov-commenter commented May 23, 2020

Codecov Report

Merging #395 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #395      +/-   ##
==========================================
+ Coverage   87.65%   87.68%   +0.02%     
==========================================
  Files          11       11              
  Lines        2001     2005       +4     
==========================================
+ Hits         1754     1758       +4     
  Misses        247      247              
Impacted Files Coverage Δ
src/utils.jl 84.74% <100.00%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d7becb...3c086b4. Read the comment docs.

@KristofferC KristofferC merged commit 423b4e6 into master May 23, 2020
@KristofferC KristofferC deleted the kc/ssa_locals branch May 23, 2020 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants