Rust School @ SNU SNU
�Jeehoon Kang (KAIST)
2023/02/08 - 2023/02/10
1
Logistics
2
Prologue
3
Background
4
But Why?
5
This school’s topic
Rust’s Design Goal 1: Safety
6
Wait, Why C/C++ is Unsafe?
7
Rust’s Design Goal 2: Low-Level Control
8
https://en.wikipedia.org/wiki/Page_table
Organization
9
Interaction
10
Assignment (Day 1)
11
Why so many assignments…?
12
The Danger of Shared Mutable States
13
What is Shared Mutable States?
14
Low-level Resources are Shared Mutable States
15
Shared Mutable States are Source of Errors (1/2)
16
Shared Mutable States are Source of Errors (2/2)
17
“Iterator invalidation”
Why? Shared Mutable States break Modularity!
18
Personal Experience of Shared Mutable States
19
Microsoft’s Experience of Shared Mutable States
20
Lessons Learned
21
Reasoning Shared Mutable States,
Previously
22
A Wisdom on Shared Mutable States
23
State
“Invariant”
Invariant Enables Modular Reasoning
24
Invariant: assume/guarantee conditions that “divides” complex systems
Invariant Examples
25
Invariant-based Modular Reasoning
26
Immutability (Invariant)
27
Immutability Example: SSA (POPL 1988)
28
Immutability Example: RDD (NSDI 2012)
29
But Not Everything is Immutable
30
No Sharing (Invariant)
31
No Sharing Example: Alias Analysis
32
Principled Sharing Example: Reference Counting
33
But Not All Programs Can Admit RC
34
Blackburn and McKinley. Ulterior reference counting: fast garbage collection without a long wait. OOPSLA 2003.
Principled Sharing Example: Garbage Collection
35
Wisdom: if GC works for you, just use it.
36
OOPSLA 2005
But Not All Programs Can Admit GC
37
Lessons Learned
38
Assignment (Day 2)
39
Reasoning Shared Mutable States,�Efficiently & Precisely
40
Type checking
(automatically w/o runtime overhead)
Invariant
Focus on memory
Review: Memory
41
Review: Memory Safety
42
Focus on UAF
Type-Checking Memory Safety in C/C++ (Fail)
43
Type-Checking Memory Safety in New Language
44
Type-Checking Memory Safety in Rust
45
Owned Type (Mutable & No Sharing)
46
Borrowed Type (Immutable & Full Sharing, 1/3)
47
Borrowed Type (Immutable & Full Sharing, 2/3)
48
Borrowed Type (Immutable & Full Sharing, 3/3)
49
https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html
Mutably Borrowed Type (Mutable & Sharing, 1/3)
50
Mutably Borrowed Type (Mutable & Sharing, 2/3)
51
Mutably Borrowed Type (Mutable & Sharing, 3/3)
52
Summary of Pointer Types in Rust (1/2)
53
Summary of Pointer Types in Rust (2/2)
54
Remaining Question: How Much Applicable?
55
Whirlwind Tour of Rust Type System
56
Summary
57
Essential for assignment
Assignment (Day 3)
58
Reasoning Shared Mutable States
In Functions
59
Review: First-Class Function
60
Question: What If a Function Captures Pointer?
61
Reasoning Shared Mutable States
With Smart Pointers
62
What is Smart Pointer?
63
Smart Pointer’s Runtime Verification
64
Supporting Runtime Verification w/ Unsafe Rust
65
Improving Modularity w/ Interior Mutability
66
Hybriding Static and Runtime Verification
67
Reasoning Shared Mutable States
In Parallel Programming
68
Concurrency API (1/3)
69
Concurrency API (2/3)
70
Concurrency API (3/3)
71
Parallelism API
72
Epilogue
73
Recall: Organization
74
Rust in FuriosaAI
75
Rust in KAIST
76
Rust in SNU?
77
Thank you!