Compiling With Constraints (long)
Compiling With Constraints (long)

www.philipzucker.com
Compiling With Constraints

Constraint programming is a general method to solve logic problems, which models the problem as a set of constraints (e.g. 0 < x
, y > 10
, x + 2y = 24
) then uses a constraint solver to find possible solutions (x = 1 & y = 11
). Constraint solving is used very often in compilers. This article focuses on compiler backends like LLVM which generate assembly from low-level IR (a process called "lowering"). It presents multiple examples of constraint solvers being used with code and goes into great detail, reflecting on the author's personal experience.
Constraint solving is also used in the frontend, particularly in type inference (including Hindley-Milner)