std.digest can't CTFE?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Jun 1 05:15:01 UTC 2018


On Thursday, May 31, 2018 21:14:18 Nick Sabalausky  via Digitalmars-d wrote:
> On 05/31/2018 06:40 PM, Jonathan M Davis wrote:
> > On Thursday, May 31, 2018 14:29:13 Manu via Digitalmars-d wrote:
> >> "CTFE
> >> Digests do not work in CTFE"
> >>
> >>
> >> That's an unfortunate limitation... why is, those things? :(
> >
> > If I had to guess without looking at the code? I would guess that it's
> > doing various casts to hash stuff, and no kind of reintpret cast is
> > allowed in CTFE. But really, you'd have to actually run the code, see
> > what works and what doesn't, and look at each error you get when it
> > doesn't to see what it's doing that can't be done during CTFE.
> > Depending on what it's doing, it may be possible to make it work during
> > CTFE, or it may not. CTFE can do a lot, but there's also a lot that it
> > can't do - especially if you start doing anything low level.
> >
> > - Jonathan M Davis
>
> I know the SHA1 implementation uses some inline asm. Although, now that
> I think about it, I think that might just be one specialization of the
> implementation, not the only implementation.
>
> Regardless, I do know that std.digest dates back a long time to when
> CTFE was WAY more limited that it is today. Most likely, CTFE at the
> time probably just wasn't quite up to the task, so it was simply left as
> runtime-only. A lot of Phobos was like that back then.
>
> Heck, I wouldn't even be surprised if that note in the docs turned out
> to be outdated and it had magically started working at CTFE at some
> point. But even if not, I'd say it's almost certainly just a classic
> case of "Nobody's needed it badly enough yet to get it working."

Yeah, unless there's something about the implementation that actually
requires something low level that can't be done during CTFE, or it requires
a C function, then it's almost certainly just a matter of someone taking the
time to make it work during CTFE (even if that involves using __ctfe).
Presumably, either no one has had enough of a need to make it work, or the
few who did didn't want to go to the effort of making it work. I have no
idea how much the need to use std.digest at compile-time actually comes up.
I would have thought that in most cases, you'd be hashing a file or
something else that's read at runtime, but I don't know. Personally, I think
that I've used std.digest all of once.

- Jonathan M Davis



More information about the Digitalmars-d mailing list