Slide 1

Slide 1 text

ܕਪ࿦ϋϯζΦϯ @omochimetaru swiftc߹॓ 2019/09/28 1

Slide 2

Slide 2 text

՝୊ • ஬৯͍ঢ়ଶͷܕਪ࿦ثΛ׬੒ͤ͞·͠ΐ͏ɻ • ϦϙδτϦ: https://github.com/omochi/ SwiftTypeInferenceHandsOn • ϒϥϯνquizɻmaster͸ݟͳ͍Ͱʂ 2

Slide 3

Slide 3 text

஬৯͍Օॴ • ίϝϯτͰͱͳ͍ͬͯΔ ͱ͜ΖʹίʔυΛॻ͘ɻXX͸൪߸ɻ •

Slide 4

Slide 4 text

ςετίʔυ • ׬੒͢Δͱςετ͕શ෦௨ΔΑ͏ʹͳΓ·͢ɻ • ͨͩ͠ɺղ͍ͯ΋ςετ௨ա͕૿͑ͳ͍໰୊΋ ͋Γ·͢ɻ • ඞཁʹԠͯࣗ͡෼ͰςετΛ௥Ճ͠Α͏ɻ 4

Slide 5

Slide 5 text

ܕਪ࿦ثͷ׬੒౓ • ܕ͸ద౰ɻ • ҉໧ม׵ͷਪ࿦ʹରԠɻ • ܕڧ੍(type coerce)Λ࣮૷ɻ • ղൺֱ, ղબ୒Λະ࣮૷ɻ 5

Slide 6

Slide 6 text

ઃܭ 6

Slide 7

Slide 7 text

ํ਑ • ίʔυͷσβΠϯΛ͋Δఔ౓ຊՈswiftίϯύΠ ϥʹدͤͯ͋Δɻ • ࣮૷࣌΋ಡղͱநग़Λ͠ͳ͕Β࡞ͬͨɻ • ϑΝΠϧ໊ɺܕ໊ɺؔ਺໊͕͋Δఔ౓ಉ͡ɻ 7

Slide 8

Slide 8 text

ύοέʔδ - SwiftcBasic: ϢʔςΟϦςΟ - SwiftcType: ܕ - SwiftcAST: ύʔαʔͱAST - SwiftcSema: ܕਪ࿦ɺ஬৯͍͸͚ͩ͜͜ɻ - SwiftcTest: ςετ༻ͷϢʔςΟϦςΟ 8

Slide 9

Slide 9 text

Semaৄࡉ - Constraint: ੍໿ - Conversion: ม׵ - ConstraintSystem: ੍໿Λղ͘Ϟδϡʔϧ - CSApply: ܕਪ࿦݁ՌʹΑΔASTͷม׵ - CSBinding: ܕม਺ͷׂ౰Ծઆͷੜ੒ - CSGen: ੍໿ͷੜ੒ - CSMatch: ܕͷϚον - CSSimplify: ੍໿ͷ؆໿ - CSSolve: ୳ࡧ - CSStep: ୳ࡧͷεςοϓ - TypeChecker: ιʔεશମΛܕνΣοΫ͢Δɻ 9

Slide 10

Slide 10 text

TypeCheckerͱConstraintSystem • ConstraintSystem(CS)͸1ͭͷࣜΛղ͘Ϟ δϡʔϧ • TypeChecker͕ߏจʹԠͯ͡CSΛىಈ͢Δ 10

Slide 11

Slide 11 text

ྫ: ୅ೖจ • ୅ೖจͷӈล͸ࣜͳͷͰCSͰղ͚Δɻ • ୅ೖͷ֓೦΍ࠨล͸จͷྖҬͳͷͰCSͷର৅ ֎ɻ • CSʹσϦήʔτ͕͋ΓɺTypeChecker͕୅ೖ จͷѻ͍Λ஫ೖ͢Δɻ (typeCheckVariableDecl) 11

Slide 12

Slide 12 text

ศརͳϝιου - ASTNode.dump() - ConstraintSystem.dump() - (͍Ζ͍Ζͳܕ).description 12

Slide 13

Slide 13 text

՝୊ͷऔΓ૊Έํͷྫ • ஬৯͍෦෼ͰͲΜͳॲཧΛ͍ͯ͠Δͷ͔ղੳ͢ Δɻ • ϒϨʔΫϙΠϯτΛష͔ͬͯΒςετΛൃՐ͠ ͯɺಥೖաఔΛௐ΂Δɻ • ͦ͜ͰԿΛ͢΂͖͔ߟ͑Δɻ • ຊՈίϯύΠϥͷ֘౰ՕॴΛݟֶͯͿɻ 13

Slide 14

Slide 14 text

ຊՈίϯύΠϥͷղੳ 14

Slide 15

Slide 15 text

Ϗϧυ $ utils/update-checkout --scheme master $ utils/build-script --xcode --debug --skip-build-benchmarks 15

Slide 16

Slide 16 text

Xcode • build/Xcode-DebugAssert/swift-macosx- x86_64/Swift.xcodeproj • swift࣮ߦϑΝΠϧͷschemeΛ࡞Δ 16

Slide 17

Slide 17 text

σόοΨΛ࢖͏ • schemeͷઃఆ: Debug Process As: root, Launch: Wait for executable to be launched • Ϗϧυͨ͠swiftʹύεΛ௨͢ • XcodeΛRun͔ͯ͠ΒλʔϛφϧͰ࣮ߦ 17

Slide 18

Slide 18 text

swiftcͷ࣮ߦ • $ swiftc -dump-ast -Xfrontend -debug- constraints 01.swift 18

Slide 19

Slide 19 text

Ԡ༻՝୊ • ରԠ͢ΔswiftcͷίʔυΛಡΜͰΈ·͠ΐ͏ɻ • ܕਪ࿦ثʹػೳΛ௥Ճ͠Α͏ɻ • ੒ՌΛൃද͠Α͏ɻ 19