gaming
Some checks failed
test / test (push) Has been cancelled

This commit is contained in:
nora 2025-09-22 17:26:08 +02:00
parent 84f98bb1ff
commit 0262ef8e42
4 changed files with 517 additions and 0 deletions

View file

@ -0,0 +1,46 @@
<?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 12.2.1 (0)
-->
<!-- Title: Mir_0_3 Pages: 1 -->
<svg width="500pt" height="286pt"
viewBox="0.00 0.00 500.25 285.75" 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 281.75)">
<title>Mir_0_3</title>
<polygon fill="white" stroke="none" points="-4,4 -4,-281.75 496.25,-281.75 496.25,4 -4,4"/>
<!-- bb0__0_3 -->
<g id="node1" class="node">
<title>bb0__0_3</title>
<polygon fill="gray" stroke="none" points="8,-250.5 8,-273.75 484.25,-273.75 484.25,-250.5 8,-250.5"/>
<polygon fill="none" stroke="black" points="8,-250.5 8,-273.75 484.25,-273.75 484.25,-250.5 8,-250.5"/>
<text text-anchor="start" x="242" y="-257.45" font-family="Courier, monospace" font-size="14.00">0</text>
<polygon fill="none" stroke="black" points="8,-175.5 8,-250.5 484.25,-250.5 484.25,-175.5 8,-175.5"/>
<text text-anchor="start" x="11" y="-234.2" font-family="Courier, monospace" font-size="14.00">StorageLive(_3)</text>
<text text-anchor="start" x="11" y="-216.95" font-family="Courier, monospace" font-size="14.00">_3 = copy _1</text>
<text text-anchor="start" x="11" y="-199.7" font-family="Courier, monospace" font-size="14.00">StorageLive(_4)</text>
<text text-anchor="start" x="11" y="-182.45" font-family="Courier, monospace" font-size="14.00">_4 = copy _2</text>
<polygon fill="none" stroke="black" points="8,-152.25 8,-175.5 484.25,-175.5 484.25,-152.25 8,-152.25"/>
<text text-anchor="start" x="11" y="-159.2" font-family="Courier, monospace" font-size="14.00">_0 = core::num::&lt;impl u8&gt;::wrapping_add(move _3, move _4)</text>
</g>
<!-- bb1__0_3 -->
<g id="node2" class="node">
<title>bb1__0_3</title>
<polygon fill="gray" stroke="none" points="181.25,-67.75 181.25,-91 311,-91 311,-67.75 181.25,-67.75"/>
<polygon fill="none" stroke="black" points="181.25,-67.75 181.25,-91 311,-91 311,-67.75 181.25,-67.75"/>
<text text-anchor="start" x="242" y="-74.7" font-family="Courier, monospace" font-size="14.00">1</text>
<polygon fill="none" stroke="black" points="181.25,-27.25 181.25,-67.75 311,-67.75 311,-27.25 181.25,-27.25"/>
<text text-anchor="start" x="184.25" y="-51.45" font-family="Courier, monospace" font-size="14.00">StorageDead(_4)</text>
<text text-anchor="start" x="184.25" y="-34.2" font-family="Courier, monospace" font-size="14.00">StorageDead(_3)</text>
<polygon fill="none" stroke="black" points="181.25,-4 181.25,-27.25 311,-27.25 311,-4 181.25,-4"/>
<text text-anchor="start" x="184.25" y="-10.95" font-family="Courier, monospace" font-size="14.00">return</text>
</g>
<!-- bb0__0_3&#45;&gt;bb1__0_3 -->
<g id="edge1" class="edge">
<title>bb0__0_3&#45;&gt;bb1__0_3</title>
<path fill="none" stroke="black" d="M246.12,-148.32C246.12,-134.38 246.12,-119.7 246.12,-106.02"/>
<polygon fill="black" stroke="black" points="249.63,-106.31 246.13,-96.31 242.63,-106.31 249.63,-106.31"/>
<text text-anchor="middle" x="270.88" y="-116.95" font-family="Courier, monospace" font-size="14.00">return</text>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -0,0 +1,424 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>how rust compiles</title>
<link rel="stylesheet" href="../dist/reset.css" />
<link rel="stylesheet" href="../dist/reveal.css" />
<link rel="stylesheet" href="../dist/theme/black.css" />
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="../plugin/highlight/monokai.css" />
<style>
* {
--r-heading-text-transform: initial;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h2>how rust compiles</h2>
</section>
<section style="height: 100%">
<div style="display: flex; align-items: flex-start; height: 100%">
<details>
<summary>the rust compilation model has surprising effects</summary>
<iframe
height="600"
width="800"
src="https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=aa4567f7a97dd255dc4f314ae2b5d63c"
referrerpolicy="no-referrer"
></iframe>
</details>
</div>
</section>
<section>
<h2>introduction to me</h2>
<div style="display: flex">
<div>
<div>Noratrieb (she/her)</div>
contributing to the compiler since 2021
<br />
</div>
<div>
<img src="me.png" height="300" />
</div>
</div>
</section>
<section>
<h2>behind cargo build</h2>
<p>cargo vs rustc</p>
<div style="display: grid; grid-template-columns: 2fr 1fr 2fr">
<pre><code data-trim>
$ cargo build
</code></pre>
<div style="display: flex; align-items: center">cargo</div>
<div style="display: flex; flex-direction: column; align-items: flex-start">
<div>rustc (clap)</div>
<div>rustc (tokio)</div>
<div>rustc (tracing)</div>
<div>rustc (yourcrate)</div>
</div>
</div>
</section>
<section>
<h2>so you want to compile a crate</h2>
</section>
<section>
<h2>so you want to compile a crate</h2>
<p>source code:</p>
<pre><code data-trim>
#[no_mangle]
pub fn add(a: u8, b: u8) -> u8 {
a.wrapping_add(b)
}
</code></pre>
</section>
<section>
<h2>so you want to compile a crate</h2>
<p>MIR</p>
<img src="add-runtime-mir.svg" />
</section>
<section data-markdown>
<textarea data-template>
## so you want to compile a crate
LLVM IR
```
; meow::add
define noundef i8 @add(i8 noundef %a, i8 noundef %b) unnamed_addr #0 {
start:
%_0 = add i8 %b, %a
ret i8 %_0
}
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## so you want to compile a crate
Assembly
```
&lt;add&gt;:
lea (%rsi,%rdi,1),%eax
ret
```
</textarea>
</section>
<section>
<h2>codegen units</h2>
<pre><code>
fn main() {}
</code></pre>
<div class="mermaid">
<pre>
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true, 'fontSize': '25px' }}}%%
flowchart LR
mainmir["main (MIR)"]
subgraph mycgu1[my CGU 1]
mainll["main (LLVM IR)"]
end
mycgu1 --> mycgu1.rcgu.o
mainmir --> mainll
mycgu1.rcgu.o --> my_binary
std["std (and others)"] --> my_binary
</pre>
</div>
</section>
<section>
<h2>codegen units (but more)</h2>
<pre><code>
fn main() {}
fn foo1() {}
fn foo2() {}
</code></pre>
<div class="mermaid">
<pre>
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true, 'fontSize': '25px' }}}%%
flowchart LR
mainmir["main (MIR)"]
foo1mir["foo1 (MIR)"]
foo2mir["foo2 (MIR)"]
subgraph mycgu1[my CGU 1]
mainll["main (LLVM IR)"]
end
subgraph mycgu2[my CGU 2]
foo1ll["foo1 (LLVM IR)"]
foo2ll["foo2 (LLVM IR)"]
end
mycgu1 --> mycgu1.rcgu.o
mycgu2 --> mycgu2.rcgu.o
mainmir --> mainll
foo1mir --> foo1ll
foo2mir --> foo2ll
mycgu1.rcgu.o --> my_binary
mycgu2.rcgu.o --> my_binary
std["std (and others)"] --> my_binary
</pre>
</div>
</section>
<section>
<h2>codegen units (cross-crate)</h2>
<div style="display: flex; flex-direction: row; gap: 16px">
<pre><code>
fn add() {}
</code></pre>
<pre><code>
fn main() { math::add() }
</code></pre>
</div>
<div class="mermaid">
<pre>
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true, 'fontSize': '25px' }}}%%
flowchart LR
subgraph crate math
addmir["add (MIR)"]
subgraph mathcgu1[math CGU 1]
addll["add (LLVM IR)"]
end
addmir --> addll
mathcgu1 --> mathcgu1.rcgu.o
mathcgu1.rcgu.o --> libmath.rlib
end
subgraph my crate
mainmir["main (MIR)"]
subgraph mycgu1[my CGU 1]
mainll["main (LLVM IR)"]
end
mycgu1 --> mycgu1.rcgu.o
mainmir --> mainll
mycgu1.rcgu.o --> my_binary
libmath.rlib --> my_binary
std["std (and others)"] --> my_binary
end
</pre>
</div>
</section>
<section data-markdown>
<textarea data-template>
## generics
```rust
fn add<T: Add>(a: T, b: T) -> T::Output {
a + b
}
add(0_u16, 0_u16); // creates add<u16> function
add(0_u32, 0_u32); // creates add<u32> function
```
</textarea>
</section>
<section>
<h2>instantiating generics</h2>
<pre><code data-trim class="language-rust">
fn add&lt;T: Add&gt;(a: T, b: T) -> T::Output { a + b }
fn main() {
add(0_u16, 0_u16);
add(0_u32, 0_u32);
}
</code></pre>
<div class="mermaid">
<pre>
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true, 'fontSize': '25px' }}}%%
flowchart LR
addmir["add (MIR)"]
useitmir["main (MIR)"]
subgraph mycgu1[my CGU 1]
addu16ll["add_u16 (LLVM IR)"]
addu32ll["add_u32 (LLVM IR)"]
useitll["main (LLVM IR)"]
end
mycgu1 --> mycgu1.rcgu.o
addmir -->|instantiate with T=u16| addu16ll
addmir -->|instantiate with T=u32| addu32ll
useitmir --> useitll
mycgu1.rcgu.o --> my_binary
std["std (and others)"] --> my_binary
</pre>
</div>
</section>
<section>
<h2>generics (cross-crate)</h2>
<div style="display: flex; flex-direction: row; gap: 16px">
<pre><code data-trim class="language-rust">
pub fn add&lt;T: Add&gt;(a: T, b: T) -> T::Output {
a + b
}
</code></pre>
<pre><code data-trim class="language-rust">
fn main() {
add(0_u16, 0_u16);
add(0_u32, 0_u32);
}
</code></pre>
</div>
<div class="mermaid">
<pre>
%%{init: {'theme': 'dark', 'themeVariables': { 'darkMode': true, 'fontSize': '25px' }}}%%
flowchart LR
subgraph crate math
addmir["add (MIR)"]
end
subgraph my crate
mainmir["main (MIR)"]
end
subgraph my crate
subgraph mycgu1[my CGU 1]
addu16ll["add_u16 (LLVM IR)"]
addu32ll["add_u32 (LLVM IR)"]
mainll["main (LLVM IR)"]
end
mainmir --> mainll
addmir --> addu16ll
addmir --> addu32ll
mycgu1 --> mycgu1.rcgu.o
mycgu1.rcgu.o --> my_binary
std["std (and others)"] --> my_binary
end
</pre>
</div>
</section>
<section data-markdown>
<textarea data-template>
## instantiation modes
the two ways to instantiate MIR:
- in the definition crate (Globally Shared)
- in the using crate (Local Copy)
- generic functions
- `#[inline]` functions
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## inlining
```rust
fn main() {
let x = 1 + 4;
println!("{x}");
}
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## inlining
```rust
fn main() {
let x = 5;
println!("{x}");
}
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## inlining
```rust
fn add(a: u8, b: u8) -> u8 {
a + b
}
fn main() {
let x = add(1, 4);
println!("{x}");
}
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## inlining
```rust
fn add(a: u8, b: u8) -> u8 {
a + b
}
fn main() {
let x = {
let a = 1;
let b = 4;
a + b
};
println!("{x}");
}
```
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## inlining
```rust
fn add(a: u8, b: u8) -> u8 {
a + b
}
fn main() {
let x = 5;
println!("{x}");
}
```
</textarea>
</section>
</div>
</div>
<script src="../dist/reveal.js"></script>
<script src="../plugin/notes/notes.js"></script>
<script src="../plugin/markdown/markdown.js"></script>
<script src="../plugin/highlight/highlight.js"></script>
<script src="./reveal.js-mermaid-plugin_11-6-0.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
hash: true,
// Learn about plugins: https://revealjs.com/plugins/
plugins: [RevealMarkdown, RevealHighlight, RevealNotes, RevealMermaid],
});
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

File diff suppressed because one or more lines are too long