-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Show variable names and remove spurious type warning in typed ast #15821
Conversation
I was hoping somebody would do this :-) |
is |
OK, I added a check for julia> @code_warntype f(Float32[])
Variables:
#self#::#f
a::Array{Float32,1}
#temp#::Int64
i::Int64
#temp#::Int64
i::Int64
Body:
begin # none, line 2: # abstractarray.jl, line 404: # abstractarray.jl, line 414:
GenSym(6) = (Base.arraylen)(a::Array{Float32,1})::Int64 # range.jl, line 83:
GenSym(8) = (Base.select_value)((Base.sle_int)(1,GenSym(6))::Bool,GenSym(6),(Base.box)(Int64,(Base.sub_int)(1,1)))::Int64
_5::Int64 = 1
8:
unless (Base.box)(Base.Bool,(Base.not_int)((_5::Int64 === (Base.box)(Int64,(Base.add_int)(GenSym(8),1)))::Bool)) goto 23
GenSym(9) = _5::Int64
GenSym(10) = (Base.box)(Int64,(Base.add_int)(_5::Int64,1))
i::Int64 = GenSym(9)
_5::Int64 = GenSym(10) # none, line 3: # promotion.jl, line 172: # promotion.jl, line 135:
Float32
Float32
GenSym(2) = (Base.box)(Base.Float32,(Base.add_float)((Base.arrayref)(a::Array{Float32,1},i::Int64)::Float32,(Base.box)(Float32,(Base.sitofp)(Float32,0))))
(Base.arrayset)(a::Array{Float32,1},GenSym(2),i::Int64)::Array{Float32,1}
21:
goto 8
23:
24: # none, line 5: # abstractarray.jl, line 404: # abstractarray.jl, line 414:
GenSym(7) = (Base.arraylen)(a::Array{Float32,1})::Int64 # range.jl, line 83:
GenSym(11) = (Base.select_value)((Base.sle_int)(1,GenSym(7))::Bool,GenSym(7),(Base.box)(Int64,(Base.sub_int)(1,1)))::Int64
_3::Int64 = 1
32:
unless (Base.box)(Base.Bool,(Base.not_int)((_3::Int64 === (Base.box)(Int64,(Base.add_int)(GenSym(11),1)))::Bool)) goto 47
GenSym(12) = _3::Int64
GenSym(13) = (Base.box)(Int64,(Base.add_int)(_3::Int64,1))
i::Int64 = GenSym(12)
_3::Int64 = GenSym(13) # none, line 6: # promotion.jl, line 172: # promotion.jl, line 135:
Float32
Float32
GenSym(5) = (Base.box)(Base.Float32,(Base.add_float)((Base.arrayref)(a::Array{Float32,1},i::Int64)::Float32,(Base.box)(Float32,(Base.sitofp)(Float32,0))))
(Base.arrayset)(a::Array{Float32,1},GenSym(5),i::Int64)::Array{Float32,1}
45:
goto 32
47:
48:
return
end::Void |
I didn't realize that inlining (and other passes) doesn't rename variables anymore (which is great!) so they can actually introduce duplicated variable names that is confusing. I'm now changing it to always print |
Travis OSX timed out restarted. |
283bb3b
to
ce79d51
Compare
As per @vtjnash 's suggestion, I added a julia> function f(a)
for i in eachindex(a)
a[i] += 0
end
for i in eachindex(a)
a[i] += 0
end
end
f (generic function with 1 method)
julia> @code_warntype f(Float32[])
Variables:
#self#@_1::#f
a@_2::Array{Float32,1}
#temp#@_3::Int64
i@_4::Int64
#temp#@_5::Int64
i@_6::Int64
Body:
begin # none, line 2: # abstractarray.jl, line 404: # abstractarray.jl, line 414:
GenSym(6) = (Base.arraylen)(a@_2::Array{Float32,1})::Int64 # range.jl, line 83:
GenSym(8) = (Base.select_value)((Base.sle_int)(1,GenSym(6))::Bool,GenSym(6),(Base.box)(Int64,(Base.sub_int)(1,1)))::Int64
#temp#@_5::Int64 = 1
8:
unless (Base.box)(Base.Bool,(Base.not_int)((#temp#@_5::Int64 === (Base.box)(Int64,(Base.add_int)(GenSym(8),1)))::Bool)) goto 23
GenSym(9) = #temp#@_5::Int64
GenSym(10) = (Base.box)(Int64,(Base.add_int)(#temp#@_5::Int64,1))
i@_6::Int64 = GenSym(9)
#temp#@_5::Int64 = GenSym(10) # none, line 3: # promotion.jl, line 172: # promotion.jl, line 135:
Float32
Float32
GenSym(2) = (Base.box)(Base.Float32,(Base.add_float)((Base.arrayref)(a@_2::Array{Float32,1},i@_6::Int64)::Float32,(Base.box)(Float32,(Base.sitofp)(Float32,0))))
(Base.arrayset)(a@_2::Array{Float32,1},GenSym(2),i@_6::Int64)::Array{Float32,1}
21:
goto 8
23:
24: # none, line 5: # abstractarray.jl, line 404: # abstractarray.jl, line 414:
GenSym(7) = (Base.arraylen)(a@_2::Array{Float32,1})::Int64 # range.jl, line 83:
GenSym(11) = (Base.select_value)((Base.sle_int)(1,GenSym(7))::Bool,GenSym(7),(Base.box)(Int64,(Base.sub_int)(1,1)))::Int64
#temp#@_3::Int64 = 1
32:
unless (Base.box)(Base.Bool,(Base.not_int)((#temp#@_3::Int64 === (Base.box)(Int64,(Base.add_int)(GenSym(11),1)))::Bool)) goto 47
GenSym(12) = #temp#@_3::Int64
GenSym(13) = (Base.box)(Int64,(Base.add_int)(#temp#@_3::Int64,1))
i@_4::Int64 = GenSym(12)
#temp#@_3::Int64 = GenSym(13) # none, line 6: # promotion.jl, line 172: # promotion.jl, line 135:
Float32
Float32
GenSym(5) = (Base.box)(Base.Float32,(Base.add_float)((Base.arrayref)(a@_2::Array{Float32,1},i@_4::Int64)::Float32,(Base.box)(Float32,(Base.sitofp)(Float32,0))))
(Base.arrayset)(a@_2::Array{Float32,1},GenSym(5),i@_4::Int64)::Array{Float32,1}
45:
goto 32
47:
48:
return
end::Void |
It's getting pretty close to line noise at this point. It would be a lot better to show the number only for variables with non-unique names, which are pretty rare. |
OK, limited to only non-unique variables now. julia> function f2(a)
for i in eachindex(a)
a[i] += 0
end
for i in eachindex(a)
a[i] += 0
end
end
f2 (generic function with 1 method)
julia> function f(a)
for i in eachindex(a)
a[i] += 0
end
end
f (generic function with 1 method)
julia> @code_warntype f(Float32[])
Variables:
#self#::#f
a::Array{Float32,1}
#temp#::Int64
i::Int64
Body:
begin # none, line 2: # abstractarray.jl, line 404: # abstractarray.jl, line 414:
GenSym(3) = (Base.arraylen)(a::Array{Float32,1})::Int64 # range.jl, line 83:
GenSym(4) = (Base.select_value)((Base.sle_int)(1,GenSym(3))::Bool,GenSym(3),(Base.box)(Int64,(Base.sub_int)(1,1)))::Int64
#temp#::Int64 = 1
8:
unless (Base.box)(Base.Bool,(Base.not_int)((#temp#::Int64 === (Base.box)(Int64,(Base.add_int)(GenSym(4),1)))::Bool)) goto 23
GenSym(5) = #temp#::Int64
GenSym(6) = (Base.box)(Int64,(Base.add_int)(#temp#::Int64,1))
i::Int64 = GenSym(5)
#temp#::Int64 = GenSym(6) # none, line 3: # promotion.jl, line 172: # promotion.jl, line 135:
Float32
Float32
GenSym(2) = (Base.box)(Base.Float32,(Base.add_float)((Base.arrayref)(a::Array{Float32,1},i::Int64)::Float32,(Base.box)(Float32,(Base.sitofp)(Float32,0))))
(Base.arrayset)(a::Array{Float32,1},GenSym(2),i::Int64)::Array{Float32,1}
21:
goto 8
23:
24:
return
end::Void
julia> @code_warntype f2(Float32[])
Variables:
#self#::#f2
a::Array{Float32,1}
#temp#@_3::Int64
i@_4::Int64
#temp#@_5::Int64
i@_6::Int64
Body:
begin # none, line 2: # abstractarray.jl, line 404: # abstractarray.jl, line 414:
GenSym(6) = (Base.arraylen)(a::Array{Float32,1})::Int64 # range.jl, line 83:
GenSym(8) = (Base.select_value)((Base.sle_int)(1,GenSym(6))::Bool,GenSym(6),(Base.box)(Int64,(Base.sub_int)(1,1)))::Int64
#temp#@_5::Int64 = 1
8:
unless (Base.box)(Base.Bool,(Base.not_int)((#temp#@_5::Int64 === (Base.box)(Int64,(Base.add_int)(GenSym(8),1)))::Bool)) goto 23
GenSym(9) = #temp#@_5::Int64
GenSym(10) = (Base.box)(Int64,(Base.add_int)(#temp#@_5::Int64,1))
i@_6::Int64 = GenSym(9)
#temp#@_5::Int64 = GenSym(10) # none, line 3: # promotion.jl, line 172: # promotion.jl, line 135:
Float32
Float32
GenSym(2) = (Base.box)(Base.Float32,(Base.add_float)((Base.arrayref)(a::Array{Float32,1},i@_6::Int64)::Float32,(Base.box)(Float32,(Base.sitofp)(Float32,0))))
(Base.arrayset)(a::Array{Float32,1},GenSym(2),i@_6::Int64)::Array{Float32,1}
21:
goto 8
23:
24: # none, line 5: # abstractarray.jl, line 404: # abstractarray.jl, line 414:
GenSym(7) = (Base.arraylen)(a::Array{Float32,1})::Int64 # range.jl, line 83:
GenSym(11) = (Base.select_value)((Base.sle_int)(1,GenSym(7))::Bool,GenSym(7),(Base.box)(Int64,(Base.sub_int)(1,1)))::Int64
#temp#@_3::Int64 = 1
32:
unless (Base.box)(Base.Bool,(Base.not_int)((#temp#@_3::Int64 === (Base.box)(Int64,(Base.add_int)(GenSym(11),1)))::Bool)) goto 47
GenSym(12) = #temp#@_3::Int64
GenSym(13) = (Base.box)(Int64,(Base.add_int)(#temp#@_3::Int64,1))
i@_4::Int64 = GenSym(12)
#temp#@_3::Int64 = GenSym(13) # none, line 6: # promotion.jl, line 172: # promotion.jl, line 135:
Float32
Float32
GenSym(5) = (Base.box)(Base.Float32,(Base.add_float)((Base.arrayref)(a::Array{Float32,1},i@_4::Int64)::Float32,(Base.box)(Float32,(Base.sitofp)(Float32,0))))
(Base.arrayset)(a::Array{Float32,1},GenSym(5),i@_4::Int64)::Array{Float32,1}
45:
goto 32
47:
48:
return
end::Void |
Much better. |
Fixes #15714
@JeffBezanson This disables printing of slot numbers and always use the variable names. Do you find the slot numbers still useful? I imagine they are mostly useful for
#temp#
s since otherwise the variable name seems to be unique.