stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.33k stars 221 forks source link

Support swift 5.0 #268

Closed kawoou closed 5 years ago

kawoou commented 5 years ago
djbe commented 5 years ago

That was quick! 😆

Are there other things we can potentially migrate? There are new String protocols, and other things (see https://www.whatsnewinswift.com).

Instead of peppering the code with #if swift checks, we add backports for new functions. See the _SwiftSupport.swift file: https://github.com/stencilproject/Stencil/blob/master/Sources/_SwiftSupport.swift

soffes commented 5 years ago

Any word on this PR? I'd love to update to Swift 5 :)

kawoou commented 5 years ago

@djbe I want to support #"..."# syntax for readability. However, you must also support versions below Swift 5. If I do, think the code will be less readable.

ex)

#if swift(<5.0)
self.format = format ?? Variable("\"yyyy-MM-dd 'at' HH:mm\"")
#else
self.format = format ?? Variable(#""yyyy-MM-dd 'at' HH:mm""#)
#endif
djbe commented 5 years ago

Is there more info about that SIL exception? Is it new in Swift 5? Radar?

djbe commented 5 years ago

Yeah, we won't be able to use raw strings until we drop 4.2 support 🤷‍♂️

kawoou commented 5 years ago

@djbe Compile-time keywords(like #file) are expected to cause problems due to type inference errors during static dispatch.

Before: Throw SIL Exception (https://travis-ci.org/stencilproject/Stencil/jobs/508764850)

let path = Path(#file) + ".."  + "fixtures" + "huge.html"

After:

let basePath: String = #file //< Specify type
let path = Path(basePath) + ".."  + "fixtures" + "huge.html"
djbe commented 5 years ago

Would this work then?

let path = Path(#file as String) + ".."  + "fixtures" + "huge.html"
keith commented 5 years ago

This changed fixed PathKit https://github.com/kylef/PathKit/pull/69/files#diff-663087ac5b85edfc8e4ff1dd83b915abL12

soffes commented 5 years ago

Awesome! Thanks so much for your effort on this!

Mind tagging a release with Swift 5 support?