From 6d2efeaca56049b85d4e418f0e735454b8e0000c Mon Sep 17 00:00:00 2001 From: "Quirin F. Schroll" Date: Tue, 25 Oct 2022 16:00:17 +0200 Subject: [PATCH 01/10] Fix Issue 2753 --- spec/type.dd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/type.dd b/spec/type.dd index 484c40f210..1cd88d909e 100644 --- a/spec/type.dd +++ b/spec/type.dd @@ -13,6 +13,7 @@ $(H2 $(LNAME2 grammar, Grammar)) $(GRAMMAR $(GNAME Type): $(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK TypeSuffixes)$(OPT) + $(D ref) $(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK CallableSuffix) $(GLINK TypeSuffixes)$(OPT) $(GNAME TypeCtors): $(GLINK TypeCtor) @@ -30,7 +31,7 @@ $(GNAME BasicType): $(GLINK QualifiedIdentifier) $(GLINK Typeof) $(GLINK Typeof) $(D .) $(GLINK QualifiedIdentifier) - $(GLINK TypeCtor) $(D $(LPAREN)) $(GLINK Type) $(D $(RPAREN)) + $(GLINK TypeCtor)$(OPT) $(D $(LPAREN)) $(GLINK Type) $(D $(RPAREN)) $(GLINK Vector) $(GLINK2 traits, TraitsExpression) $(GLINK MixinType) @@ -77,6 +78,9 @@ $(GNAME TypeSuffix): $(D [) $(GLINK2 expression, AssignExpression) $(D ]) $(D [) $(GLINK2 expression, AssignExpression) $(D ..) $(GLINK2 expression, AssignExpression) $(D ]) $(D [) $(GLINK Type) $(D ]) + $(GLINK CallableSuffix) + +$(GNAME CallableSuffix): $(D delegate) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(D function) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT) From 6c3b3788c32d4a93fe1005595640c6cc5497ba60 Mon Sep 17 00:00:00 2001 From: "Quirin F. Schroll" Date: Thu, 10 Nov 2022 10:28:03 +0100 Subject: [PATCH 02/10] Remove trailing whitespace --- spec/type.dd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/type.dd b/spec/type.dd index 1cd88d909e..d1c74a7a43 100644 --- a/spec/type.dd +++ b/spec/type.dd @@ -79,7 +79,7 @@ $(GNAME TypeSuffix): $(D [) $(GLINK2 expression, AssignExpression) $(D ..) $(GLINK2 expression, AssignExpression) $(D ]) $(D [) $(GLINK Type) $(D ]) $(GLINK CallableSuffix) - + $(GNAME CallableSuffix): $(D delegate) $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) $(D function) $(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT) From 83b407850721bb071b924d6b8a80de1650631961 Mon Sep 17 00:00:00 2001 From: Quirin Schroll Date: Thu, 25 May 2023 15:13:10 +0200 Subject: [PATCH 03/10] Fix failure in dlang/dmd#15245 --- spec/traits.dd | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/traits.dd b/spec/traits.dd index 19e6e9557c..ae84a40fe8 100644 --- a/spec/traits.dd +++ b/spec/traits.dd @@ -1733,13 +1733,16 @@ static assert(__traits(isSame, foo, daz)); ) $(P The result is `true` if the two arguments are expressions - made up of literals or enums that evaluate to the same value.) + none of which are just symbols + that evaluate to the same value at compile-time.) $(SPEC_RUNNABLE_EXAMPLE_COMPILE --- enum e = 3; -static assert(__traits(isSame, (e), 3)); -static assert(__traits(isSame, 5, 2 + e)); +static assert(!__traits(isSame, e, 3)); // e is a symbol +static assert(!__traits(isSame, (e), 3)); // (e) is a symbol +static assert( __traits(isSame, cast(typeof(e)) e, 3)); // cast is an expression +static assert( __traits(isSame, 5, 2 + e)); // 5 and 2 + e are expressions --- ) $(P If the two arguments are both From 76e7813c18de29b8333b4f48b2360011b414ea26 Mon Sep 17 00:00:00 2001 From: Quirin Schroll Date: Fri, 28 Jun 2024 16:35:30 +0200 Subject: [PATCH 04/10] Update to match DIP draft --- spec/expression.dd | 4 ++-- spec/function.dd | 2 ++ spec/type.dd | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/expression.dd b/spec/expression.dd index 4890478302..2d3a09d07b 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -2272,8 +2272,8 @@ $(H3 $(LNAME2 function_literals, Function Literals)) $(GRAMMAR $(GNAME FunctionLiteral): - $(D function) $(GLINK RefOrAutoRef)$(OPT) $(GLINK2 type, Type)$(OPT) $(GLINK ParameterWithAttributes)$(OPT) $(GLINK FunctionLiteralBody) - $(D delegate) $(GLINK RefOrAutoRef)$(OPT) $(GLINK2 type, Type)$(OPT) $(GLINK ParameterWithMemberAttributes)$(OPT) $(GLINK FunctionLiteralBody) + $(D function) $(GLINK2 attribute, LinkageAttribute)$(opt) $(GLINK RefOrAutoRef)$(OPT) $(GLINK2 type, Type)$(OPT) $(GLINK ParameterWithAttributes)$(OPT) $(GLINK FunctionLiteralBody) + $(D delegate) $(GLINK2 attribute, LinkageAttribute)$(opt) $(GLINK RefOrAutoRef)$(OPT) $(GLINK2 type, Type)$(OPT) $(GLINK ParameterWithMemberAttributes)$(OPT) $(GLINK FunctionLiteralBody) $(GLINK RefOrAutoRef)$(OPT) $(GLINK ParameterWithMemberAttributes) $(GLINK FunctionLiteralBody) $(GLINK2 statement, BlockStatement) $(IDENTIFIER) $(D =>) $(GLINK AssignExpression) diff --git a/spec/function.dd b/spec/function.dd index 11c2f44b0f..8b240a2a4e 100644 --- a/spec/function.dd +++ b/spec/function.dd @@ -48,6 +48,8 @@ $(GNAME Parameter): $(GNAME ParameterDeclaration): $(GLINK ParameterAttributes)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) + $(GLINK ParameterAttributes)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(GLINK2 type, TypeCtors)$(opt) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) + $(GLINK ParameterAttributes)$(OPT) $(GLINK2 attribute, LinkageAttribute) `ref` $(GLINK2 type, TypeCtors)$(opt) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) $(GLINK ParameterAttributes)$(OPT) $(GLINK2 type, Type) $(GNAME ParameterAttributes): diff --git a/spec/type.dd b/spec/type.dd index cc951faa12..cf2a15a836 100644 --- a/spec/type.dd +++ b/spec/type.dd @@ -13,7 +13,9 @@ $(H2 $(LNAME2 grammar, Grammar)) $(GRAMMAR $(GNAME Type): $(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK TypeSuffixes)$(OPT) - $(D ref) $(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK CallableSuffix) $(GLINK TypeSuffixes)$(OPT) + $(GLINK TypeCtors)$(OPT) $(D ref) $(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK TypeSuffixes) + $(GLINK TypeCtors)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK TypeSuffixes) + $(GLINK TypeCtors)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(D ref) $(GLINK TypeCtors)$(OPT) $(GLINK BasicType) $(GLINK TypeSuffixes) $(GNAME TypeCtors): $(GLINK TypeCtor) From ab120f92922dc51f21c121584f82027723b615ab Mon Sep 17 00:00:00 2001 From: Quirin Schroll Date: Tue, 2 Jul 2024 19:07:26 +0200 Subject: [PATCH 05/10] Fix failing tests --- spec/traits.dd | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/traits.dd b/spec/traits.dd index 0eaece0614..05c3f39059 100644 --- a/spec/traits.dd +++ b/spec/traits.dd @@ -1802,7 +1802,6 @@ $(SPEC_RUNNABLE_EXAMPLE_COMPILE --- enum e = 3; static assert(!__traits(isSame, e, 3)); // e is a symbol -static assert(!__traits(isSame, (e), 3)); // (e) is a symbol static assert( __traits(isSame, cast(typeof(e)) e, 3)); // cast is an expression static assert( __traits(isSame, 5, 2 + e)); // 5 and 2 + e are expressions --- From ee43b047deac699eac8eba7e1020f8de1d547b32 Mon Sep 17 00:00:00 2001 From: Quirin Schroll Date: Wed, 3 Jul 2024 19:36:47 +0200 Subject: [PATCH 06/10] Mention `CallableSuffix` requirement --- spec/type.dd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/type.dd b/spec/type.dd index cf2a15a836..98ed0f5834 100644 --- a/spec/type.dd +++ b/spec/type.dd @@ -99,6 +99,11 @@ $(GNAME QualifiedIdentifier): * $(RELATIVE_LINK2 derived-data-types, Derived Data Types) build on leaf types. * $(RELATIVE_LINK2 user-defined-types, User-Defined Types) are aggregates of basic and derived types. +$(P For a $(GLINK Type) to be well-formed, +if it uses a $(GLINK2 attribute, LinkageAttribute) and/or `ref`, +the sequence of $(GLINK TypeSuffixes) must include exactly one $(GLINK CallableSuffix).) + + $(H2 $(LEGACY_LNAME2 Basic Data Types, basic-data-types, Basic Data Types)) $(TABLE_3COLS Basic Data Types, From f55cbce59f629158f302cac80cdebf7a1ca90c35 Mon Sep 17 00:00:00 2001 From: Quirin Schroll Date: Wed, 3 Jul 2024 19:38:58 +0200 Subject: [PATCH 07/10] Explain linkage and `ref` for function pointer types --- spec/type.dd | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/type.dd b/spec/type.dd index 98ed0f5834..1e1eed9454 100644 --- a/spec/type.dd +++ b/spec/type.dd @@ -617,13 +617,19 @@ A function type e.g. `int(int)` $(DDSUBLINK spec/declaration, alias-function, ca A function type is only used for type tests or as the target type of a pointer.) $(P Instantiating a function type is illegal. Instead, a pointer to function -or delegate can be used. Those have these type forms respectively:) +or delegate can be used. Somewhat simplified, those have these type forms respectively:) $(GRAMMAR_INFORMATIVE -$(GLINK Type) `function` $(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT) -$(GLINK Type) `delegate` $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) +$(GLINK2 attribute, LinkageAttribute)$(OPT) $(GLINK Type) `function` $(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT) +$(GLINK2 attribute, LinkageAttribute)$(OPT) $(GLINK Type) `delegate` $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) + +$(GLINK2 attribute, LinkageAttribute)$(OPT) $(D ref) $(GLINK BasicType) `function` $(GLINK2 function, Parameters) $(GLINK2 function, FunctionAttributes)$(OPT) +$(GLINK2 attribute, LinkageAttribute)$(OPT) $(D ref) $(GLINK BasicType) `delegate` $(GLINK2 function, Parameters) $(GLINK2 function, MemberFunctionAttributes)$(OPT) ) +$(P When linkage attributes and/or `ref` are present, a function pointer or delegate type is not a $(GLINK BasicType), +and some contexts require surrounding them by parentheses. + $(SPEC_RUNNABLE_EXAMPLE_COMPILE --- void f(int); From 63ddf581dfe39dd8bc06b95895dbcba34ce78aa9 Mon Sep 17 00:00:00 2001 From: Quirin Schroll Date: Wed, 3 Jul 2024 19:39:25 +0200 Subject: [PATCH 08/10] Prepare example --- spec/type.dd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/type.dd b/spec/type.dd index 1e1eed9454..14d6c2b5d3 100644 --- a/spec/type.dd +++ b/spec/type.dd @@ -636,6 +636,10 @@ void f(int); alias Fun = void(int); static assert(is(typeof(f) == Fun)); static assert(is(Fun* == void function(int))); + +// ref int g(ref int x) => x; +// (ref int function(ref int)) fp = &g; // variable declaration requires `()` +// static assert(is(typeof(fp) == ref int function(ref int))); // `is` requires no extra `()` --- ) From 3d2a525bc56502a0919e2ed6f686189d7ba10ddf Mon Sep 17 00:00:00 2001 From: Quirin Schroll Date: Mon, 15 Jul 2024 13:53:12 +0200 Subject: [PATCH 09/10] Update spec to reflect proposed grammar changes --- spec/statement.dd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/statement.dd b/spec/statement.dd index 832ffc88ee..3e1cc6e62e 100644 --- a/spec/statement.dd +++ b/spec/statement.dd @@ -241,6 +241,8 @@ $(GNAME IfCondition): $(EXPRESSION) $(GLINK IfConditionStorageClasses) $(GLINK_LEX Identifier) $(D =) $(EXPRESSION) $(GLINK IfConditionStorageClasses)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) $(D =) $(EXPRESSION) + $(GLINK IfConditionStorageClasses)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(GLINK2 type, TypeCtors)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) $(D =) $(EXPRESSION) + $(GLINK IfConditionStorageClasses)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(D ref) $(GLINK2 type, TypeCtors)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) $(D =) $(EXPRESSION) $(GNAME IfConditionStorageClasses): $(GLINK IfConditionStorageClass) From 5d883d554d93f1ef73c0c1d3df424c85e95c793a Mon Sep 17 00:00:00 2001 From: Quirin Schroll Date: Sun, 22 Sep 2024 02:08:10 +0200 Subject: [PATCH 10/10] Update spec to reflect proposed grammar changes --- spec/expression.dd | 7 +++++-- spec/function.dd | 2 +- spec/statement.dd | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/expression.dd b/spec/expression.dd index 3055977bcf..f918d48d8d 100644 --- a/spec/expression.dd +++ b/spec/expression.dd @@ -2242,8 +2242,8 @@ $(H3 $(LNAME2 function_literals, Function Literals)) $(GRAMMAR $(GNAME FunctionLiteral): - $(D function) $(GLINK2 attribute, LinkageAttribute)$(opt) $(GLINK RefOrAutoRef)$(OPT) $(GLINK2 type, Type)$(OPT) $(GLINK ParameterWithAttributes)$(OPT) $(GLINK FunctionLiteralBody) - $(D delegate) $(GLINK2 attribute, LinkageAttribute)$(opt) $(GLINK RefOrAutoRef)$(OPT) $(GLINK2 type, Type)$(OPT) $(GLINK ParameterWithMemberAttributes)$(OPT) $(GLINK FunctionLiteralBody) + $(D function) $(GLINK2 attribute, LinkageAttribute)$(opt) $(GLINK RefOrAutoRef)$(OPT) $(GLINK SuffixedBasicType)$(OPT) $(GLINK ParameterWithAttributes)$(OPT) $(GLINK FunctionLiteralBody) + $(D delegate) $(GLINK2 attribute, LinkageAttribute)$(opt) $(GLINK RefOrAutoRef)$(OPT) $(GLINK SuffixedBasicType)$(OPT) $(GLINK ParameterWithMemberAttributes)$(OPT) $(GLINK FunctionLiteralBody) $(GLINK RefOrAutoRef)$(OPT) $(GLINK ParameterWithMemberAttributes) $(GLINK FunctionLiteralBody) $(GLINK2 statement, BlockStatement) $(IDENTIFIER) $(D =>) $(GLINK AssignExpression) @@ -2261,6 +2261,9 @@ $(GNAME FunctionLiteralBody): $(GNAME RefOrAutoRef): $(D ref) $(D auto ref) + +$(GNAME SuffixedBasicType): + $(GLINK2 type, BasicType) $(GLINK2 type, TypeSuffixes)$(OPT) ) $(P $(I FunctionLiteral)s enable embedding anonymous functions diff --git a/spec/function.dd b/spec/function.dd index 006725cf6a..33ee8c73fa 100644 --- a/spec/function.dd +++ b/spec/function.dd @@ -49,7 +49,7 @@ $(GNAME Parameter): $(GNAME ParameterDeclaration): $(GLINK ParameterAttributes)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) $(GLINK ParameterAttributes)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(GLINK2 type, TypeCtors)$(opt) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) - $(GLINK ParameterAttributes)$(OPT) $(GLINK2 attribute, LinkageAttribute) `ref` $(GLINK2 type, TypeCtors)$(opt) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) + $(GLINK ParameterAttributes)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(D ref) $(GLINK2 type, TypeCtors)$(opt) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) $(GLINK ParameterAttributes)$(OPT) $(GLINK2 type, Type) $(GNAME ParameterAttributes): diff --git a/spec/statement.dd b/spec/statement.dd index 3e1cc6e62e..f6f88aeca4 100644 --- a/spec/statement.dd +++ b/spec/statement.dd @@ -503,6 +503,8 @@ $(GNAME ForeachTypeList): $(GNAME ForeachType): $(GLINK ForeachTypeAttributes)$(OPT) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) + $(GLINK ForeachTypeAttributes)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) + $(GLINK ForeachTypeAttributes)$(OPT) $(GLINK2 attribute, LinkageAttribute) $(D ref) $(GLINK2 type, BasicType) $(GLINK2 declaration, Declarator) $(GLINK ForeachTypeAttributes)$(OPT) $(GLINK_LEX Identifier) $(GLINK ForeachTypeAttributes)$(OPT) $(D alias) $(GLINK_LEX Identifier)