<p dir="auto">As it stands <code class="notranslate">code_typed</code> returns its output, but <code class="notranslate">code_llvm</code> and <code class="notranslate">code_native</code> return <code class="notranslate">nothing</code> and instead print their output to an io stream. I would like to propose that all three have no side effects and return some kind of Julia object which displays nicely.</p>
<p dir="auto">I ran into this when trying to use these functions in a Pluto.jl notebook. <code class="notranslate">code_typed</code> works just fine but the other two don’t display their output in the notebook, which is rather annoying. You can get around this by redirecting stdout or by using sprint and returning a String, but it doesn’t look nice that way.</p>
<p dir="auto">Would the way to fix this be to have equivalents of the <code class="notranslate">Core.CodeInfo</code> type like a <code class="notranslate">LLVMInfo</code> and <code class="notranslate">NativeInfo</code> types, that just contain a string and get displayed nicely if <code class="notranslate">show</code>ed?</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; code_typed(abs, (Int,)) |&gt; typeof
Vector{Any} (alias for Array{Any, 1})

julia&gt; code_llvm(abs, (Int,)) |&gt; typeof
;  @ int.jl:170 within `abs'
define i64 @julia_abs_1497(i64 signext %0) {
top:
; ┌ @ int.jl:130 within `flipsign'
   %1 = icmp slt i64 %0, 0
   %2 = sub i64 0, %0
   %3 = select i1 %1, i64 %2, i64 %0
; └
  ret i64 %3
}
Nothing

julia&gt; code_native(abs, (Int,)) |&gt; typeof
        .section        __TEXT,__text,regular,pure_instructions
; ┌ @ int.jl:170 within `abs'
; │┌ @ int.jl:130 within `flipsign'
        movq    %rdi, %rax
        negq    %rax
        cmovlq  %rdi, %rax
; │└
        retq
        nopl    (%rax,%rax)
; └
Nothing"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">code_typed</span>(abs, (Int,)) <span class="pl-k">|&gt;</span> typeof
Vector{Any} (alias <span class="pl-k">for</span> Array{Any, <span class="pl-c1">1</span>})

julia<span class="pl-k">&gt;</span> <span class="pl-c1">code_llvm</span>(abs, (Int,)) <span class="pl-k">|&gt;</span> typeof
;  @ int<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">170</span> within <span class="pl-s"><span class="pl-pds">`</span>abs'</span>
<span class="pl-s">define i64 @julia_abs_1497(i64 signext %0) {</span>
<span class="pl-s">top:</span>
<span class="pl-s">; ┌ @ int.jl:130 within <span class="pl-pds">`</span><span class="pl-c1">flipsign</span></span><span class="pl-s"><span class="pl-pds">'</span></span>
<span class="pl-s">   %1 = icmp slt i64 %0, 0</span>
<span class="pl-s">   %2 = sub i64 0, %0</span>
<span class="pl-s">   %3 = select i1 %1, i64 %2, i64 %0</span>
<span class="pl-s">; └</span>
<span class="pl-s">  ret i64 %3</span>
<span class="pl-s">}</span>
<span class="pl-s">Nothing</span>
<span class="pl-s"></span>
<span class="pl-s">julia&gt; code_native(abs, (Int,)) |&gt; typeof</span>
<span class="pl-s">        .section        __TEXT,__text,regular,pure_instructions</span>
<span class="pl-s">; ┌ @ int.jl:170 within `abs<span class="pl-pds">'</span></span>
; │┌ @ int<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">130</span> within <span class="pl-s"><span class="pl-pds">`</span>flipsign'</span>
<span class="pl-s">        movq    %rdi, %rax</span>
<span class="pl-s">        negq    %rax</span>
<span class="pl-s">        cmovlq  %rdi, %rax</span>
<span class="pl-s">; │└</span>
<span class="pl-s">        retq</span>
<span class="pl-s">        nopl    (%rax,%rax)</span>
<span class="pl-s">; └</span>
<span class="pl-s">Nothing</span></pre></div>
<p dir="auto">A very sparse matrix with 1000 rows and 100000 columns with only 10 entries is multiplied by a dense vector column-wise:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sparse(rand(1:1000, 10), rand(1:100000, 10), rand(10), 1000, 100000) .* rand(1000, 1)"><pre class="notranslate"><code class="notranslate">sparse(rand(1:1000, 10), rand(1:100000, 10), rand(10), 1000, 100000) .* rand(1000, 1)
</code></pre></div>
<p dir="auto">This throws (maybe you have to increase the column numbers from <code class="notranslate">100000</code> to something higher, but you will get there):</p>
<blockquote>
<p dir="auto">OutOfMemoryError()<br>
Stacktrace:<br>
[1] _allocres at .\sparse\higherorderfns.jl:168 [inlined]<br>
[2] _diffshape_broadcast(::Base.#, ::SparseMatrixCSC{Float64,Int64}, ::SparseMatrixCSC{Float64,Int64}) at .\sparse\higherorderfns.jl:132<br>
[3] broadcast(::Base.#, ::SparseMatrixCSC{Float64,Int64}, ::SparseMatrixCSC{Float64,Int64}) at .\sparse\higherorderfns.jl:121</p>
</blockquote>
<p dir="auto">This memory error is thrown despite the fact the resulting matrix has only 10 entries. Maybe the broadcasting could be improved to reflect this.<br>
<a href="https://discourse.julialang.org/t/very-sparse-matrix-but-still-out-of-memory/11766" rel="nofollow">Here</a> is the thread on Discourse and here the version info, but <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/tkoolen/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/tkoolen">@tkoolen</a> saw the same behavior on the nightly build:</p>
<blockquote>
<p dir="auto">Julia Version 0.6.2<br>
Commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/JuliaLang/julia/commit/d386e40c17d43b79fc89d3e579fc04547241787c/hovercard" href="https://github.com/JuliaLang/julia/commit/d386e40c17d43b79fc89d3e579fc04547241787c"><tt>d386e40</tt></a>* (2017-12-13 18:08 UTC)<br>
Platform Info:<br>
OS: Windows (x86_64-w64-mingw32)<br>
CPU: Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz<br>
WORD_SIZE: 64<br>
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)<br>
LAPACK: libopenblas64_<br>
LIBM: libopenlibm<br>
LLVM: libLLVM-3.9.1 (ORCJIT, skylake)</p>
</blockquote>