Skip to content
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

Check for the CollectionExpression syntax kind early in UseSearchValuesAnalyzer #7279

Merged
merged 3 commits into from
Apr 9, 2024

Conversation

MihaZupan
Copy link
Member

@MihaZupan MihaZupan commented Apr 5, 2024

This appears to "resolve" the issue hit in dotnet/runtime#100520 (failures after ingesting #7252)

The issue appears to be that this else block

else
{
return
semanticModel.GetOperation(expression) is { } operation &&
IsConstantByteOrCharCollectionExpression(operation, values, out length);
}

is now being called with the @"\/"u8 expression.

While this condition will return false during the IsConstantByteOrCharCollectionExpression check, semanticModel.GetOperation(expression) intermittently fails when building System.Formats.Tar (consistently succeeds every second build ?!?).

Filtering out the expression kind before the call to semanticModel.GetOperation appears to "fix" the issue, but I don't understand why GetOperation would be failing like this in the first place 😕
We already have analyzer tests for this pattern (property returning utf8 string literals) that are perfectly happy with the current code, so this appears to be something specific to runtime code somehow.

The failing call stack from dotnet/runtime#100520:

SyntaxTree: C:\MihaZupan\runtime\src\libraries\System.Formats.Tar\src\System\Formats\Tar\TarHeader.Write.cs
SyntaxNode: pathNameBytes.LastIndexOfAny(PathInternal ... [InvocationExpressionSyntax]@[30810..30876) (554,26)-(554,92)
System.ArgumentException: Syntax node is not within syntax tree
at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.CheckSyntaxNode(CSharpSyntaxNode syntax)
at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetOperationCore(SyntaxNode node, CancellationToken cancellationToken)
at Microsoft.NetCore.CSharp.Analyzers.Performance.CSharpUseSearchValuesAnalyzer.IsConstantByteOrCharArrayCreationExpression(SemanticModel semanticModel, ExpressionSyntax expression, List`1 values, Int32& length)

Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 96.48%. Comparing base (e4d7ea6) to head (5705f38).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7279      +/-   ##
==========================================
- Coverage   96.48%   96.48%   -0.01%     
==========================================
  Files        1443     1443              
  Lines      345375   345376       +1     
  Branches    11362    11363       +1     
==========================================
- Hits       333222   333221       -1     
- Misses       9273     9276       +3     
+ Partials     2880     2879       -1     

@stephentoub
Copy link
Member

@CyrusNajmabadi, any idea what's going on here?

@CyrusNajmabadi
Copy link
Member

Nope. It's a better question for @cston or @333fred

@333fred
Copy link
Member

333fred commented Apr 5, 2024

Do we have a dump of the failure?

@MihaZupan
Copy link
Member Author

Here's a memory dump for a build of dotnet build .\src\libraries\System.Formats.Tar\src with a slightly modified analyzers build right after GetOperation throws: dump
Let me know if some other info would be more useful

@stephentoub stephentoub merged commit 7455f63 into dotnet:main Apr 9, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants