-
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
Address NRT issues found by targeting net5.0 #50895
Conversation
@@ -89,7 +89,7 @@ public static IEnumerable<TNode> GetCurrentNodes<TNode>(this SyntaxNode root, TN | |||
/// </summary> | |||
/// <param name="root">The root of the subtree containing the current node corresponding to the original tracked node.</param> | |||
/// <param name="node">The node instance originally tracked.</param> | |||
public static TNode GetCurrentNode<TNode>(this SyntaxNode root, TNode node) | |||
public static TNode? GetCurrentNode<TNode>(this SyntaxNode root, TNode node) |
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 one is public API bug, and causing bug in Features layer.
@@ -175,7 +175,7 @@ private static void ReportTelemetryIfNecessary(ImmutableArray<(TExpressionSyntax | |||
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); | |||
var spanNodes = diagnostics.SelectAsArray( | |||
d => root.FindNode(d.Location.SourceSpan, getInnermostNodeForTie: true) | |||
.GetAncestorsOrThis<TExpressionSyntax>().FirstOrDefault()); | |||
.GetAncestorsOrThis<TExpressionSyntax>().First()); |
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.
The code looks very confidential about it (defensive in outer code but not this), so I changed to First
.
...ortable/Completion/Providers/ImportCompletionProvider/AbstractTypeImportCompletionService.cs
Show resolved
Hide resolved
...orkspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.Session.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxTreeExtensions.cs
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxNodeExtensions.cs
Show resolved
Hide resolved
src/Compilers/Core/Portable/InternalUtilities/IncrementalHashExtensions.cs
Outdated
Show resolved
Hide resolved
@@ -19,11 +19,11 @@ internal static class RoslynLazyInitializer | |||
=> LazyInitializer.EnsureInitialized<T>(ref target!, valueFactory); | |||
|
|||
/// <inheritdoc cref="LazyInitializer.EnsureInitialized{T}(ref T, ref bool, ref object)"/> | |||
public static T EnsureInitialized<T>([NotNull] ref T? target, ref bool initialized, [NotNull] ref object? syncLock) | |||
public static T EnsureInitialized<T>([NotNull] ref T? target, ref bool initialized, [NotNullIfNotNull("syncLock")] ref object? syncLock) |
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.
That's clever ;-)
Do we still need RoslynLazyInitializer
now that LazyInitializer
is annotated? If it's not a trivial change, please file an issue and assign it to me.
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.
I copied the annotation from net5.0.
Lack of [NotNull]
should have impact on netstandard2.0
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.
Makes sense. Thanks
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 of compiler changes (iteration 3)
It's necessary to merge the latest master into this branch to fix the build. |
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.
Compiler changes LGTM Thanks (iteration 5)
@dotnet/roslyn-ide for review of the IDE changes. Thanks |
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.
Compiler changes LGTM, thanks.
@dotnet/roslyn-ide @jinujoseph for review of the IDE changes. Thanks |
@@ -106,6 +106,7 @@ public static ImmutableArray<string> FindSatelliteAssemblies(string filePath) | |||
var builder = ImmutableArray.CreateBuilder<string>(); | |||
|
|||
string? directory = Path.GetDirectoryName(filePath); | |||
RoslynDebug.AssertNotNull(directory); |
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.
❔ Is it ever possible for PathUtilities.IsAbsolute(filePath)
to return true but Path.GetDirectoryName(filePath)
to return null? If not, I almost prefer this form:
Debug.Assert(PathUtilities.IsAbsolute(filePath));
string directory = Path.GetDirectoryName(filePath)!;
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.
If path happens to be C:\
?
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.
Yeah, assert seems wise so I think this looks good -- there shouldn't ever be a directory name versus a file path being passed here, but if that were to happen...
src/Features/CSharp/Portable/EditAndContinue/CSharpEditAndContinueAnalyzer.cs
Outdated
Show resolved
Hide 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.
I made it partly through. It'll take a while to finish all cases since I really have to think about each one :)
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.
Generally looks good, but a few specific questions.
@@ -106,6 +106,7 @@ public static ImmutableArray<string> FindSatelliteAssemblies(string filePath) | |||
var builder = ImmutableArray.CreateBuilder<string>(); | |||
|
|||
string? directory = Path.GetDirectoryName(filePath); | |||
RoslynDebug.AssertNotNull(directory); |
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.
Yeah, assert seems wise so I think this looks good -- there shouldn't ever be a directory name versus a file path being passed here, but if that were to happen...
@@ -82,7 +82,7 @@ public NotificationOption2 Notification | |||
new("CodeStyleOption", // Ensure that we use "CodeStyleOption" as the name for back compat. | |||
new XAttribute(nameof(SerializationVersion), SerializationVersion), | |||
new XAttribute("Type", GetTypeNameForSerialization()), | |||
new XAttribute(nameof(Value), GetValueForSerialization()), | |||
new XAttribute(nameof(Value), GetValueForSerialization()!), |
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.
What's going on here? GetValueForSerialization is pretty directly marked as null-returning; can we revise that and push the suppression somewhere closer if possible?
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's only nullable when using uninitialized value with T=string. There could be a later refactor on that.
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.
I guess I'd say in that case we should:
- annotate GetValueForSerialization to return not-null.
- In the branch for string, do a Contract.ThrowIfNull().
- In the branch for bool, just ! since that's more obvious what's going on here.
Now I'm also a bit confused because the docs for the type say that T is only allowed to be bool or an enum, so clearly we are breaking that rule somewhere...? @mavasani or @jmarolf any idea if nulls are supposed to be supported here?
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.
@jmarolf confirmed that we don't expect to get nulls here, so current code is good.
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CodeStyle/CodeStyleOption2`1.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/TaskExtensions.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.Session.cs
Outdated
Show resolved
Hide resolved
...orkspaces/Core/Portable/FindSymbols/FindReferences/Finders/ParameterSymbolReferenceFinder.cs
Show resolved
Hide resolved
src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs
Outdated
Show resolved
Hide resolved
...ortable/Completion/Providers/ImportCompletionProvider/AbstractTypeImportCompletionService.cs
Show resolved
Hide resolved
public static T WaitAndGetResult<T>(this Task<T> task, CancellationToken cancellationToken) | ||
{ | ||
#if DEBUG | ||
if (IsThreadPoolThread(Thread.CurrentThread)) | ||
if (Thread.CurrentThread.IsThreadPoolThread) |
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 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.
Comments left; this is looking pretty good from my perspective although do want some of the feature area owners to comment on their own code.
@@ -82,7 +82,7 @@ public NotificationOption2 Notification | |||
new("CodeStyleOption", // Ensure that we use "CodeStyleOption" as the name for back compat. | |||
new XAttribute(nameof(SerializationVersion), SerializationVersion), | |||
new XAttribute("Type", GetTypeNameForSerialization()), | |||
new XAttribute(nameof(Value), GetValueForSerialization()), | |||
new XAttribute(nameof(Value), GetValueForSerialization()!), |
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.
I guess I'd say in that case we should:
- annotate GetValueForSerialization to return not-null.
- In the branch for string, do a Contract.ThrowIfNull().
- In the branch for bool, just ! since that's more obvious what's going on here.
Now I'm also a bit confused because the docs for the type say that T is only allowed to be bool or an enum, so clearly we are breaking that rule somewhere...? @mavasani or @jmarolf any idea if nulls are supposed to be supported here?
src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs
Outdated
Show resolved
Hide resolved
Thanks @huoyaoyuan for the fixes! |
Moving target is currently blocked by #50893 . Cherry-picking NRT commits. Part of #50822.
Mostly caused by LINQ, Path/Directory and xml dom.
I'm trying to use asset patterns in the same file.