Nested functions inside of @inlinable

Was this ever supposed to compile? Prior to Swift 5.2 this code compiled, however now it crashes the compiler. The key bit is the nested function, moving that outside, and marked @usableFromInline this compiles. https://godbolt.org/z/XveCV3 (godbolt nightly crash is slightly different than the Apple 5.2 compiler)

Edit: Filed SR-12404 for the crashing

@inlinable
public func + <T>(el: T, arr: [T]) -> [T] {
  var ret = arr

  ret.insert(el, at: 0)

  return ret
}

@inlinable
public func cartesianProduct<T>(_ arrays: [T]...) -> [[T]] {
 guard let head = arrays.first else {
   return []
 }

 let first = Array(head)

 func pel(
   _ el: T,
   _ ll: [[T]],
   _ a: [[T]] = []
 ) -> [[T]] {
   switch ll.count {
   case 0:
     return a.reversed()
   case _:
     let tail = Array(ll.dropFirst())
     let head = ll.first!

     return pel(el, tail, el + head + a)
   }
 }

 return arrays.lazy.reversed()
   .reduce([first], {res, el in el.flatMap({ pel($0, res) }) })
   .map({ $0.dropLast(first.count) })
}
Terms of Service

Privacy Policy

Cookie Policy