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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
homuler
May 30, 2016
Programming
110
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
83
Style Transfer Overview in 5 minutes
homuler
0
100
Other Decks in Programming
See All in Programming
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
200
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.6k
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
140
自作OSでスライド発表する
uyuki234
0
2.8k
どこまでゆるくて許されるのか
tk3fftk
0
290
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
770
The NotImplementedError Problem in Ruby
koic
1
1k
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.1k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
800
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
Inside Stream API
skrb
1
820
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
400
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
150
Game over? The fight for quality and originality in the time of robots
wayneb77
1
210
The Language of Interfaces
destraynor
162
27k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
440
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
sira's awesome portfolio website redesign presentation
elsirapls
0
290
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.6k
Building an army of robots
kneath
306
46k
A Tale of Four Properties
chriscoyier
163
24k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
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はいいものです