Skip to content

Instantly share code, notes, and snippets.

@solson
Created December 29, 2015 00:17
Show Gist options
  • Save solson/480175dcf7639df69906 to your computer and use it in GitHub Desktop.
Save solson/480175dcf7639df69906 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#![feature(rustc_attrs)]
#![allow(dead_code)]
#[rustc_mir(graphviz = "empty.dot")]
fn empty() {}
#[rustc_mir(graphviz = "constant.dot")]
fn constant() -> i32 {
42
}
#[rustc_mir(graphviz = "increment.dot")]
fn increment(x: i32) -> i32 {
x + 1
}
#[rustc_mir(graphviz = "factorial_recursive.dot")]
fn factorial_recursive(n: usize) -> usize {
if n == 0 {
1
} else {
n * factorial_recursive(n - 1)
}
}
#[rustc_mir(graphviz = "factorial_iterative.dot")]
fn factorial_iterative(n: usize) -> usize {
let mut prod = 1;
for x in 1..n {
prod *= x;
}
prod
}
#[rustc_mir(graphviz = "factorial_fold.dot")]
fn factorial_fold(n: usize) -> usize {
(1..n).fold(1, |prod, x| prod * x)
}
#[rustc_mir(graphviz = "wat.dot")]
fn wat(n: usize) -> usize {
let mut prod = 1;
(1..n).fold((), |(), x| { prod *= x; });
prod
}
#[rustc_mir(graphviz = "multi_switch.dot")]
fn multi_switch(n: usize) -> usize {
match n {
5 | 10 | 15 => 3,
20 | 30 => 2,
_ => 1,
}
}
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.38.0 (20140413.2041)
-->
<!-- Title: Mir Pages: 1 -->
<svg width="1483pt" height="626pt"
viewBox="0.00 0.00 1483.00 626.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 622)">
<title>Mir</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-622 1479,-622 1479,4 -4,4"/>
<text text-anchor="start" x="510.5" y="-157.8" font-family="monospace" font-size="14.00">fn(a0: usize) &#45;&gt; usize</text>
<text text-anchor="start" x="510.5" y="-142.8" font-family="monospace" font-size="14.00">let v0: usize; // n</text>
<text text-anchor="start" x="510.5" y="-127.8" font-family="monospace" font-size="14.00">let mut v1: usize; // prod</text>
<text text-anchor="start" x="510.5" y="-112.8" font-family="monospace" font-size="14.00">let t0: ();</text>
<text text-anchor="start" x="510.5" y="-97.8" font-family="monospace" font-size="14.00">let t1: ();</text>
<text text-anchor="start" x="510.5" y="-82.8" font-family="monospace" font-size="14.00">let t2: core::ops::Range&lt;usize&gt;;</text>
<text text-anchor="start" x="510.5" y="-67.8" font-family="monospace" font-size="14.00">let t3: usize;</text>
<text text-anchor="start" x="510.5" y="-52.8" font-family="monospace" font-size="14.00">let t4: ();</text>
<text text-anchor="start" x="510.5" y="-37.8" font-family="monospace" font-size="14.00">let t5: [closure@test.rs:43:21: 43:43 prod:&amp;mut usize];</text>
<text text-anchor="start" x="510.5" y="-22.8" font-family="monospace" font-size="14.00">let t6: &amp;mut usize;</text>
<text text-anchor="start" x="510.5" y="-7.8" font-family="monospace" font-size="14.00">let t7: usize;</text>
<!-- bb0 -->
<g id="node1" class="node"><title>bb0</title>
<polygon fill="gray" stroke="none" points="8.5,-592.5 8.5,-613.5 1467.5,-613.5 1467.5,-592.5 8.5,-592.5"/>
<polygon fill="none" stroke="black" points="8.5,-592.5 8.5,-613.5 1467.5,-613.5 1467.5,-592.5 8.5,-592.5"/>
<text text-anchor="start" x="733.5" y="-599.3" font-family="monospace" font-size="14.00">0</text>
<polygon fill="none" stroke="black" points="8.5,-481.5 8.5,-592.5 1467.5,-592.5 1467.5,-481.5 8.5,-481.5"/>
<text text-anchor="start" x="11.5" y="-578.3" font-family="monospace" font-size="14.00">v0 = a0</text>
<text text-anchor="start" x="11.5" y="-563.3" font-family="monospace" font-size="14.00">v1 = 1</text>
<text text-anchor="start" x="11.5" y="-548.3" font-family="monospace" font-size="14.00">t3 = v0</text>
<text text-anchor="start" x="11.5" y="-533.3" font-family="monospace" font-size="14.00">t2 = Aggregate&lt;Adt(core::ops::Range, 0, Substs[types=[[usize];[];[]], regions=[[];[];[]]])&gt;[1, t3]</text>
<text text-anchor="start" x="11.5" y="-518.3" font-family="monospace" font-size="14.00">t4 = Aggregate&lt;Tuple&gt;[]</text>
<text text-anchor="start" x="11.5" y="-503.3" font-family="monospace" font-size="14.00">t6 = &amp;ReScope(CodeExtent(130/Misc(103))) Mut v1</text>
<text text-anchor="start" x="11.5" y="-488.3" font-family="monospace" font-size="14.00">t5 = Aggregate&lt;Closure(DefId { krate: 0, node: DefIndex(24) =&gt; wat }, ClosureSubsts { func_substs: Substs[types=[[];[];[]], regions=[[];[];[]]], upvar_tys: [&amp;mut usize] })&gt;[t6]</text>
<polygon fill="none" stroke="black" points="8.5,-460.5 8.5,-481.5 1467.5,-481.5 1467.5,-460.5 8.5,-460.5"/>
<text text-anchor="start" x="11.5" y="-467.3" font-family="monospace" font-size="14.00">t1 = core::iter::Iterator::fold(t2, t4, t5)</text>
</g>
<!-- bb3 -->
<g id="node4" class="node"><title>bb3</title>
<polygon fill="gray" stroke="none" points="580.5,-381 580.5,-402 735.5,-402 735.5,-381 580.5,-381"/>
<polygon fill="none" stroke="black" points="580.5,-381 580.5,-402 735.5,-402 735.5,-381 580.5,-381"/>
<text text-anchor="start" x="653.5" y="-387.8" font-family="monospace" font-size="14.00">3</text>
<polygon fill="none" stroke="black" points="580.5,-285 580.5,-381 735.5,-381 735.5,-285 580.5,-285"/>
<text text-anchor="start" x="583.5" y="-366.8" font-family="monospace" font-size="14.00">drop t1</text>
<text text-anchor="start" x="583.5" y="-351.8" font-family="monospace" font-size="14.00">drop t2</text>
<text text-anchor="start" x="583.5" y="-336.8" font-family="monospace" font-size="14.00">drop t5</text>
<text text-anchor="start" x="583.5" y="-321.8" font-family="monospace" font-size="14.00">drop t6</text>
<text text-anchor="start" x="583.5" y="-306.8" font-family="monospace" font-size="14.00">t7 = v1</text>
<text text-anchor="start" x="583.5" y="-291.8" font-family="monospace" font-size="14.00">ReturnPointer = t7</text>
<polygon fill="none" stroke="black" points="580.5,-264 580.5,-285 735.5,-285 735.5,-264 580.5,-264"/>
<text text-anchor="start" x="583.5" y="-270.8" font-family="monospace" font-size="14.00">goto</text>
</g>
<!-- bb0&#45;&gt;bb3 -->
<g id="edge1" class="edge"><title>bb0&#45;&gt;bb3</title>
<path fill="none" stroke="black" d="M705.997,-456.757C700.632,-443.179 695.054,-429.059 689.673,-415.437"/>
<polygon fill="black" stroke="black" points="692.913,-414.113 685.983,-406.098 686.402,-416.685 692.913,-414.113"/>
<text text-anchor="middle" x="722.5" y="-427.8" font-family="monospace" font-size="14.00">return</text>
</g>
<!-- bb4 -->
<g id="node5" class="node"><title>bb4</title>
<polygon fill="gray" stroke="none" points="769.5,-358 769.5,-379 833.5,-379 833.5,-358 769.5,-358"/>
<polygon fill="none" stroke="black" points="769.5,-358 769.5,-379 833.5,-379 833.5,-358 769.5,-358"/>
<text text-anchor="start" x="797" y="-364.8" font-family="monospace" font-size="14.00">4</text>
<polygon fill="none" stroke="black" points="769.5,-307 769.5,-358 833.5,-358 833.5,-307 769.5,-307"/>
<text text-anchor="start" x="772.5" y="-343.8" font-family="monospace" font-size="14.00">drop t2</text>
<text text-anchor="start" x="772.5" y="-328.8" font-family="monospace" font-size="14.00">drop t5</text>
<text text-anchor="start" x="772.5" y="-313.8" font-family="monospace" font-size="14.00">drop t6</text>
<polygon fill="none" stroke="black" points="769.5,-286 769.5,-307 833.5,-307 833.5,-286 769.5,-286"/>
<text text-anchor="start" x="772.5" y="-292.8" font-family="monospace" font-size="14.00">goto</text>
</g>
<!-- bb0&#45;&gt;bb4 -->
<g id="edge2" class="edge"><title>bb0&#45;&gt;bb4</title>
<path fill="none" stroke="black" d="M762.703,-456.757C769.406,-435.547 776.527,-413.016 782.813,-393.125"/>
<polygon fill="black" stroke="black" points="786.151,-394.18 785.827,-383.59 779.476,-392.071 786.151,-394.18"/>
<text text-anchor="middle" x="796.5" y="-427.8" font-family="monospace" font-size="14.00">unwind</text>
</g>
<!-- bb1 -->
<g id="node2" class="node"><title>bb1</title>
<polygon fill="gray" stroke="none" points="629.5,-198 629.5,-219 685.5,-219 685.5,-198 629.5,-198"/>
<polygon fill="none" stroke="black" points="629.5,-198 629.5,-219 685.5,-219 685.5,-198 629.5,-198"/>
<text text-anchor="start" x="653" y="-204.8" font-family="monospace" font-size="14.00">1</text>
<polygon fill="none" stroke="black" points="629.5,-177 629.5,-198 685.5,-198 685.5,-177 629.5,-177"/>
<text text-anchor="start" x="632.5" y="-183.8" font-family="monospace" font-size="14.00">return</text>
</g>
<!-- bb2 -->
<g id="node3" class="node"><title>bb2</title>
<polygon fill="gray" stroke="none" points="769.5,-198 769.5,-219 833.5,-219 833.5,-198 769.5,-198"/>
<polygon fill="none" stroke="black" points="769.5,-198 769.5,-219 833.5,-219 833.5,-198 769.5,-198"/>
<text text-anchor="start" x="797" y="-204.8" font-family="monospace" font-size="14.00">2</text>
<polygon fill="none" stroke="black" points="769.5,-177 769.5,-198 833.5,-198 833.5,-177 769.5,-177"/>
<text text-anchor="start" x="772.5" y="-183.8" font-family="monospace" font-size="14.00">diverge</text>
</g>
<!-- bb3&#45;&gt;bb1 -->
<g id="edge3" class="edge"><title>bb3&#45;&gt;bb1</title>
<path fill="none" stroke="black" d="M657.5,-259.662C657.5,-250.512 657.5,-241.51 657.5,-233.357"/>
<polygon fill="black" stroke="black" points="661,-233.186 657.5,-223.187 654,-233.187 661,-233.186"/>
</g>
<!-- bb4&#45;&gt;bb2 -->
<g id="edge4" class="edge"><title>bb4&#45;&gt;bb2</title>
<path fill="none" stroke="black" d="M801.5,-282.476C801.5,-266.192 801.5,-248.453 801.5,-233.531"/>
<polygon fill="black" stroke="black" points="805,-233.225 801.5,-223.225 798,-233.225 805,-233.225"/>
</g>
</g>
</svg>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment