Upgrade to Pro — share decks privately, control downloads, hide ads and more …

switchのexhaustiveness/redundancy チェック 理論と実装 わいわいswiftc #8 @ukitaka

0cf23fed58f84e729aa59ba5d8d0baaf?s=47 ukitaka
December 31, 2019

switchのexhaustiveness/redundancy チェック 理論と実装 わいわいswiftc #8 @ukitaka

swiftcがいかにしてswitchの網羅性チェックをしているかを、背景にあるSpaceという概念を元にしたパターンマッチの網羅性チェックの理論とその実装について、lib/Sema/TypeCheckSwitchStmt.cppとソースコード中で紹介されている論文を元に紹介します。

0cf23fed58f84e729aa59ba5d8d0baaf?s=128

ukitaka

December 31, 2019
Tweet

Transcript

  1. Θ͍Θ͍swiftc #8 @ukitaka switchͷexhaustiveness/redundancy νΣοΫ ཧ࿦ͱ࣮૷

  2. None
  3. None
  4. switchͷ໢ཏੑ/৑௕ੑνΣοΫ ࠓ೔ͷ࿩ ▸ swiftc͕͍͔ʹͯ͠switchͷ໢ཏੑνΣοΫΛ͍ͯ͠Δ͔Λɺഎܠʹ͋ΔSpaceͱ ͍͏֓೦Λݩʹͨ͠ύλʔϯϚονͷ໢ཏੑνΣοΫͷཧ࿦ͱͦͷ࣮૷ʹ͍ͭ ͯɺlib/Sema/TypeCheckSwitchStmt.cppͱιʔείʔυதͰ঺հ͞Ε͍ͯΔ࿦ จΛݩʹ঺հͯ͠Έ͍ͨͱࢥ͍·͢ɻ

  5. switchͷ໢ཏੑ/৑௕ੑνΣοΫ ࠓ೔ͷ࿩

  6. switchΛ஌Δ

  7. switch ໢ཏੑνΣοΫ

  8. switch ଍Γͳ͍caseͷ௥Ճ

  9. switch ΋͏গ͠ෳࡶͳέʔεͰ΋Մ

  10. switch ଍Γͳ͍caseͷ௥Ճ

  11. switch Unreachableͳέʔε͸লུՄೳ

  12. switch where۟Λ࢖͏ͱ࣮ࡍʹ͸໢ཏ͞Ε͍ͯͯ΋Τϥʔʹ

  13. switch IntͳͲ͸໢ཏ͞Ε͍ͯͯ΋Τϥʔʹ

  14. switch ৑௕ͳέʔε͕͋ΔͱwarningʹͳΔ

  15. switch SwitchͷεϖοΫ ▸ έʔε͕໢ཏ͞Ε͍ͯΔ͜ͱΛݕࠪͰ͖ɺ໢ཏ͞Ε͍ͯͳ͍৔߹͸Τϥʔʹ͢Δ ▸ ͦͷࡍ(ิ׬͢ΔͨΊʹ)Ͳͷέʔε͕଍Γͳ͍͔Λ೺ѲͰ͖͍ͯΔඞཁ͕͋Δ ▸ ॏෳ͢Δέʔε΋ݕग़Ͱ͖Δඞཁ͕͋Δ → ͜ΕΛ࣮ݱ͍ͯ͠Δͷ͕Space

    (Engine)ͱݺ͹ΕΔ࢓૊Έ
  16. Space EngineΛ༻ ͍ͨ໢ཏੑνΣοΫ

  17. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ TypeCheckSwitchStmt.cpp

  18. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ TypeCheckSwitchStmt.cpp

  19. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ TypeCheckSwitchStmt.cpp

  20. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ TypeCheckSwitchStmt.cpp

  21. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ ࢀߟจݙ ▸ Maranget, Luc. "Warnings for pattern matching."

    Journal of Functional Programming 17.3 (2007): 387-421. ▸ ͜Ε͕ԼͷPaperͷϕʔεͱͳͬͨ࿦จ ▸ (GenericͰͳ͍) ୅਺తσʔλܕΛѻ͑ΔܕγεςϜʹ͓͚Δ໢ཏੑνΣοΫͷΞϧΰϦζϜ ▸ A generic algorithm for checking exhaustivity of pattern matching, F. Liu, Scala 16’, 2017 ▸ ͕ͬͪ͜SpaceΛ࢖ͬͨ໢ཏੑݕࠪʹؔ͢Δ࿦จɺ͜ΕΛԠ༻ͯ͠৑௕ੑݕࠪ΋ߦ͏ ▸ ಛఆͷܕγεςϜʹґଘ͠ͳ͍ΞϧΰϦζϜ ( GADTs΋ѻ͑Δ )
  22. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ A Generic Algorithm for Checking Exhaustivity of Pattern

    Matching ▸ ݩʑ͸Dottyͱ͍͏ScalaͷίϯύΠϥ (Scala 3.0~)Ͱ࠾༻͞Ε͍ͯΔ΋ͷΛSwift ʹҠ২͖ͯͨ͠΋ͷɻ https://fengy.me/
  23. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ A Generic Algorithm for Checking Exhaustivity of Pattern

    Matching ▸ ໢ཏੑνΣοΫͷΞϧΰϦζϜΛಛఆͷܕγεςϜ͔Β੾Γ཭͠ɺͲͷΑ͏ͳݴ ޠ(ͷܕγεςϜ)Ͱ΋࢖͑ΔΑ͏ͳҰൠతͳΞϧΰϦζϜΛఏڙ͢Δ ▸ ྫͱͯ͠Scala (Dotty) ͷܕγεςϜ΁ͷԠ༻Λ͍ࣔͯ͠Δ ▸ ϑΥʔϚϧͳূ໌͕͋ΔΘ͚Ͱ͸ͳ͍͚Ͳɺ͋Δఔ౓ෳࡶͳܕγεςϜΛ΋ͭ ScalaͰͷ࠾༻࣮੷͕͋Δ ▸ ͪͳΈʹFengyun Liuࢯͷࢦಋڭһ͸Oderskyઌੜ
  24. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ ͦ΋ͦ΋SpaceҎલͷ࣮૷ ▸ ݕࠪ͢Δର৅ͷܕ (Subject type) ͔Β֤έʔεΛ औΓআ͍ͯߦͬͯ࢒Γ͕ͳ͍͔ݟΔɺΈ͍ͨͳ࣮ ૷

    ▸ ࣮͸SpaceΛ༻͍࣮ͨ૷ʹ͍ۙ͜ͱΛ͍ͯ͠Δ ͕ɺ͍͔ͭ͘໰୊͕͋ͬͨͨΊScala (Dotty)Ͱͷ ࣮੷ͷ͋ΔํࣜΛվΊͯ࠾༻
  25. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ ݁Ռ

  26. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ (ࢀߟ) SR-483

  27. Space EngineΛ༻͍ͨ໢ཏੑνΣοΫ (ࢀߟ) SR-2293

  28. SpaceΛ༻͍ͨ “໢ཏ”ͷఆࣜԽ

  29. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ Space Engineͷ࣮૷ΛಡΉʹ͋ͨͬͯ ▸ SwiftͰͷ໢ཏੑνΣοΫͷ࣮૷Λཧղ͢ΔͨΊʹΞϧΰϦζϜΛ஌Δඞཁ͕͋Δ ▸ ΞϧΰϦζϜΛཧղ͢ΔͨΊʹ͸ Spaceʹؔ͢Δ༻ޠ΍ͦͷఆٛΛཧղ͓ͯ͘͠ ඞཁ͕͋Δ ▸

    SpaceʹΑͬͯఆࣜԽ͞Εͨ “໢ཏ͍ͯ͠Δ” ͜ͱΛද͍ͯ͠ΔࣜΛཧղ͢Δͷ͕ ࠷ॳͷ໨ඪ (T) ⪯ (p1 ) ∣ (p2 ) ∣ . . . ↑ ͜Ε͕໢ཏ͍ͯ͠Δ͜ͱΛදࣜ͢
  30. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ ఆٛ (Space) ▸ ܕ΍ύλʔϯ͕औΓ͏Δ஋ͷू߹ΛSpaceͱ͍͏ ▸ Space͸࠶ؼతʹҎԼͷΑ͏ʹఆٛ͞ΕΔ 1. ΛۭSpace (empty

    space) 2. ΛܕTͷSpace (type space) 3. ͕Spaceͷͱ͖ɺ Λ union space 4. ͕SpaceͰɺK͕Constructor Typeͷͱ͖ (T) s1 , s2 , . . . s1 |s2 | . . . s1 , s2 , . . . , sn (K, s1 , s2 , . . . , sn ) Λconstructor space
  31. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SwiftͰͷΠϝʔδ: (Bool) = {true, false} (Never) =

  32. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SwiftͰͷΠϝʔδ: (Bool)|(Never) = {true, false}

  33. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SwiftͰͷΠϝʔδ: (Optional . some, (Bool)) = {.some(true), . some(false)}

    Optional<Bool>.someͷྫ Type constructor
  34. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SpaceΛ࢖ͬͯ”໢ཏੑνΣοΫ”Λݴ͍׵͑Δ ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ (T) ·ͩఆ͍ٛͯ͠ͳ͍͕ɺ㲈 ू߹ͷแؚؔ܎

  35. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SpaceΛ࢖ͬͯ”໢ཏੑνΣοΫ”Λݴ͍׵͑Δ ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ (T)

  36. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SpaceΛ࢖ͬͯ”໢ཏੑνΣοΫ”Λݴ͍׵͑Δ ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ (T)

  37. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SpaceΛ࢖ͬͯ”໢ཏੑνΣοΫ”Λݴ͍׵͑Δ ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ (T) (Bool?) =

    {.some(true), . some(false), . none}
  38. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SpaceΛ࢖ͬͯ”໢ཏੑνΣοΫ”Λݴ͍׵͑Δ ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ (T) (Optional .

    none) = {.none}
  39. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SpaceΛ࢖ͬͯ”໢ཏੑνΣοΫ”Λݴ͍׵͑Δ ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ (T) s1 |s2

    |s3 s1 s2 s3
  40. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SpaceΛ࢖ͬͯ”໢ཏੑνΣοΫ”Λݴ͍׵͑Δ ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ (T) (Bool?) ⪯

    s1 |s2 |s3
  41. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ ΑΓ௚؍తʹ͸ (Bool?) ⪯ s1 |s2 |s3 ֤case͕Χόʔ͍ͯ͠Δൣғͷ΄͏͕ େ͖͍ΑɺΈ͍ͨͳΠϝʔδ “େ͖͍”

    Λఆٛ͢Δํ๏ → Subspaceؔ܎
  42. Subspaceؔ܎

  43. Subspaceؔ܎ ఆٛ (Subspaceؔ܎) ▸ ΛSpace্ͷೋ߲ؔ܎ Subspaceؔ܎ ͱ͢Δ ⪯ s1 ⪯

    s2 ▸ ௚؍తʹ͸ू߹ͷแؚؔ܎͕ͩɺཁૉʹ͸௚઀ݴٴͤͣʹ ܕ΍ܕߏஙࢠ (case) ͷؔ܎Λ࢖ͬͯఆ͍ٛͯ͘͠ɻৄࡉͳϧʔϧ͸ޙड़ɻ
  44. Subspaceؔ܎ ఆٛ (projection) ▸ Λύλʔϯͱ͢Δɻ͜ͷͱ͖ ͕Χόʔ͢ΔSpaceΛ ͱද͢ ▸ ύλʔϯ =

    case ͱࢥͬͯࠩ͠ࢧ͑ͳ͍ (ਖ਼֬Ͱ͸ͳ͍) p (p) p ͬͪ͜͸type constructor ͬͪ͜͸pattern
  45. Subspaceؔ܎ SwiftͰͷΠϝʔδ: (.some(true)) = {.some(true)} (.some(_)) = {.some(true), some(false)}

  46. Subspaceؔ܎ ໢ཏͷఆࣜԽ (࠶ܝ) ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ (T)

  47. Subspaceؔ܎ ໢ཏͷఆࣜԽ (࠶ܝ) ▸ Ϛονͤ͞Δର৅ͷܕTʹ͍ͭͯɺ ͕͢΂ͯͷcase͕Χόʔ͍ͯ͠Δspace ͷunion spaceͷsubspaceʹͳ͍ͬͯΔ͔ ▸ ύλʔϯ

    ͕ ܕ TΛ໢ཏ͍ͯ͠Δͱ͸ҎԼΛຬͨ͢͜ͱͰ͋Δɻ (T) p1 , p2 , . . . (T) ⪯ (p1 ) ∣ (p2 ) ∣ . . . ͜͜·ͰͰ”໢ཏ”ͷ͕ࣜಡΊͨʂ(͸ͣʂ)
  48. Subspaceؔ܎ SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ ▸ ໢ཏ͍ͯ͠Δ͜ͱΛSubspaceؔ܎Λ࢖ͬͯҎԼͷΑ͏ʹදͤͨ (T) ⪯ (p1 ) ∣ (p2

    ) ∣ . . . ▸ ࣍͸͜ͷSubspaceؔ܎ͷ۩ମతͳϧʔϧΛ·ͨผͷ֓೦Λ࢖ͬͯఆ͍ٛͯ͘͠…. (ΊΜͲ͍) s1 ⪯ s2 ⇔ s1 ⊖ s2 ≐ ΞϧΰϦζϜΛཧղ͢Δͷʹඞཁͳఆٛ͸ ͜ΕͰ࠷ޙͳͷͰ͕Μ͹Ζ͏…
  49. ⊖Λ࢖ͬͨSubspace ؔ܎ͷఆٛ

  50. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ ▸ Subspaceؔ܎Λ௚઀తʹఆ͍ٛͯ͘͜͠ͱΛͤͣʹ৽ͨʹ㱿 (Subtraction) Λಋ ೖ͢Δ͜ͱͰSubspaceؔ܎Λఆٛ͢Δ ▸ ௚઀ఆٛ͠Α͏ͱ͕ͨ͠ɺ“We tried

    but failed.” Β͍͠ɻ ▸ ௚؍తʹ͸ू߹ͷsubtractionͱಉ͕ͩ͡ (ry
  51. ▸ Subspaceؔ܎ΛSubtractionΛ༻͍ͯఆٛ͢Δ ▸ Space ʹ͍ͭͯɺ ͕ ҎԼΛຬͨ࣌͢(͔ͭͦͷ࣌ͷΈ) ͕ ͷ SubspaceͰ͋Δͱ͍͏

    ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ ఆٛ (Subspaceؔ܎) s1 , s2 s1 s2 s1 s2 s1 ⪯ s2 ⇔ s1 ⊖ s2 ≐
  52. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ Subtractionͷϧʔϧ A generic algorithm for checking exhaustivity of pattern

    matching, F. Liu, Scala 16’, 2017 ΑΓҾ༻
  53. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ Subtractionͷϧʔϧ A generic algorithm for checking exhaustivity of pattern

    matching, F. Liu, Scala 16’, 2017 ΑΓҾ༻ empty spaceʹؔ͢Δϧʔϧ
  54. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ Subtractionͷϧʔϧ A generic algorithm for checking exhaustivity of pattern

    matching, F. Liu, Scala 16’, 2017 ΑΓҾ༻ subtypeʹؔ͢Δϧʔϧ
  55. SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ SpaceΛ༻͍ͨ”໢ཏ”ͷఆࣜԽ (T) ⪯ (p1 ) ∣ (p2 ) ∣

    . . . (T) ⊖ (p1 ) ∣ (p2 ) ∣ . . . ≐ “໢ཏ͍ͯ͠Δ” ͜͜·ͰΘ͔Ε͹ϝΠϯͷϩδοΫ͸ಡΊΔʂ
  56. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ (T) ⊖ (p1 ) ∣ (p2 ) ∣ .

    . . ≐
  57. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ (T) ⊖ (p1 ) ∣ (p2 ) ∣ .

    . . ≐
  58. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ (T) ⊖ (p1 ) ∣ (p2 ) ∣ .

    . . ≐
  59. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ (T) ⊖ (p1 ) ∣ (p2 ) ∣ .

    . . ≐
  60. ⊖Λ࢖ͬͨSubspaceؔ܎ͷఆٛ (T) ⊖ (p1 ) ∣ (p2 ) ∣ .

    . . ≐
  61. Decompose

  62. Decompose Decompose ▸ enum E { case a, b }

    ͕͋ͬͨͱͯ͠ ͷܭࢉΛͲ͏ਐΊΔ ͔ʁ ▸ ͜ͷΑ͏ͳܭࢉΛਐΊΔͨΊʹܕEʹରͯ͠ Decompose (෼ղ) ͱ͍͏ૢ࡞Λఆ ٛ͢Δඞཁ͕͋Δ (E) ⊖ (a) ∣ (b)
  63. Decompose Decompose ▸ ۩ମతʹͲ͏ఆٛ͞ΕΔ͔͸ͦͷϓϩάϥϛϯάݴޠʹΑΔ͕ɺSwiftʹ͓͍ͯ͸ enumΛ֤caseͷprojectionͷunion spaceʹ෼ղ͢Δ͜ͱ ▸ (E) = (a)

    ∣ (b) = (a) ∣ (b)
  64. Decompose Decompose·ͰΘ͔Ε͹͍͍͍͚ͩͨΔ (E) ⊖ (a) ∣ (b) ≐ (E) ⪯

    (a) ∣ (b) ໢ཏ͍ͯ͠Δͱ͸ subtractionΛ࢖ͬͯ
  65. Decompose Decompose·ͰΘ͔Ε͹͍͍͍͚ͩͨΔ (E) ⊖ (a) ∣ (b) DecomposeΛ࢖ͬͯ (E) =

    (a) ∣ (b) (a) ∣ (b) ⊖ (a) ∣ (b) ͋ͱ͸Α͠ͳʹܭࢉΛਐΊΕ͹ (a) ∣ (b) ⊖ (a) ∣ (b) ≐
  66. Swiftͷ࣮૷ΛಡΉ

  67. Swiftͷ࣮૷ΛಡΉ Swiftͷ࣮૷ΛಡΉ ▸ ͓ർΕ༷Ͱͨ͠ɻ͜͜·ͰΘ͔Ε͹ίʔυΛಡΉͷ͸೉͘͠ͳ͍Ͱ͢ɻ ▸ ͜͜·Ͱղઆͨ͜͠ͱ͕΄΅ͦͷ··࣮૷͞Ε͍ͯΔ

  68. Swiftͷ࣮૷ΛಡΉ Swiftʹ͓͚ΔSpace Bool͸ಛผѻ͍ɻ ↓͜ΜͳΠϝʔδ

  69. Swiftͷ࣮૷ΛಡΉ ໢ཏੑνΣοΫͷΤϯτϦϙΠϯτ

  70. Swiftͷ࣮૷ΛಡΉ ໢ཏੑνΣοΫͷΤϯτϦϙΠϯτ ͢΂ͯͷCase(Pattern)ʹ͍ͭͯ

  71. Swiftͷ࣮૷ΛಡΉ ໢ཏੑνΣοΫͷΤϯτϦϙΠϯτ ProjectionΛٻΊͯ

  72. Swiftͷ࣮૷ΛಡΉ ໢ཏੑνΣοΫͷΤϯτϦϙΠϯτ spacesʹ٧ΊΔ

  73. Swiftͷ࣮૷ΛಡΉ ໢ཏੑνΣοΫͷΤϯτϦϙΠϯτ (T) ⪯ (p1 ) ∣ (p2 ) ∣

    . . .
  74. Swiftͷ࣮૷ΛಡΉ ໢ཏੑνΣοΫ (T) ⊖ (p1 ) ∣ (p2 ) ∣

    . . . ≐
  75. ▸ ͜͜·ͰͷղઆͲ͓ΓͳΒ ʹΑͬͯఆٛ͞Ε͍ͯΔ͸͕ͣͩɺEmpty sapce ޲͚ʹOptimze͞Ε͍ͯΔͨΊʹཧ࿦௨ΓͰ͸ͳ͍ Swiftͷ࣮૷ΛಡΉ Subspaceͷఆٛ ⊖

  76. Swiftͷ࣮૷ΛಡΉ Subspaceͷఆٛ

  77. Swiftͷ࣮૷ΛಡΉ Subtractionͷఆٛ

  78. Swiftͷ࣮૷ΛಡΉ Subtractionͷఆٛ

  79. ৑௕ੑνΣοΫ

  80. ৑௕ੑνΣοΫ ৑௕ੑ(Redundancy)νΣοΫ ▸ ৑௕ͳέʔεͷνΣοΫ΋Spaceͷ࢓૊Έʹ৐͔͍ͬͬͯΔ ▸ ݩͷPaperʹ͸ॻ͔Ε͍ͯͳ͍͕ɺΞϧΰϦζϜ͸ίʔυ͔ΒಡΈऔΕΔ

  81. ৑௕ੑνΣοΫ ৑௕ੑνΣοΫͷΞϧΰϦζϜ ▸ ໢ཏੑνΣοΫͷաఔͰ֤έʔεͷunion spaceΛܭࢉ͍ͯ͘͠ (T) ⪯ (p1 ) ∣

    (p2 ) ∣ . . . ͜ͷ෦෼ ▸ ܭࢉͷաఔͰɺ৽ͨʹ௥Ճ͢Δέʔε͕ͦ͜·Ͱͷunion spaceͷsubspaceʹ ͳ͍ͬͯͳ͍͔ΛνΣοΫ͢Δ (p1 ) ∣ (p2 )| . . . |(pn ) ⪯ (pn + 1)
  82. ৑௕ੑνΣοΫ ৑௕ੑνΣοΫͷΞϧΰϦζϜ

  83. ৑௕ੑνΣοΫ ৑௕ੑνΣοΫͷΞϧΰϦζϜ (a) ∣ (b) ⪯ (c) (a) ∣ (b)

    ∣ (c) ⪯ (a) (a) ⪯ (b) ੒ཱ͠ͳ͍ͷͰOK ੒ཱ͢ΔͷͰ৑௕
  84. ৑௕ੑνΣοΫ ࣮૷

  85. where۟

  86. Where۟ Where۟ ▸ ܕ΍ܕߏஙࢠಉ࢜ͷؔ܎ʹج͍ͮͯSubspace(Subtraction)͕ఆٛ͞ΕΔ ▸ ஋ʹ௚઀ݴٴ͢ΔΑ͏ͳ΋ͷ͸͜ͷΞϧΰϦζϜͰ͸ѻ͑ͳ͍ ▸ 3.4 Limitations ʹ

    “Guards in pattern clauses pose a theoretical difficulty, thus are not handled by the algorithm.” ͱॻ͔Ε͍ͯΔ௨Γ
  87. Where۟ Where۟

  88. Int

  89. Int IntͷΑ͏ʹҰҙʹDecompose͕ఆٛͰ͖ͳ͍ܕͷ৔߹ ▸ Intͷ৔߹Decompose͕ҰҙʹఆٛͰ͖ͳ͍ → ѻ͑ͳ͍ ▸ ٯʹBool͸Ұҙʹ෼ղ͕ఆٛͰ͖Δ͕Ώ͑ʹಛผѻ͍Ͱ͖Δ

  90. ·ͱΊ

  91. switchͷ໢ཏੑ/৑௕ੑνΣοΫ ·ͱΊ ▸ swiftc͕͍͔ʹͯ͠switchͷ໢ཏੑνΣοΫΛ͍ͯ͠Δ͔Λɺഎܠʹ͋ΔSpaceͱ ͍͏֓೦Λݩʹͨ͠ύλʔϯϚονͷ໢ཏੑνΣοΫͷཧ࿦ͱͦͷ࣮૷ʹ͍ͭ ͯɺlib/Sema/TypeCheckSwitchStmt.cppͱιʔείʔυதͰ঺հ͞Ε͍ͯΔ࿦ จΛݩʹ঺հͨ͠ɻ

  92. Appendix: Intersection

  93. Intersection Intersectionͷఆٛ A generic algorithm for checking exhaustivity of pattern

    matching, F. Liu, Scala 16’, 2017 ΑΓҾ༻
  94. Intersection Intersectionͷఆٛ A generic algorithm for checking exhaustivity of pattern

    matching, F. Liu, Scala 16’, 2017 ΑΓҾ༻