Aside from the fact that the case-sensitivity of simpleTest is important, the delay is in the compilation of this script rather than the runtime performance of the script. You can compile it with swiftc (which takes around 20s) but then when running it the performance is fine.
It's certainly an interesting compiler issue, probably to do with the type analysis rather than the complexity of the abs function or the Float cast directly. It's still worth raising a bug at https://bugs.swift.org <Issues · apple/swift · GitHub; with the snippet though.
Alex
···
On 7 Sep 2016, at 15:11, louislepegue via swift-users <swift-users@swift.org> wrote:
It's certainly an interesting compiler issue, probably to do with the type
analysis
I've for sure hit this before and now see with a little help to the
compiler the compile time drops dramatically:
Float(abs(Double(0) - Double(0)))
repl.swift:50:1: error: expression was too complex to be solved in
reasonable time; consider breaking up the expression into distinct
sub-expressions
Float(abs(Double(0 as Int) - Double(0 as Int)))
// Compiles instantly!
It makes the code ugly though, so we're probably better-off busting it into
subexpressions like the error above states.
simpleTest is important, the delay is in the compilation of
this script rather than the runtime performance of the script.
You can compile it with swiftc (which takes around 20s) but
then when running it the performance is fine.
It's certainly an interesting compiler issue,
probably to do with the type analysis rather than the
complexity of the abs function or the Float cast directly.
It's still worth raising a bug at https://bugs.swift.org with
the snippet though.
On Sep 7, 2016, at 11:32 AM, Lou Zell via swift-users <swift-users@swift.org> wrote:
Also hoping someone more knowledgeable can explain why these seemingly simple cases do in fact take so long! :)
_______________________________________________
swift-users mailing list
swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users
Also hoping someone more knowledgeable can explain why these seemingly
simple cases do in fact take so long! :)
Matt Gallagher wrote an excellent article where he explained how seemingly simple expressions can sometimes cause an enormous amount of work for the type checker because it has so many overloads to consider:
A must reading, at least I understand that is a compiler bug that
could happen with type conversion. Also, a workaround can be
easily done.
On this September 7, I hope that we will have a new release :-)
···
Le 07/09/2016 à 11:47, Ole Begemann via swift-users a écrit :
Matt Gallagher wrote an excellent article where he
explained how seemingly simple expressions can sometimes cause an
enormous amount of work for the type checker because it has so
many overloads to consider: