Automatic Numeric Type Promotions to Simplify Type Inference in Expressions

This topic of type promotion (i.e., promoting smaller integers and reals to larger types) has been raised before (Simplified Conversion of Integer Types) but I'd like to resurrect it in light of the Swift 6 directives (Design Priorities for the Swift 6 Language Mode), one of which was to devise ways to speed up the type inference process. At the time, Chris Lattner approved of this in principle (Simplified Conversion of Integer Types - #2 by Chris_Lattner). BTW, this discussion also surfaced later here.

Not knowing how the type inference engine works, I only ask this as a possible way to reduce type inference execution times. If types could be promoted in expressions, would that be better for the type inference process?

BTW, I have advocated for the side effects of a simpler Swift experience of having types promoted automatically (where safe and performance is not impacted). Some of this has been implemented by allowing the RHS of shifts to have different numeric types from the LHS and allowing cross-type comparisons. Both of which have made Swift a more useful and friendlier language. If we want to encourage more people to use Swift, we should also make it simpler to use.

3 Likes