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
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="2119pt" height="533pt"
viewBox="0.00 0.00 2119.00 533.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 529)">
<title>Mir</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-529 2115,-529 2115,4 -4,4"/>
<!-- BB0 -->
<g id="node1" class="node"><title>BB0</title>
<polygon fill="none" stroke="black" points="8.5,-499.5 8.5,-520.5 2103.5,-520.5 2103.5,-499.5 8.5,-499.5"/>
<text text-anchor="start" x="1043.5" y="-507.3" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₀</text>
<polygon fill="none" stroke="black" points="8.5,-478.5 8.5,-499.5 2103.5,-499.5 2103.5,-478.5 8.5,-478.5"/>
<text text-anchor="start" x="11.5" y="-485.3" font-family="Times,serif" font-size="14.00">Var₀ = Arg₀</text>
<polygon fill="none" stroke="black" points="8.5,-457.5 8.5,-478.5 2103.5,-478.5 2103.5,-457.5 8.5,-457.5"/>
<text text-anchor="start" x="11.5" y="-464.3" font-family="Times,serif" font-size="14.00">Var₁ = Constant { span: test.rs:42:20: 42:21, ty: usize, literal: Value { value: Uint(1) } }</text>
<polygon fill="none" stroke="black" points="8.5,-436.5 8.5,-457.5 2103.5,-457.5 2103.5,-436.5 8.5,-436.5"/>
<text text-anchor="start" x="11.5" y="-443.3" font-family="Times,serif" font-size="14.00">Temp₃ = Var₀</text>
<polygon fill="none" stroke="black" points="8.5,-415.5 8.5,-436.5 2103.5,-436.5 2103.5,-415.5 8.5,-415.5"/>
<text text-anchor="start" x="11.5" y="-422.3" 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:43:6: 43:7, ty: usize, literal: Value { value: Uint(1) } }, Temp₃])</text>
<polygon fill="none" stroke="black" points="8.5,-394.5 8.5,-415.5 2103.5,-415.5 2103.5,-394.5 8.5,-394.5"/>
<text text-anchor="start" x="11.5" y="-401.3" font-family="Times,serif" font-size="14.00">Temp₄ = Aggregate&lt;Tuple&gt;([])</text>
<polygon fill="none" stroke="black" points="8.5,-373.5 8.5,-394.5 2103.5,-394.5 2103.5,-373.5 8.5,-373.5"/>
<text text-anchor="start" x="11.5" y="-380.3" font-family="Times,serif" font-size="14.00">Temp₆ = &amp;ReScope(CodeExtent(130/Misc(103))) Mut Var₁</text>
<polygon fill="none" stroke="black" points="8.5,-352.5 8.5,-373.5 2103.5,-373.5 2103.5,-352.5 8.5,-352.5"/>
<text text-anchor="start" x="11.5" y="-359.3" font-family="Times,serif" font-size="14.00">Temp₅ = Aggregate&lt;Closure(DefId { krate: 0, node: DefIndex(24) =&gt; wat }, ClosureSubsts { func_substs: Substs[types=[[];[];[]], regions=[[];[];[]]], upvar_tys: [&amp;mut usize] })&gt;([Temp₆])</text>
<polygon fill="cornsilk" stroke="none" points="8.5,-331.5 8.5,-352.5 2103.5,-352.5 2103.5,-331.5 8.5,-331.5"/>
<polygon fill="none" stroke="black" points="8.5,-331.5 8.5,-352.5 2103.5,-352.5 2103.5,-331.5 8.5,-331.5"/>
<text text-anchor="start" x="11.5" y="-338.3" font-family="Times,serif" font-size="14.00">Temp₁ = Constant { span: test.rs:43:5: 43:44, ty: fn(core::ops::Range&lt;usize&gt;, (), [closure@test.rs:43:21: 43:43 prod:&amp;mut usize]), literal: Item { def_id: DefId { krate: 2, node: DefIndex(27641) }, kind: Method, substs: Substs[types=[[];[core::ops::Range&lt;usize&gt;];[(), [closure@test.rs:43:21: 43:43 prod:&amp;mut usize]]], regions=[[];[];[]]] } }(Temp₂, Temp₄, Temp₅) &#45;&gt; (BB₃, BB₄)</text>
</g>
<!-- BB3 -->
<g id="node4" class="node"><title>BB3</title>
<polygon fill="none" stroke="black" points="904.5,-252 904.5,-273 1040.5,-273 1040.5,-252 904.5,-252"/>
<text text-anchor="start" x="960" y="-259.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₃</text>
<polygon fill="none" stroke="black" points="904.5,-231 904.5,-252 1040.5,-252 1040.5,-231 904.5,-231"/>
<text text-anchor="start" x="907.5" y="-237.8" font-family="Times,serif" font-size="14.00">drop Temp₁</text>
<polygon fill="none" stroke="black" points="904.5,-210 904.5,-231 1040.5,-231 1040.5,-210 904.5,-210"/>
<text text-anchor="start" x="907.5" y="-216.8" font-family="Times,serif" font-size="14.00">drop Temp₂</text>
<polygon fill="none" stroke="black" points="904.5,-189 904.5,-210 1040.5,-210 1040.5,-189 904.5,-189"/>
<text text-anchor="start" x="907.5" y="-195.8" font-family="Times,serif" font-size="14.00">drop Temp₅</text>
<polygon fill="none" stroke="black" points="904.5,-168 904.5,-189 1040.5,-189 1040.5,-168 904.5,-168"/>
<text text-anchor="start" x="907.5" y="-174.8" font-family="Times,serif" font-size="14.00">drop Temp₆</text>
<polygon fill="none" stroke="black" points="904.5,-147 904.5,-168 1040.5,-168 1040.5,-147 904.5,-147"/>
<text text-anchor="start" x="907.5" y="-153.8" font-family="Times,serif" font-size="14.00">Temp₇ = Var₁</text>
<polygon fill="none" stroke="black" points="904.5,-126 904.5,-147 1040.5,-147 1040.5,-126 904.5,-126"/>
<text text-anchor="start" x="907.5" y="-132.8" font-family="Times,serif" font-size="14.00">ReturnPointer = Temp₇</text>
<polygon fill="cornsilk" stroke="none" points="904.5,-105 904.5,-126 1040.5,-126 1040.5,-105 904.5,-105"/>
<polygon fill="none" stroke="black" points="904.5,-105 904.5,-126 1040.5,-126 1040.5,-105 904.5,-105"/>
<text text-anchor="start" x="907.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="M1021.02,-327.673C1016.25,-314.148 1011.36,-300.262 1006.6,-286.756"/>
<polygon fill="black" stroke="black" points="1009.79,-285.268 1003.16,-277 1003.19,-287.595 1009.79,-285.268"/>
<text text-anchor="middle" x="1018" y="-298.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="1075.5,-220 1075.5,-241 1150.5,-241 1150.5,-220 1075.5,-220"/>
<text text-anchor="start" x="1100.5" y="-227.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₄</text>
<polygon fill="none" stroke="black" points="1075.5,-199 1075.5,-220 1150.5,-220 1150.5,-199 1075.5,-199"/>
<text text-anchor="start" x="1078.5" y="-205.8" font-family="Times,serif" font-size="14.00">drop Temp₂</text>
<polygon fill="none" stroke="black" points="1075.5,-178 1075.5,-199 1150.5,-199 1150.5,-178 1075.5,-178"/>
<text text-anchor="start" x="1078.5" y="-184.8" font-family="Times,serif" font-size="14.00">drop Temp₅</text>
<polygon fill="none" stroke="black" points="1075.5,-157 1075.5,-178 1150.5,-178 1150.5,-157 1075.5,-157"/>
<text text-anchor="start" x="1078.5" y="-163.8" font-family="Times,serif" font-size="14.00">drop Temp₆</text>
<polygon fill="cornsilk" stroke="none" points="1075.5,-136 1075.5,-157 1150.5,-157 1150.5,-136 1075.5,-136"/>
<polygon fill="none" stroke="black" points="1075.5,-136 1075.5,-157 1150.5,-157 1150.5,-136 1075.5,-136"/>
<text text-anchor="start" x="1078.5" y="-142.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="M1079.18,-327.673C1085.04,-303.453 1091.18,-278.076 1096.57,-255.801"/>
<polygon fill="black" stroke="black" points="1100.04,-256.342 1098.99,-245.8 1093.24,-254.696 1100.04,-256.342"/>
<text text-anchor="middle" x="1090" y="-298.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="953.5,-25 953.5,-46 992.5,-46 992.5,-25 953.5,-25"/>
<text text-anchor="start" x="960.5" y="-32.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₁</text>
<polygon fill="cornsilk" stroke="none" points="953.5,-4 953.5,-25 992.5,-25 992.5,-4 953.5,-4"/>
<polygon fill="none" stroke="black" points="953.5,-4 953.5,-25 992.5,-25 992.5,-4 953.5,-4"/>
<text text-anchor="start" x="956.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="1089.5,-25 1089.5,-46 1136.5,-46 1136.5,-25 1089.5,-25"/>
<text text-anchor="start" x="1100.5" y="-32.8" font-family="Times,serif" font-weight="bold" font-size="14.00">BB₂</text>
<polygon fill="cornsilk" stroke="none" points="1089.5,-4 1089.5,-25 1136.5,-25 1136.5,-4 1089.5,-4"/>
<polygon fill="none" stroke="black" points="1089.5,-4 1089.5,-25 1136.5,-25 1136.5,-4 1089.5,-4"/>
<text text-anchor="start" x="1092.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="M972.5,-100.835C972.5,-86.3545 972.5,-72.1379 972.5,-60.0513"/>
<polygon fill="black" stroke="black" points="976,-60.0249 972.5,-50.0249 969,-60.0249 976,-60.0249"/>
<text text-anchor="middle" x="976" 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="M1112.5,-132.249C1112.5,-108.29 1112.5,-81.0565 1112.5,-60.1598"/>
<polygon fill="black" stroke="black" points="1116,-60.1573 1112.5,-50.1573 1109,-60.1573 1116,-60.1573"/>
<text text-anchor="middle" x="1116" y="-71.8" font-family="Times,serif" font-size="14.00">0</text>
</g>
</g>
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment