Skip to content

Annotate more CodeAnalysis and CodeAnalysis.CSharp public types#43025

Merged
jcouv merged 20 commits intodotnet:masterfrom
jcouv:annotate-more5
Apr 24, 2020
Merged

Annotate more CodeAnalysis and CodeAnalysis.CSharp public types#43025
jcouv merged 20 commits intodotnet:masterfrom
jcouv:annotate-more5

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Apr 2, 2020

No description provided.

@jcouv jcouv added Area-Compilers Concept-Null Annotations The issue involves annotating an API for nullable reference types labels Apr 2, 2020
@jcouv jcouv self-assigned this Apr 2, 2020
@jcouv jcouv changed the title Annotate more CodeAnalysis and CodeAnalysis public types Annotate more CodeAnalysis and CodeAnalysis.CSharp public types Apr 2, 2020
@jcouv jcouv marked this pull request as ready for review April 2, 2020 18:32
@jcouv jcouv requested review from a team as code owners April 2, 2020 18:32
@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Apr 2, 2020
@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Apr 3, 2020
@jcouv jcouv added this to the 16.7 milestone Apr 3, 2020
@jcouv
Copy link
Member Author

jcouv commented Apr 8, 2020

@dotnet/roslyn-compiler for review. Thanks #Resolved

/// <summary>
/// Attaches the node to a SyntaxTree that the same options as <paramref name="oldTree"/>
/// </summary>
[return:NotNullIfNotNull("node")]
Copy link
Member

@333fred 333fred Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this imply that node should be annotated? #Closed

{
if (child.IsNode)
{
var d = child.AsNode().GetLastDirective(predicate);
Copy link
Member

@333fred 333fred Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth adding an extension method for this pattern with an out? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debated it, but Jared didn't introduce such pattern for most syntax changes he made. I'll stay with existing pattern.


In reply to: 405830860 [](ancestors = 405830860)

Copy link
Member

@jaredpar jaredpar Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely didn't use that pattern when I was first exploring annotating syntax. I was more getting used to the feature and didn't wan to change as much around it while I was annotating. Now though I'm more comfortable with that type of change and if we have a handy helper would opt for using it. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a helper yet. Would rather keep that separate.


In reply to: 414137782 [](ancestors = 414137782)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually, we do have AsNode(out ...). I'll use that


In reply to: 414179069 [](ancestors = 414179069,414137782)

/// <param name="cancellationToken">A cancellation token for the search.</param>
/// <returns>A DocumentationComment.</returns>
protected internal abstract string GetDocumentationForSymbol(
protected internal abstract string? GetDocumentationForSymbol(
Copy link
Member

@333fred 333fred Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string? [](start = 36, length = 7)

Man, this API is a real victim of lack of NRT. Some implementations return string.Empty when nothing is there, some return null. #WontFix

lazyLocalDiagnostics = lazyLocalDiagnostics ?? new Dictionary<SyntaxTree, Dictionary<DiagnosticAnalyzer, ImmutableArray<Diagnostic>.Builder>>();

foreach (var diagsByTree in diagnostics.GroupBy(d => d.Location.SourceTree))
foreach (var diagsByTree in diagnostics.GroupBy(d => d.Location.SourceTree!))
Copy link
Member

@333fred 333fred Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this safe? #Closed

Copy link
Member Author

@jcouv jcouv Apr 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From discussion with @mavasani, only diagnostics that are in source get into the local queues, others are treated as non-local or compilation.
Last commit (15) adds assertions instead of this suppression.


In reply to: 405838845 [](ancestors = 405838845)

private WrappedValue ComputeValue(TKey key)
{
var value = _computeValue(key);
return new WrappedValue { Value = value };
Copy link
Member

@333fred 333fred Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First time I've seen us fall victim to this pattern. #Closed


internal static XmlNameAttributeElementKind GetElementKind(this XmlNameAttributeSyntax attributeSyntax)
{
RoslynDebug.Assert(attributeSyntax.Parent is object);
Copy link
Member

@333fred 333fred Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be necessary. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will switch to to Debug.Assert (assuming that's what you meant)


In reply to: 405844872 [](ancestors = 405844872)

@333fred
Copy link
Member

333fred commented Apr 8, 2020

Done review pass (commit 13) #Resolved

@jcouv jcouv requested a review from 333fred April 22, 2020 22:51
@jcouv
Copy link
Member Author

jcouv commented Apr 22, 2020

@333fred @dotnet/roslyn-compiler Please take another look. Thanks #Resolved

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 15)

@333fred
Copy link
Member

333fred commented Apr 23, 2020

Looks like there's a newly introduced warning though. #Resolved

@jcouv
Copy link
Member Author

jcouv commented Apr 23, 2020

Yeah, I'll merge with latest master and resolve, but only after the review as some tools (cough CodeFlow) don't handle merge commits well ;-) #Resolved

case SyntaxKind.BaseConstructorInitializer:
case SyntaxKind.ThisConstructorInitializer:
var init = (ConstructorInitializerSyntax)original.Syntax;
Debug.Assert(init.Parent is object);
Copy link
Member

@jaredpar jaredpar Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused why this would be necessary but the line above was able to cast without adding a ? to the type. If init was indeed maybe null here I would expect that the type cast above would have to say that as well. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is not that init is maybe-null, but that init.Parent is.


In reply to: 414135650 [](ancestors = 414135650)

_name = declaratorSyntax.Identifier.ValueText;

var declaratorDiagnostics = DiagnosticBag.GetInstance();
Debug.Assert(declaratorSyntax.Parent is object);
Copy link
Member

@jaredpar jaredpar Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this Debug.Assert to the top of the method body as it's effectively a pre-condition for the method itself, not this specific point in the method. #Resolved

{
if (child.ContainsDirectives)
{
if (child.IsNode)
Copy link
Member

@jaredpar jaredpar Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using child.AsNode(out var node) here to avoid the ! below. #Resolved

{
if (child.IsNode)
{
var d = child.AsNode().GetLastDirective(predicate);
Copy link
Member

@jaredpar jaredpar Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely didn't use that pattern when I was first exploring annotating syntax. I was more getting used to the feature and didn't wan to change as much around it while I was annotating. Now though I'm more comfortable with that type of change and if we have a handy helper would opt for using it. #Resolved

@jcouv jcouv merged commit 2a4b133 into dotnet:master Apr 24, 2020
@ghost ghost modified the milestones: 16.7, Next Apr 24, 2020
@sharwell sharwell modified the milestones: Next, temp, 16.7.P1 Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Concept-Null Annotations The issue involves annotating an API for nullable reference types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants