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

Backtraces: some line numbers are still 0 #17317

Closed
timholy opened this issue Jul 7, 2016 · 5 comments · Fixed by #17324
Closed

Backtraces: some line numbers are still 0 #17317

timholy opened this issue Jul 7, 2016 · 5 comments · Fixed by #17324
Assignees

Comments

@timholy
Copy link
Sponsor Member

timholy commented Jul 7, 2016

@inline foo1(x) = foo2(x)
@inline foo2(x) = foo3(x)
@noinline foo3(x) = x ÷ 3

function bar(n)
    X = rand(1:10, n)
    Y = [foo1(x) for x in X]
end

bar(1)
@profile bar(10^7)
data = unique(Profile.fetch())
vsf = Base.StackTraces.lookup.(data)
for sfs in vsf
    for sf in sfs
        if sf.line == 0
            @show sf
        end
    end
end

Results:

sf =  in rand at random.jl:0 [inlined]
sf =  in rand at random.jl:0 [inlined]
sf =  in rand(::MersenneTwister, ::Base.Random.RangeGeneratorInt{Int64,UInt64}) at random.jl:0
sf =  in mt_setfull! at random.jl:0 [inlined]
sf =  in reserve_1 at random.jl:0 [inlined]
sf =  in rand_ui52_raw at random.jl:0 [inlined]
sf =  in rand at random.jl:0 [inlined]
sf =  in mt_pop! at random.jl:0 [inlined]
sf =  in rand_inbounds at random.jl:0 [inlined]
sf =  in rand_ui52_raw_inbounds at random.jl:0 [inlined]
sf =  in rand_ui52_raw at random.jl:0 [inlined]
sf =  in rand at random.jl:0 [inlined]
sf =  in rand(::MersenneTwister, ::Base.Random.RangeGeneratorInt{Int64,UInt64}) at random.jl:0
sf =  in rand(::MersenneTwister, ::Base.Random.RangeGeneratorInt{Int64,UInt64}) at random.jl:0
sf =  in gen_rand at random.jl:0 [inlined]
sf =  in reserve_1 at random.jl:0 [inlined]
sf =  in rand_ui52_raw at random.jl:0 [inlined]
sf =  in rand at random.jl:0 [inlined]
sf =  in foo3(::Int64) at testprof.jl:0

This is with a completely-fresh julia master,

julia> versioninfo()
Julia Version 0.5.0-dev+5188
Commit 36d36b0* (2016-07-07 03:28 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, broadwell)
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 7, 2016

Good find. Looks like this is broken:

                        else if (jl_is_long(arg))
                            inlined_func_lineno = jl_unbox_long(arg);
(lldb) p jl_(stmt_e)
Expr(:meta, :push_loc, :random.jl, :rand, 239)::Any
(lldb) p jl_(arg)
239
(lldb) p jl_(jl_typeof(arg))
Int32

@vtjnash vtjnash self-assigned this Jul 7, 2016
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 7, 2016

There's also at least one place were we are emitting line number locations that we shouldn't be:

  %3 = call %jl_value_t*** @jl_get_ptls_states(), !dbg !28

And jl_gdblookup and disasm.cpp needs to be updated to show inlining.

@timholy
Copy link
Sponsor Member Author

timholy commented Jul 7, 2016

Also worth noting that foo1 and foo2 don't seem to appear in the stackframes.

vtjnash added a commit that referenced this issue Jul 7, 2016
* the inlining pass would discard the first LineNumberNode, without
  checking that it matched the line number of the function declaration

* the CurrentDebugLocation shouldn't be set while emitting the prologue

* implement inlining info for pre-MCJIT llvm

* improve printing of relative symbols in disassembly (e.g. 'callq "_setindex!"')
  and hide the first line number if it is zero

* print inlining info during jl_gdblookup

also fix llvm 3.3 build

fix #17317
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 7, 2016

Note that even with my fixes, some line numbers are supposed to be 0 (to indicate that it is part of the function prologue).

The absence of foo1 / foo2 is a limitation of our current codegen and will be fixed when codegen is better at handling a linear IR.

@timholy
Copy link
Sponsor Member Author

timholy commented Jul 7, 2016

Thanks a ton, @vtjnash!

mfasi pushed a commit to mfasi/julia that referenced this issue Sep 5, 2016
* the inlining pass would discard the first LineNumberNode, without
  checking that it matched the line number of the function declaration

* the CurrentDebugLocation shouldn't be set while emitting the prologue

* implement inlining info for pre-MCJIT llvm

* improve printing of relative symbols in disassembly (e.g. 'callq "_setindex!"')
  and hide the first line number if it is zero

* print inlining info during jl_gdblookup

also fix llvm 3.3 build

fix JuliaLang#17317
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 a pull request may close this issue.

2 participants