Implement sumtypes and matching - #23540
Conversation
00cf0ac to
767d042
Compare
|
I just remembered more of the operator overloads need to be generated |
547dd3c to
2412122
Compare
2412122 to
735bbc7
Compare
|
I understand that this is a massive pull request, but sumtypes/matching is a big new feature, and one we need to keep up with even stodgy old conservative languages like C#. If we can pile into this and get multiple people to review it should be manageable. |
|
For reference, this design reduces to lowering to structs (literals + declarations), and ternary expressions (match). Overall I'm very impressed with the code quality MiMo V2.5 came up with, I couldn't have done it better (overall). |
|
I don't see what the point is. The syntax isn't an improvement over the library solution, and I don't see any new functionality being offered. Is all this just to save an import? |
|
Match expression support guard expressions and there are both named and unnamed variants. |
The latter can be supported in the library solution. The former just looks awkward and inconsistent with the rest of the language. Why does this need a fancy new syntax that we can't use anywhere else? |
|
If you want to extend match expressions to other types that is fine. But I am not working on that right now, and the scope is sufficiently large. Just because something can be done in library does not mean that it is the correct place to put it. Sumtypes are a primitive of data representation, same as tuples. Much more so than a map or a dynamic array. |
|
Oh and another thing, match functions can't actually be safe if the argument is by-ref. The match expressions, due to not using function calls can be analyzed with a borrow checker, and therefore the variables can be by-ref. Which is a pretty massive upgrade. |
It doesn't mean that it isn't the correct place to put it, either. And bitfields are far better than the C garbage that's supposedly replacing them. I used to think D's greatest strength was its metaprogramming, but it's doomed to be deficient, isn't it? |
Which can be fixed with a simple linting rule, which I implemented but wasn't accepted.
Yes, but not because of the design or implementation of metaprogramming stuff. The core problem is overall compiler architecture wasn't designed to solve cyclicity in analysis, which prevents effects analysis, and the behaviour isn't correct. On the flip side, you get fast compile times, so it isn't all bad. |
735bbc7 to
01e98a9
Compare
DMD perf check
|
Will update later.