DIP1044---"Enum Type Inference"---Formal Assessment

WebFreak001 d.forum at webfreak.org
Tue Apr 25 16:01:23 UTC 2023


On Tuesday, 25 April 2023 at 04:54:43 UTC, Mike Parker wrote:
> I submitted DIP1044, "Enum Type Inference", to Walter and Atila 
> on April 1. I received the final decision from them on April 
> 18. They have decided not to accept this proposal.
>
> https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1044.md
>
> The said the proposal was well done and an interesting read, 
> but found it to be too complex for insufficient benefit. They 
> provided the following list of concerns that led them to their 
> decision:
>
> * Given that D already has `with`, `alias`, and `auto`, it does 
> not seem worthwhile to add a special case for enums.
> * Semantic analysis in D is strictly bottom-up. This proposal 
> would add top-up type inference on top of that. This presents 
> problems in handling function and template overloads, as well 
> as variadic parameter lists.
> * The proposal only allows ETI in some contexts. This is 
> potentially confusing for the programmer, particularly in the 
> presence of mixin templates (which draw symbols from the 
> instantiation context) and function overloads.
> * Symbol tables can get very large. Lookups are done via hash 
> table for max speed, but this will not work for ETI. There may 
> be a very large number of "enums in scope", and each one will 
> have to be searched to resolve a member.
> * ETI is similar to ADL (Argument Dependent Lookup) in C++. 
> Walter implemented ADL in the Digital Mars C++ compiler and is 
> strongly against allowing anything like it in D. He finds it 
> slow and complex, and few people really know how it's going to 
> work.
>
> Regarding enums in switch statements, Walter suggested we could 
> shorten the `with final switch` syntax such that the `with` is 
> implicitly applied to the type of the switch variable:
>
> ```D
> auto myEnum = MyEnum.a;
> with final switch (myEnum) { }
> ```
>
> Alternatively, we could make the `with` implicit for case 
> statements, but that would break existing code.

I'm a little glad for reading and reviewing code that this didn't 
get through, at least without IDE, but I think this would have 
been quite a useful feature for writing code.

However I think we probably should still implement this in DCD / 
have better auto-suggest according to the rules here. I think it 
will be similarly useful having better auto-complete suggestion 
contexts compared to having new syntax in the language. (maybe 
being able to trigger it explicitly using $ at the start, but 
definitely want to have these suggestions being prioritized)


More information about the Digitalmars-d-announce mailing list