<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 21, 2017, at 11:59 PM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 21, 2017, at 10:41 PM, Robert Widmann &lt;<a href="mailto:devteam.codafi@gmail.com" class="">devteam.codafi@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">By API boundaries I mean both the one internal to MyModule.Foo and the one defined by MyModule. &nbsp;Here “the API boundary” is explicitly about the submodule MyModule.Foo, whose internal state may have been “unsealed” in the top level by the extension, but has not been re-exported.<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">I’m sorry, but I just don’t understand how modules form an API boundary in this system. &nbsp;To me a boundary means something that blocks access. &nbsp;In this system `internal` ranges over the entire module and all submodules. &nbsp;The only boundaries I can see besides the module itself are files and lexical scopes (with `fileprivate` and `private`). &nbsp;</div><div class=""><br class=""></div></div></div></div></blockquote><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div><span style="color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">A module is a named region that introduces a lexical scope into which declarations may be nested. The name of the module can be used to access these member declarations. A module, like other aggregate structures in Swift, may be extended with new declarations over one or more translation units (files).</span></div><div><span style="color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div><div><span style="color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class=""><br class=""></span></div></div></blockquote><div>Your API boundary lives, as it does today, at the edges of each (sub)module declaration. &nbsp;APIs that are public or open in a module defines code that is free to move across this boundary and into the open. &nbsp;APIs that are internal are free to have their modules unsealed into other internal modules to enable modular composition. &nbsp;APIs that are private and fileprivate do not participate in the API boundary because they are not eligible for any kind of export. &nbsp;</div><div><br class=""></div><div>If any of that is unclear, please let me know.&nbsp;</div><div><br class=""></div><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">This means that it is trivial to put code anywhere within the module that extends the submodule and wraps a symbol in a new name and declares it `public`. &nbsp;</div></div></div></div></blockquote><div><br class=""></div><div>Precisely. &nbsp;That’s the same pattern that good Swift code, arguably good code in any language that enables hiding, uses today.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">They can also trivially add a `public import MyModule.Foo` anywhere at the top level of their file because <i class="">every</i>&nbsp;file is forced to include top level scope.</div></div></div></div></blockquote><div><br class=""></div><div>Perhaps you misunderstand. &nbsp;Say the APIs in MyModule.Foo were all of internal or stricter access: The re-export is a no-op. &nbsp;You <i class="">cannot</i>&nbsp;change the access level of declarations, you can only do the modular thing and wrap them in a palatable interface for export by a module you want to be user-facing. &nbsp;You have to <i class="">decide</i>&nbsp;to make an API public, just as today you have to decide to make part of an interface public. &nbsp;I don’t see how this is distinct from the goals of this proposal.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div><div class="">In my opinion, we need to identify what goals we have for a submodule system - what problems are we trying to solve and what use cases do we intend to enable. &nbsp;</div><div class=""><br class=""></div><div class="">There are quite a few of us who want the ability to form solid API boundaries <i class="">inside</i>&nbsp;a module and view this as one of the fundamental features of a submodule system. &nbsp;It’s reasonable to ask why we view this capability as essential.</div><div class=""><br class=""></div><div class="">I can’t speak for anyone else, but here are a few reasons why it’s important to me:</div><div class=""><br class=""></div><div class="">* Solid API boundaries are essential to good design. &nbsp;</div><div class="">* Having access to an entire code base does not reduce the benefits of #1. &nbsp;Some code bases are substantial in size and hard boundaries are important to keeping them manageable.</div><div class="">* Using full-fledged modules to do this is possible, but also involves a bit of ceremony that is incidental, not essential complexity in many cases. &nbsp;It would be better to have a lighter weight mechanism to do this.</div><div class="">* Swift currently only has whole module optimization, not whole program optimization. &nbsp;There is a performance penalty to using full-fledged modules.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">~Robert Widmann<br class=""><br class=""><blockquote type="cite" class="">On Feb 21, 2017, at 11:38 PM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Feb 21, 2017, at 10:29 PM, Robert Widmann &lt;<a href="mailto:devteam.codafi@gmail.com" class="">devteam.codafi@gmail.com</a>&gt; wrote:<br class=""><br class="">This level of access, the “private to this submodule except to the select set of interfaces I want to see it” level, is the equivalent of friend classes in C++. &nbsp;I don’t consider leaving this out to be a hole, nor is it an "encapsulation-related problem” because at no point can you break the API boundary and re-export anything here with a higher level of access than it had previously.<br class=""></blockquote><br class="">By API boundary you mean the top-level module, right?<br class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">On Feb 21, 2017, at 11:13 PM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Feb 21, 2017, at 10:11 PM, Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Feb 21, 2017, at 9:47 PM, Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">On Feb 21, 2017, at 7:38 PM, Robert Widmann &lt;<a href="mailto:devteam.codafi@gmail.com" class="">devteam.codafi@gmail.com</a>&gt; wrote:<br class=""><br class="">Correct. &nbsp;Because, in dividing the submodule across an extension, you have placed what should be a private API into a differently-scoped location.<br class=""></blockquote><br class="">Okay. So is your submodule design not intended to address the "I want to encapsulate implementation details so they're only visible to several units of code in different files, but not the entire module" use case? Because if there's no way to scope a symbol to "everything inside this submodule, but nothing outside this submodule", I think it leaves that use case unserved.<br class=""></blockquote><br class="">Unless I’m missing something there is also another encapsulation-related problem with the proposed design. &nbsp;Let’s suppose for the sake of discussion there was a `submoduleprivate` access modifier (intentionally ungainly and not realistic).<br class=""><br class="">// File 1<br class="">module Foo {<br class="">// internal, visible to the whole module<br class="">class Bar { submoduleprivate var protectedState: Int = 0 }<br class="">}<br class=""><br class="">// File 2 - Has nothing to do with Foo at all<br class="">import MyModule.Foo<br class=""><br class="">module NotFoo {<br class="">// Hey, I need to see Bar.protectedState!!!<br class="">func totallyNotFoo() {<br class=""> &nbsp;&nbsp;var bar = Bar()<br class=""> &nbsp;&nbsp;bar.foosExposedPrivates = 42<br class="">}<br class="">}<br class=""><br class="">// ok, I’ll just add an extension to Foo so I can see submoduleprivate and wrap what I need<br class="">module Foo {<br class=""></blockquote><br class="">Oops, this should have been `extension Foo`, but otherwise I believe it is valid under this proposal.<br class=""><br class=""><blockquote type="cite" class="">// Hey, I’ll be nice and keep it fileprivate, but I could make it public if I wanted to.<br class="">extension Foo {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;fileprivate var foosExposedPrivates: Int {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Yep, I’m inside Foo so I can see it’s submoduleprivate stuff<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get { return protectedState }<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set &nbsp;{ protectedState = newValue }<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;}<br class="">}<br class="">}<br class=""><br class=""><blockquote type="cite" class=""><br class="">-- <br class="">Brent Royal-Gordon<br class="">Architechies<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote><br class=""></blockquote><br class=""></blockquote><br class=""></blockquote><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>