<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPad</div><div><br>On Mar 6, 2017, at 1:39 AM, Robert Widmann via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>If this were a problem that could be fixed by tooling, you'd be submitting this proposal against the package manager.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">It's important to note I'm approaching this problem from the principles that underpin modular programming practices in other languages, it is not merely "philosophical". &nbsp;A proposal that claims to support submodules should come with some consistent support for modularity or rebrand to more honestly reflect its contents. &nbsp;</div></div></blockquote><div><br></div><div>Robert, you have said several times that ideas suggested by others are not modular and have referenced other languages in the process. &nbsp;Yet (as far as I know) you haven't actually defined what you believe "modular" means or referenced other languages that you believe provide modularity in the way you are looking for. &nbsp;Perhaps it would be useful if you provide or reference a definition and mention some specific languages you believe provide good modularity. &nbsp;</div><div><br></div><div>I believe your proposal mentions the ML module system as specifically not providing the kind of modularity you are looking for. &nbsp;That makes sense because Swift's protocols already offer similar features. &nbsp;But that doesn't offer much insight into what you specifically mean by modularity or what other languages inspired that understanding.</div><div><br></div><div>I hope you are willing to elaborate further on this.</div><br><blockquote type="cite"><div><div id="AppleMailSignature">As it stands, this proposal effectively introduces another level of access (while paradoxically claiming to avoid access control discussions), and suggests more access control to support its contents later. &nbsp;Maybe discussion should start there instead of with "submodules".</div><div id="AppleMailSignature"><br>~Robert Widmann</div><div><br>2017/03/06 0:39、Michel Fortin &lt;<a href="mailto:michel.fortin@michelf.ca">michel.fortin@michelf.ca</a>&gt; のメッセージ:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On 5 mars 2017, at 22:28, 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="">This proposal strikes me not as a submodules proposal, but as a sneaky way to add 'friend' to Swift. &nbsp;It is conceptually simpler because it doesn't address modularity at all!<br class=""><br class="">~Robert Widmann<br class=""><br class="">2017/03/05 17:16、Michel Fortin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; のメッセージ:<br class=""><br class=""><blockquote type="cite" class="">Sorry for introducing yet another submodule proposal out of the blue.<br class=""><br class="">I'm a bit surprised at how far-reaching the various submodule proposals floated on this list have been. Directories, access controls, @exported imports... For comparison's sake here's one that is *really* simple and short I wrote today. Best of all: it requires no new access modifier. <br class=""><br class="">I also expect everyone to scream at it because it does not include all the desirable features of a submodule system. At the very least I'll have redefined the meaning of lightweight in that discussion. Good reading.<br class=""><br class="">Also available here: <br class=""><a href="https://gist.github.com/michelf/779b1bc26a778051b6231b5639665e18" class="">https://gist.github.com/michelf/779b1bc26a778051b6231b5639665e18</a><br class=""><br class=""><br class="">## Motivation<br class=""><br class="">The goal of this proposal is to provide lightweight intra-module boundaries so you can avoid exposing every `internal` declaration within a big module to all other files in the module.<br class=""></blockquote><br class="">I don't think this was a stated goal of anybody because that’s not the primary issue submodules are trying to solve. &nbsp;Projects with a large amount of internal declarations may be clamoring to be put into multiple (sub)modules, but because the style most have converged on doesn’t usually involve a large amount of free functions, your internal declarations are usually types and as such have members that are already encapsulated.<br class=""></div></div></blockquote><div><br class=""></div><div>Well maybe that's just a problem specific to me, but that's the goal I'd like submodule to solve. If I have four intermingled classes, I'd like to restrict the&nbsp;interminglement to those four classes. My current options for that are a) to create a separate module, b) to put them all in the same file with `fileprivate`, or c) tolerate that the rest of the module will see everything all the time with `internal`. I'm choosing (c) at the present time because (a) is too much work and (b) is more messy.</div><div><br class=""></div><div>You are absolutely right in your observation that it's some sort of "friend". But then the same observation could apply to the `internal` members in a module or the `fileprivate` members in a file. The delimiting boundaries are different, but the concept is the same. What I want is the ability to better define those boundaries.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class="">Not a goal: addressing the file-level access fileprivate/private or scoped/protected debates. This is left to other proposals.<br class=""><br class=""><br class="">## Summary<br class=""><br class="">This proposal adds the declarations `submodule` and `import submodule`. It also limits the visibility of `internal` to files with a matching `submodule` or `import submodule` declaration.<br class=""><br class="">Submodules are never exposed outside of the module. They only change the visibility of internal declarations, so there is no point in exposing them publicly.<br class=""><br class="">Submodules are not bound to directories, nor are they necessarily hierarchical.<br class=""><br class="">This change is purely additive and introduces no source compatibility issue.<br class=""></blockquote><br class="">This particular set of changes is, but the `import submodule` change is source-breaking in that we already have syntax for this.<br class=""></div></div></blockquote><div><br class=""></div><div>Good catch. If you have a module called "submodule" and you import it, that'll break.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class=""><br class=""><br class="">## Details<br class=""><br class="">A `submodule &lt;name&gt;` declaration at the beginning of a file contains an identifier with the submodule name:<br class=""><br class=""> &nbsp;submodule Foo<br class=""><br class=""> &nbsp;internal func foo() {}<br class=""> &nbsp;public func pub() {}<br class=""><br class="">`internal` declarations within that file are only visible to other files sharing the same submodule name. The submodule only protects `internal` declarations: `public` declarations in the file are visible everywhere (in other submodules and in other modules).<br class=""><br class=""></blockquote><br class="">This definition of public is anti-modular. &nbsp;It seems as though this style of submodule will encourage people to split their definitions across multiple files (good) then provide a pile of submodule-membership definitions to intertwine them with each other as they need access to each other’s symbols (bad). A module is a self-contained entity by definition. &nbsp;Dependencies should generally be on further child (sub)modules - vertically, not horizontally.</div></div></blockquote><div><br class=""></div><div>I'll say that this definition of `public` is quite handy as long as the submodules are implementing public-facing functionality. I agree it is less useful when the submodule is the backend of some other component in the module. You are thus right in that it naturally organizes things horizontally.</div><div><br class=""></div><div>So if you want to use submodules to organize self-contained dependencies, my approach does not work very well. In particular, there is no containment of anything `internal` when you `import submodule Foo`. That would be improved if we had submodule-private as discussed in Future Directions... with the caveat that it's still easy to access any submodule's internals by declaring any file to be part of the submodule. And also you want a strict hierarchy, which this proposal completely eschew.</div><div><br class=""></div><div>We obviously have a different philosophy on how strict and hierarchic the submodules should be. I say the strictness should stay at the module boundaries. If you want enforced self-contained modules, change those submodules into full modules. If you want to ship the whole thing as a single library, then we need to adapt the tooling so you can merge privately those modules inside of the main library. (Ideally this would be done with a single compiler invocation, allowing full cross-module optimization.) This is a tooling and packaging problem that does not need to leak into a plethora of new language concepts. At least, this is how I see it.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class="">A file can be part of more than one submodule:<br class=""><br class=""> &nbsp;submodule Foo<br class=""> &nbsp;submodule Bar<br class=""><br class=""> &nbsp;internal func achoo() {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo() // available in Foo (from other file)<br class=""> &nbsp;}<br class=""><br class="">This makes the internal `achoo` function visible within both the `Foo` and `Bar` submodules. Also note that it makes internal members of both submodules `Foo` and `Bar` visible within the file.<br class=""><br class="">A file can access internal declarations of a submodule without having to expose its own internal functions to the submodule with `import submodule`:<br class=""><br class=""> &nbsp;submodule Test<br class=""> &nbsp;import submodule Foo<br class=""><br class=""> &nbsp;internal func test() {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo() // internal, imported from Foo<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;achoo() // internal, imported from Foo<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pub() // public, so always visible<br class=""> &nbsp;}<br class=""><br class="">Finally, when a file has no submodule declaration, its internal declarations are visible everywhere in the module and all its submodules:<br class=""><br class=""> &nbsp;--- Hello.swift ---<br class=""> &nbsp;// no submodule declaration<br class=""> &nbsp;internal func hello() {}<br class=""><br class=""> &nbsp;--- World.swift ---<br class=""> &nbsp;submodule World<br class=""> &nbsp;internal func test() {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hello() // visible!<br class=""> &nbsp;}<br class=""><br class=""><br class="">## Nitpicky Details (Conflicting Declarations)<br class=""><br class="">Declaring `internal` things that share the same name in two separate submodules is not a conflict:<br class=""><br class=""> &nbsp;--- Foo1.swift ---<br class=""> &nbsp;submodule Foo1<br class=""> &nbsp;class Foo {} // added to Foo1<br class=""><br class=""> &nbsp;--- Foo2.swift ---<br class=""> &nbsp;submodule Foo2<br class=""> &nbsp;submodule Foo3<br class=""> &nbsp;class Foo {} // added to Foo2 and Foo3<br class=""><br class="">(Note: It would be a conflict if one of them was `public`, because `public` declarations are always visible everywhere inside (and outside of) the module.)<br class=""><br class="">Attempting to use both from another submodule will create ambiguity errors. You can disambiguate using the submodule name as a prefix:<br class=""><br class=""> &nbsp;--- Main.swift ---<br class=""> &nbsp;import submodule Foo1<br class=""> &nbsp;import submodule Foo2<br class=""> &nbsp;import submodule Foo3<br class=""> &nbsp;let f0 = Foo() // ambiguity error<br class=""> &nbsp;let f1 = Foo1.Foo() // good<br class=""> &nbsp;let f2 = Foo2.Foo() // good<br class=""> &nbsp;let f3 = Foo3.Foo() // good<br class=""><br class="">Best to avoid this for your own sanity however.<br class=""><br class=""><br class="">## Alternatives Considered<br class=""><br class="">### Conflicting Declarations<br class=""><br class="">Instead of allowing conflicting symbols in different submodules, we could continue to disallow conflicting `internal` declarations even when they belong to different submodules. This would make the design simpler, as it is closer to how `internal` currently works and prevent ambiguity errors from arising when importing multiple submodules. The behavior would be a little surprising however.<br class=""><br class="">We could also simplify by removing the ability to use the submodule name as a prefix to disambiguate. This has the advantage that if you put a type inside of a submodule with the same name, no conflict can arise between the name of the type and the name of the submodule. Disambiguation would have to be done by renaming one of the conflicting declarations. Since this ambiguity can only affect `internal` declarations (submodules only group internal declarations), requiring a rename will never break any public API. But forcing a rename is not a very elegant solution.<br class=""><br class="">### `import` syntax<br class=""><br class="">Renaming `import submodule` to `import internal`. Having "internal" in the name could make it clearer that we are giving access to internal declarations of the submodule. But it also make the import less relatable to the `submodule` declaration in other files.<br class=""><br class=""><br class="">## Future Directions<br class=""><br class="">### Submodule-Private<br class=""><br class="">While a submodule-private access modifier could have been added to this proposal, the belief is that this proposal can live without it, and not having this greatly reduce the little details to explore and thus simplifies the design.<br class=""><br class="">In many cases you can work around this by putting "private" stuff in a separate submodule (somewhat similar to private headers in C land). For instance:<br class=""><br class=""> &nbsp;--- Stuff.swift ---<br class=""> &nbsp;submodule Stuff<br class=""> &nbsp;submdoule StuffImpl<br class=""><br class=""> &nbsp;func pack() { packImpl() }<br class=""><br class=""> &nbsp;--- StuffImpl.swift ---<br class=""> &nbsp;submodule StuffImpl<br class=""><br class=""> &nbsp;func packImpl() { ... }<br class=""><br class="">This will not work for stored properties however. A future proposal could suggest allowing stored properties in extensions to help with this.<br class=""><br class="">And a future proposal could also add submodule-private to limit visibility of some declarations to only those files that are part of a specific module. <br class=""><br class=""><br class="">-- <br class="">Michel Fortin<br class=""><a href="https://michelf.ca" class="">https://michelf.ca</a><br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote></div></div></blockquote></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">--&nbsp;<br class="">Michel Fortin</div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="text-align: -webkit-auto;" class=""><a href="https://michelf.ca" class="">https://michelf.ca</a></span></div></span></div></span></div></span></div></div></div></div>
</div>
<br class=""></div></blockquote></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>