www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Are templates required ?

reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Are templates an optional feature of D 1.0,
or are they required by any implementation ?

Reason I ask is because they *don't* work OK
with Mac OS X 10.3 (or 10.2) version of GDC
that I did using GCC 3.x because the compiler
doesn't have "one-only linkage" that is required.

Most of Phobos and D programs work anyway, using
the -femit-templates parameter set to "private",
but for more complex programs this tends to fail.
(DMDScript and readf being two such examples...)

The Mac OS X 10.4 GDC version has no such problems,
so if it is required I'll just drop Panther support.

--anders
Jan 19 2007
parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Anders F Björklund wrote:
 Are templates an optional feature of D 1.0,
 or are they required by any implementation ?
 
 Reason I ask is because they *don't* work OK
 with Mac OS X 10.3 (or 10.2) version of GDC
 that I did using GCC 3.x because the compiler
 doesn't have "one-only linkage" that is required.
 
 Most of Phobos and D programs work anyway, using
 the -femit-templates parameter set to "private",
 but for more complex programs this tends to fail.
 (DMDScript and readf being two such examples...)
 
 The Mac OS X 10.4 GDC version has no such problems,
 so if it is required I'll just drop Panther support.

I'd say it's required to be fully compliant to the spec. However, I don't think it's necessarily sufficient reason to deny the other benefits of D to users of an old toolchain. How does g++ fix this, by the way? C++ has templates, so it should be possible. Or does that also fail for 'more complex programs'? And in what way would "private" template emission fail, anyway? It might cause extra bloat but I can't see how it would fail? After some more thinking: Though comparing addresses of template instances might be problematic. And value types whose hash depends on an address (function pointers and delegates for instance) might then cause problems with associative arrays if the address points to a template instantiated from multiple modules... Something else about the original problem: Would it maybe be possible to backport once-only linkage to the old GCC? Or would that be a lot of work?
Jan 19 2007
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Frits van Bommel wrote:

 Are templates an optional feature of D 1.0,
 or are they required by any implementation ?
 

don't think it's necessarily sufficient reason to deny the other benefits of D to users of an old toolchain.

Which spec is that ? I don't recall them failing any tests. For me it would be cool to just have a version(D_Templates), but that doesn't work if/when crucial parts of D uses them.
 How does g++ fix this, by the way? C++ has templates, so it should be 
 possible. Or does that also fail for 'more complex programs'?

Apple's GCC 3.3 supports C, C++ and Objective-C. But not D... (and GDC doesn't build with Apple GCC 3.3, only with GCC 4.0) I believe that in the Dark Ages, templates used to fail all over the place, but that C++ compilers eventually caught up ?
 And in what way would "private" template emission fail, anyway? It might 
 cause extra bloat but I can't see how it would fail?

DMDscript doesn't work because it throws exceptions at start: "Error: circular initialization dependency with module script" readf/TypeInfo doesn't work, because it uses "is" to compare. (and since it emits multiple instances, that doesn't work OK)
 Something else about the original problem: Would it maybe be possible to 
 backport once-only linkage to the old GCC? Or would that be a lot of work?

It's a lot of work, and I haven't been able to complete it yet. (there is also very little demand for such a thing, it seems...) I think David has deprecated GCC 3.3 for GDC in general, as well. And DMD doesn't have any support for Mac, just Windows and linux. --anders
Jan 19 2007
parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Anders F Björklund wrote:
 Frits van Bommel wrote:
 
 Are templates an optional feature of D 1.0,
 or are they required by any implementation ?

don't think it's necessarily sufficient reason to deny the other benefits of D to users of an old toolchain.

Which spec is that ? I don't recall them failing any tests.

I was talking about the D 1.0 spec, which seemed to be what you were talking about.
 For me it would be cool to just have a version(D_Templates),
 but that doesn't work if/when crucial parts of D uses them.

Well, I believe they're in the spec for D 1.0, specifically the part located at http://www.digitalmars.com/d/template.html. So IMHO to be fully compliant to the spec, they'd have to work :P. As far as I'm aware though, they're pretty self-contained. I don't think there are major parts of Phobos that would be broken if templates didn't work, unless you count boxing. I think a version of D without template support would still be pretty useful. Though obviously not as useful as a version that *does* support templates :).
 How does g++ fix this, by the way? C++ has templates, so it should be 
 possible. Or does that also fail for 'more complex programs'?

Apple's GCC 3.3 supports C, C++ and Objective-C. But not D...

That much I'm aware of. Though I must say I've never used Mac OS for more than a few hours, and then only for word processing and image editing, not programming.
 (and GDC doesn't build with Apple GCC 3.3, only with GCC 4.0)

How about 3.4? Or was that never shipped by Apple?
 I believe that in the Dark Ages, templates used to fail all
 over the place, but that C++ compilers eventually caught up ?

I only got into C-like languages when GCC 3.4 was out, so I also never used 3.3.
 And in what way would "private" template emission fail, anyway? It 
 might cause extra bloat but I can't see how it would fail?

DMDscript doesn't work because it throws exceptions at start: "Error: circular initialization dependency with module script"

How is this related to templates? (Does it use "static this()" in a template or something?)
 readf/TypeInfo doesn't work, because it uses "is" to compare.
 (and since it emits multiple instances, that doesn't work OK)

That seems to be an instance of what I expected might happen and wrote in the paragraph you seem to have cut...
 Something else about the original problem: Would it maybe be possible 
 to backport once-only linkage to the old GCC? Or would that be a lot 
 of work?

It's a lot of work, and I haven't been able to complete it yet. (there is also very little demand for such a thing, it seems...)

I must say I have no idea how many people are using old versions of Mac OS. Another option might be to supply an entire new toolchain. Or was the ABI changed before the first version of GCC that GDC supports?
 I think David has deprecated GCC 3.3 for GDC in general, as well.

Well, it *is* pretty old by now. 3.4 has been out for almost 3 years now, and 4.0 was almost 2 years ago. (Though IIRC 4.0.0 was buggy at first...) [Reference: http://gcc.gnu.org/releases.html]
 And DMD doesn't have any support for Mac, just Windows and linux.

Aside: that's all I've ever needed :). Though I can definitely understand people on macs might not like that...
Jan 19 2007
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Frits van Bommel wrote:

 Which spec is that ? I don't recall them failing any tests.

I was talking about the D 1.0 spec, which seemed to be what you were talking about.

I only saw a DMD 1.00, so I wasn't sure where the D language is/was... But if "D 1.0" is the same as what DMD 1.00 supports, then it should.
 Well, I believe they're in the spec for D 1.0, specifically the part 
 located at http://www.digitalmars.com/d/template.html. So IMHO to be 
 fully compliant to the spec, they'd have to work :P.

It "kinda" works, depending on what "compliant to the D spec" means ? I don't think the spec covers -femit-templates[=full|private|none|auto]
 As far as I'm aware though, they're pretty self-contained. I don't think 
 there are major parts of Phobos that would be broken if templates didn't 
 work, unless you count boxing.
 I think a version of D without template support would still be pretty 
 useful. Though obviously not as useful as a version that *does* support 
 templates :).

Yes, I've been using it for a few years (without templates). I guess it could still remain as-is, with the warning label.
 (and GDC doesn't build with Apple GCC 3.3, only with GCC 4.0)


No, but then again they have a fairly heavily patched GCC 3.3. gcc (GCC) 3.3 20030304 (Apple Computer, Inc. build 1666)
 How is this related to templates?
 (Does it use "static this()" in a template or something?)

Didn't dig in too deep, just know it works out-of-the-box in Tiger. Then again, DMDScript was broken again by GDC 0.21 so I'm not sure.
 readf/TypeInfo doesn't work, because it uses "is" to compare.
 (and since it emits multiple instances, that doesn't work OK)

That seems to be an instance of what I expected might happen and wrote in the paragraph you seem to have cut...

Sorry about that.
 It's a lot of work, and I haven't been able to complete it yet.
 (there is also very little demand for such a thing, it seems...)

I must say I have no idea how many people are using old versions of Mac OS. Another option might be to supply an entire new toolchain. Or was the ABI changed before the first version of GCC that GDC supports?

It is theoretically possible to build with the GCC 4.0 and deploy on Mac OS X 10.3.9 (latest) which does have the newer GCC runtime. But in practice you run into some issues, so I normally use 3.3.
 I think David has deprecated GCC 3.3 for GDC in general, as well.

Well, it *is* pretty old by now. 3.4 has been out for almost 3 years now, and 4.0 was almost 2 years ago. (Though IIRC 4.0.0 was buggy at first...) [Reference: http://gcc.gnu.org/releases.html]

Tiger was also out almost two years ago, it was also buggy at first. We've already given up on support for older platforms that C/C++ supports, like Mac OS 9 or Mac OS X 10.1, so might drop 10.3 too ? After all, soon it will be all about Mac OS X 10.5 (or Vista :-P).
 And DMD doesn't have any support for Mac, just Windows and linux.

Aside: that's all I've ever needed :). Though I can definitely understand people on macs might not like that...

It's a problem, since what DMD doesn't support doesn't go in the spec. Maybe GDC should have a separate spec, for the portable version of D ? I just wondered if a D without fully working templates is still a D... Of if it is more of a "platform quirk", like reals or string constants. --anders
Jan 19 2007