March 29, 2022
On Tuesday, 29 March 2022 at 13:49:41 UTC, Max Samukha wrote:
> [snip]
>
> Nice! I didn't know it'd been added to object.d.

Same.

I can't recall, but in the examples where they have imported!"std.XXX".YYY, am I right that it all of XXX for that declaration?
March 29, 2022

On Tuesday, 29 March 2022 at 14:00:20 UTC, jmh530 wrote:

>

On Tuesday, 29 March 2022 at 13:49:41 UTC, Max Samukha wrote:

>

[snip]

Nice! I didn't know it'd been added to object.d.

Same.

I can't recall, but in the examples where they have imported!"std.XXX".YYY, am I right that it all of XXX for that declaration?

imported!"XXX".YYY imports the symbol YYY from the module named XXX. It doesn't use selective imports (although I think it could with opDispatch), so the whole module named XXX will be imported. XXX could be std.algorithm.iteration, but also mir.ndslice, vibe.core.net, or any other module from a D library (of course, assuming you have that third-party library installed somehow, say with Dub).

In the case of Phobos, there's a convenience module called std that publicly imports most of Phobos, so you simply say imported!"std".map, instead of imported!"std.algorithm".map, or imported!"std.algorithm.iteration".map. Of course, importing the whole Phobos will make your compilation slower, but for now that's the price to pay for a bit of convenience.
Even though some regard import std; as an anit-pattern, I think it's a nice feature and it's the compiler's job to make it fast (e.g. assuming the Phobos source files rarely change, the compiler could generate an import cache file to make look ups faster).

March 29, 2022

On Tuesday, 29 March 2022 at 16:23:12 UTC, Petar Kirov [ZombineDev] wrote:

>

[snip]

imported!"XXX".YYY imports the symbol YYY from the module named XXX. It doesn't use selective imports (although I think it could with opDispatch), so the whole module named XXX will be imported. XXX could be std.algorithm.iteration, but also mir.ndslice, vibe.core.net, or any other module from a D library (of course, assuming you have that third-party library installed somehow, say with Dub).

[snip]

Thanks!

March 29, 2022
On Tue, Mar 29, 2022 at 04:23:12PM +0000, Petar via Digitalmars-d wrote: [...]
> Even though some regard `import std;` as an anit-pattern, I think it's a nice feature and it's the compiler's job to make it fast (e.g. assuming the Phobos source files rarely change, the compiler could generate an import cache file to make look ups faster).
[...]

To add more substance to this discussion, I decided to make some real measurements on the impact of `import std;`.

The following timings were obtained by compiling the same input file 100 times with dmd. The loop was done in the shell, so there's likely to be some shell overhead, but I'm making the assumption that this is negligible.

// Empty main() with no imports (base case)
real	0m12.830s
user	0m9.970s
sys	0m2.822s

// Empty main() with `import std;`
real	1m21.429s
user	1m7.603s
sys	0m13.529s

// Empty main() with `import std.stdio;`
real	0m17.745s
user	0m13.888s
sys	0m3.793s

// main() prints "Hello, World!" with `import std.stdio;`
real	0m20.710s
user	0m16.317s
sys	0m4.316s

// main() prints "Hello, World!" with `import std;`
real	1m21.547s
user	1m7.709s
sys	0m13.549s

The impact of `import std;` is quite apparent. It adds about a minute to the overall compile time, over a more specific `import std.stdio;`. Invoking `writeln` adds only 3 seconds to the measurement, negligible.

Though keep in mind that these measurements are magnified 100x, so the actual impact of `import std;` (when compiling only once) is only about 0.8s.

//

I was curious about how this compares with the impact of using some of the well-known heavyweight template functions like writefln. So here are some further measurements:

// `import std.stdio;` with `writefln("Hello, %s!", "World");`
real	0m58.014s
user	0m48.912s
sys	0m8.858s

// `import std;` with `writefln("Hello, %s!", "World");`
real	1m33.955s
user	1m19.148s
sys	0m14.460s

Interestingly enough, the impact of `import std;` vs `import std.stdio;` seems narrower here. The instantiation of writefln added about 30-40 seconds to the measurement in the `import std.stdio;` case, but seems to have less impact in the `import std;` case.  This suggests that in non-trivial template-heavy code, the cost of instantiating templates may quickly overshadow the overhead of `import std;`, which jives with my own experience in my recent projects (`import std;` is just so darned convenient I have little motivation for writing specific imports!).


T

-- 
Life is unfair. Ask too much from it, and it may decide you don't deserve what you have now either.
March 29, 2022
On Tuesday, 29 March 2022 at 17:13:14 UTC, H. S. Teoh wrote:
> [snip]

Interesting. Thanks.

I know it's annoying to endless produce performance comparisons, but it would be interesting to see the impact of selective imports and whether the imported template as in below has an impact.
```
void main() {
    with(imported!"std.stdio") {
        writeln("Hello, World!");
    }
}
```
March 29, 2022
On Tue, Mar 29, 2022 at 05:52:14PM +0000, jmh530 via Digitalmars-d wrote: [...]
> I know it's annoying to endless produce performance comparisons, but
> it would be interesting to see the impact of selective imports and
> whether the imported template as in below has an impact.
> ```
> void main() {
>     with(imported!"std.stdio") {
>         writeln("Hello, World!");
>     }
> }
> ```

Using `with(imported!"std.stdio")`, printing "Hello, World!":

real	0m20.430s
user	0m16.199s
sys	0m4.153s

Basically, indistinguishible from the global `import std.stdio;` case. (I consider sub-second differences as noise in the measurement, it's not significant.)


T

-- 
BREAKFAST.COM halted...Cereal Port Not Responding. -- YHL
March 30, 2022

On Tuesday, 29 March 2022 at 07:25:57 UTC, Max Samukha wrote:

>

On Tuesday, 29 March 2022 at 07:06:57 UTC, Timon Gehr wrote:

>

On 28.03.22 16:34, H. S. Teoh wrote:

>
import std.stdio;
int main() => !(1 + "Hello World".puts);

int main() => !~"Hello World".puts;

Or simply int main() => "Hello World".puts < 0;

Why not pragma(msg, "Hello World");

March 30, 2022

On Wednesday, 30 March 2022 at 08:13:48 UTC, Andrea Fontana wrote:

>

Why not pragma(msg, "Hello World");

Because pragma(msg) is an inglorious hack. We need proper I/O at compile time.

March 30, 2022
On Wed, Mar 30, 2022 at 08:34:09AM +0000, Max Samukha via Digitalmars-d wrote:
> On Wednesday, 30 March 2022 at 08:13:48 UTC, Andrea Fontana wrote:
> 
> > 
> > Why not ```pragma(msg, "Hello World");```
> 
> Because pragma(msg) is an inglorious hack. We need proper I/O at
> compile time.

And pragma(msg) is technically not your program outputting the message,
but the compiler. You need to put it in main() for a proper
implementation of Hello World. ;-)


T

-- 
It only takes one twig to burn down a forest.
March 30, 2022
On Wednesday, 30 March 2022 at 15:49:08 UTC, H. S. Teoh wrote:

>
> And pragma(msg) is technically not your program outputting the message,
> but the compiler. You need to put it in main() for a proper
> implementation of Hello World. ;-)
>
>
> T

template add(int x)
{
    pragma(msg, x);
    int add(int y)
    {
        import std.stdio: writeln;
        writeln(y);
        return x + y;
    }
}

void main()
{
    auto z = add!1(2);
}

Is this a program that starts at compile time and continues at run time, or a meta-program that generates another program? )