[swift-evolution] Enhancing access levels without breaking changes

Chris Lattner clattner at nondot.org
Wed Apr 12 00:16:04 CDT 2017


On Apr 11, 2017, at 3:53 AM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
>>> I understand what you are saying and I wouldn't be against relaxing that requirement (not talking for Chris here).
>>> 
>>> The model would change from "Types share scopes with their extensions in the same file the type was defined" to "Types and their extensions share the same scope in each file".
>> 
>> Oh, I had missed that somehow.  I agree that that is a very strange rule.  Do you know why it was proposed that way?
> 
> We had to take a stance and Chris seemed to prefer the rule that was proposed. I didn't press because I'm sure he has reasons for preferring it that way. But I have a preference for generalizing visibility to all extensions, even to those in a different file than the type.

To me, the reason for limiting it to a file is about predictability, the ability to locally reason about a type, and the need to define some boundary (for symbol visibility reasons).  Saying that extensions to a type have access to private members if they are in the same module is just as arbitrary as limiting it to a single file, and a whole lot less useful from the “reasoning about a type” perspective.  

Expanding it beyond a module would require a ton of stuff to be exported that otherwise wouldn’t be, and would defeat a ton of optimization potential that we can’t accept.

-Chris



More information about the swift-evolution mailing list