Slide 1

Slide 1 text

4XJGUͷNeverͱ
 ϘτϜܕ 2019/04/14 ୈ7ճΧϯϑΝϨϯεಈըؑ৆ձ Mobile Act OSAKA #9 (ิܽ) try! Swift Tokyo 2019 (Backup)

Slide 2

Slide 2 text

About Me w ͻΖΜʢҰٶߒڭʣ w 5XJUUFS(JU)VC
 2JJUB4MJEF4IBSF 4QFBLFS%FDL
 ˠIJSPOZUJD w ಙౡࡏॅ

Slide 3

Slide 3 text

ݱ࣌఺ͷ4XJGUͰ͸
 Never͸ϘτϜܕͰ͸͋Γ·ͤΜ

Slide 4

Slide 4 text

Agenda w NeverܕͬͯԿ͚ͩͬʁ w ϘτϜܕͬͯԿΑʁ w ΋͠Never͕ϘτϜܕͩͬͨΒʁ

Slide 5

Slide 5 text

Never Type

Slide 6

Slide 6 text

func foo() -> Type foo͸TypeͷΠϯελϯεΛฦ͢

Slide 7

Slide 7 text

func foo() -> Int foo͸IntͷΠϯελϯεΛฦ͢ -3, 0, 10, 42, …

Slide 8

Slide 8 text

func foo() -> Void foo͸஋Λฦ͞ͳ͍

Slide 9

Slide 9 text

func foo() -> Type foo͸TypeͷΠϯελϯεΛฦ͢

Slide 10

Slide 10 text

func foo() -> Void foo͸VoidͷΠϯελϯεΛฦ͢

Slide 11

Slide 11 text

Void Type w ۭͷλϓϧܕͷΤΠϦΞε w ۭͷλϓϧͷܕʜ() w ͦͷ།Ұͷ஋ʜ()

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

func foo() -> Never foo͸ฦͬͯ͜ͳ͍

Slide 14

Slide 14 text

func foo() -> Type foo͸TypeͷΠϯελϯεΛฦ͢

Slide 15

Slide 15 text

func foo() -> Never foo͸NeverͷΠϯελϯεΛฦ͢

Slide 16

Slide 16 text

Never Type w DBTFΛ࣋ͨͳ͍FOVN FOVN/FWFS\^ w ΠϯελϯεΛ࣋ͨͳ͍ w ؔ਺͸/FWFSͷΠϯελϯεΛฦͤͳ͍ w ແݶϧʔϓɺΫϥογϡɺϓϩάϥϜऴྃɺྫ֎

Slide 17

Slide 17 text

Bottom Type

Slide 18

Slide 18 text

Subtype class Animal { ... } class Dog: Animal { ... } Animal Dog

Slide 19

Slide 19 text

Subtype Dog͸AnimalͷαϒλΠϓ DogͷΠϯελϯεΛ
 Animalͱͯ͠ѻ͑Δ Animal Dog

Slide 20

Slide 20 text

Animal Dog Cat Animal Dog Cat

Slide 21

Slide 21 text

Animal Dog Cat Plant Flower Star … ?

Slide 22

Slide 22 text

Animal Dog Cat Plant Flower Star … Any Top Type

Slide 23

Slide 23 text

Animal Dog Cat Plant Flower Star … Any Top Type ? Bottom Type

Slide 24

Slide 24 text

Bottom Type w ϘτϜܕ͸͢΂ͯͷܕͷαϒλΠϓ w ϘτϜܕͷΠϯελϯεΛͲͷܕͱͯ͠΋ѻ͑Δ

Slide 25

Slide 25 text

4501ࡀະຬҿञ ະ੒೥ऀͷҿञ͸๏཯Ͱې͡ΒΕ͍ͯ·͢

Slide 26

Slide 26 text

Bottom Type w ϘτϜܕ͸͢΂ͯͷܕͷαϒλΠϓ w ϘτϜܕͷΠϯελϯεΛͲͷܕͱͯ͠΋ѻ͑Δ w ϘτϜܕ͸ΠϯελϯεΛ࣋ͨͳ͍ܕ

Slide 27

Slide 27 text

Imagine:
 Never as a Bottom Type

Slide 28

Slide 28 text

Case 1 class FooViewController: UIViewController { var label: UILabel! ... }

Slide 29

Slide 29 text

Case 1 class FooViewController: UIViewController { lazy var label: UILabel = fatalError() ... }

Slide 30

Slide 30 text

Case 2 let data: [String: String] = ... guard let name = data["name"] else { throw ParseError.missing("name") } speaker.name = name guard let icon = data["icon"] else { throw ParseError.missing("icon") } speaker.icon = icon

Slide 31

Slide 31 text

Case 2 let data: [String: String] = ... speaker.name = data["name"] ?? try missing("name") speaker.icon = data["icon"] ?? try missing("icon") func missing(_ key: String) throws -> Never { throw ParseError.missing(key) }

Slide 32

Slide 32 text

Case 2+ let data: [String: String] = ... speaker.name = data["name"] ?? throw ParseError.missing("name") speaker.icon = data["icon"] ?? throw ParseError.missing("icon") ͞Βʹthrow͕NeverΛฦࣜ͢ͳΒ

Slide 33

Slide 33 text

Case 3 enum Result { case success(Value) case failure(Error) } func foo() -> Result { ... } foo͸ࣦഊ͠ͳ͍

Slide 34

Slide 34 text

Case 3 • 4XJGUͰ࣮ݱ͞Ε·ͨ͠ 4& https://github.com/apple/swift-evolution/blob/master/proposals/0215-conform-never-to- hashable-and-equatable.md

Slide 35

Slide 35 text

Case 3 w 4&ͷٞ࿦ʹͯ https://forums.swift.org/t/se-0215-conform-never-to-equatable-and-hashable/13586

Slide 36

Slide 36 text

Protocol • ΠϯελϯεϓϩύςΟ (var) • Πϯελϯεϝιου (func) • ܕϓϩύςΟ (static var) • ܕϝιου (static func) • ΠχγϟϥΠβ (init) Πϯελϯεʹର͢Δ
 ੍໿Ͱ͸ͳ͍

Slide 37

Slide 37 text

Recap

Slide 38

Slide 38 text

Recap w NeverܕͬͯԿ͚ͩͬʁ w ϘτϜܕͬͯԿΑʁ w ΋͠Never͕ϘτϜܕͩͬͨΒʁ
 ˠΠϯελϯεΛ࣋ͨͳ͍ܕ ˠ͢΂ͯͷܕͷαϒλΠϓʹͳΔܕ ˠ͍Ζ͍ΖεοΩϦ͢Δ͜ͱ͕͋Δ

Slide 39

Slide 39 text

Never as a Bottom Type • SE-0215 - Conform Never to Equatable and Hashable
 https://forums.swift.org/t/se-0215-conform-never-to-equatable-and-hashable/13586 • SE-0102: Remove @noreturn attribute and introduce an empty Never type
 https://github.com/apple/swift-evolution/blob/master/proposals/0102-noreturn-bottom- type.md • [Pitch] Never as a bottom type
 https://forums.swift.org/t/pitch-never-as-a-bottom-type/5920

Slide 40

Slide 40 text

One more thing: Kotlin 4XJGU Void Never ,PUMJO Unit Nothing Nothing͸ϘτϜܕ

Slide 41

Slide 41 text

Case 2 (Kotlin) val data: Map = ... speaker.name = data["name"] ?: throw MissingException("name") speaker.icon = data["icon"] ?: throw MissingException("icon") throw͸NothingΛฦࣜ͢

Slide 42

Slide 42 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠