Slide 1

Slide 1 text

PNPDIJNFUBSV!USZ4XJGU5PLZP -FUT-FBSO"CPVU 5ZQF*OGFSFODFJO4XJGU

Slide 2

Slide 2 text

"CPVU.F w *FOKPZSFBEJOHQSPQPTBMTPO4XJGU&WPMVUJPOBOE CSPXTJOHUIF4XJGUP ffi DJBMGPSVNBTBIPCCZ w *DPPSHBOJ[FTUVEZHSPVQTGPDVTFEPOUIF4XJGU DPNQJMFS w *BNSFDPHOJ[FEBTBDPNNJUUFSUPUIF4XJGU DPNQJMFS PNPDIJNFUBSV

Slide 3

Slide 3 text

5ZQF*OGFSFODF w 0OFPG4XJGUTHSFBUFTUBQQFBMT w 5IFDPFYJTUFODFPGTBGFUZBOEFBTFPGXSJUJOH w 6OEFSTUBOEJOHUIF.JOETFUPGUIF$PNQJMFS w *IBWFMPPLFEJOUPJUBOEJNQMFNFOUFEJUJOUIFQBTU https://github.com/omochi/SwiftTypeInferenceHandsOn w *IBWFDSFBUFEBTVJUBCMFFYQMBOBUJPOGPSCFHJOOFST

Slide 4

Slide 4 text

0VUMJOF w #BTJD#JEJSFDUJPOBM*OGFSFODF"MHPSJUIN w &YUFOTJPOTGPS4XJGU w *NQMJDJU5ZQF$POWFSTJPO w 0WFSMPBEJOH w )PXUP*OWFTUJHBUF6TJOHUIF$PNQJMFS

Slide 5

Slide 5 text

#JEJSFDUJPOBM5ZQF*OGFSFODF

Slide 6

Slide 6 text

&YBNQMFPG'PSXBSE*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 7

Slide 7 text

&YBNQMFPG'PSXBSE*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 8

Slide 8 text

&YBNQMFPG'PSXBSE*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 9

Slide 9 text

&YBNQMFPG'PSXBSE*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 10

Slide 10 text

&YBNQMFPG'PSXBSE*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 11

Slide 11 text

&YBNQMFPG3FWFSTF*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a: Int = id(.init()) }

Slide 12

Slide 12 text

&YBNQMFPG3FWFSTF*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a: Int = id(.init()) }

Slide 13

Slide 13 text

&YBNQMFPG3FWFSTF*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a: Int = id(.init()) }

Slide 14

Slide 14 text

&YBNQMFPG3FWFSTF*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a: Int = id(.init()) }

Slide 15

Slide 15 text

&YBNQMFPG3FWFSTF*OGFSFODF func id(_ x: X) -> X func main(i: Int) { let a: Int = id(.init()) }

Slide 16

Slide 16 text

#BTJD5ZQF*OGFSFODF

Slide 17

Slide 17 text

"MHPSJUIN8 w "WPJEJOHGPSNBMEJTDVTTJPOT *XJMMCSJF fl ZFYQMBJOUIF fl PXPG PQFSBUJPOT w ⚠1MFBTFGPSHFUBCPVUlJNQMJDJUUZQFJOGFSFODFzGPSBNPNFOU

Slide 18

Slide 18 text

5ZQF*OGFSFODF1SPDFTT0VUMJOF w 1BSTJOH$PEFJOUPBO"45 "CTUSBDU4ZOUBY5SFF w #JOEJOH5ZQF7BSJBCMFTUPUIF"45 w (FOFSBUJOH$POTUSBJOUTGSPN"45 w 3FQFBUFEMZ1FSGPSNJOH6OJ fi DBUJPOBOE4JNQMJ fi DBUJPO

Slide 19

Slide 19 text

"45 "CTUSBDU4ZOUBY5SFF w "SFQSFTFOUBUJPOPGUIFDPEFJOBUSFFTUSVDUVSF w 5IFDPNQJMFS fi OETJUFBTZUPIBOEMF

Slide 20

Slide 20 text

&YBNQMFPG"45 func id(_ x: X) -> X func main(i: Int) { let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ

Slide 21

Slide 21 text

&YBNQMFPG"45 func id(_ x: X) -> X func main(i: Int) { let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ

Slide 22

Slide 22 text

&YBNQMFPG"45 func id(_ x: X) -> X func main(i: Int) { let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ

Slide 23

Slide 23 text

&YBNQMFPG"45 func id(_ x: X) -> X func main(i: Int) { let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ

Slide 24

Slide 24 text

&YBNQMFPG"45 func id(_ x: X) -> X func main(i: Int) { let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ

Slide 25

Slide 25 text

&YBNQMFPG"45 func id(_ x: X) -> X func main(i: Int) { let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ

Slide 26

Slide 26 text

#JOEJOH5ZQF7BSJBCMFT w 5ZQFWBSJBCMFTBSFWBSJBCMFTXIFSFUZQFTBSFBTTJHOFE w #JOHJOHUZQFWBSJBCMFTUPUIFQBSUTPGUIF"45XIFSFUIFUZQFJTOPU ZFULOPXO w 5ZQFJOGFSFODFJTUIFUBTLPGEFUFSNJOJOHUIFUZQFTGPSBMMUZQF WBSJBCMFT

Slide 27

Slide 27 text

&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int (X) -> X func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 28

Slide 28 text

&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int (X) -> X func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 29

Slide 29 text

&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int (X) -> X func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 30

Slide 30 text

&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int (X) -> X func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 31

Slide 31 text

&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int (X) -> X func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 32

Slide 32 text

&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int (X) -> X func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 33

Slide 33 text

(FOFSBUJOH$POTUSBJOUT w *OEJDBUJOHUIFSFMBUJPOTIJQCFUXFFOUZQFTBOEUZQFWBSJBCMFT w (FOFSBUJOHGSPN"45 w *OGFSFODFQSPHSFTTFTCZNBOJQVMBUJOHUIFTFUPGDPOTUSBJOUT

Slide 34

Slide 34 text

(FOFSBUJOH$POTUSBJOUTGSPN"TTJHONFOU4UBUFNFOU WBSEFDM init A B eq(A, B)

Slide 35

Slide 35 text

(FOFSBUJOH$POTUSBJOUTGSPN'VODUJPODBMMJOH DBMM DBMMFF BSHT R F A call(F, A, R)

Slide 36

Slide 36 text

&YBNQMFPG(FOFSBUJOH$POTUSBJOUT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2)

Slide 37

Slide 37 text

&YBNQMFPG(FOFSBUJOH$POTUSBJOUT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2)

Slide 38

Slide 38 text

&YBNQMFPG(FOFSBUJOH$POTUSBJOUT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2)

Slide 39

Slide 39 text

&YBNQMFPG(FOFSBUJOH$POTUSBJOUT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2)

Slide 40

Slide 40 text

*OGFSFODF w 3FQFBUFEMZBQQMZJOHVOJ fi DBUJPOBOETJNQMJ fi DBUJPOUPUIFTFUPG DPOTUSBJOUT w 5IFQSPDFTTJTDPNQMFUFPODFUIFUZQFTPGBMMUZQFWBSJBCMFTIBWF CFFOEFUFSNJOFE

Slide 41

Slide 41 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 42

Slide 42 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 43

Slide 43 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 44

Slide 44 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 45

Slide 45 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 46

Slide 46 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 47

Slide 47 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 48

Slide 48 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 49

Slide 49 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 50

Slide 50 text

6OJGJDBUJPO w 'JOEFRVBMDPOTUSBJOUTGPSUZQFWBSJBCMFTBOESFQMBDFBMMUIFJSPDDVSSFODFT eq($T1, Int) eq($T2, ($T1) -> $T1) eq($T3, ($T1) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> $T2) eq($T1, Int) eq($T2, (Int) -> Int) eq($T3, (Int) -> (Int) -> Int)

Slide 51

Slide 51 text

4JNQMJGJDBUJPOPGFRVBMDPOTUSBJOUT eq(A?, B?) eq(A, B) 0QUJPOBMT eq((A) -> B, (C) -> D) eq(B, D) eq(A, C) 'VODUJPOT eq((A, B), (C, D)) eq(B, D) eq(A, C) 5VQMFT

Slide 52

Slide 52 text

4JNQMJGJDBUJPOPGFRVBMDPOTUSBJOUT eq(A?, B?) eq(A, B) 0QUJPOBMT eq((A) -> B, (C) -> D) eq(B, D) eq(A, C) 'VODUJPOT eq((A, B), (C, D)) eq(B, D) eq(A, C) 5VQMFT

Slide 53

Slide 53 text

4JNQMJGJDBUJPOPGFRVBMDPOTUSBJOUT eq(A?, B?) eq(A, B) 0QUJPOBMT eq((A) -> B, (C) -> D) eq(B, D) eq(A, C) 'VODUJPOT eq((A, B), (C, D)) eq(B, D) eq(A, C) 5VQMFT

Slide 54

Slide 54 text

4JNQMJGJDBUJPOPGGVODUJPODBMMJOHDPOTUSBJOUT call((A) -> B, C, D) eq(B, D) eq(A, C) 1BSBNFUFST 3FUVSOWBMVF

Slide 55

Slide 55 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 56

Slide 56 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 57

Slide 57 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 58

Slide 58 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 59

Slide 59 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 60

Slide 60 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 61

Slide 61 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 62

Slide 62 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 63

Slide 63 text

5IFJOUFSQMBZCFUXFFOVOJGJDBUJPOBOETJNQMJGJDBUJPO call($T1, $T2, $T3) eq($T1, (Int) -> Bool) call((Int) -> Bool, $T2, $T3) eq($T1, (Int) -> Bool) eq(Int, $T2) eq($T1, (Int) -> Bool) eq(Bool, $T3)

Slide 64

Slide 64 text

&YBNQMFPG*OGFSFODF 1SPCMFN4UBUFNFOU func id(_ x: X) -> X func main(i: Int) { let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2)

Slide 65

Slide 65 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 66

Slide 66 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 67

Slide 67 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 68

Slide 68 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 69

Slide 69 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 70

Slide 70 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 71

Slide 71 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 72

Slide 72 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 73

Slide 73 text

&YBNQMFPG*OGFSFODF eq($T1, $T2) call(($T3) -> $T3, Int, $T2) eq($T1, $T2) eq($T3, Int) eq($T3, $T2) eq($T1, $T2) eq($T3, Int) eq(Int, $T2) eq($T1, Int) eq($T3, Int) eq(Int, $T2)

Slide 74

Slide 74 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 75

Slide 75 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 76

Slide 76 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 77

Slide 77 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 78

Slide 78 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 79

Slide 79 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 80

Slide 80 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 81

Slide 81 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 82

Slide 82 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 83

Slide 83 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 84

Slide 84 text

eq($T3, Int) 7FSJGJDBUJPOPG*OGFSFODF3FTVMUT eq($T1, Int) eq(Int, $T2) WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3 Int Int Int (Int) -> Int func id(_ x: X) -> X func main(i: Int) { let a = id(i) }

Slide 85

Slide 85 text

$PNQMFUJPOPG5ZQF*OGFSFODF w "MMUZQFWBSJBCMFTUZQFTBSFEFUFSNJOFEˠ5ZQFJOGFSFODFTVDDFTTGVM w $POUSBEJDUJPOPDDVSTˠ5IFDPEFJTJODPSSFDU w 6OLOPXOUZQFWBSJBCMFTSFNBJO CVUJOGFSFODFDBOOPUQSPDFFEˠ5IF DPEFTUZQFJTBNCJHVPVT

Slide 86

Slide 86 text

#JEJSFDUJPOBMJUZ func readInt() -> Int func read() -> X func main() { let a = readInt() let b: Int = read() } eq($T1, $T2) eq(Int, $T3) call(() -> $T4, $T4, $T3) call(() -> Int, (), $T2)

Slide 87

Slide 87 text

#JEJSFDUJPOBMJUZ func readInt() -> Int func read() -> X func main() { let a = readInt() let b: Int = read() } eq($T1, $T2) eq(Int, $T3) call(() -> $T4, $T4, $T3) call(() -> Int, (), $T2)

Slide 88

Slide 88 text

#JEJSFDUJPOBMJUZ func readInt() -> Int func read() -> X func main() { let a = readInt() let b: Int = read() } eq($T1, $T2) eq(Int, $T3) call(() -> $T4, $T4, $T3) call(() -> Int, (), $T2)

Slide 89

Slide 89 text

#JEJSFDUJPOBMJUZ func readInt() -> Int func read() -> X func main() { let a = readInt() let b: Int = read() } eq($T1, $T2) eq(Int, $T3) call(() -> $T4, $T4, $T3) call(() -> Int, (), $T2)

Slide 90

Slide 90 text

&YUFOTJPOTGPS4XJGU

Slide 91

Slide 91 text

*OUSPEVDUJPOPGDPOWFSTJPOSFMBUJPOTBOENPEJGJDBUJPOPGBTTJHONFOU TUBUFNFOUDPOTUSBJOUT w 4XJGUIBTJNQMJDJUUZQFDPOWFSTJPOT func main(i: Int) { let a: Int? = i } eq(Int?, Int) conv(Int, Int?) ❌ ✅

Slide 92

Slide 92 text

4JNQMJGJDBUJPOPG$POWFSTJPO$POTUSBJOUT conv((A) -> B, (C) -> D) conv(B, D) conv(C, A) 1BSBNFUFST 🙃DPOUSBWBSJBODF 3FUVSOWBMVFT 🙂DPWBSJBODF

Slide 93

Slide 93 text

.PEJGJDBUJPOPGTJNQMJGJDBUJPOPGGVODUJPODBMMJOHDPOTUSBJOUT call((A) -> B, C, D) eq(B, D) conv(C, A) 1BSBNFUFST 🙃 3FUVSOWBMVFT

Slide 94

Slide 94 text

1SPCMFNPG$POWFSTJPO$POTUSBJOUT func main(i: Int) { let a = i } conv(Int, $T1) 🤷 eq($T1, Int) eq($T1, Int?) eq($T1, Any) 0, 0, 0,

Slide 95

Slide 95 text

(FOFSBUJPOBOE"UUFNQUPG6OJGJDBUJPO$BOEJEBUFT conv(Int, $T1) eq($T1, Int) QPTTJCJMF func main(i: Int) { let a = i } func main(i: Int) { let a: Int = i }

Slide 96

Slide 96 text

&YBNQMFPG$BOEJEBUF4FBSDI conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1, Int) eq($T1, Int?) eq($T2, Int?)

Slide 97

Slide 97 text

&YBNQMFPG4FBSDI1MBO 4UBSU 5*OU 5*OU 5*OU 5*OU

Slide 98

Slide 98 text

4UBSU 5*OU 5*OU 5*OU 5*OU conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, $T2) eq(Int, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, Int) eq(Int, $T2) eq($T1, Int)

Slide 99

Slide 99 text

4UBSU 5*OU 5*OU 5*OU 5*OU conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, $T2) eq(Int, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, Int) eq(Int, $T2) eq($T1, Int)

Slide 100

Slide 100 text

4UBSU 5*OU 5*OU 5*OU 5*OU conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, $T2) eq(Int, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, Int) eq(Int, $T2) eq($T1, Int)

Slide 101

Slide 101 text

4UBSU 5*OU 5*OU 5*OU 5*OU conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, $T2) eq(Int, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, Int) eq(Int, $T2) eq($T1, Int)

Slide 102

Slide 102 text

4UBSU 5*OU 5*OU 5*OU 5*OU conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, $T2) eq(Int, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, Int) eq(Int, $T2) eq($T1, Int)

Slide 103

Slide 103 text

4UBSU 5*OU 5*OU 5*OU 5*OU conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, $T2) eq(Int, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, Int) eq(Int, $T2) eq($T1, Int)

Slide 104

Slide 104 text

4UBSU 5*OU 5*OU 5*OU 5*OU conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, $T2) eq(Int, $T2) eq($T1, Int) conv(Int, Int?) conv(Int?, Int) eq(Int, $T2) eq($T1, Int)

Slide 105

Slide 105 text

4UBSU 5*OU 5*OU 5*OU 5*OU ❌ eq($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1, Int?) conv(Int?, $T2) eq(Int?, $T2) conv(Int, Int?) eq($T1, Int?) conv(Int?, Int?) eq(Int?, $T2) conv(Int, Int?)

Slide 106

Slide 106 text

4UBSU 5*OU 5*OU 5*OU 5*OU ❌ eq($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1, Int?) conv(Int?, $T2) eq(Int?, $T2) conv(Int, Int?) eq($T1, Int?) conv(Int?, Int?) eq(Int?, $T2) conv(Int, Int?)

Slide 107

Slide 107 text

4UBSU 5*OU 5*OU 5*OU 5*OU ❌ eq($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1, Int?) conv(Int?, $T2) eq(Int?, $T2) conv(Int, Int?) eq($T1, Int?) conv(Int?, Int?) eq(Int?, $T2) conv(Int, Int?)

Slide 108

Slide 108 text

4UBSU 5*OU 5*OU 5*OU 5*OU ❌ eq($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1, Int?) conv(Int?, $T2) eq(Int?, $T2) conv(Int, Int?) eq($T1, Int?) conv(Int?, Int?) eq(Int?, $T2) conv(Int, Int?)

Slide 109

Slide 109 text

4UBSU 5*OU 5*OU 5*OU 5*OU ❌ eq($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1, Int?) conv(Int?, $T2) eq(Int?, $T2) conv(Int, Int?) eq($T1, Int?) conv(Int?, Int?) eq(Int?, $T2) conv(Int, Int?)

Slide 110

Slide 110 text

4UBSU 5*OU 5*OU 5*OU 5*OU ❌ eq($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1, Int?) conv(Int?, $T2) eq(Int?, $T2) conv(Int, Int?) eq($T1, Int?) conv(Int?, Int?) eq(Int?, $T2) conv(Int, Int?)

Slide 111

Slide 111 text

4UBSU 5*OU 5*OU 5*OU 5*OU ❌ eq($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1, Int?) conv(Int?, $T2) eq(Int?, $T2) conv(Int, Int?) eq($T1, Int?) conv(Int?, Int?) eq(Int?, $T2) conv(Int, Int?)

Slide 112

Slide 112 text

)BOEMJOH0WFSMPBET func foo() -> Bool func foo() -> Int func foo() -> String func main(i: Int) { let a: Int = foo() } call($T1, (), Int) eq($T1, () -> Bool) eq($T1, () -> Int) eq($T1, () -> String) QPTTJCJMFY

Slide 113

Slide 113 text

)BOEMJOH0WFSMPBET func foo() -> Bool func foo() -> Int func foo() -> String func main(i: Int) { let a: Int = foo() } call($T1, (), Int) eq($T1, () -> Bool) eq($T1, () -> Int) eq($T1, () -> String) QPTTJCJMFY

Slide 114

Slide 114 text

)BOEMJOH0WFSMPBET func foo() -> Bool func foo() -> Int func foo() -> String func main(i: Int) { let a: Int = foo() } call($T1, (), Int) eq($T1, () -> Bool) eq($T1, () -> Int) eq($T1, () -> String) QPTTJCJMFY

Slide 115

Slide 115 text

)BOEMJOH0WFSMPBET func foo() -> Bool func foo() -> Int func foo() -> String func main(i: Int) { let a: Int = foo() } call($T1, (), Int) eq($T1, () -> Bool) eq($T1, () -> Int) eq($T1, () -> String) QPTTJCJMFY

Slide 116

Slide 116 text

"UUFNQUTBOE$PNQVUBUJPOBM$PNQMFYJUZ w 5IFNFDIBOJTNPGlBUUFNQUDBOEJEBUFTzIBTUIFQPUFOUJBMUPFYQMPEF JODPNQVUBUJPOBMDPNQMFYJUZ 💣 code.swift:11:9: error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

Slide 117

Slide 117 text

-FBSOJOHGSPNUIF$PNQJMFS

Slide 118

Slide 118 text

.BLJOHUIF$PNQJMFS0VUQVUUIF0QFSBUJPOTPG5ZQF*OGFSFODF $ swiftc -Xfrontend -debug-constraints code.swift func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 0VUQVUFYDFFEJOHMJOFT🤯

Slide 119

Slide 119 text

*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 120

Slide 120 text

*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 121

Slide 121 text

*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 122

Slide 122 text

*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 123

Slide 123 text

*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 124

Slide 124 text

*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 125

Slide 125 text

*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 126

Slide 126 text

*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 127

Slide 127 text

$ swiftc -Xfrontend -debug-constraints code.swift ---Constraint solving at [code.swift:1:21 - line:1:21]--- (…) ---Constraint solving at [code.swift:2:22 - line:2:22]--- (…) ---Constraint solving at [code.swift:5:9 - line:5:22]--- (…) func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 0VUQVUGPSUIF&OUJSF$PEF

Slide 128

Slide 128 text

$ swiftc -Xfrontend -debug-constraints code.swift ---Constraint solving at [code.swift:1:21 - line:1:21]--- (…) ---Constraint solving at [code.swift:2:22 - line:2:22]--- (…) ---Constraint solving at [code.swift:5:9 - line:5:22]--- (…) func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 0VUQVUGPSUIF&OUJSF$PEF

Slide 129

Slide 129 text

$ swiftc -Xfrontend -debug-constraints code.swift ---Constraint solving at [code.swift:1:21 - line:1:21]--- (…) ---Constraint solving at [code.swift:2:22 - line:2:22]--- (…) ---Constraint solving at [code.swift:5:9 - line:5:22]--- (…) func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 0VUQVUGPSUIF&OUJSF$PEF

Slide 130

Slide 130 text

$ swiftc -Xfrontend -debug-constraints code.swift ---Constraint solving at [code.swift:1:21 - line:1:21]--- (…) ---Constraint solving at [code.swift:2:22 - line:2:22]--- (…) ---Constraint solving at [code.swift:5:9 - line:5:22]--- (…) func foo() -> Int { 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 0VUQVUGPSUIF&OUJSF$PEF

Slide 131

Slide 131 text

0VUQVUGPS*OEJWJEVBM*OGFSFODFT ---Constraint solving at [code.swift:5:9 - line:5:22]--- ---Initial constraints for the given expression--- (Initial State of the AST) (Initial State of the Constraints) (Inference Process) ---Solution--- (Solution) ---Type-checked expression--- (Typed AST)

Slide 132

Slide 132 text

*OJUJBM4UBUFPGUIF"45 ---Initial constraints for the given expression— (call_expr type='$T1' location=code.swift:5:18 range=[code.swift:5:18 - line:5:22] isolationCrossing=none (overloaded_decl_ref_expr type='$T0' location=code.swift:5:18 range=[code.swift:5:18 - line:5:18] name=foo number_of_decls=2 function_ref=single decls=[ code.(file).foo()@code.swift:1:6, code.(file).foo()@code.swift:2:6]) (argument_list)) let a: Int = foo() DBMM EFDMSFGJE $T0 $T1

Slide 133

Slide 133 text

*OJUJBM4UBUFPGUIF"45 ---Initial constraints for the given expression— (call_expr type='$T1' location=code.swift:5:18 range=[code.swift:5:18 - line:5:22] isolationCrossing=none (overloaded_decl_ref_expr type='$T0' location=code.swift:5:18 range=[code.swift:5:18 - line:5:18] name=foo number_of_decls=2 function_ref=single decls=[ code.(file).foo()@code.swift:1:6, code.(file).foo()@code.swift:2:6]) (argument_list)) let a: Int = foo() DBMM EFDMSFGJE $T0 $T1

Slide 134

Slide 134 text

*OJUJBM4UBUFPGUIF"45 ---Initial constraints for the given expression— (call_expr type='$T1' location=code.swift:5:18 range=[code.swift:5:18 - line:5:22] isolationCrossing=none (overloaded_decl_ref_expr type='$T0' location=code.swift:5:18 range=[code.swift:5:18 - line:5:18] name=foo number_of_decls=2 function_ref=single decls=[ code.(file).foo()@code.swift:1:6, code.(file).foo()@code.swift:2:6]) (argument_list)) let a: Int = foo() DBMM EFDMSFGJE $T0 $T1

Slide 135

Slide 135 text

*OJUJBM4UBUFPGUIF"45 ---Initial constraints for the given expression— (call_expr type='$T1' location=code.swift:5:18 range=[code.swift:5:18 - line:5:22] isolationCrossing=none (overloaded_decl_ref_expr type='$T0' location=code.swift:5:18 range=[code.swift:5:18 - line:5:18] name=foo number_of_decls=2 function_ref=single decls=[ code.(file).foo()@code.swift:1:6, code.(file).foo()@code.swift:2:6]) (argument_list)) let a: Int = foo() DBMM EFDMSFGJE $T0 $T1

Slide 136

Slide 136 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 137

Slide 137 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 138

Slide 138 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 139

Slide 139 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 140

Slide 140 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 141

Slide 141 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 142

Slide 142 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 143

Slide 143 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 144

Slide 144 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 145

Slide 145 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 146

Slide 146 text

*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: ] @ locator@0x11b81ac00 [[email protected]:5:18] $T1 [allows bindings to: noescape] [attributes: delayed] [with possible bindings: (subtypes of) Int] @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Inactive Constraints: disjunction @ locator@0x11b81ac00 [[email protected]:5:18]: > $T0 bound to decl code.(file).foo()@code.swift:1:6 : () -> Int > $T0 bound to decl code.(file).foo()@code.swift:2:6 : () -> Bool () -> $T1 applicable fn $T0 @ locator@0x11b81ae30 [[email protected]:5:18 → apply function] $T1 conv Int @ locator@0x11b81aec8 [[email protected]:5:18 → contextual type]

Slide 147

Slide 147 text

*OGFSFODF1SPDFTT (attempting type variable binding $T1 := Int ... (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:1:6 : () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] ... (found solution: ) ) (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:2:6 : () -> Bool @ locator@0x11b81ac00 [[email protected]:5:18] ... (outcome: error) ) ) 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 148

Slide 148 text

*OGFSFODF1SPDFTT (attempting type variable binding $T1 := Int ... (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:1:6 : () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] ... (found solution: ) ) (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:2:6 : () -> Bool @ locator@0x11b81ac00 [[email protected]:5:18] ... (outcome: error) ) ) 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 149

Slide 149 text

*OGFSFODF1SPDFTT (attempting type variable binding $T1 := Int ... (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:1:6 : () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] ... (found solution: ) ) (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:2:6 : () -> Bool @ locator@0x11b81ac00 [[email protected]:5:18] ... (outcome: error) ) ) 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 150

Slide 150 text

*OGFSFODF1SPDFTT (attempting type variable binding $T1 := Int ... (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:1:6 : () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] ... (found solution: ) ) (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:2:6 : () -> Bool @ locator@0x11b81ac00 [[email protected]:5:18] ... (outcome: error) ) ) 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 151

Slide 151 text

*OGFSFODF1SPDFTT (attempting type variable binding $T1 := Int ... (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:1:6 : () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] ... (found solution: ) ) (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:2:6 : () -> Bool @ locator@0x11b81ac00 [[email protected]:5:18] ... (outcome: error) ) ) 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 152

Slide 152 text

*OGFSFODF1SPDFTT (attempting type variable binding $T1 := Int ... (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:1:6 : () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] ... (found solution: ) ) (attempting disjunction choice $T0 bound to decl code. (file).foo()@code.swift:2:6 : () -> Bool @ locator@0x11b81ac00 [[email protected]:5:18] ... (outcome: error) ) ) 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF

Slide 153

Slide 153 text

4PMVUJPO ---Solution--- Fixed score: Type variables: $T0 as () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] $T1 as Int @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Overload choices: locator@0x11b81ac00 [[email protected]:5:18] with code. (file).foo()@code.swift:1:6 as foo: () -> Int Trailing closure matching: locator@0x11b81afe8 [[email protected]:5:18 → apply argument]: forward

Slide 154

Slide 154 text

4PMVUJPO ---Solution--- Fixed score: Type variables: $T0 as () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] $T1 as Int @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Overload choices: locator@0x11b81ac00 [[email protected]:5:18] with code. (file).foo()@code.swift:1:6 as foo: () -> Int Trailing closure matching: locator@0x11b81afe8 [[email protected]:5:18 → apply argument]: forward

Slide 155

Slide 155 text

4PMVUJPO ---Solution--- Fixed score: Type variables: $T0 as () -> Int @ locator@0x11b81ac00 [[email protected]:5:18] $T1 as Int @ locator@0x11b81adb0 [[email protected]:5:18 → function result] $T2 as Int @ locator@0x11b81aef0 [[email protected]:5:18 → contextual type → pattern match → pattern match → named pattern decl] Overload choices: locator@0x11b81ac00 [[email protected]:5:18] with code. (file).foo()@code.swift:1:6 as foo: () -> Int Trailing closure matching: locator@0x11b81afe8 [[email protected]:5:18 → apply argument]: forward

Slide 156

Slide 156 text

5ZQFE"45 ---Type-checked expression--- (call_expr type=‘Int' location=code.swift:5:18 range=[code.swift:5:18 - line:5:22] isolationCrossing=none (declref_expr type='() -> Int’ location=code.swift:5:18 range=[code.swift:5:18 - line:5:18] decl=code.(file).foo()@code.swift:1:6 function_ref=single) (argument_list)) let a: Int = foo() DBMM EFDMSFGJE () -> Int Int

Slide 157

Slide 157 text

5ZQFE"45 ---Type-checked expression--- (call_expr type=‘Int' location=code.swift:5:18 range=[code.swift:5:18 - line:5:22] isolationCrossing=none (declref_expr type='() -> Int’ location=code.swift:5:18 range=[code.swift:5:18 - line:5:18] decl=code.(file).foo()@code.swift:1:6 function_ref=single) (argument_list)) let a: Int = foo() DBMM EFDMSFGJE () -> Int Int

Slide 158

Slide 158 text

5ZQFE"45 ---Type-checked expression--- (call_expr type=‘Int' location=code.swift:5:18 range=[code.swift:5:18 - line:5:22] isolationCrossing=none (declref_expr type='() -> Int’ location=code.swift:5:18 range=[code.swift:5:18 - line:5:18] decl=code.(file).foo()@code.swift:1:6 function_ref=single) (argument_list)) let a: Int = foo() DBMM EFDMSFGJE () -> Int Int

Slide 159

Slide 159 text

5ZQFE"45 ---Type-checked expression--- (call_expr type=‘Int' location=code.swift:5:18 range=[code.swift:5:18 - line:5:22] isolationCrossing=none (declref_expr type='() -> Int’ location=code.swift:5:18 range=[code.swift:5:18 - line:5:18] decl=code.(file).foo()@code.swift:1:6 function_ref=single) (argument_list)) let a: Int = foo() DBMM EFDMSFGJE () -> Int Int

Slide 160

Slide 160 text

3FDBQ w 5IFCBTJDTPGUZQFJOGFSFODFBSFVOJ fi DBUJPOBOETJNQMJ fi DBUJPOPG DPOTUSBJOUT w 4XJGUFYUFOETJUCZBEEJOHTFBSDIUPUIFQSPDFTT w 8FDBOVOEFSTUBOEJUTPQFSBUJPOTCZMPPLJOHBUUIFDPNQJMFSTPVUQVU

Slide 161

Slide 161 text

/FYU4UFQT w JNQMFNFOUJOHUZQFJOGFSFODF https://stackoverflow.com/questions/415532/implementing-type- inference w 5ZQF$IFDLFS%FTJHOBOE*NQMFNFOUBUJPO https://github.com/apple/swift/blob/main/docs/TypeChecker.md w 4XJGU5ZQF*OGFSFODF)BOET0O https://github.com/omochi/SwiftTypeInferenceHandsOn w $PNQJMJOH4XJGUHFOFSJDT 1BSU* https://forums.swift.org/t/compiling-swift-generics-part-i/60898