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

Remove remaining artifacts of symbol-centric NonNullTypes context. #31607

Merged
merged 4 commits into from
Dec 10, 2018

Conversation

AlekseyTs
Copy link
Contributor

Closes #30171.
Closes #29838.

@AlekseyTs AlekseyTs requested review from 333fred, cston and jcouv December 7, 2018 03:06
@AlekseyTs AlekseyTs requested a review from a team as a code owner December 7, 2018 03:06
@AlekseyTs
Copy link
Contributor Author

@cston, @jcouv, @333fred Please review.

@@ -10,32 +11,33 @@ namespace Microsoft.CodeAnalysis.CSharp
internal sealed class LazyMissingNonNullTypesContextDiagnosticInfo : LazyDiagnosticInfo
Copy link
Member

@jcouv jcouv Dec 7, 2018

Choose a reason for hiding this comment

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

LazyMissingNonNullTypesContextDiagnosticInfo [](start = 26, length = 44)

Feels like we don't need this anymore (we can do this check eagerly). #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feels like we don't need this anymore (we can do this check eagerly).

No, we cannot do this eagerly because this class is used when we cannot ask if a type is a value type due to the risk of going into a cycle.


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

@@ -834,7 +831,7 @@ private NamespaceOrTypeOrAliasSymbolWithAnnotations UnwrapAlias(NamespaceOrTypeO
if (symbol.IsAlias)
{
AliasSymbol discarded;
return NamespaceOrTypeOrAliasSymbolWithAnnotations.CreateUnannotated(NonNullTypesContext, (NamespaceOrTypeSymbol)UnwrapAlias(symbol.Symbol, out discarded, diagnostics, syntax, basesBeingResolved));
return NamespaceOrTypeOrAliasSymbolWithAnnotations.CreateUnannotated(symbol.IsNullableEnabled, (NamespaceOrTypeSymbol)UnwrapAlias(symbol.Symbol, out discarded, diagnostics, syntax, basesBeingResolved));
Copy link
Member

@jcouv jcouv Dec 7, 2018

Choose a reason for hiding this comment

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

symbol.IsNullableEnabled [](start = 85, length = 24)

It would be good to update the speclet to cover aliases.
My recollection is that the nullable context at the definition of the alias should not affect its top-level nullability, because it doesn't have one. The nullability comes from the place where the alias is used.
Is that correct? #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be good to update the speclet to cover aliases.

There is no change around aliases here, the context was taken from the binding position before and is taken from the binding position now. The symbol here is not an alias symbol, it is an NamespaceOrTypeOrAliasSymbolWithAnnotations structure. AliasSymbol stores only NamespaceOrTypeSymbol it never stored nullability or context. UsingDirectiveSyntax was never allowing NullableTypeSyntax as the target name.


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

case TypeParameterConstraintKind.NotNullableReferenceType:
break;
default:
ExceptionUtilities.UnexpectedValue(constraints); // This call asserts.
Copy link
Member

@jcouv jcouv Dec 7, 2018

Choose a reason for hiding this comment

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

// This call asserts. [](start = 69, length = 21)

nit: seems simpler to do throw ExceptionUtilities.UnexpectedValue(...); as we do everywhere else #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems simpler to do throw ExceptionUtilities.UnexpectedValue(...); as we do everywhere else

I do not find this simpler and we do use this method for asserts in several places in the codebase, this is not a unique instance.


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

AssertNonNullTypesContext_22(source, WithNonNullTypesTrue(), type, "A<System.String!>");
}

private static void AssertNonNullTypesContext_22(string source, CSharpCompilationOptions options, TypeSyntax type, string expected)
Copy link
Member

@jcouv jcouv Dec 7, 2018

Choose a reason for hiding this comment

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

AssertNonNullTypesContext_22 [](start = 28, length = 28)

Since this method is re-used, consider giving it a meaningful name. Perhaps VerifySpeculativeTypeInfo or something even more specific (to distinguish from AssertNonNullTypesContext_30). #Resolved

"
);

AssertNonNullTypesContext_30(source, WithNonNullTypesFalse(), type, "A<System.String>");
}
Copy link
Member

@jcouv jcouv Dec 7, 2018

Choose a reason for hiding this comment

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

} [](start = 8, length = 1)

Consider adding a test showing that the last token in a qualified type name is the one that determines the nullable context. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider adding a test showing that the last token in a qualified type name is the one that determines the nullable context.

Current tests cover all the cases when the context is queried. Implementation doesn't depend on whether IdentifiernameSyntax,or GenericNamesyntax are quilified.


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

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 1). Minor questions/feedback on aliases, and removing one more lazy diagnostic.

@jcouv jcouv self-assigned this Dec 7, 2018
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 2)

@AlekseyTs
Copy link
Contributor Author

@cston, @333fred Please review.

customModifiers.NullToEmpty());
}

internal static TypeSymbolWithAnnotations Create(TypeSymbol typeSymbol, ImmutableArray<ModifierInfo<TypeSymbol>> customModifiers)
Copy link
Member

@cston cston Dec 10, 2018

Choose a reason for hiding this comment

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

Create [](start = 50, length = 6)

Is this used by SymbolFactory only? If so, please move the method back to that class as a helper method to avoid adding the extra overload here, especially since it uses ModifierInfo<T>. #Resolved

return typeParameters.SelectAsArray((tp) =>
TypeSymbolWithAnnotations.Create(NonNullTypesNullContext.Instance, tp, isAnnotated: false, customModifiers: ImmutableArray<CustomModifier>.Empty)
);
return typeParameters.SelectAsArray((tp) => TypeSymbolWithAnnotations.Create(tp));
Copy link
Member

Choose a reason for hiding this comment

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

There seem to be a few places using this method of creation. We could consider extracting this into a helper and doing the iteration by hand, saving the lambda allocations.

Copy link
Member

@cston cston Dec 10, 2018

Choose a reason for hiding this comment

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

A helper method should continue to use a lambda since the additional memory for a single static delegate instance is probably similar to the extra instructions from a loop.

@AlekseyTs AlekseyTs merged commit 0610c79 into dotnet:master Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants