[swift-evolution] Make non-void functions @warn_unused_result by default

Chris Lattner clattner at apple.com
Fri Dec 11 00:55:20 CST 2015

> On Dec 10, 2015, at 10:23 PM, Kametrixom Tikara <kametrixom at icloud.com> wrote:
> I think we actually have two things colliding here: Think about it, why would we need a @suppress_unused_result attribute? Because of side effects! That's the only reason we would ever need to have this attribute. Now we already have the @effects(readnone) attribute to enable optimizations for pure functions. Now we can combine both of those into one: @pure. This attribute does this:
> - It indicates that the function is purely functional (= no side-effects, same result for same input)
> - It implicitly adds the @effects(readnone) attribute to enable such optimizations
> - It implicitly adds the @warn_unused_result attribute
> To make sure that the function actually is pure we need to check that every called function within is pure itself and no external variables get accessed.
> Now the only thing to do is to make the compiler implicitly add the @pure keyword where the conditions are satisfied.
> Something I haven't thought about yet: Not being able to read external variables (@effects(readonly)) are also functions without side effects, but they're not pure, since the result doesn't have to be the same for the same input. I don't want to suggest another keyword for that (we have too many already) but I believe this is actually what we want here.

Discussions of @pure-like attributes are different, and complicated.  We also lack a mutability model for classes at the moment.


More information about the swift-evolution mailing list