GSoC 2021: Type Inference

Hello, I'm Ian and I'm a iOS developer and Master's student from Brazil. I absolutely love Swift and would like to participate in GSoC 2021, specifically in the type inference project! Does anyone have any tips on where to start for that one? Any resources on the subject, proposals or PRs to look at would be helpful! Also, the coding period is short but I'm interested in the command line tool that was mentioned!

7 Likes

Hi Ian, welcome!

I believe you mean Tracking for typechecker’s type inference?

Let's ping @hborla who will be able to point you in the right direction :slight_smile:

3 Likes

Hi Ian, welcome to the Swift community!

First, I recommend getting to know how Swift's type inference algorithm works. Swift's type inference algorithm is implemented as a constraint system, which is described in detail here, and its strategy for producing diagnostics, which you can learn about in this blog post on Swift.org.

I've also found that one of the best ways to solidify your understanding of the algorithm is to step through it in a debugger! I recommend getting started with checking out and building the Swift compiler. Once you've done that, try setting a breakpoint in ConstraintSystem::simplifyConstraint in CSSimplify.cpp. To start, I recommend creating a simple test.swift file that only contains one simple expression, and then step through the execution of the type inference algorithm. You can also use the flags -Xfrontend -debug-constraints (or just -typecheck -debug-constraints if you're running swift-frontend instead of swiftc) to see the debugging output of the constraint system.

This is quite a bit of information to dig into, so please let me know if you have any questions! Also cc @xedin who is another potential mentor for this project.

EDIT: Also, I've been meaning to improve our documentation on the expression type checker (the first document I linked) for some time now, so I'd love to hear your feedback on which parts are helpful and which parts are confusing.

5 Likes