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
<?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="1474pt" height="446pt"
viewBox="0.00 0.00 1474.00 446.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 442)">
<title>Mir</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-442 1470,-442 1470,4 -4,4"/>
<text text-anchor="start" x="572" y="-82.8" font-family="monospace" font-size="14.00">fn(a0: usize) &#45;&gt; usize</text>
<text text-anchor="start" x="572" y="-67.8" font-family="monospace" font-size="14.00">let v0: usize; // n</text>
<text text-anchor="start" x="572" y="-52.8" font-family="monospace" font-size="14.00">let t0: ();</text>
<text text-anchor="start" x="572" y="-37.8" font-family="monospace" font-size="14.00">let t1: core::ops::Range&lt;usize&gt;;</text>
<text text-anchor="start" x="572" y="-22.8" font-family="monospace" font-size="14.00">let t2: usize;</text>
<text text-anchor="start" x="572" y="-7.8" font-family="monospace" font-size="14.00">let t3: [closure@test.rs:37:20: 37:38];</text>
<!-- bb0 -->
<g id="node1" class="node"><title>bb0</title>
<polygon fill="gray" stroke="none" points="8,-413 8,-434 1458,-434 1458,-413 8,-413"/>
<polygon fill="none" stroke="black" points="8,-413 8,-434 1458,-434 1458,-413 8,-413"/>
<text text-anchor="start" x="728.5" y="-419.8" font-family="monospace" font-size="14.00">0</text>
<polygon fill="none" stroke="black" points="8,-347 8,-413 1458,-413 1458,-347 8,-347"/>
<text text-anchor="start" x="11" y="-398.8" font-family="monospace" font-size="14.00">v0 = a0</text>
<text text-anchor="start" x="11" y="-383.8" font-family="monospace" font-size="14.00">t2 = v0</text>
<text text-anchor="start" x="11" y="-368.8" font-family="monospace" font-size="14.00">t1 = Aggregate&lt;Adt(core::ops::Range, 0, Substs[types=[[usize];[];[]], regions=[[];[];[]]])&gt;[1, t2]</text>
<text text-anchor="start" x="11" y="-353.8" font-family="monospace" font-size="14.00">t3 = Aggregate&lt;Closure(DefId { krate: 0, node: DefIndex(18) =&gt; factorial_fold }, ClosureSubsts { func_substs: Substs[types=[[];[];[]], regions=[[];[];[]]], upvar_tys: [] })&gt;[]</text>
<polygon fill="none" stroke="black" points="8,-326 8,-347 1458,-347 1458,-326 8,-326"/>
<text text-anchor="start" x="11" y="-332.8" font-family="monospace" font-size="14.00">ReturnPointer = core::iter::Iterator::fold(t1, 1, t3)</text>
</g>
<!-- bb3 -->
<g id="node4" class="node"><title>bb3</title>
<polygon fill="gray" stroke="none" points="650,-246 650,-267 714,-267 714,-246 650,-246"/>
<polygon fill="none" stroke="black" points="650,-246 650,-267 714,-267 714,-246 650,-246"/>
<text text-anchor="start" x="677.5" y="-252.8" font-family="monospace" font-size="14.00">3</text>
<polygon fill="none" stroke="black" points="650,-210 650,-246 714,-246 714,-210 650,-210"/>
<text text-anchor="start" x="653" y="-231.8" font-family="monospace" font-size="14.00">drop t1</text>
<text text-anchor="start" x="653" y="-216.8" font-family="monospace" font-size="14.00">drop t3</text>
<polygon fill="none" stroke="black" points="650,-189 650,-210 714,-210 714,-189 650,-189"/>
<text text-anchor="start" x="653" y="-195.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="M708.52,-321.966C706.207,-315.941 703.987,-309.872 702,-304 699.51,-296.64 697.127,-288.791 694.929,-281.047"/>
<polygon fill="black" stroke="black" points="698.284,-280.047 692.25,-271.338 691.536,-281.909 698.284,-280.047"/>
<text text-anchor="middle" x="727" y="-292.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="748,-246 748,-267 812,-267 812,-246 748,-246"/>
<polygon fill="none" stroke="black" points="748,-246 748,-267 812,-267 812,-246 748,-246"/>
<text text-anchor="start" x="775.5" y="-252.8" font-family="monospace" font-size="14.00">4</text>
<polygon fill="none" stroke="black" points="748,-210 748,-246 812,-246 812,-210 748,-210"/>
<text text-anchor="start" x="751" y="-231.8" font-family="monospace" font-size="14.00">drop t1</text>
<text text-anchor="start" x="751" y="-216.8" font-family="monospace" font-size="14.00">drop t3</text>
<polygon fill="none" stroke="black" points="748,-189 748,-210 812,-210 812,-189 748,-189"/>
<text text-anchor="start" x="751" y="-195.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="M750.903,-321.864C755.12,-308.405 759.592,-294.131 763.733,-280.916"/>
<polygon fill="black" stroke="black" points="767.175,-281.637 766.825,-271.048 760.495,-279.544 767.175,-281.637"/>
<text text-anchor="middle" x="785" y="-292.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="654,-123 654,-144 710,-144 710,-123 654,-123"/>
<polygon fill="none" stroke="black" points="654,-123 654,-144 710,-144 710,-123 654,-123"/>
<text text-anchor="start" x="677.5" y="-129.8" font-family="monospace" font-size="14.00">1</text>
<polygon fill="none" stroke="black" points="654,-102 654,-123 710,-123 710,-102 654,-102"/>
<text text-anchor="start" x="657" y="-108.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="748,-123 748,-144 812,-144 812,-123 748,-123"/>
<polygon fill="none" stroke="black" points="748,-123 748,-144 812,-144 812,-123 748,-123"/>
<text text-anchor="start" x="775.5" y="-129.8" font-family="monospace" font-size="14.00">2</text>
<polygon fill="none" stroke="black" points="748,-102 748,-123 812,-123 812,-102 748,-102"/>
<text text-anchor="start" x="751" y="-108.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="M682,-184.809C682,-176.059 682,-166.938 682,-158.502"/>
<polygon fill="black" stroke="black" points="685.5,-158.263 682,-148.263 678.5,-158.263 685.5,-158.263"/>
</g>
<!-- bb4&#45;&gt;bb2 -->
<g id="edge4" class="edge"><title>bb4&#45;&gt;bb2</title>
<path fill="none" stroke="black" d="M780,-184.809C780,-176.059 780,-166.938 780,-158.502"/>
<polygon fill="black" stroke="black" points="783.5,-158.263 780,-148.263 776.5,-158.263 783.5,-158.263"/>
</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.
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
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment