Trying to use Mir ion, its a perfect example of the failure of D's attribute system

Quirin Schroll qs.il.paperinik at gmail.com
Thu Feb 2 17:18:46 UTC 2023


On Tuesday, 24 January 2023 at 07:45:00 UTC, Walter Bright wrote:
> Help us help you by posting the bug reports to bugzilla!

I filed issues about `opApply` in the past. An example is 
[this](https://issues.dlang.org/show_bug.cgi?id=19597).

Recognizing `ref`-ness is already filed if I remember correctly; 
apart from that, technically speaking, those aren’t bugs, but 
various degrees of potential enhancements.

The empty template parameter case is the easiest. Not supporting 
just makes the spec a little easier (function templates don’t 
infer vs. function templates don’t infer unless instantiating the 
template with empty parentheses compiles). It’s still rather 
useless. It cannot infer attributes based on the caller-side 
delegate supplied: The delegate type – and with it its attributes 
– is fixed.

Recognizing the restriction pattern `int opApply(DG : int 
delegate(string)(DG dg)` would save a lot of typing (enhancement 
filed as [issue 
23666](https://issues.dlang.org/show_bug.cgi?id=23666)). The 
repetition of up to 16 overloads can be automated using a mixin 
template ([I posted one before in this 
thread](https://forum.dlang.org/post/fzujvfmtckvcusdelzqj@forum.dlang.org)) that takes a implementation template and instantiates it with the given delegate type varied with all combinations of attributes. I tried to improve this so that the mixin template needs not be given the delegate type, but finds the template parameter’s constraint type and uses that. This didn’t work for two reasons: 1. For some reason, the string extracted cannot be mixed-in as a type, even if comprised of built-in types only, e.g. `int delegate(int)`. 2. I know that even if one got the first problem solved, the mixed-in string need not designate a valid type because of various ways scoping works; it could still be a good best-effort solution. The compiler quite likely has information about the parameter constraint, the language just lacks `__traits` to expose it. (Enhancement filed as [issue 23665](https://issues.dlang.org/show_bug.cgi?id=23665); it’s only long because it’s inherently complicated.)


More information about the Digitalmars-d mailing list