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

Charles Srstka cocoadev at charlessoft.com
Fri Feb 17 10:34:50 CST 2017


> On Feb 17, 2017, at 7:37 AM, David Hart <david at hartbit.com> wrote:
> 
> On 17 Feb 2017, at 08:59, Nicolas Fezans via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>> > 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.
> 
> Wouldn't we need a way to declare value semantics? Array has such references but has value semantics so should be fine, no?

Arrays can contain reference types. If you have an array of references, you can call a mutating function on one of them…

There’s also the other built-in value types that are backed by reference types: URL is backed by NSURL, Data is backed by NSData. They won’t mutate, because they’re set up to make sure they get immutable versions of them, but how is the compiler going to prove it?

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170217/552023c3/attachment.html>


More information about the swift-evolution mailing list