Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, February 08, 2018 20:16:22 Marc via Digitalmars-d-learn wrote:
> What's a di file? (sorry google didn't help with that)

I"m not sure where the documentation for it is, but it's the D equivalent of
a header file. Basically, it's essentially the same as a .d file except that
it's only imported, never compiled. So, it just contains declarations and
stuff that has to be defined in order to be used when importing (e.g.
templates and anything used during CTFE has to be in the .di file). It's
essentially a stripped down version of the .d file.

So, if a library is going to use a .di file, it declares a .d file as per
normal, and that's compiled into the library, but then a .di file is
distributed with the library instead of a .d file, and that's what a program
using the library would import instead of the .d file. The import itself
doesn't change in any way, but the program then only sees what's declared in
the .di version of the module instead of the .d version.

The whole reason that .di files exist is to provide a way for someone to
distribute a library without distributing the full source (which is
something that companies often like to do). It's a pretty restrictive
feature though, since templates still have to be in the .di file, and if
something isn't defined in the .di file instead of just declared, then it
can't be used with CTFE. And with how much templates and CTFE gets used in a
lot of D code, that tends to mean that either you give up on those features,
or you're forced to put a lot of your implementation in the .di file anyway,
making them kind of useless. So, most of use don't go anywhere near .di
files, and personally, I wish that the feature didn't exist, but it's the
kind of thing that some companies insist on.

- Jonathan M Davis



Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 8 February 2018 at 20:16:22 UTC, Marc wrote:

What's a di file? (sorry google didn't help with that)


A di file is just a D file that, by convention, only has function 
signatures without bodies.


Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Marc via Digitalmars-d-learn
On Thursday, 8 February 2018 at 07:21:05 UTC, Jonathan M Davis 
wrote:
On Wednesday, February 07, 2018 13:39:55 Timothee Cour via 
Digitalmars-d- learn wrote:

[...]


It's useful with stuff like version(Ddoc).


[...]




What's a di file? (sorry google didn't help with that)
It's been my understanding that it's always been illegal to 
provide a definition for a function that was declared 
previously unless it was declared in a .di file, in which case, 
you're not really both declaring and defining it, but the .d 
file is used when the module is compiled, and the .di file is 
used by other modules which use that module, so the declaration 
and definition are not seen by the same run of the compiler.


- Jonathan M Davis




Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
makes sense to show these (version X11), but that could be done using
dmd and a special flag instead of having to rely on a new parser
(which would need to be kept updated)



On Thu, Feb 8, 2018 at 6:49 AM, Adam D. Ruppe via Digitalmars-d-learn
 wrote:
> On Thursday, 8 February 2018 at 09:42:08 UTC, Timothee Cour wrote:
>>
>> I guess you mean `version(StdDdoc)` ?
>>
>> On that note, I see things like this, which are not DRY:
>
>
> This is actually one of the reasons why I abandoned dmd for my dpldocs.info
> fork and used an independent parser.
>
> dmd tries to build docs as it builds the program, but these are slightly
> contradictory - when building the program, you need to honor versioned out
> blocks. When building the docs, you just want it documented, not ignored.
> dmd is (rightfully) prioritized toward building actual code, but that leaves
> doc generation a bit second-hand.
>
> To work around dmd's clashing goals, version(StdDdoc) manually makes a
> separate doc branch.
>
> Whereas my doc generator just shows them all, bringing the version into the
> definition.
> http://dpldocs.info/experimental-docs/arsd.simpledisplay.XDisplayConnection.html
>


Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 8 February 2018 at 09:42:08 UTC, Timothee Cour wrote:

I guess you mean `version(StdDdoc)` ?

On that note, I see things like this, which are not DRY:


This is actually one of the reasons why I abandoned dmd for my 
dpldocs.info fork and used an independent parser.


dmd tries to build docs as it builds the program, but these are 
slightly contradictory - when building the program, you need to 
honor versioned out blocks. When building the docs, you just want 
it documented, not ignored. dmd is (rightfully) prioritized 
toward building actual code, but that leaves doc generation a bit 
second-hand.


To work around dmd's clashing goals, version(StdDdoc) manually 
makes a separate doc branch.


Whereas my doc generator just shows them all, bringing the 
version into the definition. 
http://dpldocs.info/experimental-docs/arsd.simpledisplay.XDisplayConnection.html




Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Jacob Carlborg via Digitalmars-d-learn

On 2018-02-07 22:39, Timothee Cour wrote:

```
void fun_bad3(T)(T a);  // declaration [1]
void fun_bad3(T)(T a){};  // definition [2]
void test(){
   fun_bad3(1);
}
```
Error: test_all.fun_bad3 called with argument types (int) matches both:
main.d(11): test_all.fun_bad3!int.fun_bad3(int a)
and:
main.d(12): test_all.fun_bad3!int.fun_bad3(int a)

should [1] be allowed? compler doens't allow defining it afterwards in
[2] (unlike function definitions, and, well, modulo this regression
https://issues.dlang.org/show_bug.cgi?id=18393)


Perhaps if it's defined in another file.

--
/Jacob Carlborg


Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
> It's been my understanding that it's always been illegal to provide a
definition for a function that was declared previously unless it was
declared in a .di file

Compiler has always allowed that:
```
void fun();
void fun(){}
```
(but see details in bug report)

> It's useful with stuff like version(Ddoc).

I guess you mean `version(StdDdoc)` ?

On that note, I see things like this, which are not DRY:
```
version(StdDdoc) string readLink(R)(R link)
if (isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) ||
isConvertibleToString!R);
else version(Posix) string readLink(R)(R link)
if (isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) ||
isConvertibleToString!R)
 ```

Is this pattern used because we want to build DDoc on a
not-necessarily Posix system (ie to get a DDoc regardless of which
environment)?

If so, it seems like an anti-pattern; better options could be:
* build platform specific documentation (which actually makes sense,
eg a windows user may not want to see Posix-only functions)
* add a special compiler flag that overrides predefined builtins (eg Posix)



On Wed, Feb 7, 2018 at 11:21 PM, Jonathan M Davis via
Digitalmars-d-learn  wrote:
> On Wednesday, February 07, 2018 13:39:55 Timothee Cour via Digitalmars-d-
> learn wrote:
>> ```
>> void fun_bad3(T)(T a);  // declaration [1]
>> void fun_bad3(T)(T a){};  // definition [2]
>> void test(){
>>   fun_bad3(1);
>> }
>> ```
>> Error: test_all.fun_bad3 called with argument types (int) matches both:
>> main.d(11): test_all.fun_bad3!int.fun_bad3(int a)
>> and:
>> main.d(12): test_all.fun_bad3!int.fun_bad3(int a)
>>
>> should [1] be allowed?
>
> It's useful with stuff like version(Ddoc).
>
>> compler doens't allow defining it afterwards in
>> [2] (unlike function definitions, and, well, modulo this regression
>> https://issues.dlang.org/show_bug.cgi?id=18393)
>
> It's been my understanding that it's always been illegal to provide a
> definition for a function that was declared previously unless it was
> declared in a .di file, in which case, you're not really both declaring and
> defining it, but the .d file is used when the module is compiled, and the
> .di file is used by other modules which use that module, so the declaration
> and definition are not seen by the same run of the compiler.
>
> - Jonathan M Davis
>


Re: what's the point of function template declarations if they can't be defined?

2018-02-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 07, 2018 13:39:55 Timothee Cour via Digitalmars-d-
learn wrote:
> ```
> void fun_bad3(T)(T a);  // declaration [1]
> void fun_bad3(T)(T a){};  // definition [2]
> void test(){
>   fun_bad3(1);
> }
> ```
> Error: test_all.fun_bad3 called with argument types (int) matches both:
> main.d(11): test_all.fun_bad3!int.fun_bad3(int a)
> and:
> main.d(12): test_all.fun_bad3!int.fun_bad3(int a)
>
> should [1] be allowed?

It's useful with stuff like version(Ddoc).

> compler doens't allow defining it afterwards in
> [2] (unlike function definitions, and, well, modulo this regression
> https://issues.dlang.org/show_bug.cgi?id=18393)

It's been my understanding that it's always been illegal to provide a
definition for a function that was declared previously unless it was
declared in a .di file, in which case, you're not really both declaring and
defining it, but the .d file is used when the module is compiled, and the
.di file is used by other modules which use that module, so the declaration
and definition are not seen by the same run of the compiler.

- Jonathan M Davis



what's the point of function template declarations if they can't be defined?

2018-02-07 Thread Timothee Cour via Digitalmars-d-learn
```
void fun_bad3(T)(T a);  // declaration [1]
void fun_bad3(T)(T a){};  // definition [2]
void test(){
  fun_bad3(1);
}
```
Error: test_all.fun_bad3 called with argument types (int) matches both:
main.d(11): test_all.fun_bad3!int.fun_bad3(int a)
and:
main.d(12): test_all.fun_bad3!int.fun_bad3(int a)

should [1] be allowed? compler doens't allow defining it afterwards in
[2] (unlike function definitions, and, well, modulo this regression
https://issues.dlang.org/show_bug.cgi?id=18393)