Gallium.jl icon indicating copy to clipboard operation
Gallium.jl copied to clipboard

Simple Gallium example not working

Open josefsachsconning opened this issue 9 years ago • 4 comments

This worked in 0.5.0-pre, i.e. ended up in the debug prompt in the REPL. Am I doing something wrong? What changed?

AWS-Sachs-Ubuntu$ cat /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl
function myfunction1(x)
    return "monadic"
end

function myfunction1(x, y)
    text = "alpha"
    z = myfunction2(x + y)
    return z
end

function myfunction2(a)
    r = a * 10
end
AWS-Sachs-Ubuntu$ ~/src/julia-release-0.5/usr/bin/julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.1-pre+27 (2016-11-04 08:41 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 25f7066 (11 days old release-0.5)
|__/                   |  x86_64-linux-gnu

julia> using Gallium

julia> include("/home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl")
myfunction2 (generic function with 1 method)

julia> bp = Gallium.breakpoint(myfunction1)
Locations (+: active, -: inactive, *: source):
 * Any matching method added to #myfunction1
 * Any matching specialization of myfunction1(x) at /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl:2
 * Any matching specialization of myfunction1(x, y) at /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl:6


julia> myfunction1(1)
"monadic"

Back in 0.5.0-pre, I got this:

julia> bp = Gallium.breakpoint(myfunction1)
Locations (+: active, -: inactive, *: source):
 + myfunction1(x::Int64) at /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl:2
 + myfunction1(x::Int64, y::Int64) at /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl:6
 * Any matching method added to #myfunction1
 * Any matching specialization of myfunction1(x) at /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl:2
 * Any matching specialization of myfunction1(x, y) at /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl:6

josefsachsconning avatar Nov 16 '16 02:11 josefsachsconning

Try putting @noinline in front of your definition of myfunction1, or start julia with julia --inline=no. It's possible that julia -O0 would help, but I think that's more about avoiding the elision of variables than the inlining of functions.

timholy avatar Nov 16 '16 08:11 timholy

Using -O0 and --inline=no did not produce different behavior.

AWS-Sachs-Ubuntu$ ~/src/julia-release-0.5/usr/bin/julia -O0 --inline=no
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.1-pre+27 (2016-11-04 08:41 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 25f7066 (12 days old release-0.5)
|__/                   |  x86_64-linux-gnu

julia> using Gallium

julia> include("/home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl")
myfunction2 (generic function with 1 method)

julia> bp = Gallium.breakpoint(myfunction1)
Locations (+: active, -: inactive, *: source):
 * Any matching method added to #myfunction1
 * Any matching specialization of myfunction1(x) at /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl:2
 * Any matching specialization of myfunction1(x, y) at /home/sachs/lib/julia/GalliumExample.jl/src/GalliumExample.jl:6


julia> myfunction1(1)
"monadic"

josefsachsconning avatar Nov 16 '16 12:11 josefsachsconning

I'm curious about a couple things.

(1) What would myfunction1 be inlined into, since it is being called from the REPL?

(2) What changed between 0.5.0-pre, when this worked (see above), and 0.5.0 to produce the different behavior?

josefsachsconning avatar Nov 16 '16 13:11 josefsachsconning

There's a new optimization in 0.5, where it avoids specializing functions if it realizes the return value is always the same and just uses the value directly. That's probably what happens here, so the function never actually gets run. We're looking into disabling that optimization in --inline=no mode.

Keno avatar Nov 18 '16 20:11 Keno