This repository was archived by the owner on Aug 2, 2023. It is now read-only.
Add a code analyzer to fix certain Span<T> usage#2206
Merged
ahsonkhan merged 4 commits intodotnet:masterfrom Apr 16, 2018
Merged
Add a code analyzer to fix certain Span<T> usage#2206ahsonkhan merged 4 commits intodotnet:masterfrom
ahsonkhan merged 4 commits intodotnet:masterfrom
Conversation
Contributor
Author
This was referenced Apr 13, 2018
Contributor
Author
|
Fixed all AsSpan() calls in aspnet: |
Contributor
Author
|
And corefxlab: #2207 |
| # Visual Studio 15 | ||
| VisualStudioVersion = 15.0.27604.0 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpanUsage", "SpanUsage\SpanUsage\SpanUsage.csproj", "{A99829A8-F185-4044-904F-211077DD11B8}" |
Member
There was a problem hiding this comment.
Is it really a sample?
Contributor
Author
There was a problem hiding this comment.
TODO: 1. Add to corefxlab.sln
It could be considered a sample code analyzer for span. I wanted to start it there, and move it to the solution. Would you be fine with adding it to the solution?
Member
There was a problem hiding this comment.
@terrajobst is working on a package for many .NET analyzers. I think this analyzer might be a good fit for such package.
Having said that, I am totally fine with adding it to this samples project short term.
This was referenced Apr 16, 2018
Contributor
Author
|
@dotnet-bot test Innerloop Ubuntu16.04 Release Build and Test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I wanted to try and create a code analyzer and used the following
Span<T>usage scenario as motivation:Collapse AsSpan().Slice(start, length) into AsSpan(start, length)
This can be used to fix https://github.com/dotnet/corefx/issues/27330 (see dotnet/corefx#29078)
Screenshots:
Majority of the code here is template code. Focus on the following files:
TODOs (I will file separate issues, and address outside this PR):
Update the VSIX descriptionFuture code analysis rules that we can introduce:
Memory<T>.Slice(...).Span=>Memory<T>.Span.Slice(...)- Extend the SpanUsage code analyzer to check for Memory<T>.Slice(...).Span #2215cc @dotnet/corefxlab-contrib, @tarekgh, @stephentoub, @atsushikan, @khellang, @VSadov, @KrzysztofCwalina