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
<?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="2453pt" height="386pt"
viewBox="0.00 0.00 2453.00 386.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 382)">
<title>Mir</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-382 2449,-382 2449,4 -4,4"/>
<!-- BB0 -->
<g id="node1" class="node"><title>BB0</title>
<polygon fill="none" stroke="black" points="8.5,-353 8.5,-374 2437.5,-374 2437.5,-353 8.5,-353"/>
<text text-anchor="start" x="1210.5" y="-360.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₀</text>
<polygon fill="none" stroke="black" points="8.5,-332 8.5,-353 2437.5,-353 2437.5,-332 8.5,-332"/>
<text text-anchor="start" x="11.5" y="-338.8" font-family="Times,serif" font-size="14.00">Var₀ = Arg₀</text>
<polygon fill="none" stroke="black" points="8.5,-311 8.5,-332 2437.5,-332 2437.5,-311 8.5,-311"/>
<text text-anchor="start" x="11.5" y="-317.8" font-family="Times,serif" font-size="14.00">Temp₂ = Var₀</text>
<polygon fill="none" stroke="black" points="8.5,-290 8.5,-311 2437.5,-311 2437.5,-290 8.5,-290"/>
<text text-anchor="start" x="11.5" y="-296.8" font-family="Times,serif" font-size="14.00">Temp₁ = Aggregate&lt;Adt(core::ops::Range, 0, Substs[types=[[usize];[];[]], regions=[[];[];[]]])&gt;([Constant { span: test.rs:37:6: 37:7, ty: usize, literal: Value { value: Uint(1) } }, Temp₂])</text>
<polygon fill="none" stroke="black" points="8.5,-269 8.5,-290 2437.5,-290 2437.5,-269 8.5,-269"/>
<text text-anchor="start" x="11.5" y="-275.8" font-family="Times,serif" font-size="14.00">Temp₃ = Aggregate&lt;Closure(DefId { krate: 0, node: DefIndex(18) =&gt; factorial_fold }, ClosureSubsts { func_substs: Substs[types=[[];[];[]], regions=[[];[];[]]], upvar_tys: [] })&gt;([])</text>
<polygon fill="cornsilk" stroke="none" points="8.5,-248 8.5,-269 2437.5,-269 2437.5,-248 8.5,-248"/>
<polygon fill="none" stroke="black" points="8.5,-248 8.5,-269 2437.5,-269 2437.5,-248 8.5,-248"/>
<text text-anchor="start" x="11.5" y="-254.8" font-family="Times,serif" font-size="14.00">ReturnPointer = Constant { span: test.rs:37:5: 37:39, ty: fn(core::ops::Range&lt;usize&gt;, usize, [closure@test.rs:37:20: 37:38]) &#45;&gt; usize, literal: Item { def_id: DefId { krate: 2, node: DefIndex(27641) }, kind: Method, substs: Substs[types=[[];[core::ops::Range&lt;usize&gt;];[usize, [closure@test.rs:37:20: 37:38]]], regions=[[];[];[]]] } }(Temp₁, Constant { span: test.rs:37:17: 37:18, ty: usize, literal: Value { value: Uint(1) } }, Temp₃) &#45;&gt; (BB₃, BB₄)</text>
</g>
<!-- BB3 -->
<g id="node4" class="node"><title>BB3</title>
<polygon fill="none" stroke="black" points="1121.5,-168 1121.5,-189 1196.5,-189 1196.5,-168 1121.5,-168"/>
<text text-anchor="start" x="1146.5" y="-175.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₃</text>
<polygon fill="none" stroke="black" points="1121.5,-147 1121.5,-168 1196.5,-168 1196.5,-147 1121.5,-147"/>
<text text-anchor="start" x="1124.5" y="-153.8" font-family="Times,serif" font-size="14.00">drop Temp₁</text>
<polygon fill="none" stroke="black" points="1121.5,-126 1121.5,-147 1196.5,-147 1196.5,-126 1121.5,-126"/>
<text text-anchor="start" x="1124.5" y="-132.8" font-family="Times,serif" font-size="14.00">drop Temp₃</text>
<polygon fill="cornsilk" stroke="none" points="1121.5,-105 1121.5,-126 1196.5,-126 1196.5,-105 1121.5,-105"/>
<polygon fill="none" stroke="black" points="1121.5,-105 1121.5,-126 1196.5,-126 1196.5,-105 1121.5,-105"/>
<text text-anchor="start" x="1124.5" y="-111.8" font-family="Times,serif" font-size="14.00">goto &#45;&gt; BB₁</text>
</g>
<!-- BB0&#45;&gt;BB3 -->
<g id="edge1" class="edge"><title>BB0&#45;&gt;BB3</title>
<path fill="none" stroke="black" d="M1196.28,-243.641C1190.9,-230 1185.28,-215.786 1180.08,-202.617"/>
<polygon fill="black" stroke="black" points="1183.3,-201.25 1176.37,-193.235 1176.79,-203.822 1183.3,-201.25"/>
<text text-anchor="middle" x="1193" y="-214.8" font-family="Times,serif" font-size="14.00">0</text>
</g>
<!-- BB4 -->
<g id="node5" class="node"><title>BB4</title>
<polygon fill="none" stroke="black" points="1230.5,-168 1230.5,-189 1305.5,-189 1305.5,-168 1230.5,-168"/>
<text text-anchor="start" x="1255.5" y="-175.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₄</text>
<polygon fill="none" stroke="black" points="1230.5,-147 1230.5,-168 1305.5,-168 1305.5,-147 1230.5,-147"/>
<text text-anchor="start" x="1233.5" y="-153.8" font-family="Times,serif" font-size="14.00">drop Temp₁</text>
<polygon fill="none" stroke="black" points="1230.5,-126 1230.5,-147 1305.5,-147 1305.5,-126 1230.5,-126"/>
<text text-anchor="start" x="1233.5" y="-132.8" font-family="Times,serif" font-size="14.00">drop Temp₃</text>
<polygon fill="cornsilk" stroke="none" points="1230.5,-105 1230.5,-126 1305.5,-126 1305.5,-105 1230.5,-105"/>
<polygon fill="none" stroke="black" points="1230.5,-105 1230.5,-126 1305.5,-126 1305.5,-105 1230.5,-105"/>
<text text-anchor="start" x="1233.5" y="-111.8" font-family="Times,serif" font-size="14.00">goto &#45;&gt; BB₂</text>
</g>
<!-- BB0&#45;&gt;BB4 -->
<g id="edge2" class="edge"><title>BB0&#45;&gt;BB4</title>
<path fill="none" stroke="black" d="M1240.93,-243.641C1244.69,-230.133 1248.59,-216.062 1252.22,-203.001"/>
<polygon fill="black" stroke="black" points="1255.63,-203.807 1254.93,-193.235 1248.89,-201.934 1255.63,-203.807"/>
<text text-anchor="middle" x="1252" y="-214.8" font-family="Times,serif" font-size="14.00">1</text>
</g>
<!-- BB1 -->
<g id="node2" class="node"><title>BB1</title>
<polygon fill="none" stroke="black" points="1139.5,-25 1139.5,-46 1178.5,-46 1178.5,-25 1139.5,-25"/>
<text text-anchor="start" x="1146.5" y="-32.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₁</text>
<polygon fill="cornsilk" stroke="none" points="1139.5,-4 1139.5,-25 1178.5,-25 1178.5,-4 1139.5,-4"/>
<polygon fill="none" stroke="black" points="1139.5,-4 1139.5,-25 1178.5,-25 1178.5,-4 1139.5,-4"/>
<text text-anchor="start" x="1142.5" y="-10.8" font-family="Times,serif" font-size="14.00">return</text>
</g>
<!-- BB2 -->
<g id="node3" class="node"><title>BB2</title>
<polygon fill="none" stroke="black" points="1244.5,-25 1244.5,-46 1291.5,-46 1291.5,-25 1244.5,-25"/>
<text text-anchor="start" x="1255.5" y="-32.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₂</text>
<polygon fill="cornsilk" stroke="none" points="1244.5,-4 1244.5,-25 1291.5,-25 1291.5,-4 1244.5,-4"/>
<polygon fill="none" stroke="black" points="1244.5,-4 1244.5,-25 1291.5,-25 1291.5,-4 1244.5,-4"/>
<text text-anchor="start" x="1247.5" y="-10.8" font-family="Times,serif" 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="M1158.5,-100.975C1158.5,-87.4662 1158.5,-72.8755 1158.5,-60.1875"/>
<polygon fill="black" stroke="black" points="1162,-60.0426 1158.5,-50.0426 1155,-60.0427 1162,-60.0426"/>
<text text-anchor="middle" x="1162" y="-71.8" font-family="Times,serif" font-size="14.00">0</text>
</g>
<!-- BB4&#45;&gt;BB2 -->
<g id="edge4" class="edge"><title>BB4&#45;&gt;BB2</title>
<path fill="none" stroke="black" d="M1267.5,-100.975C1267.5,-87.4662 1267.5,-72.8755 1267.5,-60.1875"/>
<polygon fill="black" stroke="black" points="1271,-60.0426 1267.5,-50.0426 1264,-60.0427 1271,-60.0426"/>
<text text-anchor="middle" x="1271" y="-71.8" font-family="Times,serif" font-size="14.00">0</text>
</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.
#![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