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

code_warntype shows unused slots #41793

Open
simeonschaub opened this issue Aug 5, 2021 · 4 comments
Open

code_warntype shows unused slots #41793

simeonschaub opened this issue Aug 5, 2021 · 4 comments
Labels
display and printing Aesthetics and correctness of printed representations of objects.

Comments

@simeonschaub
Copy link
Member

Is it intentional that we display the unused slots z@_8, z@_9 and z@_10 and their NewvarNodes here? Or should that have been cleaned up before printing?

julia> function foo(x, y)
           z = x + y
           while z < 4
               z += 1
           end
           u = (x -> x + z)(x)
           v = Ref{Union{Int, Missing}}(x)[] + y
           return z * 7
       end
foo (generic function with 1 method)

julia> @code_warntype foo(1, 2)
MethodInstance for foo(::Int64, ::Int64)
  from foo(x, y) in Main at REPL[10]:1
Arguments
  #self#::Core.Const(foo)
  x::Int64
  y::Int64
Locals
  #3::var"#3#4"
  v::Union{Missing, Int64}
  u::Any
  z@_7::Core.Box
  z@_8::Union{}
  z@_9::Union{}
  z@_10::Union{}
Body::Any
1 ──       Core.NewvarNode(:(#3))
│          Core.NewvarNode(:(v))
│          Core.NewvarNode(:(u))
│          (z@_7 = Core.Box())
│    %5  = (x + y)::Int64
└───       Core.setfield!(z@_7, :contents, %5)
2 ┄─ %7  = Core.isdefined(z@_7, :contents)::Bool
└───       goto #4 if not %7
3 ──       goto #5
4 ──       Core.NewvarNode(:(z@_8))
└───       z@_8
5 ┄─ %12 = Core.getfield(z@_7, :contents)::Any%13 = (%12 < 4)::Any
└───       goto #10 if not %13
6 ── %15 = Core.isdefined(z@_7, :contents)::Bool
└───       goto #8 if not %15
7 ──       goto #9
8 ──       Core.NewvarNode(:(z@_9))
└───       z@_9
9 ┄─ %20 = Core.getfield(z@_7, :contents)::Any%21 = (%20 + 1)::Any
│          Core.setfield!(z@_7, :contents, %21)
└───       goto #2
10 ─       (#3 = %new(Main.:(var"#3#4"), z@_7))%25 = #3::var"#3#4"
│          (u = (%25)(x))
│    %27 = Core.apply_type(Main.Union, Main.Int, Main.Missing)::Core.Const(Union{Missing, Int64})
│    %28 = Core.apply_type(Main.Ref, %27)::Core.Const(Ref{Union{Missing, Int64}})
│    %29 = (%28)(x)::Base.RefValue{Union{Missing, Int64}}%30 = Base.getindex(%29)::Union{Missing, Int64}
│          (v = %30 + y)
│    %32 = Core.isdefined(z@_7, :contents)::Bool
└───       goto #12 if not %32
11 ─       goto #13
12 ─       Core.NewvarNode(:(z@_10))
└───       z@_10
13%37 = Core.getfield(z@_7, :contents)::Any%38 = (%37 * 7)::Any
└───       return %38
@simeonschaub simeonschaub added the display and printing Aesthetics and correctness of printed representations of objects. label Aug 5, 2021
@KristofferC
Copy link
Sponsor Member

#23735 used to clean up some of them at least.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 5, 2021

We currently show pre-optimized code (so that it more closely corresponds to the original, pre-inlining)

@simeonschaub
Copy link
Member Author

Ah, I didn't realize these slots are in the lowered code already. In that case, maybe the better question is why lowering emitted these unused slots in the first place.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 5, 2021

It is used to throw an UndefVarError(:z)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

No branches or pull requests

3 participants