Time for Phobos CTFE-ability unittests...right? RIGHT?

Nick Sabalausky a at a.a
Tue Jul 12 15:29:29 PDT 2011


Yet again, a new DMD release has broken my code, and other people's code, 
too, just because of Phobos functions loosing their CTFE-ability. (strip(), 
toLower(), etc... And yes, I did bring up the strip() regression on the beta 
list, to no effect.)

We praise and promote the hell out of CTFE (and rightly so) for being able 
to take ordinary functions and run them at compile-time. Except, with every 
new release, I become more and more convinced that Phobos should *not* be 
used in CTFE, because I know from experience that if I do, chances are it 
will soon break. So we have to maintain separate CTFE-guaranteed versions of 
whatever we need from Phobos. Obviously, aside from being a royal pain in 
the ass,  that completely defeats the point of CTFE. Worse still, it makes 
us look really, really bad when we go out and promote a CTFE that just plain 
doesn't work as advertised when it comes the language's own standard 
library.

Granted, I *completely* understand and sympathize with the practical issues 
involved (Phobos being heavily in-development, CTFE itself undergoing big 
improvements, etc...) So I fully agree it made perfect sense for this 
"bleeding-edge/unstable" branch of D to not concern itself with CTFE-ability 
regressions in Phobos just yet...

BUT...*Now* D2 has been declared the "main" version of D, suitable and 
recommended for new projects, and is being promoted as such. That changes 
the situation. Our old, previously sensible, approach to Phobos CTFE-ability 
has now become "Breaking regressions in each release."

Therefore, I think *now* is the time when Phobos needs to start having 
regression tests for CTFE-ability. If something doesn't work, then hell, at 
least a quick-and-dirty if(_ctfe) branch would at least be better than 
outright breakage. And if there are worries about that hindering improvement 
of DMD's CTFE mechanism, then a version identifier could be added to turn 
off the CTFE-workaround codepaths.

I realize it's not exactly helpful to say "Hey, you should do X!" instead of 
just simply pitching in and helping. But I'm hoping we can at least agree 
that we've reached a point where it's appropriate, and not premature, for 
this to be done. (One step at a time, right?)




More information about the Digitalmars-d mailing list