Creating lenses with Swift macros (usecase for arbitrary names at the global scope)

In tera's version example, the inout parameters to birthday and nameChange were changed to regular value parameters, so the calls birthday(me) and nameChange(me) will pass a copy of me at the point of the call instead of attempting to make an overlapping write access. So there wouldn't be any exclusivity trap in that case.

The upcoming strict concurrency checking for global variables will hopefully help discourage wanton use of mutable global variables, since the safety implications of shared global state will be more in your face with strict concurrency checking enforced. I do think it would be nice to formalize a "pure" function annotation that prevents accessing shared mutable state and only allows immutable and/or local mutation operations.

11 Likes