Giter VIP home page Giter VIP logo

Comments (6)

nsajko avatar nsajko commented on June 16, 2024

Can you reproduce with a supported Julia version?

from julia.

barucden avatar barucden commented on June 16, 2024

I can reproduce it with 1.10.3:

julia> function test_maximum()
           a = [0.5 1 3]
           d = -1
           c = maximum(a)
           if c < d
               c = maximum[a]
           else
               c = maximum[a]
           end
       end
test_maximum (generic function with 1 method)

julia> test_maximum()
ERROR: MethodError: no method matching getindex(::typeof(maximum), ::Matrix{Float64})
Stacktrace:
 [1] test_maximum()
   @ Main ./REPL[1]:0
 [2] top-level scope
   @ REPL[2]:1

julia> versioninfo()
Julia Version 1.10.3
Commit 0b4590a5507 (2024-04-30 10:59 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

Also, as OP said, changing one branch leads to the correct line number being reported:

julia> function test_maximum()
           a = [0.5 1 3]
           d = -1
           c = maximum(a)
           if c < d
               c = 1. # changed here
           else
               c = maximum[a]
           end
       end
test_maximum (generic function with 1 method)

julia> test_maximum()
ERROR: MethodError: no method matching getindex(::typeof(maximum), ::Matrix{Float64})
Stacktrace:
 [1] test_maximum()
   @ Main ./REPL[6]:8
 [2] top-level scope
   @ REPL[7]:1

from julia.

martinholters avatar martinholters commented on June 16, 2024

I think what's happening here is that the two branches are recognized as equal and therefore the whole if ... end is effectively replaced with a single c = maximum[a]. But that no longer has a unique line number (could be 6 or 8), and that is apparently signaled by setting the line number to zero.

BTW, a smaller reproducer is

function test_maximum(b)
    if b
        maximum[1]
    else
        maximum[1]
    end
end

for which @code_llvm easily confirms that the branch has been eliminated.

from julia.

KristofferC avatar KristofferC commented on June 16, 2024

Running with -O0 gives the correct line number.

from julia.

oscardssmith avatar oscardssmith commented on June 16, 2024

This might be an interesting test-case for JuliaLowering @c42f

from julia.

martinholters avatar martinholters commented on June 16, 2024

Lowering is doing fine here. For the reduced test_maximum from #54541 (comment), we have

julia> @code_typed debuginfo=:source test_maximum(true)
CodeInfo(
    @ REPL[1]:2 within `test_maximum`
1 ─     goto #3 if not b
    @ REPL[1]:3 within `test_maximum`
2 ─     Base.getindex(Main.maximum, 1)::Union{}
└──     unreachable
    @ REPL[1]:5 within `test_maximum`
3 ─     Base.getindex(Main.maximum, 1)::Union{}
└──     unreachable
) => Union{}

We can see that the line info is there even after inference/Julia level optimization. But than LLVM elides the unnecessary branch and doesn't know which line info to keep:

julia> @code_llvm debuginfo=:source test_maximum(true)
; Function Signature: test_maximum(Bool)
;  @ REPL[1]:1 within `test_maximum`
; Function Attrs: noreturn
define void @julia_test_maximum_3590(i8 zeroext %"b::Bool") #0 {
top:
  %jlcallframe1 = alloca [2 x ptr], align 8
;  @ REPL[1] within `test_maximum`
  store ptr @"jl_global#3595.jit", ptr %jlcallframe1, align 8
  %0 = getelementptr inbounds ptr, ptr %jlcallframe1, i64 1
  store ptr @"jl_global#3596.jit", ptr %0, align 8
  %1 = call nonnull ptr @ijl_apply_generic(ptr nonnull @"jl_global#3594.jit", ptr nonnull %jlcallframe1, i32 2)
  call void @llvm.trap()
  unreachable
}

from julia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.