mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
In the constraint solver, we've traditionally modeled nested type via a "type member" constraint of the form $T1 = $T0.NameOfTypeMember and treated $T1 as a type variable. While the solver did generally try to avoid attempting bindings for $T1 (it would wait until $T0 was bound, which solves the constraint), on occasion we would get weird behavior because the solver did try to bind the type variable. With this commit, model nested types via DependentMemberType, the same way we handle (e.g.) the nested type of a generic type parameter. This solution maintains more information (e.g., we know specifically which associated type we're referring to), fits in better with the type system (we know how to deal with dependent members throughout the type checker, AST, and so on), and is easier to reason able. This change is a performance optimization for the type checker for a few reasons. First, it reduces the number of type variables we need to deal with significantly (we create half as many type variables while type checking the standard library), and the solver scales poorly with the number of type variables because it visits all of the as-yet-unbound type variables at each solving step. Second, it eliminates a number of redundant by-name lookups in cases where we already know which associated type we want. Overall, this change provides a 25% speedup when type-checking the standard library.
162 KiB
162 KiB