Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v15.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Jul 27, 2017
2 parents d09218e + 44b4f47 commit b7e23fe
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,49 @@ void F() {
}
}
}
";
this.VerifyCSharpDiagnostic(test);
}

[Fact]
public void DoNotReportWarningOnJTFRun()
{
var test = @"
using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Threading;
class ProjectProperties {
JoinableTaskFactory jtf;
void F() {
jtf.Run(async delegate {
await Task.Yield();
});
}
}
";
this.VerifyCSharpDiagnostic(test);
}

[Fact]
public void DoNotReportWarningOnJoinableTaskJoin()
{
var test = @"
using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Threading;
class ProjectProperties {
JoinableTaskFactory jtf;
void F() {
var jt = jtf.RunAsync(async delegate {
await Task.Yield();
});
jt.Join();
}
}
";
this.VerifyCSharpDiagnostic(test);
}
Expand Down
13 changes: 7 additions & 6 deletions src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
Expand All @@ -11,21 +12,21 @@

internal static class CommonInterest
{
internal static readonly IReadOnlyList<SyncBlockingMethod> JTFSyncBlockers = new[]
internal static readonly IEnumerable<SyncBlockingMethod> JTFSyncBlockers = new[]
{
new SyncBlockingMethod(Namespaces.MicrosoftVisualStudioThreading, Types.JoinableTaskFactory.TypeName, Types.JoinableTaskFactory.Run, Types.JoinableTaskFactory.RunAsync),
new SyncBlockingMethod(Namespaces.MicrosoftVisualStudioThreading, Types.JoinableTask.TypeName, Types.JoinableTask.Join, Types.JoinableTask.JoinAsync),
};

internal static readonly IReadOnlyList<SyncBlockingMethod> SyncBlockingMethods = new[]
internal static readonly IEnumerable<SyncBlockingMethod> ProblematicSyncBlockingMethods = new[]
{
new SyncBlockingMethod(Namespaces.MicrosoftVisualStudioThreading, Types.JoinableTaskFactory.TypeName, Types.JoinableTaskFactory.Run, Types.JoinableTaskFactory.RunAsync),
new SyncBlockingMethod(Namespaces.MicrosoftVisualStudioThreading, Types.JoinableTask.TypeName, Types.JoinableTask.Join, Types.JoinableTask.JoinAsync),
new SyncBlockingMethod(Namespaces.SystemThreadingTasks, nameof(Task), nameof(Task.Wait), null),
new SyncBlockingMethod(Namespaces.SystemRuntimeCompilerServices, nameof(TaskAwaiter), nameof(TaskAwaiter.GetResult), null),
};

internal static readonly IReadOnlyList<LegacyThreadSwitchingMethod> LegacyThreadSwitchingMethods = new[]
internal static readonly IEnumerable<SyncBlockingMethod> SyncBlockingMethods = JTFSyncBlockers.Concat(ProblematicSyncBlockingMethods);

internal static readonly IEnumerable<LegacyThreadSwitchingMethod> LegacyThreadSwitchingMethods = new[]
{
new LegacyThreadSwitchingMethod(Namespaces.MicrosoftVisualStudioShell, Types.ThreadHelper.TypeName, Types.ThreadHelper.Invoke),
new LegacyThreadSwitchingMethod(Namespaces.MicrosoftVisualStudioShell, Types.ThreadHelper.TypeName, Types.ThreadHelper.InvokeAsync),
Expand Down Expand Up @@ -76,7 +77,7 @@ internal static void InspectMemberAccess(
SyntaxNodeAnalysisContext context,
MemberAccessExpressionSyntax memberAccessSyntax,
DiagnosticDescriptor descriptor,
IReadOnlyList<SyncBlockingMethod> problematicMethods,
IEnumerable<SyncBlockingMethod> problematicMethods,
bool ignoreIfInsideAnonymousDelegate = false)
{
if (descriptor == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,7 @@ private void AnalyzeInvocation(SyntaxNodeAnalysisContext context)
context,
invocationExpressionSyntax.Expression as MemberAccessExpressionSyntax,
Descriptor,
CommonInterest.SyncBlockingMethods);

//if (CommonInterest.ShouldIgnoreContext(context))
//{
// return;
//}

//var node = (InvocationExpressionSyntax)context.Node;
//var invokeMethod = context.SemanticModel.GetSymbolInfo(context.Node).Symbol as IMethodSymbol;
//if (invokeMethod != null)
//{
// var taskType = context.SemanticModel.Compilation.GetTypeByMetadataName(typeof(Task).FullName);
// if (string.Equals(invokeMethod.Name, nameof(Task.Wait), StringComparison.Ordinal)
// && Utils.IsEqualToOrDerivedFrom(invokeMethod.ContainingType, taskType))
// {
// context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation()));
// }
// else if (string.Equals(invokeMethod.Name, "GetResult", StringComparison.Ordinal)
// && invokeMethod.ContainingType.Name.EndsWith("Awaiter", StringComparison.Ordinal))
// {
// context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation()));
// }
//}
CommonInterest.ProblematicSyncBlockingMethods);
}

private void AnalyzeMemberAccess(SyntaxNodeAnalysisContext context)
Expand All @@ -111,28 +89,6 @@ private void AnalyzeMemberAccess(SyntaxNodeAnalysisContext context)
memberAccessSyntax,
Descriptor,
CommonInterest.SyncBlockingProperties);

//if (CommonInterest.ShouldIgnoreContext(context))
//{
// return;
//}

//if (Utils.IsWithinNameOf(context.Node as ExpressionSyntax))
//{
// // We do not consider arguments to nameof( ) because they do not represent invocations of code.
// return;
//}

//var property = context.SemanticModel.GetSymbolInfo(context.Node).Symbol as IPropertySymbol;
//if (property != null)
//{
// var taskType = context.SemanticModel.Compilation.GetTypeByMetadataName(typeof(Task).FullName);
// if (string.Equals(property.Name, nameof(Task<object>.Result), StringComparison.Ordinal)
// && Utils.IsEqualToOrDerivedFrom(property.ContainingType, taskType))
// {
// context.ReportDiagnostic(Diagnostic.Create(Descriptor, context.Node.GetLocation()));
// }
//}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private static bool IsInTaskReturningMethodOrDelegate(SyntaxNodeAnalysisContext
&& returnType.BelongsToNamespace(Namespaces.SystemThreadingTasks);
}

private static bool InspectMemberAccess(SyntaxNodeAnalysisContext context, MemberAccessExpressionSyntax memberAccessSyntax, IReadOnlyList<CommonInterest.SyncBlockingMethod> problematicMethods)
private static bool InspectMemberAccess(SyntaxNodeAnalysisContext context, MemberAccessExpressionSyntax memberAccessSyntax, IEnumerable<CommonInterest.SyncBlockingMethod> problematicMethods)
{
if (memberAccessSyntax == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal void AnalyzeInvocation(SyntaxNodeAnalysisContext context)
this.InspectMemberAccess(context, invocationExpressionSyntax.Expression as MemberAccessExpressionSyntax, CommonInterest.JTFSyncBlockers);
}

private void InspectMemberAccess(SyntaxNodeAnalysisContext context, MemberAccessExpressionSyntax memberAccessSyntax, IReadOnlyList<CommonInterest.SyncBlockingMethod> problematicMethods)
private void InspectMemberAccess(SyntaxNodeAnalysisContext context, MemberAccessExpressionSyntax memberAccessSyntax, IEnumerable<CommonInterest.SyncBlockingMethod> problematicMethods)
{
if (memberAccessSyntax == null)
{
Expand Down

0 comments on commit b7e23fe

Please sign in to comment.