Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark if(__ctfe) blocks as SCOPEctfe #3572

Closed
wants to merge 1 commit into from
Closed

Mark if(__ctfe) blocks as SCOPEctfe #3572

wants to merge 1 commit into from

Conversation

jpf91
Copy link
Contributor

@jpf91 jpf91 commented May 23, 2014

Allows e.g. allocating in an if(__ctfe) block in a @nogc function

Allows e.g. allocating in an if(__ctfe) block in a @nogc function
@jpf91
Copy link
Contributor Author

jpf91 commented May 27, 2014

ping @k-hara @WalterBright

@WalterBright
Copy link
Member

Not a bad idea. But since it is an enhancement, it needs a bugzilla entry for it. It also apparently needs to be rebased.

@9rnsr
Copy link
Contributor

9rnsr commented Jun 6, 2014

@jpf91 @WalterBright A blocker issue of this idea is that currently the special variable __ctfe could appear everywhere.

void main() {
    int x = __ctfe;
    if (__ctfe + 1) {}   // this is CTFE-ed branch?
    if (__ctfe * 0) {}   // this is not CTFE-ed branch?
}

Therefore, compiler cannot determine the CTFE-specific code branch in semantic analysis stage.

An easy way to resolve the issue is, that defining the statement if (__ctfe) { ... } as a special form, and stop considering __ctfe variable in other places.

@jpf91
Copy link
Contributor Author

jpf91 commented Jun 6, 2014

@WalterBright OK.
@9rnsr I think it's good enough to support only this special case in SCOPEctfe.

A little background: I've hacked gdc to report all GC allocations to completely remove the GC dependencies from druntime. I'll use that for a first port to the NintendoDS were our GC probably wouldn't work. And there's some code in druntime which uses this if(__ctfe){//Use GC} else {complex pointer stuff} pattern. More complicated patters can always be rewritten into this form.

@WalterBright
Copy link
Member

@9rnsr you're right about this being a kludge that doesn't work in the general case. Your solution has a lot of merit - and I think it merits a wider discussion. We need a bugzilla entry and a newsgroup discussion on it.

@WalterBright
Copy link
Member

BTW, other unconsidered cases include:

a = __ctfe ? c : d;
a = (__ctfe && func());
switch (__ctfe) { ... }
case __ctfe:

where do we stop?

@9rnsr
Copy link
Contributor

9rnsr commented Jun 6, 2014

The form of conditional expression a = __ctfe ? c : d; is one more useful case for one-liner hack for CTFE-ability. Other cases are not generic pattern IMO.

@MartinNowak
Copy link
Member

where do we stop?

Probably at function border?
If it were possible to mark a function as ctfe-only than we could relax the @nogc rules for calling it.

@andralex
Copy link
Member

andralex commented Feb 7, 2015

So... what's the status of this? Fix? Close? Please advise.

@ibuclaw
Copy link
Member

ibuclaw commented Dec 24, 2017

I suggest close, however remind me again. Why isn't static if (__ctfe) allowed? I always returns true during the interpret pass, why not the ctfe?

@ibuclaw
Copy link
Member

ibuclaw commented Dec 24, 2017

I always returns true during the interpret pass, why not the ctfe?

Ah right, because the false branch would always be removed.

@ibuclaw
Copy link
Member

ibuclaw commented Dec 24, 2017

Closing for #7509

@ibuclaw ibuclaw closed this Dec 24, 2017
ibuclaw pushed a commit to ibuclaw/dmd that referenced this pull request Jul 10, 2022
More readable message in ArrayIndexError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants