<div dir="ltr">typo: <div>s/<span style="font-size:12.8px">dmd -c -o- -deps A.d/</span><span style="font-size:12.8px">dmd -c -o- -deps B.d</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 20, 2016 at 12:45 AM, Timothee Cour <span dir="ltr"><<a href="mailto:thelastmammoth@gmail.com" target="_blank">thelastmammoth@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">currently, top-level imports in a module A are visible by other modules B importing A, and are visited (recursively) during compilation of A, slowing down compilation and increasing dependencies (eg with separate compilation model, a single file change will trigger a lot of recompilations).<div><br></div><div>I propose a private import [1] to mean an import that's only used inside function definitions, not on the outside scope. It behaves exactly as if it the import occurred inside each scope (function and template definitions). This is applicable for the common use case where an import is only used for symbols inside functions, not for types in function signature.</div><div><br></div><div>----</div><div>module A;</div><div>private import util;</div><div>void fun1(){</div><div>// as if we had 'import util;'</div><div>}</div><div><div><br></div><div>void fun2(){</div><div>// as if we had 'import util;'</div><div>}</div></div><div><br></div><div>// ERROR: we need 'import util' to use baz in function declaration</div><div><div>void fun3(baz a){}</div></div><div><br></div><div>----</div><div>module util;</div><div>void bar(){}</div><div>struct baz{}</div><div><div>----</div></div><div>module B;<br></div><div>import A;</div><div><div>----</div></div><div><br></div><div>The following should not list 'util' as a dependency of B, since it's a 'private import'</div><div>dmd -c -o- -deps A.d</div><div><br></div><div><br></div><div>The benefits: faster compilation and recompilation (less dependencies).</div><div><br></div><div>NOTE [1] on syntax: currently private import just means import, we could use a different name if needed, but the particular syntax to use is a separate discussion.</div></div>
</blockquote></div><br></div>