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
Issue 6169 - [CTFE] pure functions cannot compute constants using functions not marked as pure #652
Conversation
There's a huge similarity between this bug, and the gagging that occurs in speculative template instantiation (bug 4269, for example, which I'm currently working on). In both cases, semantic is run in a different mode, and a certain subset of errors need to be suppressed/ignored. I think they can both be treated in the same way. |
Yeah, this is a new type of gagging (eek) but as it can't leak outside expressions there hopefully won't be too many problems with it. The only ways I could think of for solving 4269 is to make semantic completely reversible for declarations or to suspend gagging when evaulating non-speculative declarations. The first options requires lots of work and has hundreds of corner cases, and the second doesn't work inside speculative declarations... I'll be interested to see your solution. |
I'm taking the second approach: ungag if non-speculative, when semantic is called from a speculative context. |
Ok, but I don't know how this will work for declarations that must be evaluated speculatively - basically anything can be inside a template declaration, and unless semantic can be re-run how can the errors be detected later?
The issue here isn't that semantic is being run gagged when it shouldn't be, it's that to generate the correct errors semantic has to be run again. |
Yeah, I dealt with that in a previous pull request. TemplateInstance has a member for speculative errors. If an error occurs, that counter gets updated. But it currently only applies to errors inside function bodies. It needs to be extended to work on other declarations. |
Won't that result in a generic 'errors instantiating' message rather than the specifics? I guess it would change this bug from accepts-invalid to a massive diagnostic problem. |
No. If there are semantic speculative errors, and a non-speculative instantiation is requested, the existing instantiation is discarded.
|
Updated to match Don's recent There is one change: Runtime values in case statements are no longer allowed. |
Please undo that. Although I would love for that to happen, it's a language change so it needs to be in its own pull request. |
Ok, I'll leave the original behavior for case variables. |
Done. |
OK to assign @donc to this? Please advise. I'm uneasy about two things: (a) inferring |
The "disallowing runtime values" was removed from the pull request as part of the "restore case variables" commit. |
@andralex |
Issue 8310 - writeln of Range of fixed size array
Updated. |
Updated again. |
… functions not marked as pure When running semantic on an expression used anywhere that forces compile time evaluation, use a scope flag to prevent purity and safety checks on function calls. This allows better purity/safety inferrence as well.
Issue 6169 - [CTFE] pure functions cannot compute constants using functions not marked as pure
When running semantic on an expression used anywhere that forces compile time evaluation, use a scope flag to prevent purity and safety checks on function calls.
This allows more functions to be inferred @safe/pure.
http://d.puremagic.com/issues/show_bug.cgi?id=6169