Share
Embed
Swiftの型推論を学ぼう | Let's Learn About Type Inference in Swift
try! Swift Tokyo 2024 で発表しました。
スクリプトはこちら
https://speakerdeck.com/omochi/sukuriputo-swiftnoxing-tui-lun-woxue-bou
omochimetaru
March 23, 2024
Transcript
161 slides
-
"CPVU.F w *FOKPZSFBEJOHQSPQPTBMTPO4XJGU&WPMVUJPOBOE CSPXTJOHUIF4XJGUP ffi DJBMGPSVNBTBIPCCZ w *DPPSHBOJ[FTUVEZHSPVQTGPDVTFEPOUIF4XJGU DPNQJMFS w
*BNSFDPHOJ[FEBTBDPNNJUUFSUPUIF4XJGU DPNQJMFS PNPDIJNFUBSV -
0VUMJOF w #BTJD#JEJSFDUJPOBM*OGFSFODF"MHPSJUIN w &YUFOTJPOTGPS4XJGU w *NQMJDJU5ZQF$POWFSTJPO w 0WFSMPBEJOH w
)PXUP*OWFTUJHBUF6TJOHUIF$PNQJMFS -
&YBNQMFPG'PSXBSE*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } -
&YBNQMFPG'PSXBSE*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } -
&YBNQMFPG'PSXBSE*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } -
&YBNQMFPG'PSXBSE*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } -
&YBNQMFPG'PSXBSE*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } -
&YBNQMFPG3FWFSTF*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a: Int = id(.init()) } -
&YBNQMFPG3FWFSTF*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a: Int = id(.init()) } -
&YBNQMFPG3FWFSTF*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a: Int = id(.init()) } -
&YBNQMFPG3FWFSTF*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a: Int = id(.init()) } -
&YBNQMFPG3FWFSTF*OGFSFODF func id<X>(_ x: X) -> X func main(i: Int)
{ let a: Int = id(.init()) } -
"MHPSJUIN8 w "WPJEJOHGPSNBMEJTDVTTJPOT *XJMMCSJF fl ZFYQMBJOUIF fl PXPG PQFSBUJPOT w
⚠1MFBTFGPSHFUBCPVUlJNQMJDJUUZQFJOGFSFODFzGPSBNPNFOU -
5ZQF*OGFSFODF1SPDFTT0VUMJOF w 1BSTJOH$PEFJOUPBO"45 "CTUSBDU4ZOUBY5SFF w #JOEJOH5ZQF7BSJBCMFTUPUIF"45 w (FOFSBUJOH$POTUSBJOUTGSPN"45 w
3FQFBUFEMZ1FSGPSNJOH6OJ fi DBUJPOBOE4JNQMJ fi DBUJPO -
&YBNQMFPG"45 func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ -
&YBNQMFPG"45 func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ -
&YBNQMFPG"45 func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ -
&YBNQMFPG"45 func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ -
&YBNQMFPG"45 func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ -
&YBNQMFPG"45 func id<X>(_ x: X) -> X func main(i: Int)
{ let a = id(i) } WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ -
&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int <X> (X) -> X func id<X>(_ x: X) -> X func main(i: Int) { let a = id(i) } -
&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int <X> (X) -> X func id<X>(_ x: X) -> X func main(i: Int) { let a = id(i) } -
&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int <X> (X) -> X func id<X>(_ x: X) -> X func main(i: Int) { let a = id(i) } -
&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int <X> (X) -> X func id<X>(_ x: X) -> X func main(i: Int) { let a = id(i) } -
&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int <X> (X) -> X func id<X>(_ x: X) -> X func main(i: Int) { let a = id(i) } -
&YBNQMFPG#JOEJOH5ZQF7BSJBCMFT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int <X> (X) -> X func id<X>(_ x: X) -> X func main(i: Int) { let a = id(i) } -
&YBNQMFPG(FOFSBUJOH$POTUSBJOUT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2) -
&YBNQMFPG(FOFSBUJOH$POTUSBJOUT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2) -
&YBNQMFPG(FOFSBUJOH$POTUSBJOUT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2) -
&YBNQMFPG(FOFSBUJOH$POTUSBJOUT WBSEFDMB DBMM EFDMSFGJE EFDMSFGJ $T1 $T2 ($T3) -> $T3
Int eq($T1, $T2) call(($T3) -> $T3, Int, $T2) -
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) -
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) -
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) -
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) -
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) -
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) -
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) -
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) -
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) -
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) -
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 -
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 -
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 -
4JNQMJGJDBUJPOPGGVODUJPODBMMJOHDPOTUSBJOUT call((A) -> B, C, D) eq(B, D) eq(A, C)
1BSBNFUFST 3FUVSOWBMVF -
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) -
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) -
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) -
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) -
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) -
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) -
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) -
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) -
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) -
&YBNQMFPG*OGFSFODF 1SPCMFN4UBUFNFOU func id<X>(_ 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) -
&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) -
&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) -
&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) -
&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) -
&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) -
&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) -
&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) -
&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) -
&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) -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
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) -> X func main(i: Int) { let a = id(i) } -
#JEJSFDUJPOBMJUZ func readInt() -> Int func read<X>() -> X func
main() { let a = readInt() let b: Int = read() } eq($T1, $T2) eq(Int, $T3) call(() -> $T4, $T4, $T3) call(() -> Int, (), $T2) -
#JEJSFDUJPOBMJUZ func readInt() -> Int func read<X>() -> X func
main() { let a = readInt() let b: Int = read() } eq($T1, $T2) eq(Int, $T3) call(() -> $T4, $T4, $T3) call(() -> Int, (), $T2) -
#JEJSFDUJPOBMJUZ func readInt() -> Int func read<X>() -> X func
main() { let a = readInt() let b: Int = read() } eq($T1, $T2) eq(Int, $T3) call(() -> $T4, $T4, $T3) call(() -> Int, (), $T2) -
#JEJSFDUJPOBMJUZ func readInt() -> Int func read<X>() -> X func
main() { let a = readInt() let b: Int = read() } eq($T1, $T2) eq(Int, $T3) call(() -> $T4, $T4, $T3) call(() -> Int, (), $T2) -
*OUSPEVDUJPOPGDPOWFSTJPOSFMBUJPOTBOENPEJGJDBUJPOPGBTTJHONFOU TUBUFNFOUDPOTUSBJOUT w 4XJGUIBTJNQMJDJUUZQFDPOWFSTJPOT func main(i: Int) { let a:
Int? = i } eq(Int?, Int) conv(Int, Int?) ❌ ✅ -
4JNQMJGJDBUJPOPG$POWFSTJPO$POTUSBJOUT conv((A) -> B, (C) -> D) conv(B, D) conv(C,
A) 1BSBNFUFST 🙃DPOUSBWBSJBODF 3FUVSOWBMVFT 🙂DPWBSJBODF -
.PEJGJDBUJPOPGTJNQMJGJDBUJPOPGGVODUJPODBMMJOHDPOTUSBJOUT call((A) -> B, C, D) eq(B, D) conv(C, A)
1BSBNFUFST 🙃 3FUVSOWBMVFT -
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, -
(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 } -
&YBNQMFPG$BOEJEBUF4FBSDI conv($T1, Int?) conv(Int?, $T2) eq($T1, $T2) conv(Int, $T1) eq($T1,
Int) eq($T1, Int?) eq($T2, Int?) -
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) -
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) -
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) -
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) -
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) -
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) -
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) -
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?) -
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?) -
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?) -
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?) -
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?) -
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?) -
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?) -
)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 -
)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 -
)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 -
)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 -
"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 -
.BLJOHUIF$PNQJMFS0VUQVUUIF0QFSBUJPOTPG5ZQF*OGFSFODF $ swiftc -Xfrontend -debug-constraints code.swift func foo() -> Int
{ 0 } func foo() -> Bool { true } func main() { let a: Int = foo() } 0VUQVUFYDFFEJOHMJOFT🤯 -
*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo()
-> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF -
*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo()
-> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF -
*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo()
-> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF -
*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo()
-> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF -
*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo()
-> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF -
*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo()
-> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF -
*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo()
-> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF -
*OGFSFODFQSPDFTT func foo() -> Int { 0 } func foo()
-> Bool { true } func main() { let a: Int = foo() } 4UBSU 5*OU 5 *OU 5 #PPM 4VDDFTT 'BJMVSF -
$ 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 -
$ 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 -
$ 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 -
$ 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 -
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) -
*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 -
*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 -
*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 -
*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 -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*OJUJBM4UBUFPGUIF$POTUSBJOUT Score: <default 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0> Contextual Type: Int at [code.swift:5:12 - line:5:12] Type Variables: $T0 [allows bindings to: lvalue, noescape] [attributes: delayed] [with possible bindings: <empty>] @ 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] -
*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: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>) ) (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 -
*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: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>) ) (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 -
*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: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>) ) (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 -
*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: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>) ) (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 -
*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: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>) ) (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 -
*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: <default 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0>) ) (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 -
4PMVUJPO ---Solution--- Fixed score: <default 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0> 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 -
4PMVUJPO ---Solution--- Fixed score: <default 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0> 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 -
4PMVUJPO ---Solution--- Fixed score: <default 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0> 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 -
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 -
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 -
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 -
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 -
3FDBQ w 5IFCBTJDTPGUZQFJOGFSFODFBSFVOJ fi DBUJPOBOETJNQMJ fi DBUJPOPG DPOTUSBJOUT w 4XJGUFYUFOETJUCZBEEJOHTFBSDIUPUIFQSPDFTT
w 8FDBOVOEFSTUBOEJUTPQFSBUJPOTCZMPPLJOHBUUIFDPNQJMFSTPVUQVU -
/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