From f0b8c36c103fe590ef289a201b25356b027652ac Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Mon, 26 Nov 2018 14:31:07 -0800 Subject: [PATCH 01/12] Make CpuMath not depending on ML.Core again --- src/Microsoft.ML.Core/BestFriendAttribute.cs | 6 +++++ .../Microsoft.ML.Core.csproj | 4 ---- .../Properties/AssemblyInfo.cs | 10 -------- src/Microsoft.ML.Core/Properties/PublicKey.cs | 19 +++++++++++++++ src/Microsoft.ML.Core/Utilities/Contracts.cs | 23 +++++++++++++++++++ src/Microsoft.ML.CpuMath/AssemblyInfo.cs | 2 +- .../Microsoft.ML.CpuMath.csproj | 14 +++++++---- 7 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 src/Microsoft.ML.Core/Properties/PublicKey.cs diff --git a/src/Microsoft.ML.Core/BestFriendAttribute.cs b/src/Microsoft.ML.Core/BestFriendAttribute.cs index e73c10e241..4d19b60836 100644 --- a/src/Microsoft.ML.Core/BestFriendAttribute.cs +++ b/src/Microsoft.ML.Core/BestFriendAttribute.cs @@ -4,7 +4,13 @@ using System; +#if PRIVATE_CONTRACTS +// CpuMath has its own BestFriend and WantsToBeBestFriends attributes for making itself a standalone module +namespace Microsoft.ML.Runtime.Internal.CpuMath +#else +// This namespace contains the BestFriend and WantsToBeBestFriends attributes generally used in ML.NET project settings namespace Microsoft.ML +#endif { /// /// Intended to be applied to types and members marked as internal to indicate that friend access of this diff --git a/src/Microsoft.ML.Core/Microsoft.ML.Core.csproj b/src/Microsoft.ML.Core/Microsoft.ML.Core.csproj index b41d089d03..a672faca77 100644 --- a/src/Microsoft.ML.Core/Microsoft.ML.Core.csproj +++ b/src/Microsoft.ML.Core/Microsoft.ML.Core.csproj @@ -8,10 +8,6 @@ Microsoft.ML - - - - diff --git a/src/Microsoft.ML.Core/Properties/AssemblyInfo.cs b/src/Microsoft.ML.Core/Properties/AssemblyInfo.cs index aaa44a6bc7..a61e96ce7b 100644 --- a/src/Microsoft.ML.Core/Properties/AssemblyInfo.cs +++ b/src/Microsoft.ML.Core/Properties/AssemblyInfo.cs @@ -40,13 +40,3 @@ [assembly: InternalsVisibleTo(assemblyName: "Microsoft.ML.Transforms" + PublicKey.Value)] [assembly: WantsToBeBestFriends] - -namespace Microsoft.ML -{ - [BestFriend] - internal static class PublicKey - { - public const string Value = ", PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb"; - public const string TestValue = ", PublicKey=002400000480000094000000060200000024000052534131000400000100010015c01ae1f50e8cc09ba9eac9147cf8fd9fce2cfe9f8dce4f7301c4132ca9fb50ce8cbf1df4dc18dd4d210e4345c744ecb3365ed327efdbc52603faa5e21daa11234c8c4a73e51f03bf192544581ebe107adee3a34928e39d04e524a9ce729d5090bfd7dad9d10c722c0def9ccc08ff0a03790e48bcd1f9b6c476063e1966a1c4"; - } -} diff --git a/src/Microsoft.ML.Core/Properties/PublicKey.cs b/src/Microsoft.ML.Core/Properties/PublicKey.cs new file mode 100644 index 0000000000..94ece8914b --- /dev/null +++ b/src/Microsoft.ML.Core/Properties/PublicKey.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#if !PRIVATE_CONTRACTS +// This namespace contains the PublicKey generally used in ML.NET project settings +namespace Microsoft.ML +#else +// CpuMath module has its own PublicKey for isolating itself from Microsoft.ML.Core +namespace Microsoft.ML.Runtime.Internal.CpuMath +#endif +{ + [BestFriend] + internal static class PublicKey + { + public const string Value = ", PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb"; + public const string TestValue = ", PublicKey=002400000480000094000000060200000024000052534131000400000100010015c01ae1f50e8cc09ba9eac9147cf8fd9fce2cfe9f8dce4f7301c4132ca9fb50ce8cbf1df4dc18dd4d210e4345c744ecb3365ed327efdbc52603faa5e21daa11234c8c4a73e51f03bf192544581ebe107adee3a34928e39d04e524a9ce729d5090bfd7dad9d10c722c0def9ccc08ff0a03790e48bcd1f9b6c476063e1966a1c4"; + } +} diff --git a/src/Microsoft.ML.Core/Utilities/Contracts.cs b/src/Microsoft.ML.Core/Utilities/Contracts.cs index 67f559d2fb..9a4ed9b8e1 100644 --- a/src/Microsoft.ML.Core/Utilities/Contracts.cs +++ b/src/Microsoft.ML.Core/Utilities/Contracts.cs @@ -16,7 +16,11 @@ using System.IO; using System.Threading; +#if PRIVATE_CONTRACTS +namespace Microsoft.ML.Runtime.Internal +#else namespace Microsoft.ML.Runtime +#endif { using Conditional = System.Diagnostics.ConditionalAttribute; using Debug = System.Diagnostics.Debug; @@ -27,7 +31,11 @@ namespace Microsoft.ML.Runtime /// totally replace the exception, etc. It is not legal to return null from /// Process (unless null was passed in, which really shouldn't happen). /// +#if PRIVATE_CONTRACTS + internal interface IExceptionContext +#else public interface IExceptionContext +#endif { TException Process(TException ex) where TException : Exception; @@ -38,7 +46,18 @@ TException Process(TException ex) string ContextDescription { get; } } +#if PRIVATE_CONTRACTS + [Flags] + internal enum MessageSensitivity + { + None = 0, + Unknown = ~None + } +#endif + +#if !PRIVATE_CONTRACTS [BestFriend] +#endif internal static partial class Contracts { public const string IsMarkedKey = "ML_IsMarked"; @@ -137,6 +156,7 @@ public static MessageSensitivity Sensitivity(this Exception ex) return (ex.Data[SensitivityKey] as MessageSensitivity?) ?? MessageSensitivity.Unknown; } +#if !PRIVATE_CONTRACTS /// /// This is an internal convenience implementation of an exception context to make marking /// exceptions with a specific sensitivity flag a bit less onorous. The alternative to a scheme @@ -213,6 +233,7 @@ public static IExceptionContext UserSensitive(this IExceptionContext ctx) /// public static IExceptionContext SchemaSensitive(this IExceptionContext ctx) => new SensitiveExceptionContext(ctx, MessageSensitivity.Schema); +#endif /// /// Sets the assert handler to the given function, returning the previous handler. @@ -721,6 +742,7 @@ public static void CheckIO(this IExceptionContext ctx, bool f, string msg) throw ExceptIO(ctx, msg); } +#if !PRIVATE_CONTRACTS /// /// Check state of the host and throw exception if host marked to stop all exection. /// @@ -729,6 +751,7 @@ public static void CheckAlive(this IHostEnvironment env) if (env.IsCancelled) throw Process(new OperationCanceledException("Operation was cancelled."), env); } +#endif /// /// This documents that the parameter can legally be null. diff --git a/src/Microsoft.ML.CpuMath/AssemblyInfo.cs b/src/Microsoft.ML.CpuMath/AssemblyInfo.cs index 17bdf84324..edf19fa782 100644 --- a/src/Microsoft.ML.CpuMath/AssemblyInfo.cs +++ b/src/Microsoft.ML.CpuMath/AssemblyInfo.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Runtime.CompilerServices; -using Microsoft.ML; +using Microsoft.ML.Runtime.Internal.CpuMath; [assembly: InternalsVisibleTo("Microsoft.ML.CpuMath.UnitTests.netstandard" + PublicKey.TestValue)] [assembly: InternalsVisibleTo("Microsoft.ML.CpuMath.UnitTests.netcoreapp" + PublicKey.TestValue)] diff --git a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj index 8fa97116ba..5bb36c11a6 100644 --- a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj +++ b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj @@ -5,6 +5,7 @@ netstandard2.0;netcoreapp3.0 Microsoft.ML.CpuMath true + $(DefineConstants);CORECLR;PRIVATE_CONTRACTS 7.3 @@ -12,6 +13,15 @@ + + + + + + + + + @@ -24,8 +34,4 @@ - - - - From 1ee058d165a2c54ccdeb036dabd6ef89bbe50344 Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Mon, 26 Nov 2018 17:27:47 -0800 Subject: [PATCH 02/12] Modify BestFriend attributes and their analyzer --- src/Microsoft.ML.Core/BestFriendAttribute.cs | 2 +- src/Microsoft.ML.Core/Properties/PublicKey.cs | 2 ++ src/Microsoft.ML.Core/Utilities/Contracts.cs | 4 +--- src/Microsoft.ML.CpuMath/AlignedArray.cs | 1 + src/Microsoft.ML.CpuMath/AlignedMatrix.cs | 1 + src/Microsoft.ML.CpuMath/AssemblyInfo.cs | 1 + .../CpuAligenedMathUtils.cs | 2 ++ .../CpuMathUtils.netcoreapp.cs | 1 + .../CpuMathUtils.netstandard.cs | 1 + src/Microsoft.ML.CpuMath/EigenUtils.cs | 2 ++ src/Microsoft.ML.CpuMath/ICpuBuffer.cs | 1 + src/Microsoft.ML.CpuMath/IntUtils.cs | 1 + .../Microsoft.ML.CpuMath.csproj | 4 ---- .../ProbabilityFunctions.cs | 1 + src/Microsoft.ML.CpuMath/Sse.cs | 1 + src/Microsoft.ML.CpuMath/Thunk.cs | 1 + .../BestFriendAnalyzer.cs | 19 ++++++++++++++----- 17 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.ML.Core/BestFriendAttribute.cs b/src/Microsoft.ML.Core/BestFriendAttribute.cs index 4d19b60836..21e1c9c954 100644 --- a/src/Microsoft.ML.Core/BestFriendAttribute.cs +++ b/src/Microsoft.ML.Core/BestFriendAttribute.cs @@ -6,7 +6,7 @@ #if PRIVATE_CONTRACTS // CpuMath has its own BestFriend and WantsToBeBestFriends attributes for making itself a standalone module -namespace Microsoft.ML.Runtime.Internal.CpuMath +namespace Microsoft.ML.Hidden #else // This namespace contains the BestFriend and WantsToBeBestFriends attributes generally used in ML.NET project settings namespace Microsoft.ML diff --git a/src/Microsoft.ML.Core/Properties/PublicKey.cs b/src/Microsoft.ML.Core/Properties/PublicKey.cs index 94ece8914b..8df6c9536d 100644 --- a/src/Microsoft.ML.Core/Properties/PublicKey.cs +++ b/src/Microsoft.ML.Core/Properties/PublicKey.cs @@ -7,6 +7,8 @@ namespace Microsoft.ML #else // CpuMath module has its own PublicKey for isolating itself from Microsoft.ML.Core +// CpuMath has its own BestFriend defined in Microsoft.ML.Private +using Microsoft.ML.Hidden; namespace Microsoft.ML.Runtime.Internal.CpuMath #endif { diff --git a/src/Microsoft.ML.Core/Utilities/Contracts.cs b/src/Microsoft.ML.Core/Utilities/Contracts.cs index 9a4ed9b8e1..bd71f7583c 100644 --- a/src/Microsoft.ML.Core/Utilities/Contracts.cs +++ b/src/Microsoft.ML.Core/Utilities/Contracts.cs @@ -17,7 +17,7 @@ using System.Threading; #if PRIVATE_CONTRACTS -namespace Microsoft.ML.Runtime.Internal +namespace Microsoft.ML.Hidden #else namespace Microsoft.ML.Runtime #endif @@ -55,9 +55,7 @@ internal enum MessageSensitivity } #endif -#if !PRIVATE_CONTRACTS [BestFriend] -#endif internal static partial class Contracts { public const string IsMarkedKey = "ML_IsMarked"; diff --git a/src/Microsoft.ML.CpuMath/AlignedArray.cs b/src/Microsoft.ML.CpuMath/AlignedArray.cs index cfbee22eab..8bc71e41ec 100644 --- a/src/Microsoft.ML.CpuMath/AlignedArray.cs +++ b/src/Microsoft.ML.CpuMath/AlignedArray.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using Microsoft.ML.Hidden; namespace Microsoft.ML.Runtime.Internal.CpuMath { diff --git a/src/Microsoft.ML.CpuMath/AlignedMatrix.cs b/src/Microsoft.ML.CpuMath/AlignedMatrix.cs index 5412e5fd77..767e88de83 100644 --- a/src/Microsoft.ML.CpuMath/AlignedMatrix.cs +++ b/src/Microsoft.ML.CpuMath/AlignedMatrix.cs @@ -4,6 +4,7 @@ using Float = System.Single; +using Microsoft.ML.Hidden; using System; using System.Collections; using System.Collections.Generic; diff --git a/src/Microsoft.ML.CpuMath/AssemblyInfo.cs b/src/Microsoft.ML.CpuMath/AssemblyInfo.cs index edf19fa782..ded540a91e 100644 --- a/src/Microsoft.ML.CpuMath/AssemblyInfo.cs +++ b/src/Microsoft.ML.CpuMath/AssemblyInfo.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Hidden; using System.Runtime.CompilerServices; using Microsoft.ML.Runtime.Internal.CpuMath; diff --git a/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs b/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs index d4c8e8e087..7d6b4ac484 100644 --- a/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs +++ b/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Hidden; + namespace Microsoft.ML.Runtime.Internal.CpuMath { [BestFriend] diff --git a/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs b/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs index ed5be5390a..7d9e9f4acf 100644 --- a/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs +++ b/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Private; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics.X86; using System; diff --git a/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs b/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs index b3f46f0a5a..d283c6bee5 100644 --- a/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs +++ b/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Hidden; using System; using System.Runtime.CompilerServices; diff --git a/src/Microsoft.ML.CpuMath/EigenUtils.cs b/src/Microsoft.ML.CpuMath/EigenUtils.cs index fc20b8bfe7..96341b0711 100644 --- a/src/Microsoft.ML.CpuMath/EigenUtils.cs +++ b/src/Microsoft.ML.CpuMath/EigenUtils.cs @@ -5,6 +5,8 @@ using System; using Float = System.Single; +using Microsoft.ML.Hidden; + namespace Microsoft.ML.Runtime.Internal.CpuMath { [BestFriend] diff --git a/src/Microsoft.ML.CpuMath/ICpuBuffer.cs b/src/Microsoft.ML.CpuMath/ICpuBuffer.cs index 7f0c0e8126..88a78f6084 100644 --- a/src/Microsoft.ML.CpuMath/ICpuBuffer.cs +++ b/src/Microsoft.ML.CpuMath/ICpuBuffer.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Hidden; using System; using System.Collections.Generic; using Float = System.Single; diff --git a/src/Microsoft.ML.CpuMath/IntUtils.cs b/src/Microsoft.ML.CpuMath/IntUtils.cs index cec2b71dfb..0d3f8d038b 100644 --- a/src/Microsoft.ML.CpuMath/IntUtils.cs +++ b/src/Microsoft.ML.CpuMath/IntUtils.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Hidden; using System; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; diff --git a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj index 5bb36c11a6..4ef449bb56 100644 --- a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj +++ b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj @@ -9,10 +9,6 @@ 7.3 - - - - diff --git a/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs b/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs index ed1208c80c..64c5fb83f6 100644 --- a/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs +++ b/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Hidden; using System; namespace Microsoft.ML.Runtime.Internal.CpuMath diff --git a/src/Microsoft.ML.CpuMath/Sse.cs b/src/Microsoft.ML.CpuMath/Sse.cs index b3f00d1136..c08c9a1246 100644 --- a/src/Microsoft.ML.CpuMath/Sse.cs +++ b/src/Microsoft.ML.CpuMath/Sse.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Hidden; using System; using System.Runtime.InteropServices; diff --git a/src/Microsoft.ML.CpuMath/Thunk.cs b/src/Microsoft.ML.CpuMath/Thunk.cs index faf0b82c66..2d59365661 100644 --- a/src/Microsoft.ML.CpuMath/Thunk.cs +++ b/src/Microsoft.ML.CpuMath/Thunk.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Hidden; using System.Runtime.InteropServices; using System.Security; diff --git a/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs b/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs index 1adc735b25..e5f955ae2a 100644 --- a/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs +++ b/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs @@ -30,8 +30,8 @@ public sealed class BestFriendAnalyzer : DiagnosticAnalyzer new DiagnosticDescriptor(DiagnosticId, Title, Format, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description); - private const string AttributeName = "Microsoft.ML.BestFriendAttribute"; - private const string AssemblyAttributeName = "Microsoft.ML.WantsToBeBestFriendsAttribute"; + 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 SupportedDiagnostics => ImmutableArray.Create(Rule); @@ -41,17 +41,17 @@ public override void Initialize(AnalysisContext context) context.RegisterSemanticModelAction(Analyze); } - private void Analyze(SemanticModelAnalysisContext context) + private void AnalyzeCore(SemanticModelAnalysisContext context, string attributeName, string assemblyAttributeName) { var model = context.SemanticModel; var comp = model.Compilation; // Get the symbols of the key types we are analyzing. If we can't find either // of them there is no point in going further. - var bestFriendAttributeType = comp.GetTypeByMetadataName(AttributeName); + var bestFriendAttributeType = comp.GetTypeByMetadataName(attributeName); if (bestFriendAttributeType == null) return; - var wantsToBeBestFriendsAttributeType = comp.GetTypeByMetadataName(AssemblyAttributeName); + var wantsToBeBestFriendsAttributeType = comp.GetTypeByMetadataName(assemblyAttributeName); if (wantsToBeBestFriendsAttributeType == null) return; @@ -89,6 +89,9 @@ private void Analyze(SemanticModelAnalysisContext context) // further. if (!assemblyHasAttrMap.TryGetValue(symbolAssembly, out bool assemblyWantsBestFriends)) { + // It's the first of seeing the assembly containing symbol. A key-value pair is added into assemblyHasAttrMap to + // indicate if that assembly includes an attribute WantsToBeBestFriends. If an assembly has WantsToBeBestFriends then + // its associated value would be true. assemblyWantsBestFriends = symbolAssembly.GetAttributes().Any(a => a.AttributeClass == wantsToBeBestFriendsAttributeType); assemblyHasAttrMap[symbolAssembly] = assemblyWantsBestFriends; } @@ -104,5 +107,11 @@ private void Analyze(SemanticModelAnalysisContext context) context.ReportDiagnostic(diagnostic); } } + + private void Analyze(SemanticModelAnalysisContext context) + { + AnalyzeCore(context, "Microsoft.ML.BestFriendAttribute", "Microsoft.ML.WantsToBeBestFriendsAttribute"); + AnalyzeCore(context, "Microsoft.ML.Hidden.BestFriendAttribute", "Microsoft.ML.Hidden.WantsToBeBestFriendsAttribute"); + } } } From c89cf1ff30b0a88fc0d9ed5dc1ab9fb064cf8eea Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Mon, 26 Nov 2018 17:29:56 -0800 Subject: [PATCH 03/12] Drop redundant macro variable --- src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj index 4ef449bb56..818e5ea45c 100644 --- a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj +++ b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj @@ -5,7 +5,7 @@ netstandard2.0;netcoreapp3.0 Microsoft.ML.CpuMath true - $(DefineConstants);CORECLR;PRIVATE_CONTRACTS + $(DefineConstants);PRIVATE_CONTRACTS 7.3 From 25c3b62479f2cdc64907f8fc404c4cbf928fc40a Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Mon, 26 Nov 2018 19:09:16 -0800 Subject: [PATCH 04/12] Update src/Microsoft.ML.Core/Properties/PublicKey.cs --- src/Microsoft.ML.Core/Properties/PublicKey.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ML.Core/Properties/PublicKey.cs b/src/Microsoft.ML.Core/Properties/PublicKey.cs index 8df6c9536d..9730e507c2 100644 --- a/src/Microsoft.ML.Core/Properties/PublicKey.cs +++ b/src/Microsoft.ML.Core/Properties/PublicKey.cs @@ -7,7 +7,7 @@ namespace Microsoft.ML #else // CpuMath module has its own PublicKey for isolating itself from Microsoft.ML.Core -// CpuMath has its own BestFriend defined in Microsoft.ML.Private +// CpuMath has its own BestFriend defined in Microsoft.ML.Hidden``` using Microsoft.ML.Hidden; namespace Microsoft.ML.Runtime.Internal.CpuMath #endif From 911aee6c68d53609b9dbd0356ec05e589f6652b5 Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Mon, 26 Nov 2018 23:53:09 -0800 Subject: [PATCH 05/12] Use distinct messages for the two BestFriend analyzers --- .../BestFriendAnalyzer.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs b/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs index e5f955ae2a..10aa742a31 100644 --- a/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs +++ b/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs @@ -17,21 +17,21 @@ public sealed class BestFriendAnalyzer : DiagnosticAnalyzer private const string Category = "Access"; internal const string DiagnosticId = "MSML_NoBestFriendInternal"; - 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 " + + 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 " + "reference, and the declaring assembly wants these accesses to be on something " + - "with the attribute " + AttributeName + "."; - private const string Description = + "with the attribute " + _attributeName + "."; + private 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 static DiagnosticDescriptor Rule = + private DiagnosticDescriptor Rule => new DiagnosticDescriptor(DiagnosticId, Title, Format, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description); - 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)"; + private string _attributeName; + private string _assemblyAttributeName; public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(Rule); @@ -110,8 +110,15 @@ private void AnalyzeCore(SemanticModelAnalysisContext context, string attributeN private void Analyze(SemanticModelAnalysisContext context) { - AnalyzeCore(context, "Microsoft.ML.BestFriendAttribute", "Microsoft.ML.WantsToBeBestFriendsAttribute"); - AnalyzeCore(context, "Microsoft.ML.Hidden.BestFriendAttribute", "Microsoft.ML.Hidden.WantsToBeBestFriendsAttribute"); + // 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); } } } From 7f374c6c14386c916c155e41402c76d3f27b5600 Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Mon, 26 Nov 2018 23:56:15 -0800 Subject: [PATCH 06/12] Remove wrong symbols --- src/Microsoft.ML.Core/Properties/PublicKey.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.ML.Core/Properties/PublicKey.cs b/src/Microsoft.ML.Core/Properties/PublicKey.cs index 9730e507c2..2c20289360 100644 --- a/src/Microsoft.ML.Core/Properties/PublicKey.cs +++ b/src/Microsoft.ML.Core/Properties/PublicKey.cs @@ -7,7 +7,7 @@ namespace Microsoft.ML #else // CpuMath module has its own PublicKey for isolating itself from Microsoft.ML.Core -// CpuMath has its own BestFriend defined in Microsoft.ML.Hidden``` +// CpuMath has its own BestFriend defined in Microsoft.ML.Hidden. using Microsoft.ML.Hidden; namespace Microsoft.ML.Runtime.Internal.CpuMath #endif From 36e3a3cfa42b38994bd7aa7793a433cb33e63c17 Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Tue, 27 Nov 2018 08:28:16 -0800 Subject: [PATCH 07/12] Revert "Use distinct messages for the two BestFriend analyzers" This reverts commit 911aee6c68d53609b9dbd0356ec05e589f6652b5. --- .../BestFriendAnalyzer.cs | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs b/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs index 10aa742a31..e5f955ae2a 100644 --- a/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs +++ b/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs @@ -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 SupportedDiagnostics => ImmutableArray.Create(Rule); @@ -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"); } } } From 037c3c9b0a677350b5165d1f4e9981895585af24 Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Tue, 27 Nov 2018 10:20:09 -0800 Subject: [PATCH 08/12] Address comments --- src/Microsoft.ML.Core/BestFriendAttribute.cs | 2 +- src/Microsoft.ML.Core/{Properties => }/PublicKey.cs | 5 ++--- src/Microsoft.ML.Core/Utilities/Contracts.cs | 2 +- src/Microsoft.ML.CpuMath/AlignedArray.cs | 2 +- src/Microsoft.ML.CpuMath/AlignedMatrix.cs | 2 +- src/Microsoft.ML.CpuMath/AssemblyInfo.cs | 3 +-- src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs | 3 +-- src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs | 2 +- src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs | 2 +- src/Microsoft.ML.CpuMath/EigenUtils.cs | 3 +-- src/Microsoft.ML.CpuMath/ICpuBuffer.cs | 2 +- src/Microsoft.ML.CpuMath/IntUtils.cs | 3 +-- src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj | 2 +- src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs | 2 +- src/Microsoft.ML.CpuMath/Sse.cs | 2 +- src/Microsoft.ML.CpuMath/Thunk.cs | 2 +- .../Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs | 6 +++--- .../ContractsCheckAnalyzer.cs | 5 ++++- 18 files changed, 24 insertions(+), 26 deletions(-) rename src/Microsoft.ML.Core/{Properties => }/PublicKey.cs (89%) diff --git a/src/Microsoft.ML.Core/BestFriendAttribute.cs b/src/Microsoft.ML.Core/BestFriendAttribute.cs index 21e1c9c954..813e8a61b6 100644 --- a/src/Microsoft.ML.Core/BestFriendAttribute.cs +++ b/src/Microsoft.ML.Core/BestFriendAttribute.cs @@ -6,7 +6,7 @@ #if PRIVATE_CONTRACTS // CpuMath has its own BestFriend and WantsToBeBestFriends attributes for making itself a standalone module -namespace Microsoft.ML.Hidden +namespace Microsoft.ML.Runtime.Internal.CpuMath.Core #else // This namespace contains the BestFriend and WantsToBeBestFriends attributes generally used in ML.NET project settings namespace Microsoft.ML diff --git a/src/Microsoft.ML.Core/Properties/PublicKey.cs b/src/Microsoft.ML.Core/PublicKey.cs similarity index 89% rename from src/Microsoft.ML.Core/Properties/PublicKey.cs rename to src/Microsoft.ML.Core/PublicKey.cs index 2c20289360..32ca993c78 100644 --- a/src/Microsoft.ML.Core/Properties/PublicKey.cs +++ b/src/Microsoft.ML.Core/PublicKey.cs @@ -7,9 +7,8 @@ namespace Microsoft.ML #else // CpuMath module has its own PublicKey for isolating itself from Microsoft.ML.Core -// CpuMath has its own BestFriend defined in Microsoft.ML.Hidden. -using Microsoft.ML.Hidden; -namespace Microsoft.ML.Runtime.Internal.CpuMath +// Note that CpuMath uses its own BestFriend defined in Microsoft.ML.Runtime.Internal.CpuMath.Core. +namespace Microsoft.ML.Runtime.Internal.CpuMath.Core #endif { [BestFriend] diff --git a/src/Microsoft.ML.Core/Utilities/Contracts.cs b/src/Microsoft.ML.Core/Utilities/Contracts.cs index bd71f7583c..bd966ecefa 100644 --- a/src/Microsoft.ML.Core/Utilities/Contracts.cs +++ b/src/Microsoft.ML.Core/Utilities/Contracts.cs @@ -17,7 +17,7 @@ using System.Threading; #if PRIVATE_CONTRACTS -namespace Microsoft.ML.Hidden +namespace Microsoft.ML.Runtime.Internal.CpuMath.Core #else namespace Microsoft.ML.Runtime #endif diff --git a/src/Microsoft.ML.CpuMath/AlignedArray.cs b/src/Microsoft.ML.CpuMath/AlignedArray.cs index 8bc71e41ec..dec60038f6 100644 --- a/src/Microsoft.ML.CpuMath/AlignedArray.cs +++ b/src/Microsoft.ML.CpuMath/AlignedArray.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. using System; -using Microsoft.ML.Hidden; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; namespace Microsoft.ML.Runtime.Internal.CpuMath { diff --git a/src/Microsoft.ML.CpuMath/AlignedMatrix.cs b/src/Microsoft.ML.CpuMath/AlignedMatrix.cs index 767e88de83..6d550fc3fc 100644 --- a/src/Microsoft.ML.CpuMath/AlignedMatrix.cs +++ b/src/Microsoft.ML.CpuMath/AlignedMatrix.cs @@ -4,7 +4,7 @@ using Float = System.Single; -using Microsoft.ML.Hidden; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System; using System.Collections; using System.Collections.Generic; diff --git a/src/Microsoft.ML.CpuMath/AssemblyInfo.cs b/src/Microsoft.ML.CpuMath/AssemblyInfo.cs index ded540a91e..7710703c29 100644 --- a/src/Microsoft.ML.CpuMath/AssemblyInfo.cs +++ b/src/Microsoft.ML.CpuMath/AssemblyInfo.cs @@ -2,9 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Hidden; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System.Runtime.CompilerServices; -using Microsoft.ML.Runtime.Internal.CpuMath; [assembly: InternalsVisibleTo("Microsoft.ML.CpuMath.UnitTests.netstandard" + PublicKey.TestValue)] [assembly: InternalsVisibleTo("Microsoft.ML.CpuMath.UnitTests.netcoreapp" + PublicKey.TestValue)] diff --git a/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs b/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs index 7d6b4ac484..e0984b6509 100644 --- a/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs +++ b/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Hidden; - +using Microsoft.ML.Runtime.Internal.CpuMath.Core; namespace Microsoft.ML.Runtime.Internal.CpuMath { [BestFriend] diff --git a/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs b/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs index 7d9e9f4acf..d895e590a9 100644 --- a/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs +++ b/src/Microsoft.ML.CpuMath/CpuMathUtils.netcoreapp.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Private; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics.X86; using System; diff --git a/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs b/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs index d283c6bee5..5ecbc62be1 100644 --- a/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs +++ b/src/Microsoft.ML.CpuMath/CpuMathUtils.netstandard.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Hidden; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System; using System.Runtime.CompilerServices; diff --git a/src/Microsoft.ML.CpuMath/EigenUtils.cs b/src/Microsoft.ML.CpuMath/EigenUtils.cs index 96341b0711..cff9d1b32d 100644 --- a/src/Microsoft.ML.CpuMath/EigenUtils.cs +++ b/src/Microsoft.ML.CpuMath/EigenUtils.cs @@ -2,11 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System; using Float = System.Single; -using Microsoft.ML.Hidden; - namespace Microsoft.ML.Runtime.Internal.CpuMath { [BestFriend] diff --git a/src/Microsoft.ML.CpuMath/ICpuBuffer.cs b/src/Microsoft.ML.CpuMath/ICpuBuffer.cs index 88a78f6084..a121351cff 100644 --- a/src/Microsoft.ML.CpuMath/ICpuBuffer.cs +++ b/src/Microsoft.ML.CpuMath/ICpuBuffer.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Hidden; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System; using System.Collections.Generic; using Float = System.Single; diff --git a/src/Microsoft.ML.CpuMath/IntUtils.cs b/src/Microsoft.ML.CpuMath/IntUtils.cs index 0d3f8d038b..dbb07e31cb 100644 --- a/src/Microsoft.ML.CpuMath/IntUtils.cs +++ b/src/Microsoft.ML.CpuMath/IntUtils.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Hidden; -using System; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Security; diff --git a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj index 818e5ea45c..5db4479a61 100644 --- a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj +++ b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs b/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs index 64c5fb83f6..64875bb8b6 100644 --- a/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs +++ b/src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Hidden; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System; namespace Microsoft.ML.Runtime.Internal.CpuMath diff --git a/src/Microsoft.ML.CpuMath/Sse.cs b/src/Microsoft.ML.CpuMath/Sse.cs index c08c9a1246..8b1c4da70f 100644 --- a/src/Microsoft.ML.CpuMath/Sse.cs +++ b/src/Microsoft.ML.CpuMath/Sse.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Hidden; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System; using System.Runtime.InteropServices; diff --git a/src/Microsoft.ML.CpuMath/Thunk.cs b/src/Microsoft.ML.CpuMath/Thunk.cs index 2d59365661..8ff725b54a 100644 --- a/src/Microsoft.ML.CpuMath/Thunk.cs +++ b/src/Microsoft.ML.CpuMath/Thunk.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.ML.Hidden; +using Microsoft.ML.Runtime.Internal.CpuMath.Core; using System.Runtime.InteropServices; using System.Security; diff --git a/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs b/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs index e5f955ae2a..98066222b3 100644 --- a/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs +++ b/tools-local/Microsoft.ML.InternalCodeAnalyzer/BestFriendAnalyzer.cs @@ -30,8 +30,8 @@ public sealed class BestFriendAnalyzer : DiagnosticAnalyzer new DiagnosticDescriptor(DiagnosticId, Title, Format, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: Description); - 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)"; + private const string AttributeName = "Microsoft.ML.BestFriendAttribute"; + private const string AssemblyAttributeName = "Microsoft.ML.WantsToBeBestFriendsAttribute"; public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(Rule); @@ -111,7 +111,7 @@ private void AnalyzeCore(SemanticModelAnalysisContext context, string attributeN private void Analyze(SemanticModelAnalysisContext context) { AnalyzeCore(context, "Microsoft.ML.BestFriendAttribute", "Microsoft.ML.WantsToBeBestFriendsAttribute"); - AnalyzeCore(context, "Microsoft.ML.Hidden.BestFriendAttribute", "Microsoft.ML.Hidden.WantsToBeBestFriendsAttribute"); + AnalyzeCore(context, "Microsoft.ML.Runtime.Internal.CpuMath.Core.BestFriendAttribute", "Microsoft.ML.Runtime.Internal.CpuMath.Core.WantsToBeBestFriendsAttribute"); } } } diff --git a/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs b/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs index 6143d7386b..4eea126798 100644 --- a/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs +++ b/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs @@ -196,8 +196,11 @@ private static void Analyze(SyntaxNodeAnalysisContext context) var containingSymbolName = methodSymbol.ContainingSymbol.ToString(); // The "internal" version is one used by some projects that want to benefit from Contracts, // but for some reason cannot reference MLCore. + // Contract functions defined Microsoft.ML.Hidden are introduced for breaking the dependencies + // from CpuMath project to Microsoft.ML.Core. if (containingSymbolName != "Microsoft.ML.Runtime.Contracts" && - containingSymbolName != "Microsoft.ML.Runtime.Internal.Contracts") + containingSymbolName != "Microsoft.ML.Runtime.Internal.Contracts" && + containingSymbolName != "Microsoft.ML.Runtime.Internal.CpuMath.Core.Contracts") { return; } From ec4bdf1cc6dee17e30e760882070da3cbdf52151 Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Tue, 27 Nov 2018 11:01:44 -0800 Subject: [PATCH 09/12] Rename PRIVATE_CONTRACTS compiler flag to CPUMATH_INFRASTRUCTURE --- src/Microsoft.ML.Core/BestFriendAttribute.cs | 2 +- src/Microsoft.ML.Core/PublicKey.cs | 2 +- src/Microsoft.ML.Core/Utilities/Contracts.cs | 10 +++++----- src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.ML.Core/BestFriendAttribute.cs b/src/Microsoft.ML.Core/BestFriendAttribute.cs index 813e8a61b6..1470f95c34 100644 --- a/src/Microsoft.ML.Core/BestFriendAttribute.cs +++ b/src/Microsoft.ML.Core/BestFriendAttribute.cs @@ -4,7 +4,7 @@ using System; -#if PRIVATE_CONTRACTS +#if CPUMATH_INFRASTRUCTURE // CpuMath has its own BestFriend and WantsToBeBestFriends attributes for making itself a standalone module namespace Microsoft.ML.Runtime.Internal.CpuMath.Core #else diff --git a/src/Microsoft.ML.Core/PublicKey.cs b/src/Microsoft.ML.Core/PublicKey.cs index 32ca993c78..9a944c3d18 100644 --- a/src/Microsoft.ML.Core/PublicKey.cs +++ b/src/Microsoft.ML.Core/PublicKey.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#if !PRIVATE_CONTRACTS +#if !CPUMATH_INFRASTRUCTURE // This namespace contains the PublicKey generally used in ML.NET project settings namespace Microsoft.ML #else diff --git a/src/Microsoft.ML.Core/Utilities/Contracts.cs b/src/Microsoft.ML.Core/Utilities/Contracts.cs index bd966ecefa..d567d6e883 100644 --- a/src/Microsoft.ML.Core/Utilities/Contracts.cs +++ b/src/Microsoft.ML.Core/Utilities/Contracts.cs @@ -16,7 +16,7 @@ using System.IO; using System.Threading; -#if PRIVATE_CONTRACTS +#if CPUMATH_INFRASTRUCTURE namespace Microsoft.ML.Runtime.Internal.CpuMath.Core #else namespace Microsoft.ML.Runtime @@ -31,7 +31,7 @@ namespace Microsoft.ML.Runtime /// totally replace the exception, etc. It is not legal to return null from /// Process (unless null was passed in, which really shouldn't happen). /// -#if PRIVATE_CONTRACTS +#if CPUMATH_INFRASTRUCTURE internal interface IExceptionContext #else public interface IExceptionContext @@ -46,7 +46,7 @@ TException Process(TException ex) string ContextDescription { get; } } -#if PRIVATE_CONTRACTS +#if CPUMATH_INFRASTRUCTURE [Flags] internal enum MessageSensitivity { @@ -154,7 +154,7 @@ public static MessageSensitivity Sensitivity(this Exception ex) return (ex.Data[SensitivityKey] as MessageSensitivity?) ?? MessageSensitivity.Unknown; } -#if !PRIVATE_CONTRACTS +#if !CPUMATH_INFRASTRUCTURE /// /// This is an internal convenience implementation of an exception context to make marking /// exceptions with a specific sensitivity flag a bit less onorous. The alternative to a scheme @@ -740,7 +740,7 @@ public static void CheckIO(this IExceptionContext ctx, bool f, string msg) throw ExceptIO(ctx, msg); } -#if !PRIVATE_CONTRACTS +#if !CPUMATH_INFRASTRUCTURE /// /// Check state of the host and throw exception if host marked to stop all exection. /// diff --git a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj index 5db4479a61..938b2b2d5a 100644 --- a/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj +++ b/src/Microsoft.ML.CpuMath/Microsoft.ML.CpuMath.csproj @@ -5,7 +5,7 @@ netstandard2.0;netcoreapp3.0 Microsoft.ML.CpuMath true - $(DefineConstants);PRIVATE_CONTRACTS + $(DefineConstants);CPUMATH_INFRASTRUCTURE 7.3 From 2a9451df49e3fbe672d7678e8a10425207ef74ff Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Tue, 27 Nov 2018 11:04:30 -0800 Subject: [PATCH 10/12] Remove unused namespace --- .../Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs b/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs index 4eea126798..01560dc18d 100644 --- a/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs +++ b/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs @@ -199,7 +199,6 @@ private static void Analyze(SyntaxNodeAnalysisContext context) // Contract functions defined Microsoft.ML.Hidden are introduced for breaking the dependencies // from CpuMath project to Microsoft.ML.Core. if (containingSymbolName != "Microsoft.ML.Runtime.Contracts" && - containingSymbolName != "Microsoft.ML.Runtime.Internal.Contracts" && containingSymbolName != "Microsoft.ML.Runtime.Internal.CpuMath.Core.Contracts") { return; From 9d0b89268b9a12a262f01f7e3880ab5aa3c737f9 Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Tue, 27 Nov 2018 11:07:17 -0800 Subject: [PATCH 11/12] Swap usings --- src/Microsoft.ML.CpuMath/AlignedArray.cs | 2 +- src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.ML.CpuMath/AlignedArray.cs b/src/Microsoft.ML.CpuMath/AlignedArray.cs index dec60038f6..4602e884e4 100644 --- a/src/Microsoft.ML.CpuMath/AlignedArray.cs +++ b/src/Microsoft.ML.CpuMath/AlignedArray.cs @@ -2,8 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using Microsoft.ML.Runtime.Internal.CpuMath.Core; +using System; namespace Microsoft.ML.Runtime.Internal.CpuMath { diff --git a/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs b/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs index e0984b6509..33690055b2 100644 --- a/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs +++ b/src/Microsoft.ML.CpuMath/CpuAligenedMathUtils.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using Microsoft.ML.Runtime.Internal.CpuMath.Core; + namespace Microsoft.ML.Runtime.Internal.CpuMath { [BestFriend] From 9bd1d0d90e074c53c891f5c7658a437252af01a1 Mon Sep 17 00:00:00 2001 From: Wei-Sheng Chin Date: Tue, 27 Nov 2018 11:21:07 -0800 Subject: [PATCH 12/12] Fix comment --- .../Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs b/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs index 01560dc18d..6328a7cf5f 100644 --- a/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs +++ b/tools-local/Microsoft.ML.InternalCodeAnalyzer/ContractsCheckAnalyzer.cs @@ -196,7 +196,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context) var containingSymbolName = methodSymbol.ContainingSymbol.ToString(); // The "internal" version is one used by some projects that want to benefit from Contracts, // but for some reason cannot reference MLCore. - // Contract functions defined Microsoft.ML.Hidden are introduced for breaking the dependencies + // Contract functions defined Microsoft.ML.Runtime.Internal.CpuMath.Core are introduced for breaking the dependencies // from CpuMath project to Microsoft.ML.Core. if (containingSymbolName != "Microsoft.ML.Runtime.Contracts" && containingSymbolName != "Microsoft.ML.Runtime.Internal.CpuMath.Core.Contracts")