[swift-evolution] [Pitch] Support for pure functions. Part n + 1.

Nicolas Fezans nicolas.fezans at gmail.com
Fri Feb 17 01:59:58 CST 2017


> Not only that, but even if you pass a value type as a parameter, that
value type might have reference types as ivars.

I think that arguments passed to a pure function shall be checked against
containing such references or objects that contains such references
themselves: I guess that this check could be made by the compiler.
Programmers will then have to see whether they choose a) to go to "pure
value-type arguments" (i.e. not containing directly nor indirectly such
references) and be able to declare some of their functions as pure or b) to
keep these references and not declare the corresponding functions as pure.

This seems to me to be the first and relatively easy way to solve this
problem. Later on I could imagine even that the compiler would be clever
enough to check whether the contained references are used (regardless of
whether it is just for a read access or also to mutate some values existing
outside the scope of the function itself) and if they are not used the
purity of the function could be validated also in that case.


Nicolas



On Fri, Feb 17, 2017 at 8:26 AM, Charles Srstka via swift-evolution <
swift-evolution at swift.org> wrote:

> On Feb 16, 2017, at 1:27 PM, Sean Heber via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > Doesn’t this break down if you can pass a reference as a parameter to a
> pure function? If that’s not allowed, I guess I must have missed it. Also
> this seems to require the function has a return value. I suppose generally
> a pure function without a return value wouldn’t make much sense - unless
> you pass it a reference.
>
> Not only that, but even if you pass a value type as a parameter, that
> value type might have reference types as ivars. So since any call to any
> reference type can potentially mutate it, and any call to any value type
> could call through to a reference type which might then be mutated, it does
> seem that purity is quite difficult to guarantee.
>
> Charles
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170217/bd23f010/attachment.html>


More information about the swift-evolution mailing list