<p dir="auto">Hi,</p>
<p dir="auto">I was trying to profile the <a href="https://github.com/guolas/julia_test/commit/e365ca510f82b752ccd759421b12567e86c8d452">code</a> provided in <a href="https://github.com/JuliaLang/julia/issues/3965" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/3965/hovercard">this</a> OpenBLAS issue.</p>
<p dir="auto">It was a simple modification that wraps the code inside a function and then calls it</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="function f()
tic()
for ii in 1:1e4
      # BD
      W_bd, S, U = bd_precoding(H, antennas_tx, antennas_rx)
      p_tx_bd = equal_power_assignment(W_bd, antennas_tx, antennas_rx, p_max)
....
      stream_rate_bd = log2(1 + p_tx_bd .* S / sigma_n)
....
      # ZF
      W_zf = zf_precoding(H)
      p_tx_zf = equal_power_assignment(W_zf, antennas_tx, antennas_rx, p_max)
      stream_rate_zf = log2(1 + p_tx_zf * ones(number_of_bs * antennas_rx) / sigma_n)
end
toc()
end

@profile f()"><pre class="notranslate"><code class="notranslate">function f()
tic()
for ii in 1:1e4
      # BD
      W_bd, S, U = bd_precoding(H, antennas_tx, antennas_rx)
      p_tx_bd = equal_power_assignment(W_bd, antennas_tx, antennas_rx, p_max)
....
      stream_rate_bd = log2(1 + p_tx_bd .* S / sigma_n)
....
      # ZF
      W_zf = zf_precoding(H)
      p_tx_zf = equal_power_assignment(W_zf, antennas_tx, antennas_rx, p_max)
      stream_rate_zf = log2(1 + p_tx_zf * ones(number_of_bs * antennas_rx) / sigma_n)
end
toc()
end

@profile f()
</code></pre></div>
<p dir="auto">However, when I ran this code, in the first 2 instances I got a <code class="notranslate">segmentation fault 11</code>. After that the code just went into an non-terminating state, and I had to stop processing after around 5 mins of execution.</p>
<p dir="auto"><code class="notranslate">htop</code> was showing cores being used, so it's possible that the code was running but was terribly slowing down due to the profiler, or it entered some kind of infinite loop.</p>
<p dir="auto">I ran this code a couple of times (in original) without the <code class="notranslate">@profile</code> and it completed comfortable after about 80 seconds.</p>
<p dir="auto">If I fully specify the type parameters for a constructor and the arguments are compatible, I expected it to work. However, I'm seeing errors from the default constructor:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; struct Struct1{T,S&gt;:T}
           x::S
       end

julia&gt; Struct1{Int,Real}(0)
ERROR: UndefVarError: S not defined
...

julia&gt; struct Struct2{T,S&gt;:T}
           x::S
           Struct2{T,S}(x) where {T,S} = new{T,S}(x)  # no bound for S
       end

julia&gt; Struct2{Int,Real}(0)
Struct2{Int64, Real}(0)"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">struct</span> Struct1{T,S<span class="pl-k">&gt;:</span><span class="pl-c1">T</span>}
           x<span class="pl-k">::</span><span class="pl-c1">S</span>
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">Struct1</span><span class="pl-c1">{Int,Real}</span>(<span class="pl-c1">0</span>)
ERROR<span class="pl-k">:</span> UndefVarError<span class="pl-k">:</span> S not defined
<span class="pl-k">...</span>

julia<span class="pl-k">&gt;</span> <span class="pl-k">struct</span> Struct2{T,S<span class="pl-k">&gt;:</span><span class="pl-c1">T</span>}
           x<span class="pl-k">::</span><span class="pl-c1">S</span>
           <span class="pl-en">Struct2</span><span class="pl-c1">{T,S}</span>(x) <span class="pl-k">where</span> {T,S} <span class="pl-k">=</span> <span class="pl-c1">new</span><span class="pl-c1">{T,S}</span>(x)  <span class="pl-c"><span class="pl-c">#</span> no bound for S</span>
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">Struct2</span><span class="pl-c1">{Int,Real}</span>(<span class="pl-c1">0</span>)
<span class="pl-c1">Struct2</span><span class="pl-c1">{Int64, Real}</span>(<span class="pl-c1">0</span>)</pre></div>
<p dir="auto">I can also get the same error with a manual constructor with the same bound:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; struct Struct3{T,S&gt;:T}
           x::S
           Struct3{T,S}(x) where {T,S&gt;:T} = new{T,S}(x)
       end

julia&gt; Struct3{Int,Real}(0)
ERROR: UndefVarError: S not defined
..."><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">struct</span> Struct3{T,S<span class="pl-k">&gt;:</span><span class="pl-c1">T</span>}
           x<span class="pl-k">::</span><span class="pl-c1">S</span>
           <span class="pl-en">Struct3</span><span class="pl-c1">{T,S}</span>(x) <span class="pl-k">where</span> {T,S<span class="pl-k">&gt;:</span><span class="pl-c1">T</span>} <span class="pl-k">=</span> <span class="pl-c1">new</span><span class="pl-c1">{T,S}</span>(x)
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">Struct3</span><span class="pl-c1">{Int,Real}</span>(<span class="pl-c1">0</span>)
ERROR<span class="pl-k">:</span> UndefVarError<span class="pl-k">:</span> S not defined
<span class="pl-k">...</span></pre></div>
<p dir="auto">But, interestingly, it doesn't happen with the upper bound <code class="notranslate">T&lt;:S</code></p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; struct Struct4{S,T&lt;:S}
           x::S
       end

julia&gt; Struct4{Real,Int}(0)
Struct4{Real, Int64}(0)

julia&gt; struct Struct5{S,T&lt;:S}
           x::S
           Struct5{S,T}(x) where {S,T&lt;:S} = new{S,T}(x)
       end

julia&gt; Struct5{Real,Int}(0)
Struct5{Real, Int64}(0)"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">struct</span> Struct4{S,T<span class="pl-k">&lt;:</span><span class="pl-c1">S</span>}
           x<span class="pl-k">::</span><span class="pl-c1">S</span>
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">Struct4</span><span class="pl-c1">{Real,Int}</span>(<span class="pl-c1">0</span>)
<span class="pl-c1">Struct4</span><span class="pl-c1">{Real, Int64}</span>(<span class="pl-c1">0</span>)

julia<span class="pl-k">&gt;</span> <span class="pl-k">struct</span> Struct5{S,T<span class="pl-k">&lt;:</span><span class="pl-c1">S</span>}
           x<span class="pl-k">::</span><span class="pl-c1">S</span>
           <span class="pl-en">Struct5</span><span class="pl-c1">{S,T}</span>(x) <span class="pl-k">where</span> {S,T<span class="pl-k">&lt;:</span><span class="pl-c1">S</span>} <span class="pl-k">=</span> <span class="pl-c1">new</span><span class="pl-c1">{S,T}</span>(x)
       <span class="pl-k">end</span>

julia<span class="pl-k">&gt;</span> <span class="pl-c1">Struct5</span><span class="pl-c1">{Real,Int}</span>(<span class="pl-c1">0</span>)
<span class="pl-c1">Struct5</span><span class="pl-c1">{Real, Int64}</span>(<span class="pl-c1">0</span>)</pre></div>
<p dir="auto">I wonder if this is a symptom of what <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/JeffBezanson/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/JeffBezanson">@JeffBezanson</a> described in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="787322863" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/39280" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/39280/hovercard?comment_id=763077129&amp;comment_type=issue_comment" href="https://github.com/JuliaLang/julia/issues/39280#issuecomment-763077129">#39280 (comment)</a></p>
<blockquote>
<p dir="auto">It helps here to understand that two different processes are happening: (1) picking a method to call, and (2) once inside the method, determining the value of <code class="notranslate">T</code> (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="787266794" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/39277" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/39277/hovercard" href="https://github.com/JuliaLang/julia/issues/39277">#39277</a> has a similar concern).</p>
</blockquote>
<p dir="auto">But, since <code class="notranslate">Struct1{Int,Real}(0)</code> specifies the type, would it be possible to use the specified types as-is in the method body?</p>