digitalmars.dip.ideas - New syntax for comma expression
- Richard (Rikki) Andrew Cattermole (24/24) Nov 20 During semantic analysis, some code gets lowered to the comma
- Paul Backus (8/18) Nov 20 As a general rule, I don't think we should be adding new syntax
- Richard (Rikki) Andrew Cattermole (44/63) Nov 20 This is not an ease of use situation.
- Paul Backus (4/10) Nov 20 Why does the lowering have to map to anything? It's an
- Richard (Rikki) Andrew Cattermole (12/26) Nov 20 It's not an implementation detail of the compiler.
- Nick Treleaven (17/28) Nov 21 When we have tuples: `(e1, e2, e3)[$-1]` instead of `(e1, e2,
- Richard (Rikki) Andrew Cattermole (36/44) Nov 21 Context pointer is irrelevant, it won't work.
During semantic analysis, some code gets lowered to the comma expression. New'ing anonymous classes are a good example of this. Right now if hdrgen were to emit it, it looks like this (-vcg-ast to get it): ``` __anonclass1 foo = Object, LeInterface { void* this; } , foo = new __anonclass1; ``` Proposed grammar: ```diff CommaExpression: + "class" ConstructorArgs|opt AnonBaseClassList|opt AggregateBody + "__commaExpr" '(' CommaExpression ')' ``` This would not break code, nor would it affect tuples. No new AST nodes or semantic behaviour. Just hooking an existing language feature to be fully expressable in syntax. Ideally, this would be able to bypass the DIP process, due to the bug-fixing nature of it.
Nov 20
On Wednesday, 20 November 2024 at 23:11:37 UTC, Richard (Rikki) Andrew Cattermole wrote:During semantic analysis, some code gets lowered to the comma expression. [...] Proposed grammar: ```diff CommaExpression: + "class" ConstructorArgs|opt AnonBaseClassList|opt AggregateBody + "__commaExpr" '(' CommaExpression ')' ```As a general rule, I don't think we should be adding new syntax to D because it's easier for the compiler to generate than the existing syntax. If there's something in D's semantics that the existing syntax *can't express*, then there's a discussion to be had. But I don't think this qualifies.
Nov 20
On 21/11/2024 2:59 PM, Paul Backus wrote:On Wednesday, 20 November 2024 at 23:11:37 UTC, Richard (Rikki) Andrew Cattermole wrote:This is not an ease of use situation. There is nothing for the lowering to map to in the syntax. I.e. ```d void main() { bool b; auto v = b ? ( new class LeClass, LeInterface {} ) : ( new class LeClass, LeInterface {} ); } ``` ``` void main() { bool b = false; LeClass v = b ? LeClass, LeInterface { void* this; system this() { super.this(); return this; } } , new __anonclass2 : (LeClass, LeInterface { void* this; system this() { super.this(); return this; } } , new __anonclass3); return 0; } ``` Can't go and mess around with statement insertion for something like this. Of course feel free to try ;)During semantic analysis, some code gets lowered to the comma expression. [...] Proposed grammar: ```diff CommaExpression: + "class" ConstructorArgs|opt AnonBaseClassList|opt AggregateBody + "__commaExpr" '(' CommaExpression ')' ```As a general rule, I don't think we should be adding new syntax to D because it's easier for the compiler to generate than the existing syntax.If there's something in D's semantics that the existing syntax *can't express*, then there's a discussion to be had. But I don't think this qualifies.Yup, there is plenty unfortunately. https://github.com/search?q=repo%3Adlang%2Fdmd+%22new+CommaExp%22&type=code
Nov 20
On Thursday, 21 November 2024 at 02:09:14 UTC, Richard (Rikki) Andrew Cattermole wrote:On 21/11/2024 2:59 PM, Paul Backus wrote:Why does the lowering have to map to anything? It's an implementation detail of the compiler.As a general rule, I don't think we should be adding new syntax to D because it's easier for the compiler to generate than the existing syntax.This is not an ease of use situation. There is nothing for the lowering to map to in the syntax.
Nov 20
On 21/11/2024 3:26 PM, Paul Backus wrote:On Thursday, 21 November 2024 at 02:09:14 UTC, Richard (Rikki) Andrew Cattermole wrote:It's not an implementation detail of the compiler. The comma expression is in the language. But because of tuples its on the way out and so it doesn't support everything that it needs to. Regardless the .di generator is broken for D code. That means errors are not emitting correct code either. This affects a lot more than just a couple of switches. A simple parser change that won't break code and which has the chance to fix some hard problems should be an easy win. If you think this can be fixed another way, please prove me wrong. I'd love for the .di generator to be functional regardless of who or what approach is taken to achieve it.On 21/11/2024 2:59 PM, Paul Backus wrote:Why does the lowering have to map to anything? It's an implementation detail of the compiler.As a general rule, I don't think we should be adding new syntax to D because it's easier for the compiler to generate than the existing syntax.This is not an ease of use situation. There is nothing for the lowering to map to in the syntax.
Nov 20
On Thursday, 21 November 2024 at 02:40:15 UTC, Richard (Rikki) Andrew Cattermole wrote:The comma expression is in the language. But because of tuples its on the way out and so it doesn't support everything that it needs to.When we have tuples: `(e1, e2, e3)[$-1]` instead of `(e1, e2, e3)` in C.Regardless the .di generator is broken for D code. That means errors are not emitting correct code either. This affects a lot more than just a couple of switches. A simple parser change that won't break code and which has the chance to fix some hard problems should be an easy win. If you think this can be fixed another way, please prove me wrong. I'd love for the .di generator to be functional regardless of who or what approach is taken to achieve it.Maybe: ```d (){ class __anonclass1 : BaseClassList { void* this; } return new __anonclass1 args; }() ``` Could that work correctly with the context pointer? Otherwise to generally fix it, there would need to be a way of declaring inline types in an expression. (We also might want inline template syntax).
Nov 21
On 22/11/2024 6:56 AM, Nick Treleaven wrote:Maybe: |(){ class __anonclass1 : BaseClassList { void* this; } return new __anonclass1 args; }() | Could that work correctly with the context pointer?Context pointer is irrelevant, it won't work. ```d bool b; auto v = b ? ( new class LeClass, LeInterface {} ) : ( new class LeClass, LeInterface {} ); ``` ``` bool b = false; LeClass v = b ? LeClass, LeInterface { void* this; system this() { super.this(); return this; } } , new __anonclass2 : (LeClass, LeInterface { void* this; system this() { super.this(); return this; } } , new __anonclass3); ``` The joys of expressions being a tree.Otherwise to generally fix it, there would need to be a way of declaring inline types in an expression. (We also might want inline template syntax).The only type we need to declare inline is classes, as far as I'm aware, which I did add to the grammar (but may have forgotten the class name identifier *sigh*).
Nov 21