Thread overview
[Issue 10334] New: ddoc should prefer simple syntax for template instantiations with one parameter
Jun 11, 2013
Andrej Mitrovic
Jun 11, 2013
Andrej Mitrovic
Jun 13, 2013
Kenji Hara
Jun 18, 2013
Andrej Mitrovic
Jun 18, 2013
Andrej Mitrovic
Jun 18, 2013
Kenji Hara
June 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334

           Summary: ddoc should prefer simple syntax for template
                    instantiations with one parameter
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: ddoc
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-06-11 07:46:42 PDT ---
-----
/** */
template templ(T...)
    if (someConstraint!T)
{
}
-----

This currently emits:

> template templ(T...) if (someConstraint!(T))

But for readability purposes it can be:

> template templ(T...) if (someConstraint!T)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-06-11 09:07:31 PDT ---
This is a little bit complicated to implement. I have to take into account at least the following (where left is the input, right is the output), and these are also used for .di header generation so they must have valid D syntax:

Templ!() -> Templ!()
Templ!(T) -> Templ!T
Templ!T -> Templ!T
Templ!([1]) -> Templ!([1])  // cannot be Templ![1]
Templ!(Templ2!(T)) -> Templ!(Templ2(T)  // cannot be Templ!Templ2!T

That last case is what I'm struggling with. How do I figure out whether an Object from 'tiargs' is a template instance in DMDFE?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 13, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2013-06-13 01:59:13 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2173

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334



--- Comment #3 from github-bugzilla@puremagic.com 2013-06-17 17:49:58 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/920c3c1344d4f74ca04eb29cd2a7cc59169745d6 Supplemental fix for issue 10334

https://github.com/D-Programming-Language/phobos/commit/b39768890581b423a85186aa4c6ded1337051641 Merge pull request #1353 from 9rnsr/fix10334

Supplemental fix for issue 10334

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334



--- Comment #3 from github-bugzilla@puremagic.com 2013-06-17 17:49:58 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/920c3c1344d4f74ca04eb29cd2a7cc59169745d6 Supplemental fix for issue 10334

https://github.com/D-Programming-Language/phobos/commit/b39768890581b423a85186aa4c6ded1337051641 Merge pull request #1353 from 9rnsr/fix10334

Supplemental fix for issue 10334

--- Comment #4 from github-bugzilla@puremagic.com 2013-06-17 17:50:04 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/905c4dd8e6a0377c518cce443f63a237df39ac7d
fix Issue 10334 - ddoc should prefer simple syntax for template instantiations
with one parameter

https://github.com/D-Programming-Language/dmd/commit/26022fb60e542f387257359d347cb9f3a21653ca Merge pull request #2173 from 9rnsr/fix10334

Issue 10334 - ddoc should prefer simple syntax for template instantiations with one parameter

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #5 from bearophile_hugs@eml.cc 2013-06-17 18:01:01 PDT ---
This code:


template isBar(T) {
    enum isBar = false;
}
template Foo(T) if (isBar!T) {
}
void main() {
    alias F = Foo!int;
}


Gives (before this patch):

temp.d(7): Error: template instance Foo!(int) does not match template
declaration Foo(T) if (isBar!(T))

isn't it better to use that ddoc logic to generate a simpler error message similar to:

temp.d(7): Error: template instance Foo!(int) does not match template
declaration Foo(T) if (isBar!T)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334



--- Comment #6 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-06-17 18:14:55 PDT ---
(In reply to comment #5)
> isn't it better to use that ddoc logic to generate a simpler error message similar to:

Yes, although the pull request didn't touch any ddoc code, it specifically targeted the internal Template "stringification" functions which are used by both ddoc and diagnostics.

I thought all diagnostics would be affected, but some slipped out (they weren't directly tested in the autotester, only ddoc output was tested).

I think the diagnostics can be improved. Could you file a separate bug for it?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334



--- Comment #7 from bearophile_hugs@eml.cc 2013-06-17 18:55:03 PDT ---
(In reply to comment #6)

> I think the diagnostics can be improved. Could you file a separate bug for it?

I have compiled the compiler with this last change, and indeed there is no need to file a bug, the error message now is:


temp.d(7): Error: template instance Foo!int does not match template declaration
Foo(T) if (isBar!T)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334



--- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-06-17 18:56:13 PDT ---
(In reply to comment #7)
> (In reply to comment #6)
> 
> > I think the diagnostics can be improved. Could you file a separate bug for it?
> 
> I have compiled the compiler with this last change, and indeed there is no need to file a bug, the error message now is:
> 
> 
> temp.d(7): Error: template instance Foo!int does not match template declaration
> Foo(T) if (isBar!T)

Ah yes, my bad. I used the wrong version when testing it now.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10334


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------