<p dir="auto">Seen on <code class="notranslate">rustc 0.12.0-pre-nightly (4d4eb1023 2014-08-02 23:36:09 +0000)</code></p>
<p dir="auto">When compiling my <a href="https://github.com/TyOverby/irc-message/tree/e66c15e216720a2af23325a150318ea2c2d8bc4b">irc message parsing library</a> rustc uses as much CPU and memory as it can before crashing due to either an out of memory exception or an "illegal instruction" (stack overflow?).</p>
<p dir="auto">The weird thing about this is that a single change didn't introduce the bug.  As I worked on it, compile times got slower and slower until my machine could no longer even build the project.</p>
<p dir="auto">Uninterestingly, I'm not using macros or any other rust features that might have explosive properties.</p>
<h1 dir="auto">Test Case</h1>
<p dir="auto">To reproduce, download the two files in this gist and attempt to build <code class="notranslate">mkrust.rs</code>:</p>
<p dir="auto"><a href="https://gist.github.com/bkoropoff/537951c596ba24166f06">https://gist.github.com/bkoropoff/537951c596ba24166f06</a></p>
<h1 dir="auto">Analysis</h1>
<p dir="auto">The complex <code class="notranslate">json.query(...)</code> expression in <code class="notranslate">mkrust.rs</code> seems to be the culprit.  Progressively simplifying the expression will eventually cause the bug to no longer reproduce.</p>
<p dir="auto">Running rustc under massif yields the following (truncated for space) stack for the primary memory hog, which appears to be a hash map associated with region inference:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="99.25% (522,819,638B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
-&gt;68.00% (358,203,360B) 0x7E5562C: je_mallocx (in /home/bkoropoff/Software/rust/lib/librustrt-d8560cb2-0.11.0-pre.so)
| -&gt;50.16% (264,241,152B) 0x57AF077: collections::hashmap::table::RawTable$LT$K$C$$x20V$GT$::new::h16071681466547729146::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | -&gt;50.16% (264,241,152B) 0x57B1D51: collections::hashmap::HashMap$LT$K$C$$x20V$C$$x20H$GT$::resize::h9544924386944675449::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | | -&gt;50.16% (264,241,152B) 0x57B81D1: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::add_constraint::he966b592d2e519c2Sxo::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   -&gt;50.16% (264,241,152B) 0x57BA642: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::make_subregion::h5a25349bdfe40532sBo::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   | -&gt;50.16% (264,241,152B) 0x57BC9F6: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::lub_regions::closure.93817 (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   | | -&gt;50.16% (264,241,152B) 0x57BC0D0: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::combine_vars::h5ec95b92851d887cDUo::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   | | | -&gt;50.16% (264,241,152B) 0x57A23E6: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::lub_regions::hc2ef972d6db9d001eIo::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   | | |   -&gt;50.16% (264,241,152B) 0x578A07A: middle::typeck::infer::lub::Lub$LT$$x27f$GT$.Combine::regions::h96b097927410ccd30sn::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)"><pre class="notranslate"><code class="notranslate">99.25% (522,819,638B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
-&gt;68.00% (358,203,360B) 0x7E5562C: je_mallocx (in /home/bkoropoff/Software/rust/lib/librustrt-d8560cb2-0.11.0-pre.so)
| -&gt;50.16% (264,241,152B) 0x57AF077: collections::hashmap::table::RawTable$LT$K$C$$x20V$GT$::new::h16071681466547729146::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | -&gt;50.16% (264,241,152B) 0x57B1D51: collections::hashmap::HashMap$LT$K$C$$x20V$C$$x20H$GT$::resize::h9544924386944675449::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | | -&gt;50.16% (264,241,152B) 0x57B81D1: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::add_constraint::he966b592d2e519c2Sxo::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   -&gt;50.16% (264,241,152B) 0x57BA642: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::make_subregion::h5a25349bdfe40532sBo::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   | -&gt;50.16% (264,241,152B) 0x57BC9F6: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::lub_regions::closure.93817 (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   | | -&gt;50.16% (264,241,152B) 0x57BC0D0: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::combine_vars::h5ec95b92851d887cDUo::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   | | | -&gt;50.16% (264,241,152B) 0x57A23E6: middle::typeck::infer::region_inference::RegionVarBindings$LT$$x27a$GT$::lub_regions::hc2ef972d6db9d001eIo::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
| | |   | | |   -&gt;50.16% (264,241,152B) 0x578A07A: middle::typeck::infer::lub::Lub$LT$$x27f$GT$.Combine::regions::h96b097927410ccd30sn::v0.11.0.pre (in /home/bkoropoff/Software/rust/lib/librustc-d252d482-0.11.0-pre.so)
</code></pre></div>