dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Implement pragma(ctfe)

Open dkorpel opened this issue 3 years ago • 7 comments

Rebase of https://github.com/dlang/dmd/pull/11014, which was stalled because of a trailing whitespace. I made a new PR because the rebase was non-trivial and a force push is risky, and it seems the original author is no longer active here.

This came up in the forum again: https://forum.dlang.org/post/[email protected]

dkorpel avatar Apr 28 '22 15:04 dkorpel

Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#14036"

dlang-bot avatar Apr 28 '22 15:04 dlang-bot

Currently this works by effectively saying if(betterC && !pragmaCTFE). It would be worth investigating whether this can be changed to effectively turning betterC off during semantic analysis of symbols with this pragma, partly because dmd is already full of Kafkaesque if statements, but also because this is a route to making all use of D at CTFE inside WorseD more tolerable (this is more complicated than just what is mentioned here, however this is the framework).

maxhaton avatar Apr 29 '22 01:04 maxhaton

@WalterBright @atilaneves What do you think of this feature? You can find a description in the changelog entry: https://github.com/dlang/dmd/blob/63b7594e546221aa5aaa34f64bff7f71fd90c64d/changelog/pragma_ctfe.dd

dkorpel avatar Apr 29 '22 08:04 dkorpel

but also because this is a route to making all use of D at CTFE inside WorseD more tolerable (this is more complicated than just what is mentioned here, however this is the framework).

TypeInfo is being phased out with the project to translate the relevant druntime hooks to templates, so this might just solve itself.

dkorpel avatar Apr 29 '22 08:04 dkorpel

I like the feature but am wondering about the approach from a syntax perspective.

atilaneves avatar Apr 29 '22 08:04 atilaneves

but also because this is a route to making all use of D at CTFE inside WorseD more tolerable (this is more complicated than just what is mentioned here, however this is the framework).

TypeInfo is being phased out with the project to translate the relevant druntime hooks to templates, so this might just solve itself.

but also because this is a route to making all use of D at CTFE inside WorseD more tolerable (this is more complicated than just what is mentioned here, however this is the framework).

TypeInfo is being phased out with the project to translate the relevant druntime hooks to templates, so this might just solve itself.

There's more to it than typeinfo

maxhaton avatar Apr 29 '22 16:04 maxhaton

I've thought about this a bit more recently and we should aim for assert(_ctfe) rather than a pragma if possible.

maxhaton avatar Jun 08 '22 22:06 maxhaton

Superseded by recent improvements in betterC's CTFE handling

dkorpel avatar Feb 16 '23 21:02 dkorpel