[swift-evolution] [Pitch] Support for pure functions. Part n + 1.
Michel Fortin
michel.fortin at michelf.ca
Mon Feb 20 18:39:00 CST 2017
> Le 20 févr. 2017 à 17:56, David Sweeris <davesweeris at mac.com> a écrit :
>
> Could we only infer purity for one “level”? As a technical limitation rather than part of the language spec, to be removed at some later date when we have time to implement the diagnostic logic? So in your example, the purity of func2 or func3 could be inferred, but the other would have to be annotated.
This is not about the diagnostic logic. It's simply that the diagnostic messages will almost always be overwhelming by necessity of having enough information to properly debug the problem.
For instance, you add a `print("debug info: blah")` in a few places, one of them being `func3`, and suddenly functions all over your code base start screaming they can no longer compile. None of these errors occur where you made a change, you have to follow the "call stack" in the compiler logs to find why the assumption about purity doesn't hold anymore. Example:
error: func1 cannot be pure because it calls func2 which isn't pure.
note: func2 isn't pure because it calls func3 which isn't pure.
note: func3 isn't pure because it calls Swift.print which isn't pure
error: foo cannot be pure because it calls bar which isn't pure.
note: bar isn't pure because it calls baz which isn't pure.
note: baz isn't pure because it calls raa which isn't pure.
note: raa isn't pure because it calls func3 which isn't pure.
note: func3 isn't pure because it calls Swift.print which isn't pure
error: wee cannot be pure because it calls ery which isn't pure.
note: ery isn't pure because it calls tyi which isn't pure.
note: tyi isn't pure because it calls func3 which isn't pure.
note: func3 isn't pure because it calls Swift.print which isn't pure
This isn't a good user experience. I've done enough C++ template debugging to know how confusing this can be.
While if you write `pure` in front of every function as you edit those functions, this doesn't happen. Errors aren't spread all over the call tree and are easier to link to specific edits.
--
Michel Fortin
https://michelf.ca
More information about the swift-evolution
mailing list