Possible bug: Julia falis to auto guess retval type of functions returned by functions

111 views
Skip to first unread message

Marek Gagolewski

unread,
Mar 2, 2014, 7:11:46 AM3/2/14
to juli...@googlegroups.com
Hi,

Here are 2 functions g1, g2 that return its Int64 argument as-is. What is important, both of them are identical w.r.t. code_(typed|lowered|llvm|native)\(g(1|2), \(Int64,\)\). The only difference is - as you see - that the second one is the result of calling some method.

function g1(x::Int64)
  x
end

function generate_g2()
 
function g2(x::Int64)
    x
# substituting x for x::Int64 does not change anything
 
end
end
g2
= generate_g2()



It seems that there are problems with auto guessing retval types, for example:

[g1(x) for x in 1:3]

3-element Array{Int64,1}: ### Int64 - OK 1 2 3

 
[g2(x) for x in 1:3]
3-element Array{Any,1}:  ### Any :(
 1
 2
 3

This of course has a huge impact for the performance of certain ops, like:

@time [g1(i) for i in 1:1000000]

elapsed time: 0.004126231 seconds (8000048 bytes allocated)
 
@time [g2(i) for i in 1:1000000]


elapsed time: 0.393538948 seconds (71967360 bytes allocated)

 
Should I post this as an issue on GitHub?

The result were obtained on Julia version 0.3.0-prerelease+1805 (2014-03-01 23:11 UTC) Commit a5b5d64* (0 days old master, fetched 10 mins ago).

Best regards,
Marek

Stefan Karpinski

unread,
Mar 2, 2014, 1:37:46 PM3/2/14
to Julia Dev
This is a well-known problem, so there's no need to file an issue. Basically, top-level named functions are the only ones that currently get the full optimization treatment. Obviously, this needs to be addressed, but it's pretty straightforward to work around most of the time.

Marek Gagolewski

unread,
Mar 3, 2014, 3:59:03 AM3/3/14
to juli...@googlegroups.com
On Sunday, March 2, 2014 7:37:46 PM UTC+1, Stefan Karpinski wrote:
This is a well-known problem, so there's no need to file an issue. Basically, top-level named functions are the only ones that currently get the full optimization treatment. Obviously, this needs to be addressed, but it's pretty straightforward to work around most of the time.

OK, sorry, seems that I didn't do my homework thoroughly enough (https://github.com/JuliaLang/julia/issues/1864 + references).

Is there any way to call the optimization routines manually, sth like g2 <- code_force_manual_optimize(g2) ?
Reply all
Reply to author
Forward
0 new messages