Skip to content

Make CpuMath not depending on ML.Core again #1724

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

Merged
merged 12 commits into from
Nov 27, 2018
29 changes: 11 additions & 18 deletions tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public sealed class BestFriendAnalyzer : DiagnosticAnalyzer
private const string Category = "Access";
internal const string DiagnosticId = "MSML_NoBestFriendInternal";

private string Title => "Cross-assembly internal access requires referenced item to have " + _attributeName + " attribute.";
private string Format => "Access of '{0}' is a cross assembly internal " +
private const string Title = "Cross-assembly internal access requires referenced item to have " + AttributeName + " attribute.";
private const string Format = "Access of '{0}' is a cross assembly internal " +
"reference, and the declaring assembly wants these accesses to be on something " +
"with the attribute " + _attributeName + ".";
private string Description =>
"with the attribute " + AttributeName + ".";
private const string Description =
"The identifier indicated is defined as an internal member of an assembly that has the " +
_assemblyAttributeName + " assembly-level attribute set. Even with friend access to that " +
"assembly, such a usage requires that the item have the " + _attributeName + " on it.";
AssemblyAttributeName + " assembly-level attribute set. Even with friend access to that " +
"assembly, such a usage requires that the item have the " + AttributeName + " on it.";

private DiagnosticDescriptor Rule =>
private static DiagnosticDescriptor Rule =
new DiagnosticDescriptor(DiagnosticId, Title, Format, Category,
DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description);

private string _attributeName;
private string _assemblyAttributeName;
private const string AttributeName = "Microsoft.ML.BestFriendAttribute (or Microsoft.ML.Runtime.Internal.CpuMath.BestFriendAttribute)";
private const string AssemblyAttributeName = "Microsoft.ML.WantsToBeBestFriendsAttribute (or Microsoft.ML.Runtime.Internal.CpuMath.WantsToBeBestFriendsAttribute)";

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
ImmutableArray.Create(Rule);
Expand Down Expand Up @@ -110,15 +110,8 @@ private void AnalyzeCore(SemanticModelAnalysisContext context, string attributeN

private void Analyze(SemanticModelAnalysisContext context)
{
// Analyzer function for BestFriend defined in Microsoft.ML
_attributeName = "Microsoft.ML.BestFriendAttribute";
_assemblyAttributeName = "Microsoft.ML.WantsToBeBestFriendsAttribute";
AnalyzeCore(context, _attributeName, _assemblyAttributeName);

// Analyzer function for BestFriend defined in Microsoft.ML.Hidden
_attributeName = "Microsoft.ML.Hidden.BestFriendAttribute";
_assemblyAttributeName = "Microsoft.ML.Hidden.WantsToBeBestFriendsAttribute";
AnalyzeCore(context, _attributeName, _assemblyAttributeName);
AnalyzeCore(context, "Microsoft.ML.BestFriendAttribute", "Microsoft.ML.WantsToBeBestFriendsAttribute");
AnalyzeCore(context, "Microsoft.ML.Hidden.BestFriendAttribute", "Microsoft.ML.Hidden.WantsToBeBestFriendsAttribute");
}
}
}