Uploaded image for project: 'Swift'
  1. Swift
  2. SR-10461

Unable to type check expression, Xcode 10.2 regression

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Environment:

      macOS 10.14.4, Xcode 10.2 default toolchain and most recent dev (snapshot 2019-04-10).

      Description

      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.

      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))
      

      test.swift doesn't compile, although I know it did before I upgraded to Xcode 10.2 and macOS 10.14.4:

      $ 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
      

      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))
      

      testB.swift compiles, but veeery slowly:

      $ time swiftc testB.swift 
      
      real	0m12.477s
      user	0m11.975s
      sys	0m0.490s
      

      A better workaround is possible, noting that it is only the first of the three that is deemed too complex to type check, 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!

      That's much longer than it took Xcode 10.1 (and macOS 10.14.3) to compile an entire medium size project that included the exact unaltered expression for `i` from test.swift above, and lots and lots of other similar expressions.

      Is this because float2 is now a typealias for the new generic SIMD2<Float> (cc Stephen Canon )?

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jens Jens Persson
              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: