Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rust ownership from legal perspective
Search
homuler
May 30, 2016
Programming
1
100
Rust ownership from legal perspective
Rustのownershipは所有権ではなかった件
homuler
May 30, 2016
Tweet
Share
More Decks by homuler
See All by homuler
JavaScript Course at Arzano Royal Institute of Magic
homuler
0
68
Style Transfer Overview in 5 minutes
homuler
0
85
Other Decks in Programming
See All in Programming
Catch Up: Go Style Guide Update
andpad
0
220
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
220
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
380
育てるアーキテクチャ:戦い抜くPythonマイクロサービスの設計と進化戦略
fujidomoe
1
170
Cursorハンズオン実践!
eltociear
2
1k
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
170
タスクの特性や不確実性に応じた最適な作業スタイルの選択(ペアプロ・モブプロ・ソロプロ)と実践 / Optimal Work Style Selection: Pair, Mob, or Solo Programming.
honyanya
3
160
Devoxx BE - Local Development in the AI Era
kdubois
0
130
Pull-Requestの内容を1クリックで動作確認可能にするワークフロー
natmark
2
500
Server Side Kotlin Meetup vol.16: 内部動作を理解して ハイパフォーマンスなサーバサイド Kotlin アプリケーションを書こう
ternbusty
3
180
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
250
明日から始めるリファクタリング
ryounasso
0
140
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
185
22k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
900
Context Engineering - Making Every Token Count
addyosmani
5
230
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Optimizing for Happiness
mojombo
379
70k
Visualization
eitanlees
149
16k
Six Lessons from altMBA
skipperchong
28
4k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Raft: Consensus for Rubyists
vanstee
139
7.1k
Designing for Performance
lara
610
69k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
Faster Mobile Websites
deanohume
310
31k
Transcript
Rustのownershipは 所有権のこと だと思った?
1. Rust • Mozillaが開発中のプログラミング言語 – C++が対抗馬 • GCがないが、メモリ安全性を担保 • Firefox(Gecko)の一部実装に使われている
– https://wiki.mozilla.org/Oxidation
2. Memory safe • Ownership – 所有権にたとえられる • Borrowing –
(使用/消費)貸借にたとえられる • Lifetimes
2. Memory safe • Ownership – 所有権? • Borrowing –
(使用/消費)貸借? • Lifetimes – 「人が深淵を覗く時、深淵もまた人を覗いている」
3. OwnershipとBorrowing • 変数宣言に関するルール • ある値に対するownershipを持つ変数(x)がある • 別の変数が同じ値を使う際は、(xの)ownershipをborrowする – この表現がかなりミソ
• 常にどちらかの状態を維持する – 値を参照するだけの変数(Immutable borrowing)が複数 – 値を変更可能な変数(Mutable borrowing)がただ一つ • 違反するとコンパイルエラー • 実行時のオーバーヘッドはない – コンパイル時チェックのみ
本当に貸借? borrowingのサンプル // コンパイルエラーになる fn main() { let xs =
vec![1, 2, 3]; for x in xs { println!("{}", x); } println!("{:?}", xs); }
本当に貸借? borrowingのサンプル // コンパイルエラーになる fn main() { let xs =
vec![1, 2, 3]; for x in xs { // move(ownershipが移る) println!("{}", x); } println!("{:?}", xs); // Error }
本当に貸借? borrowingのサンプル fn main() { let xs = vec![1, 2,
3]; for x in &xs { // borrowing(ownershipはそのまま) println!("{}", x); } println!("{:?}", xs); }
本当に貸借? borrowingのサンプル fn main() { let xs = vec![1, 2,
3]; for x in &xs { // borrowing(ownershipはそのまま) println!("{}", x); } println!("{:?}", xs); } 見せてもらっただけ、だけど一応借りてそう
本当に所有権? Borrowingのサンプル(mutable) // 配列を空にする fn emptify(xs: &Vec<usize>) { while
xs.len() > 0 { xs.pop(); // Error(Immutable!) } } fn main() { let xs = vec![1, 2, 3]; emptify(&xs); }
本当に所有権? Borrowingのサンプル(mutable) // 配列を空にする fn emptify(xs: &mut Vec<usize>) { while
xs.len() > 0 { xs.pop(); } } fn main() { let mut xs = vec![1, 2, 3]; emptify(&mut xs); }
本当に所有権? Borrowingのサンプル(mutable) // 配列を空にする fn emptify(xs: &mut Vec<usize>) {
while xs.len() > 0 { xs.pop(); } } fn main() { let mut xs = vec![1, 2, 3]; emptify(&mut xs); } 中身全部抜いてますけど・・
5. Borrowing再考 • Immutableのborrowing – 値は見るだけ – 法律行為(契約)でない可能性も • 渋谷駅にある「明日の神話」みたいな
• 警備員(コンパイラ)に止められるだけ • 入場規制はあるので、微妙なところ – 揚げ足を取るのはやめます
5. Borrowing再考 • Mutableのborrowing – 「借主」はやりたい放題 – もはや所有権を一度譲渡しているように見える – いずれ返されるので、「貸主」は何か
(ownership)を保持しているはず
• そういえば、ローマ法にあった – 「権原」 – 所有権の上位概念で、所有権の根拠になるもの – 日本では立法者が理解できなかったので、権原≒所有権 • 所有権だって条件(期限)付き譲渡できる、はず
– (日本法だと苦しい) – cf. 忘恩行為による贈与取り消し、終期付き譲渡など (東京地裁昭和50年12月25日判決) – 日本法ではなかった • 所有権(ownership)を借りる(borrow)という表現自体がおかしい • 「何か」 = ownership ≒ 権原 ≠ 所有権 Q.E.D 6. Ownership再考
まとめ • 譬え話にマジレスしてはいけない • でも、Rustはいいものです