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
100
1
Share
Rust ownership from legal perspective
Rustのownershipは所有権ではなかった件
homuler
May 30, 2016
More Decks by homuler
See All by homuler
JavaScript Course at Arzano Royal Institute of Magic
homuler
0
81
Style Transfer Overview in 5 minutes
homuler
0
98
Other Decks in Programming
See All in Programming
OCRを使ってゲームのアイテムをデータ化する
kishikawakatsumi
0
120
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
190
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
320
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
300
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3k
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
390
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
670
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.1k
デフォルト運用のCodeRabbit、1年で何が変わったか / How CodeRabbit Changed Our Code Review in 1 Year
bake0937
1
110
CSC307 Lecture 17
javiergs
PRO
0
270
[KCD Czech] eBPF Meets the GPU: Future of AI Infra Observability
doniacld
0
120
Featured
See All Featured
Marketing to machines
jonoalderson
1
5.3k
Site-Speed That Sticks
csswizardry
13
1.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
200
Facilitating Awesome Meetings
lara
57
6.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
199
74k
Scaling GitHub
holman
464
140k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
760
The Language of Interfaces
destraynor
162
26k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
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はいいものです