I know for certain that the three lines with i
, j
and k
in test.swift did type check (quickly) prior to upgrading to Xcode 10.2 and macOS 10.14.4. But the compiler is now unable to type check them in reasonable time (i
takes forever).
test.swift:
import simd
func test(_ p0: float2, _ p1: float2, _ p2: float2, _ p3: float2) {
let i = 3*(-p0 + 3*p1) - (3*p2 + p3)
let j = 6*(p0 - 2*p1 + p2)
let k = 3*(p1 - p0)
print(i, j, k)
}
test(float2(0.1, 1.2), float2(2.3, 3.4), float2(4.5, 5.6), float2(6.7, 7.8))
$ swiftc --version
Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
$ time swiftc test.swift
test.swift:4:28: error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
let i = 3*(-p0 + 3*p1) - (3*p2 + p3)
~~~~~~~~~~~~~~~^~~~~~~~~~~~~
real 0m17.296s
user 0m16.647s
sys 0m0.613s
And a naive workaround like wrapping parts of the expressions in float2(…)
will make this tiny program compile, but in 12 seconds!
testB.swift:
import simd
func test(_ p0: float2, _ p1: float2, _ p2: float2, _ p3: float2) {
let i = 3*float2(-p0 + float2(3*p1)) - float2(3*p2 + p3)
let j = float2(6*(p0 - 2*p1 + p2))
let k = float2(3*(p1 - p0))
print(i, j, k)
}
test(float2(0.1, 1.2), float2(2.3, 3.4), float2(4.5, 5.6), float2(6.7, 7.8))
$ time swiftc testB.swift
real 0m12.477s
user 0m11.975s
sys 0m0.490s
Is this because float2 is now a typealias for the new generic SIMD2<Float>
(cc @scanon )?
We have had to go through and modify a lot of our code because of this, and the build time has increased dramatically, especially in release builds.
There are of course better workaround/ways to break up the expressions. For example, in order to get it to compile it suffices to break up the expression for i
into two parts iA
and iB
:
testC.swift:
import simd
func test(_ p0: float2, _ p1: float2, _ p2: float2, _ p3: float2) {
let iA = 3*(-p0 + 3*p1)
let iB = (3*p2 + p3)
let i = iA - iB
let j = 6*(p0 - 2*p1 + p2)
let k = 3*(p1 - p0)
print(i, j, k)
print(i)
}
test(float2(0.1, 1.2), float2(2.3, 3.4), float2(4.5, 5.6), float2(6.7, 7.8))
But testC.swift still takes a long time to compile, 7 seconds, for 10 lines of code!
That's much longer than it took Xcode 10.1 (and macOS 10.14.3) to compile an entire medium sized project that included exactly the original expression for i
from test.swift above, and lots and lots of other similar expressions.
This is a serious regression. We have to jump through hoops in order to try and reduce the ridiculously long compile times that now arises whenever we are writing code that uses SIMD types, this was not necessary before.