Thread overview
Re: proposal: private module-level import for faster compilation
Jul 20, 2016
Timothee Cour
Jul 22, 2016
Bauss
Jul 22, 2016
sdhdfhed
July 20, 2016
typo:
s/dmd -c -o- -deps A.d/dmd -c -o- -deps B.d

On Wed, Jul 20, 2016 at 12:45 AM, Timothee Cour <thelastmammoth@gmail.com> wrote:

> 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).
>
> 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.
>
> ----
> module A;
> private import util;
> void fun1(){
> // as if we had 'import util;'
> }
>
> void fun2(){
> // as if we had 'import util;'
> }
>
> // ERROR: we need 'import util' to use baz in function declaration
> void fun3(baz a){}
>
> ----
> module util;
> void bar(){}
> struct baz{}
> ----
> module B;
> import A;
> ----
>
> The following should not list 'util' as a dependency of B, since it's a
> 'private import'
> dmd -c -o- -deps A.d
>
>
> The benefits: faster compilation and recompilation (less dependencies).
>
> 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.
>


July 22, 2016
On Wednesday, 20 July 2016 at 07:50:13 UTC, Timothee Cour wrote:
> typo:
> s/dmd -c -o- -deps A.d/dmd -c -o- -deps B.d
>
> On Wed, Jul 20, 2016 at 12:45 AM, Timothee Cour <thelastmammoth@gmail.com> wrote:
>
>> [...]

I believe private import is already reserved. It's being used 618 places inside of official D code.

See: https://github.com/search?q=org%3Adlang+private+import&type=Code
July 22, 2016
On Friday, 22 July 2016 at 10:47:33 UTC, Bauss wrote:
> On Wednesday, 20 July 2016 at 07:50:13 UTC, Timothee Cour wrote:
>> typo:
>> s/dmd -c -o- -deps A.d/dmd -c -o- -deps B.d
>>
>> On Wed, Jul 20, 2016 at 12:45 AM, Timothee Cour <thelastmammoth@gmail.com> wrote:
>>
>>> [...]
>
> I believe private import is already reserved. It's being used 618 places inside of official D code.
>
> See: https://github.com/search?q=org%3Adlang+private+import&type=Code

it's legit in several tests that verify the protection attributes but otherwise it's approximatively 600 times useless ;) since import are private by default.

But therorically you're right, it already has a specific semantic. And it's probably perfectly legit in some cases, like here:

    public:
       declA;
       declB;
       private import stuff;
       declX;

where it's used to temprarily override the protection attribute of the scope.