Explcit impure function attribute

Quirin Schroll qs.il.paperinik at gmail.com
Mon Jun 24 16:38:51 UTC 2024


As I’m working getting the `@gc` function attribute into D, the 
last remaining covariant attribute without contravariant inverse 
will be `pure`. The biggest question will not be how useful it is 
because its use will be exactly like that of other contravariant 
attributes (`@system`, `throw`, and `@gc`), no, the biggest 
question is syntax.

What are your preferences?

A few inspirations:
1. Make `impure` a hard keyword, so `pure` and `impure` falls 
into the same syntactical category as `throw` and `nothrow`.
    This has the downside of breaking code that has identifiers 
named `impure`. I’d guess those would be rare, though.
2. Make `@impure` a compiler-recognized AtAttribute.
    This has the downside of being asymmetric: `pure` has no `@`, 
but its inverse `@impure` would have it.
3. Make `impure` a contextual keyword, i.e. a compiler-recognized 
identifier with special meaning in certain places, similar to 
`body`.
    This has the downside that it breaks very specific code (e.g. 
`int function() impure`) and that it uses contextual keywords 
which Walter really doesn’t like. This option is interesting for 
the base language when Option 1 is pursued in the next Edition.
4. ―???―


More information about the dip.ideas mailing list