-
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
Remove remaining artifacts of symbol-centric NonNullTypes context. #31607
Conversation
@@ -10,32 +11,33 @@ namespace Microsoft.CodeAnalysis.CSharp | |||
internal sealed class LazyMissingNonNullTypesContextDiagnosticInfo : LazyDiagnosticInfo |
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.
LazyMissingNonNullTypesContextDiagnosticInfo [](start = 26, length = 44)
Feels like we don't need this anymore (we can do this check eagerly). #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.
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)); |
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.
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
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 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. |
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.
// This call asserts. [](start = 69, length = 21)
nit: seems simpler to do throw ExceptionUtilities.UnexpectedValue(...);
as we do everywhere else #WontFix
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.
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) |
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.
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>"); | ||
} |
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.
} [](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
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.
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)
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.
Done with review pass (iteration 1). Minor questions/feedback on aliases, and removing one more lazy diagnostic.
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 Thanks (iteration 2)
customModifiers.NullToEmpty()); | ||
} | ||
|
||
internal static TypeSymbolWithAnnotations Create(TypeSymbol typeSymbol, ImmutableArray<ModifierInfo<TypeSymbol>> customModifiers) |
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.
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)); |
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.
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.
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.
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.
Closes #30171.
Closes #29838.