Jump to page: 1 2 3
Thread overview
Header-Only Library - pragma(root)
Jun 14, 2020
Walter Bright
Jun 14, 2020
Tove
Jun 14, 2020
Max Samukha
Jun 14, 2020
Ali Çehreli
Jun 14, 2020
Max Samukha
Jun 14, 2020
Walter Bright
Jun 14, 2020
Stanislav Blinov
Jun 14, 2020
Mathias LANG
Jun 14, 2020
Walter Bright
Jun 14, 2020
Stefan Koch
Jun 14, 2020
Stefan Koch
Jun 14, 2020
Adam D. Ruppe
Jun 15, 2020
Adam D. Ruppe
Jun 16, 2020
Mathias LANG
Jun 17, 2020
Adam D. Ruppe
Jun 17, 2020
Mathias LANG
Jun 15, 2020
Walter Bright
Jun 15, 2020
Adam D. Ruppe
Jun 14, 2020
Adam D. Ruppe
Jun 14, 2020
Seb
Jun 15, 2020
Adam D. Ruppe
Jun 15, 2020
Paolo Invernizzi
Jun 16, 2020
novice2
Jun 14, 2020
Johannes Pfau
Jun 14, 2020
Stefan Koch
June 14, 2020
There is much misunderstanding in the "What does 'inline' mean?" thread.

I've slowly come to realize that it's not about inlining at all, it's about a desire for "header-only" libraries. To use a header-only library, you only have to import the module for it.

This works today in D if you also add the imported module to the command line. But, of course, it's good to make it simpler.

So, I propose the addition of `pragma(root);` which looks like:

--- electron.di ---
module electron;
pragma(root);    // header-only library!

int orbit() { return 3; }

--- atom.d ---
module atom;
import core.stdc.stdio;

import electron;

void main() {
    printf("%d orbits\n", orbit());
}
--------------

To compile, just:

  dmd atom

and the pragma(root) will cause the compiler to behave as if you'd typed:

  dmd atom electron

Not only does this make for header-only libraries, but if you have a project that is split up into several modules, it becomes super convenient to compile it if the other modules are all annotated with pragma(root).

Note that there's no "inline" anywhere. Inlining will remain about inlining, and nothing else.
June 14, 2020
On Sunday, 14 June 2020 at 08:36:50 UTC, Walter Bright wrote:
> There is much misunderstanding in the "What does 'inline' mean?" thread.
>
> I've slowly come to realize that it's not about inlining at all, it's about a desire for "header-only" libraries. To use a header-only library, you only have to import the module for it.
>
> This works today in D if you also add the imported module to the command line. But, of course, it's good to make it simpler.
>
> So, I propose the addition of `pragma(root);` which looks like:
>
> --- electron.di ---
> module electron;
> pragma(root);    // header-only library!
>

I like this feature.

Could *.di always be root?

June 14, 2020
On Sunday, 14 June 2020 at 08:36:50 UTC, Walter Bright wrote:

> To compile, just:
>
>   dmd atom
>

We have -i already for automatic inclusion of imported modules:

dmd atom -i=.

What does the pragma add to this?

I think Manu was asking for something different.


June 14, 2020
On 6/14/20 2:33 AM, Max Samukha wrote:

> We have -i already for automatic inclusion of imported modules:
> 
> dmd atom -i=.
> 
> What does the pragma add to this?

-i would mean "assume everything has pragma(auto_add)".

Note how I could not say "root". :) Where does it come from? Why root? Most programmers wouldn't understand it at all. "Header" wouldn't mean anything to anybody unless they are coming from C or C++.

And you said "automatic inclusion". Perhaps pragma(auto_include) but then it would confuse C and C++ programmers because they "include" header files.

Tough naming situation... :)

Ali
June 14, 2020
On 6/14/2020 2:33 AM, Max Samukha wrote:
> On Sunday, 14 June 2020 at 08:36:50 UTC, Walter Bright wrote:
> 
>> To compile, just:
>>
>>   dmd atom
>>
> 
> We have -i already for automatic inclusion of imported modules:
> 
> dmd atom -i=.
> 
> What does the pragma add to this?
> 
> I think Manu was asking for something different.

I don't know what -i does exactly, or why it was added.

https://dlang.org/dmd-windows.html#switch-i
June 14, 2020
On Sunday, 14 June 2020 at 09:42:45 UTC, Walter Bright wrote:

> I don't know what -i does exactly, or why it was added.
>
> https://dlang.org/dmd-windows.html#switch-i

https://dlang.org/dmd-windows.html#switch-i[

>.<
June 14, 2020
On Sunday, 14 June 2020 at 09:42:45 UTC, Walter Bright wrote:
> On 6/14/2020 2:33 AM, Max Samukha wrote:
>> On Sunday, 14 June 2020 at 08:36:50 UTC, Walter Bright wrote:
>> 
>>> To compile, just:
>>>
>>>   dmd atom
>>>
>> 
>> We have -i already for automatic inclusion of imported modules:
>> 
>> dmd atom -i=.
>> 
>> What does the pragma add to this?
>> 
>> I think Manu was asking for something different.
>
> I don't know what -i does exactly, or why it was added.
>
> https://dlang.org/dmd-windows.html#switch-i

https://github.com/dlang/dmd/pull/7099
It's essentially putting rdmd in the compiler because rdmd was considered too slow.
June 14, 2020
On Sunday, 14 June 2020 at 09:39:52 UTC, Ali Çehreli wrote:
> On 6/14/20 2:33 AM, Max Samukha wrote:
>
>> We have -i already for automatic inclusion of imported modules:
>> 
>> dmd atom -i=.
>> 
>> What does the pragma add to this?
>
> -i would mean "assume everything has pragma(auto_add)".

Yes. However, you can specify patterns as strict as matching single modules. Anyway, I can see the difference.

>
> Note how I could not say "root". :) Where does it come from? Why root? Most programmers wouldn't understand it at all.
> "Header" wouldn't mean anything to anybody unless they are coming from C or C++.
>
> And you said "automatic inclusion".
> Perhaps pragma(auto_include) but then it would confuse C and C++ programmers because they "include" header files.
>
> Tough naming situation... :)

pragma(static) ))

>
> Ali


June 14, 2020
On 6/14/2020 2:52 AM, Mathias LANG wrote:
> https://github.com/dlang/dmd/pull/7099
> It's essentially putting rdmd in the compiler because rdmd was considered too slow.

Thank you. I see I was involved in the discussion.

The issue is then should the implementer of the module decide if it is header-only (i.e. pragma(root)) or the caller (-i).

It would probably be better as the implementer, as a header-only library has to be designed for it. It also means the user needn't need to set the switches, he can just compile.
June 14, 2020
On Sunday, 14 June 2020 at 10:24:33 UTC, Walter Bright wrote:
> On 6/14/2020 2:52 AM, Mathias LANG wrote:
>> https://github.com/dlang/dmd/pull/7099
>> It's essentially putting rdmd in the compiler because rdmd was considered too slow.
>
> Thank you. I see I was involved in the discussion.
>
> The issue is then should the implementer of the module decide if it is header-only (i.e. pragma(root)) or the caller (-i).
>
> It would probably be better as the implementer, as a header-only library has to be designed for it. It also means the user needn't need to set the switches, he can just compile.

I agree with everything except for the name.

I same sure there are better names than root.
Perhaps extern(static) ?

Also this needs to be either restricted to leaf functions,
or draw in callees as well.
« First   ‹ Prev
1 2 3