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!
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
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.