Comment

Comment by WalterBright

D guarantees that a function annotated with `pure` will also work at compile time. But compile time does allow calling some impure functions, as long as the path taken through the function's body is pure. This greatly expands the palette of functions able to be executed at compile time.

Not including functions never called for runtime execution in the runtime is a normal compiler optimization. No user input is necessary.

If the function's semantics change so it is no longer runnable at compile time, the compiler will let you know when you try it. If you want to force the detection, just call it at compile time with dummy declaration.

> that's how we probably arrive at a declarative mechanism like constexpr that goes on the function, rather than trying to orchestrate thing remotely/indirectly by placing a call to the function into a compile-time context.

This issue is raised now and then, and in 16 years of CTFE in D it has never ever been reported as causing an actual problem.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton