-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Function Pointer Syntax #45684
New Function Pointer Syntax #45684
Conversation
… generators on Linux doesn't produce newline differences.
@dotnet/roslyn-compiler @AlekseyTs, this is now ready for review. @dotnet/roslyn-ide, this includes syntax changes to function pointer types, and formatter/intellisense context fixes to ensure the existing tests still pass. We'll still need to make intellisense changes for the calling convention location at a later point. |
await AssertFormatAsync(expected, content); | ||
} | ||
|
||
[Fact(Skip = "PROTOTYPE(func-ptr): Even though the rule is returning put a space, it's getting ignored, resulting in delegate*invalid <")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that this is because invalid
is parsed as trivia on a missing managed
or unmanaged
token? Those two are the only valid token types for the spot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "invalid" token isn't being parsed into the calling convention position? It looks based on the formatting change that's what you intended, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is parsed into the calling convention position, it's parsed as trivia on a missing managed
token.
In reply to: 451061448 [](ancestors = 451061448)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess if the formatter's rule is we don't touch things around missing stuff, then maybe the behavior you're seeing is correct. Once the user has typed correct code, it'll format correctly; if the user put their code into a broken state while they're doing other editing, not touching is fine for that small window.
...haredUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/SyntaxTreeExtensions.cs
Outdated
Show resolved
Hide resolved
@@ -961,15 +961,27 @@ public static bool IsDefaultExpressionContext(this SyntaxTree syntaxTree, int po | |||
{ | |||
case SyntaxKind.LessThanToken: | |||
case SyntaxKind.CommaToken: | |||
return token.Parent is FunctionPointerTypeSyntax; | |||
return token.Parent is FunctionPointerParameterList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you can delete the reference to #39865 now on line 959. #Resolved
await AssertFormatAsync(expected, content); | ||
} | ||
|
||
[Fact(Skip = "PROTOTYPE(func-ptr): Even though the rule is returning put a space, it's getting ignored, resulting in delegate*invalid <")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "invalid" token isn't being parsed into the calling convention position? It looks based on the formatting change that's what you intended, right?
switch (currentKind) | ||
{ | ||
case SyntaxKind.IdentifierToken: | ||
case SyntaxKindEx.ManagedKeyword: | ||
case SyntaxKindEx.UnmanagedKeyword: | ||
return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we just checked that the currentToken is the FunctionPointerCallingConvention's ManagedSpecifier then we can remove this block, right? And we're having to do this because of the funkiness around not being able to reference new syntax node types in our code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we could accomplish it that way. And yes, it would rely on new syntax node types.
In reply to: 451066787 [](ancestors = 451066787)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@333fred If you could either do that work or just file a bug to do it, I think I'd feel better since this then is a bit more flexible around precisely what we might get out of the parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #45897.
...haredUtilitiesAndExtensions/Workspace/CSharp/Extensions/ContextQuery/SyntaxTreeExtensions.cs
Outdated
Show resolved
Hide resolved
src/Features/CSharp/Portable/Completion/KeywordRecommenders/ReadOnlyKeywordRecommender.cs
Outdated
Show resolved
Hide resolved
* Revert unneeded publicapi file changes. * Simplify handling in some IDE code.
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/FunctionPointers/FunctionPointerMethodSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/FunctionPointers/FunctionPointerMethodSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/FunctionPointers/FunctionPointerMethodSymbol.cs
Outdated
Show resolved
Hide resolved
...ource/CompilerGeneratorTools/Source/VisualBasicSyntaxGenerator/GreenNodes/GreenNodeWriter.vb
Show resolved
Hide resolved
Done with review pass (iteration 8) #Closed |
* Rename ManagedSpecifier for clarity. * Handle more cases in symbol binding and increase code clarity. * Deduplicate type checks when binding parameters.
@AlekseyTs addressed feedback. In reply to: 655231532 [](ancestors = 655231532) |
src/Compilers/CSharp/Portable/Symbols/FunctionPointers/FunctionPointerMethodSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/FunctionPointers/FunctionPointerMethodSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs
Outdated
Show resolved
Hide resolved
Done with review pass (iteration 10) #Closed |
@AlekseyTs addressed feedback. In reply to: 656247690 [](ancestors = 656247690) |
src/Compilers/CSharp/Portable/Symbols/FunctionPointers/FunctionPointerMethodSymbol.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (iteration 11), modulo the remaining use of Text property #45684 (review)
@dotnet/roslyn-compiler for a second review. |
@jasonmalinowski did you have any more comments? |
} | ||
|
||
return token.Parent is ParameterSyntax { Parent: FunctionPointerTypeSyntax _ }; | ||
return token switch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to merge this and the previous switch into a single pattern patch...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to duplicate the parent is
check. When we can use C# 9 or
patterns this can be cleaned up :)
switch (currentKind) | ||
{ | ||
case SyntaxKind.IdentifierToken: | ||
case SyntaxKindEx.ManagedKeyword: | ||
case SyntaxKindEx.UnmanagedKeyword: | ||
return CreateAdjustSpacesOperation(1, AdjustSpacesOption.ForceSpacesIfOnSingleLine); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@333fred If you could either do that work or just file a bug to do it, I think I'd feel better since this then is a bit more flexible around precisely what we might get out of the parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, regarding the two formatting tests I think you should update the baseline to lock the current behavior; if the rule is we don't touch spacing of tokens when something is missing, then the behavior is actually expected. It's just as likely somebody got themselves into that broken state and doesn't want to be fighting with the formatter while stuff is clearly broken.
Other request is to either move some code to use the types to simplify the formatter checks, or file a bug on the IDE for later cleanup. Your call.
await AssertFormatAsync(expected, content); | ||
} | ||
|
||
[Fact(Skip = "PROTOTYPE(func-ptr): Even though the rule is returning put a space, it's getting ignored, resulting in delegate*invalid <")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess if the formatter's rule is we don't touch things around missing stuff, then maybe the behavior you're seeing is correct. Once the user has typed correct code, it'll format correctly; if the user put their code into a broken state while they're doing other editing, not touching is fine for that small window.
await AssertFormatAsync(expected, content); | ||
} | ||
|
||
[Fact(Skip = "PROTOTYPE(func-ptr): Even though the rule is returning put a space, it's getting ignored, resulting in delegate*invalid [")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: as long s it's formatting the stuff that it does understand, I guess that's good.
@dotnet/roslyn-compiler for a second review please |
Taking a look |
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
* Enable tests as appropriate * Fix doc comments * Remove unnecessary generic parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto-approval
This updates function pointers to use the new syntax decided on in LDM. This is syntax-level changes only: the updated calling convention binding will come in the next PR.
Fixes #44312.