# \[GSoC\] Type Inference Algorithm Improvements

**URL:** <https://forums.swift.org/t/gsoc-type-inference-algorithm-improvements/56484>\
**Category:** Standard Library\
**Tags:** type-inference, gsoc-2022\
**Created:** [April 3, 2022, 3:22am UTC](https://forums.swift.org/t/gsoc-type-inference-algorithm-improvements/56484 "2022-04-03T03:22:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dguthner](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@dguthner](https://forums.swift.org/u/dguthner)\
**Post date:** [April 3, 2022, 3:22am UTC](https://forums.swift.org/t/gsoc-type-inference-algorithm-improvements/56484/1 "2022-04-03T03:22:01Z")

</div>

Hello all!

I am Dane, an undergraduate university computer science student, and I was looking to participate in GSoC in 2022, specifically the improvement of debugging output of the type inference algorithm.

I haven't yet worked with a type inference algorithm so I familiarized myself with the current design implementation of the type inference algorithm that Swift incorporates. However, I am confused as to why Swift undergoes such complexity with intertwining the bi-directional type inference, the more classical type, with non classical systems? I guess I am also confused as to how the two are incorporated into the algorithm.

I was also wondering where to start when expanding my overall knowledge regarding the constraint system and why it was implemented in the type inference algorithm over other programming logics.

I have also started becoming far more familiar with Swift as a programming language, and have experienced the effects of the interface of the type inference algorithm. Is there any other way to view the algorithm?

@xedin

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [April 4, 2022, 2:16am UTC](https://forums.swift.org/t/gsoc-type-inference-algorithm-improvements/56484/2 "2022-04-04T02:16:46Z")

</div>

Here are two documents you can review to start:

- [https://github.com/apple/swift/blob/main/docs/TypeChecker.md](https://github.com/apple/swift/blob/main/docs/TypeChecker.md)
- [Swift.org - New Diagnostic Architecture Overview](https://www.swift.org/blog/new-diagnostic-arch-overview/)

Also, try type checking a simple source file with the '-Xfrontend -debug-constraints' flag.

> [@dguthner](#):
>
> However, I am confused as to why Swift undergoes such complexity with intertwining the bi-directional type inference, the more classical type, with non classical systems?

What do you mean by non-classical systems?

> [@dguthner](#):
>
> I was also wondering where to start when expanding my overall knowledge regarding the constraint system and why it was implemented in the type inference algorithm over other programming logics.

What other programming logics do you have in mind?

> [@dguthner](#):
>
> Is there any other way to view the algorithm?

You can find the code in [https://github.com/apple/swift/tree/main/lib/Sema](https://github.com/apple/swift/tree/main/lib/Sema); the solver is implemented in various files whose names start with "CS", as well as "ConstraintSystem.cpp", "ConstraintGraph.cpp", "Constraint.cpp", and "TypeCheckExpr.cpp".

---

<div class="post-metadata">

**Author:** ![xedin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/xedin/32/309_2.png) [@xedin](https://forums.swift.org/u/xedin)\
**Post date:** [April 4, 2022, 4:28am UTC](https://forums.swift.org/t/gsoc-type-inference-algorithm-improvements/56484/3 "2022-04-04T04:28:30Z")

</div>

Thank you, Slava! Just to add to your links - [swift/DebuggingTheCompiler.md at main · apple/swift · GitHub](https://github.com/apple/swift/blob/main/docs/DebuggingTheCompiler.md#debugging-the-type-checker). This has an example of output we are seeking to improve and other details.

---

<div class="post-metadata">

**Author:** ![dguthner](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@dguthner](https://forums.swift.org/u/dguthner)\
**Post date:** [April 7, 2022, 3:59am UTC](https://forums.swift.org/t/gsoc-type-inference-algorithm-improvements/56484/4 "2022-04-07T03:59:09Z")

</div>

Thank you for your response!

I have been reading the documents you have sent, and when referencing non-classical systems, I was referring to the Hindley-Milner system. I believe I better understand the type inference algorithm system and how it connects to the debugging system.

Thank you for your help!
