From 540c29303d7cb92c4c9a209ab7ec4114e4e1bb46 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 18 Jun 2025 19:53:39 -0700 Subject: [PATCH 01/12] Update Roslyn to '4.14.0' --- .../UnsupportedCSharpLanguageVersionAnalyzer.cs | 2 +- .../Diagnostics/DiagnosticDescriptors.cs | 11 +++++------ .../AnalyzerConfigOptionsProviderExtensions.cs | 2 +- .../Extensions/DiagnosticsExtensions.cs | 2 +- .../PolySharp.SourceGenerators.csproj | 5 +++-- src/PolySharp.SourceGenerators/PolySharp.targets | 8 ++++---- .../PolyfillsGenerator.Polyfills.cs | 14 ++++++-------- .../PolyfillsGenerator.TypeForwards.cs | 8 +++++--- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/PolySharp.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs b/src/PolySharp.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs index e934a80..4130853 100644 --- a/src/PolySharp.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs +++ b/src/PolySharp.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs @@ -18,7 +18,7 @@ namespace PolySharp.SourceGenerators; public sealed partial class UnsupportedCSharpLanguageVersionAnalyzer : DiagnosticAnalyzer { /// - public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(UnsupportedCSharpLanguageVersionError); + public override ImmutableArray SupportedDiagnostics { get; } = [UnsupportedCSharpLanguageVersionError]; /// public override void Initialize(AnalysisContext context) diff --git a/src/PolySharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/PolySharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 61ca921..4d6f6d1 100644 --- a/src/PolySharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/PolySharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -5,8 +5,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -#pragma warning disable IDE0090 // Use 'new DiagnosticDescriptor(...)' - namespace PolySharp.SourceGenerators.Diagnostics; /// @@ -20,7 +18,7 @@ internal static class DiagnosticDescriptors /// Format: "The value "{0}" is not valid for property "{1}" (it has to be a valid MSBuild bool value)". /// /// - public static readonly DiagnosticDescriptor InvalidBoolMSBuildProperty = new DiagnosticDescriptor( + public static readonly DiagnosticDescriptor InvalidBoolMSBuildProperty = new( id: "POLYSP0001", title: "Invalid PolySharp bool MSBuild property", messageFormat: "The value \"{0}\" is not valid for property \"{1}\" (it has to be a valid MSBuild bool value)", @@ -36,7 +34,7 @@ internal static class DiagnosticDescriptors /// Format: "The fully qualified metadata name "{0}" used in property "{1}" is not valid, and it does not match any available polyfill type". /// /// - public static readonly DiagnosticDescriptor InvalidPolyfillFullyQualifiedMetadataName = new DiagnosticDescriptor( + public static readonly DiagnosticDescriptor InvalidPolyfillFullyQualifiedMetadataName = new( id: "POLYSP0002", title: "Invalid fully qualified metadata name for polyfill", messageFormat: "The fully qualified metadata name \"{0}\" used in property \"{1}\" is not a valid fully qualified type name, or it does not match any available polyfill type", @@ -49,7 +47,7 @@ internal static class DiagnosticDescriptors /// /// Gets a indicating when an unsupported C# language version is being used. /// - public static readonly DiagnosticDescriptor UnsupportedCSharpLanguageVersionError = new DiagnosticDescriptor( + public static readonly DiagnosticDescriptor UnsupportedCSharpLanguageVersionError = new( id: "POLYSP0003", title: "Unsupported C# language version", messageFormat: "The source generator features from PolySharp require consuming projects to set the C# language version to at least C# 8.0", @@ -57,5 +55,6 @@ internal static class DiagnosticDescriptors defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true, description: "The source generator features from PolySharp require consuming projects to set the C# language version to at least C# 8.0. Make sure to add 8.0 (or above) to your .csproj file.", - helpLinkUri: "https://github.com/Sergio0694/PolySharp"); + helpLinkUri: "https://github.com/Sergio0694/PolySharp", + customTags: WellKnownDiagnosticTags.CompilationEnd); } diff --git a/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs b/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs index d4521af..65fe757 100644 --- a/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs +++ b/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs @@ -71,6 +71,6 @@ public static ImmutableArray GetStringArrayMSBuildProperty(this Analyzer return builder.ToImmutable(); } - return ImmutableArray.Empty; + return []; } } \ No newline at end of file diff --git a/src/PolySharp.SourceGenerators/Extensions/DiagnosticsExtensions.cs b/src/PolySharp.SourceGenerators/Extensions/DiagnosticsExtensions.cs index 3cd9f7b..1be9b5a 100644 --- a/src/PolySharp.SourceGenerators/Extensions/DiagnosticsExtensions.cs +++ b/src/PolySharp.SourceGenerators/Extensions/DiagnosticsExtensions.cs @@ -5,7 +5,7 @@ namespace PolySharp.SourceGenerators.Extensions; /// -/// Extension methods for , specifically for reporting diagnostics. +/// Extension methods for , in various scenarios. /// internal static class DiagnosticsExtensions { diff --git a/src/PolySharp.SourceGenerators/PolySharp.SourceGenerators.csproj b/src/PolySharp.SourceGenerators/PolySharp.SourceGenerators.csproj index a154b68..26d6116 100644 --- a/src/PolySharp.SourceGenerators/PolySharp.SourceGenerators.csproj +++ b/src/PolySharp.SourceGenerators/PolySharp.SourceGenerators.csproj @@ -1,12 +1,13 @@ - + netstandard2.0 + true false - + diff --git a/src/PolySharp.SourceGenerators/PolySharp.targets b/src/PolySharp.SourceGenerators/PolySharp.targets index e9f4075..532bcba 100644 --- a/src/PolySharp.SourceGenerators/PolySharp.targets +++ b/src/PolySharp.SourceGenerators/PolySharp.targets @@ -7,7 +7,7 @@ - + @(PolySharpCurrentCompilerAssemblyIdentity->'%(Version)') - true + true - + @@ -44,7 +44,7 @@ --> + Text="The PolySharp source generators have been disabled on the current configuration, as they need Roslyn 4.14 in order to work. PolySharp requires the source generators to run in order to generate polyfills, so the library cannot be used without a more up to date IDE (eg. VS 2022 17.14 or greater) or .NET SDK version (.NET 8.0.411 SDK or greater)."/> diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index eec140e..bb6b53b 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -35,23 +35,21 @@ from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResou /// /// The collection of fully qualified type names for language support types. /// - private static readonly ImmutableArray LanguageSupportTypeNames = ImmutableArray.CreateRange( - from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResourceNames() + private static readonly ImmutableArray LanguageSupportTypeNames = [.. from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResourceNames() where !resourceName.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.RuntimeSupported.") - select Regex.Match(resourceName, EmbeddedResourceNameToFullyQualifiedTypeNameRegex).Groups[1].Value); + select Regex.Match(resourceName, EmbeddedResourceNameToFullyQualifiedTypeNameRegex).Groups[1].Value]; /// /// The collection of fully qualified type names for runtime supported types. /// - private static readonly ImmutableArray RuntimeSupportedTypeNames = ImmutableArray.CreateRange( - from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResourceNames() + private static readonly ImmutableArray RuntimeSupportedTypeNames = [.. from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResourceNames() where resourceName.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.RuntimeSupported.") - select Regex.Match(resourceName, EmbeddedResourceNameToFullyQualifiedTypeNameRegex).Groups[1].Value); + select Regex.Match(resourceName, EmbeddedResourceNameToFullyQualifiedTypeNameRegex).Groups[1].Value]; /// /// The collection of all fully qualified type names for available polyfill types. /// - private static readonly ImmutableArray AllSupportTypeNames = ImmutableArray.CreateRange(LanguageSupportTypeNames.Concat(RuntimeSupportedTypeNames)); + private static readonly ImmutableArray AllSupportTypeNames = [.. LanguageSupportTypeNames.Concat(RuntimeSupportedTypeNames)]; /// /// The to find all uses. @@ -112,7 +110,7 @@ private static ImmutableArray GetAvailableTypes(Compilation compi // A minimum of C# 8.0 is required to benefit from the polyfills if (!compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp8)) { - return ImmutableArray.Empty; + return []; } // Helper function to check whether a type is available diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.TypeForwards.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.TypeForwards.cs index afb6f35..d4097a8 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.TypeForwards.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.TypeForwards.cs @@ -14,11 +14,13 @@ partial class PolyfillsGenerator /// /// The collection of fully qualified type names for types that could require a modreq. /// - private static readonly ImmutableArray ModreqCandidateFullyQualifiedTypeNames = ImmutableArray.Create( + private static readonly ImmutableArray ModreqCandidateFullyQualifiedTypeNames = + [ "System.Index", "System.Range", "System.Runtime.CompilerServices.IsExternalInit", - "System.Runtime.CompilerServices.RequiresLocationAttribute"); + "System.Runtime.CompilerServices.RequiresLocationAttribute", + ]; /// /// Gets the types from the BCL that should potentially receive type forwards. @@ -31,7 +33,7 @@ private static ImmutableArray GetCoreLibTypes(Compilation compilation, C // Same check as when generating polyfills (if none can be generated, there's no need for type forwards) if (!compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp8)) { - return ImmutableArray.Empty; + return []; } IAssemblySymbol coreLibAssemblySymbol = compilation.GetSpecialType(SpecialType.System_Object).ContainingAssembly; From 742d2d75d1d401aa0eda90d415ba0a7cd534d712 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 18 Jun 2025 20:03:40 -0700 Subject: [PATCH 02/12] Emit '[Embedded]' attribute --- .../PolyfillsGenerator.Polyfills.cs | 12 ++++++++++++ src/PolySharp.SourceGenerators/PolyfillsGenerator.cs | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index bb6b53b..1549a56 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -66,6 +66,18 @@ where resourceName.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.Runt /// private readonly ConcurrentDictionary manifestSources = new(); + /// + /// Emits any sources that are needed right after initialization. + /// + /// The input value to use. + private static void EmitPostInitializationSources(IncrementalGeneratorPostInitializationContext context) + { + // Emit the '[Embedded]' definition, which is used by all polyfill types. This is needed to avoid + // conflicts when multiple polyfills are transitively visible in scenarios such as '[InternalsVisibleTo]'. + // When '[Embedded]' is used, Roslyn will instead just pick one of the accessible copies, with no errors. + context.AddEmbeddedAttributeDefinition(); + } + /// /// Extracts the value for the current generation. /// diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs index aff08fd..1ef2d43 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs @@ -13,6 +13,9 @@ public sealed partial class PolyfillsGenerator : IIncrementalGenerator /// public void Initialize(IncrementalGeneratorInitializationContext context) { + // Emit any sources that are needed right after initialization + context.RegisterPostInitializationOutput(EmitPostInitializationSources); + // Prepare all the generation options in a single incremental model IncrementalValueProvider generationOptions = context.AnalyzerConfigOptionsProvider From 823d10d70cc1af601e3a3f24b03e17705df9582a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 18 Jun 2025 20:03:55 -0700 Subject: [PATCH 03/12] Add '[Embedded]' on polyfill types --- ...System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute.cs | 1 + ...em.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.cs | 1 + ...agnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.FeatureGuardAttribute.cs | 1 + ....Diagnostics.CodeAnalysis.FeatureSwitchDefinitionAttribute.cs | 1 + ...em.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttribute.cs | 1 + ...stem.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute.cs | 1 + ...Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute.cs | 1 + ...nostics.CodeAnalysis.UnconditionalSuppressMessageAttribute.cs | 1 + ...iagnostics.DebuggerDisableUserUnhandledExceptionsAttribute.cs | 1 + .../System.Diagnostics.StackTraceHiddenAttribute.cs | 1 + ...untime.CompilerServices.DisableRuntimeMarshallingAttribute.cs | 1 + .../System.Runtime.CompilerServices.InlineArrayAttribute.cs | 1 + .../System.Runtime.CompilerServices.UnsafeAccessorAttribute.cs | 1 + .../System.Runtime.CompilerServices.UnsafeAccessorKind.cs | 1 + ...stem.Runtime.InteropServices.SuppressGCTransitionAttribute.cs | 1 + ...stem.Runtime.InteropServices.UnmanagedCallersOnlyAttribute.cs | 1 + .../System.Runtime.InteropServices.WasmImportLinkageAttribute.cs | 1 + .../System.Runtime.Versioning.ObsoletedOSPlatformAttribute.cs | 1 + .../System.Runtime.Versioning.SupportedOSPlatformAttribute.cs | 1 + ...ystem.Runtime.Versioning.SupportedOSPlatformGuardAttribute.cs | 1 + .../System.Runtime.Versioning.TargetPlatformAttribute.cs | 1 + .../System.Runtime.Versioning.UnsupportedOSPlatformAttribute.cs | 1 + ...tem.Runtime.Versioning.UnsupportedOSPlatformGuardAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs | 1 + ...System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.NotNullAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs | 1 + ...stem.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs | 1 + .../System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs | 1 + src/PolySharp.SourceGenerators/EmbeddedResources/System.Index.cs | 1 + src/PolySharp.SourceGenerators/EmbeddedResources/System.Range.cs | 1 + ...ystem.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs | 1 + ...Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs | 1 + ...System.Runtime.CompilerServices.CollectionBuilderAttribute.cs | 1 + ....Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs | 1 + ...ompilerServices.InterpolatedStringHandlerArgumentAttribute.cs | 1 + ...untime.CompilerServices.InterpolatedStringHandlerAttribute.cs | 1 + .../System.Runtime.CompilerServices.IsExternalInit.cs | 1 + ...System.Runtime.CompilerServices.ModuleInitializerAttribute.cs | 1 + ...ntime.CompilerServices.OverloadResolutionPriorityAttribute.cs | 1 + .../System.Runtime.CompilerServices.ParamCollectionAttribute.cs | 1 + .../System.Runtime.CompilerServices.RequiredMemberAttribute.cs | 1 + .../System.Runtime.CompilerServices.RequiresLocationAttribute.cs | 1 + .../System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs | 1 + ...System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs | 1 + 56 files changed, 56 insertions(+) diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute.cs index f01bd10..6930625 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute.cs @@ -20,6 +20,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Method, AllowMultiple = true, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class DynamicDependencyAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.cs index 961048b..58bf27a 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.cs @@ -14,6 +14,7 @@ namespace System.Diagnostics.CodeAnalysis /// bitwise combination of its member values. /// [global::System.Flags] + [global::Microsoft.CodeAnalysis.Embedded] internal enum DynamicallyAccessedMemberTypes { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute.cs index 0e7db46..6edb6e2 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute.cs @@ -41,6 +41,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Struct, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class DynamicallyAccessedMembersAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.FeatureGuardAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.FeatureGuardAttribute.cs index 8fc64ac..43109d8 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.FeatureGuardAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.FeatureGuardAttribute.cs @@ -18,6 +18,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(global::System.AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class FeatureGuardAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.FeatureSwitchDefinitionAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.FeatureSwitchDefinitionAttribute.cs index aa010fd..bb3cf2c 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.FeatureSwitchDefinitionAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.FeatureSwitchDefinitionAttribute.cs @@ -17,6 +17,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(global::System.AttributeTargets.Property, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class FeatureSwitchDefinitionAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttribute.cs index a8af0dc..26a0ba2 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresAssemblyFilesAttribute.cs @@ -17,6 +17,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Property, Inherited = false, AllowMultiple = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class RequiresAssemblyFilesAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute.cs index 67b4f00..a4e6b2f 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute.cs @@ -20,6 +20,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Class, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class RequiresDynamicCodeAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute.cs index 50015b0..614c09e 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute.cs @@ -20,6 +20,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Constructor | global::System.AttributeTargets.Class, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class RequiresUnreferencedCodeAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute.cs index 82d3044..3c2915e 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute.cs @@ -18,6 +18,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(global::System.AttributeTargets.All, Inherited = false, AllowMultiple = true)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class UnconditionalSuppressMessageAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.DebuggerDisableUserUnhandledExceptionsAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.DebuggerDisableUserUnhandledExceptionsAttribute.cs index 6212cb9..4766347 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.DebuggerDisableUserUnhandledExceptionsAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.DebuggerDisableUserUnhandledExceptionsAttribute.cs @@ -14,6 +14,7 @@ namespace System.Diagnostics /// [global::System.AttributeUsage(global::System.AttributeTargets.Method)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class DebuggerDisableUserUnhandledExceptionsAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.StackTraceHiddenAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.StackTraceHiddenAttribute.cs index 883fd7b..906f421 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.StackTraceHiddenAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Diagnostics.StackTraceHiddenAttribute.cs @@ -18,6 +18,7 @@ namespace System.Diagnostics global::System.AttributeTargets.Struct, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class StackTraceHiddenAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute.cs index 5d38661..808717e 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute.cs @@ -26,6 +26,7 @@ namespace System.Runtime.CompilerServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class DisableRuntimeMarshallingAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.InlineArrayAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.InlineArrayAttribute.cs index 0a87456..9e84164 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.InlineArrayAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.InlineArrayAttribute.cs @@ -28,6 +28,7 @@ namespace System.Runtime.CompilerServices2 /// [global::System.AttributeUsage(global::System.AttributeTargets.Struct, AllowMultiple = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class InlineArrayAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.UnsafeAccessorAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.UnsafeAccessorAttribute.cs index 0a2591c..efd561d 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.UnsafeAccessorAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.UnsafeAccessorAttribute.cs @@ -50,6 +50,7 @@ namespace System.Runtime.CompilerServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class UnsafeAccessorAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.UnsafeAccessorKind.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.UnsafeAccessorKind.cs index 7cb4fc3..58f12e6 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.UnsafeAccessorKind.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.CompilerServices.UnsafeAccessorKind.cs @@ -10,6 +10,7 @@ namespace System.Runtime.CompilerServices /// /// Specifies the kind of target to which an is providing access. /// + [global::Microsoft.CodeAnalysis.Embedded] internal enum UnsafeAccessorKind { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.SuppressGCTransitionAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.SuppressGCTransitionAttribute.cs index b2056d6..088ddcb 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.SuppressGCTransitionAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.SuppressGCTransitionAttribute.cs @@ -63,6 +63,7 @@ namespace System.Runtime.InteropServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Method, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class SuppressGCTransitionAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute.cs index a2b1b22..1797dc0 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute.cs @@ -20,6 +20,7 @@ namespace System.Runtime.InteropServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Method, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class UnmanagedCallersOnlyAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.WasmImportLinkageAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.WasmImportLinkageAttribute.cs index b1f62fc..2300606 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.WasmImportLinkageAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.InteropServices.WasmImportLinkageAttribute.cs @@ -15,6 +15,7 @@ namespace System.Runtime.InteropServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Method, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class WasmImportLinkageAttribute : global::System.Attribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.ObsoletedOSPlatformAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.ObsoletedOSPlatformAttribute.cs index 344fcc9..c7a6b64 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.ObsoletedOSPlatformAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.ObsoletedOSPlatformAttribute.cs @@ -27,6 +27,7 @@ namespace System.Runtime.Versioning global::System.AttributeTargets.Struct, AllowMultiple = true, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class ObsoletedOSPlatformAttribute : global::System.Attribute // OSPlatformAttribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.SupportedOSPlatformAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.SupportedOSPlatformAttribute.cs index 04284dc..596d8df 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.SupportedOSPlatformAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.SupportedOSPlatformAttribute.cs @@ -31,6 +31,7 @@ namespace System.Runtime.Versioning global::System.AttributeTargets.Struct, AllowMultiple = true, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class SupportedOSPlatformAttribute : global::System.Attribute // OSPlatformAttribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.SupportedOSPlatformGuardAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.SupportedOSPlatformGuardAttribute.cs index f66938f..2965c9d 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.SupportedOSPlatformGuardAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.SupportedOSPlatformGuardAttribute.cs @@ -23,6 +23,7 @@ namespace System.Runtime.Versioning global::System.AttributeTargets.Property, AllowMultiple = true, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class SupportedOSPlatformGuardAttribute : global::System.Attribute // OSPlatformAttribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.TargetPlatformAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.TargetPlatformAttribute.cs index 4f564e5..8ba7ebe 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.TargetPlatformAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.TargetPlatformAttribute.cs @@ -12,6 +12,7 @@ namespace System.Runtime.Versioning /// [global::System.AttributeUsage(global::System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class TargetPlatformAttribute : global::System.Attribute // OSPlatformAttribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.UnsupportedOSPlatformAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.UnsupportedOSPlatformAttribute.cs index 69d86c0..cc77296 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.UnsupportedOSPlatformAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.UnsupportedOSPlatformAttribute.cs @@ -28,6 +28,7 @@ namespace System.Runtime.Versioning global::System.AttributeTargets.Struct, AllowMultiple = true, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class UnsupportedOSPlatformAttribute : global::System.Attribute // OSPlatformAttribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.UnsupportedOSPlatformGuardAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.UnsupportedOSPlatformGuardAttribute.cs index 77aa96d..9634013 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.UnsupportedOSPlatformGuardAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RuntimeSupported/System.Runtime.Versioning.UnsupportedOSPlatformGuardAttribute.cs @@ -23,6 +23,7 @@ namespace System.Runtime.Versioning global::System.AttributeTargets.Property, AllowMultiple = true, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] [global::System.Diagnostics.Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")] internal sealed class UnsupportedOSPlatformGuardAttribute : global::System.Attribute // OSPlatformAttribute { diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs index 966a32f..4ba8168 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs @@ -16,6 +16,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Property, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class AllowNullAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs index 0c85229..7ede491 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs @@ -15,6 +15,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(AttributeTargets.Parameter, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class ConstantExpectedAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs index 749216a..a8a5776 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs @@ -16,6 +16,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Property, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class DisallowNullAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs index a8a8c14..096a0d7 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs @@ -12,6 +12,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(global::System.AttributeTargets.Method, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class DoesNotReturnAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs index 90c066a..f4cfe4d 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs @@ -12,6 +12,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(global::System.AttributeTargets.Parameter, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class DoesNotReturnIfAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs index 0ffefc8..1eb2d05 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs @@ -29,6 +29,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Delegate, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class ExperimentalAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs index 21a631b..81efb9a 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs @@ -17,6 +17,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.ReturnValue, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class MaybeNullAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs index 86d2817..4f69532 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs @@ -12,6 +12,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(global::System.AttributeTargets.Parameter, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class MaybeNullWhenAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs index d8481a8..a3e1f41 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs @@ -15,6 +15,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class MemberNotNullAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs index 40355d0..77e0555 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs @@ -16,6 +16,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class MemberNotNullWhenAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs index ef52104..4232d87 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs @@ -18,6 +18,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.ReturnValue, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class NotNullAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs index 839b717..c48a3e3 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs @@ -16,6 +16,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class NotNullIfNotNullAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs index e91adc3..bfbcc50 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs @@ -12,6 +12,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(global::System.AttributeTargets.Parameter, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class NotNullWhenAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs index cc10d01..118d3ad 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs @@ -13,6 +13,7 @@ namespace System.Diagnostics.CodeAnalysis /// [global::System.AttributeUsage(global::System.AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class SetsRequiredMembersAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs index d5324ef..e69d8c9 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs @@ -16,6 +16,7 @@ namespace System.Diagnostics.CodeAnalysis global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class StringSyntaxAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs index 71c248d..54da81d 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs @@ -38,6 +38,7 @@ namespace System.Diagnostics.CodeAnalysis AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class UnscopedRefAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Index.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Index.cs index 4b41933..8d60cb2 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Index.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Index.cs @@ -16,6 +16,7 @@ namespace System /// /// [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal readonly struct Index : global::System.IEquatable { private readonly int _value; diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Range.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Range.cs index d0e8a48..753450e 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Range.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Range.cs @@ -17,6 +17,7 @@ namespace System /// /// [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal readonly struct Range : global::System.IEquatable { /// Represent the inclusive start index of the Range. diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs index 3fd90fe..37417fb 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs @@ -21,6 +21,7 @@ namespace System.Runtime.CompilerServices global::System.AttributeTargets.Method, Inherited = false, AllowMultiple = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class AsyncMethodBuilderAttribute : global::System.Attribute { /// Initializes the . diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs index a22c7d8..751bb6b 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs @@ -12,6 +12,7 @@ namespace System.Runtime.CompilerServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class CallerArgumentExpressionAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs index d1a037e..ed965e5 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs @@ -13,6 +13,7 @@ namespace System.Runtime.CompilerServices global::System.AttributeTargets.Interface, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class CollectionBuilderAttribute : Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs index 1f64f35..3909985 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs @@ -12,6 +12,7 @@ namespace System.Runtime.CompilerServices /// [global::System.AttributeUsage(global::System.AttributeTargets.All, AllowMultiple = true, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class CompilerFeatureRequiredAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs index f8b1d28..0042cb9 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs @@ -12,6 +12,7 @@ namespace System.Runtime.CompilerServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class InterpolatedStringHandlerArgumentAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs index 89fe96c..8bb10db 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs @@ -15,6 +15,7 @@ namespace System.Runtime.CompilerServices global::System.AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class InterpolatedStringHandlerAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.IsExternalInit.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.IsExternalInit.cs index 72de835..91064ef 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.IsExternalInit.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.IsExternalInit.cs @@ -13,6 +13,7 @@ namespace System.Runtime.CompilerServices /// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal static class IsExternalInit { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs index 19711cc..6e6028e 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs @@ -29,6 +29,7 @@ namespace System.Runtime.CompilerServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Method, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class ModuleInitializerAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs index bdaeaf6..0bf2680 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs @@ -17,6 +17,7 @@ namespace System.Runtime.CompilerServices AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class OverloadResolutionPriorityAttribute : global::System.Attribute { /// diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ParamCollectionAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ParamCollectionAttribute.cs index 9874cfd..f8db646 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ParamCollectionAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ParamCollectionAttribute.cs @@ -12,6 +12,7 @@ namespace System.Runtime.CompilerServices /// [global::System.AttributeUsage(global::System.AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class ParamCollectionAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiredMemberAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiredMemberAttribute.cs index 414c9c0..e1c830c 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiredMemberAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiredMemberAttribute.cs @@ -18,6 +18,7 @@ namespace System.Runtime.CompilerServices AllowMultiple = false, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class RequiredMemberAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiresLocationAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiresLocationAttribute.cs index 53ea973..5a422b7 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiresLocationAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiresLocationAttribute.cs @@ -14,6 +14,7 @@ namespace System.Runtime.CompilerServices [global::System.AttributeUsage(global::System.AttributeTargets.Parameter, Inherited = false)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class RequiresLocationAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs index 4b4df5e..62b6cd9 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs @@ -21,6 +21,7 @@ namespace System.Runtime.CompilerServices global::System.AttributeTargets.Event, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class SkipLocalsInitAttribute : global::System.Attribute { } diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs index 153f0ca..a74dfc0 100644 --- a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs @@ -21,6 +21,7 @@ namespace System.Runtime.Versioning global::System.AttributeTargets.Field | AttributeTargets.Event, Inherited = false)] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + [global::Microsoft.CodeAnalysis.Embedded] internal sealed class RequiresPreviewFeaturesAttribute : global::System.Attribute { /// From 84e432d57fe2d7acb2c291abb7734122447a85ec Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 18 Jun 2025 20:13:50 -0700 Subject: [PATCH 04/12] Strip '[Embedded]' when types are public --- .../PolyfillsGenerator.Polyfills.cs | 8 ++++++++ .../PrivatePolyfills/EmbeddedAttribute.cs | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/PolySharp.SourceGenerators/PrivatePolyfills/EmbeddedAttribute.cs diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index 1549a56..24235e6 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -61,6 +61,11 @@ where resourceName.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.Runt /// private static readonly Regex ExcludeFromCodeCoverageRegex = new(@" *\[global::System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverage\]\r?\n", RegexOptions.Compiled); + /// + /// The to find all uses. + /// + private static readonly Regex EmbeddedAttributeRegex = new(@" *\[global::Microsoft\.CodeAnalysis\.Embedded\]\r?\n", RegexOptions.Compiled); + /// /// The dictionary of cached sources to produce. /// @@ -282,6 +287,9 @@ private void EmitGeneratedType(SourceProductionContext context, GeneratedType ty // rewriter, or just by retrieving the type declaration syntax and updating the modifier tokens, but since the // change is so minimal, it can very well just be done this way to keep things simple, that's fine in this case. adjustedSource = adjustedSource.Replace(" internal ", " public "); + + // If types are public, we also need to strip the '[Embedded]' attributes, as it's only allowed on public types + adjustedSource = EmbeddedAttributeRegex.Replace(adjustedSource, ""); } if ((type.FixupType & SyntaxFixupType.RemoveMethodImplAttributes) != 0) diff --git a/src/PolySharp.SourceGenerators/PrivatePolyfills/EmbeddedAttribute.cs b/src/PolySharp.SourceGenerators/PrivatePolyfills/EmbeddedAttribute.cs new file mode 100644 index 0000000..7ee6b9d --- /dev/null +++ b/src/PolySharp.SourceGenerators/PrivatePolyfills/EmbeddedAttribute.cs @@ -0,0 +1,12 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; + +namespace Microsoft.CodeAnalysis; + +/// +/// Marks a type as "embedded", meaning it won't ever be visible from other assemblies. +/// +[AttributeUsage(AttributeTargets.All)] +internal sealed class EmbeddedAttribute : Attribute; \ No newline at end of file From 15bbbee4f12ea3b7f8828be8d1d75f2b92e31da6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 18 Jun 2025 23:22:15 -0700 Subject: [PATCH 05/12] Refactor polyfills, manually emit '[Embedded]' --- ...nostics.CodeAnalysis.AllowNullAttribute.cs | 0 ....CodeAnalysis.ConstantExpectedAttribute.cs | 0 ...tics.CodeAnalysis.DisallowNullAttribute.cs | 0 ...ics.CodeAnalysis.DoesNotReturnAttribute.cs | 0 ...s.CodeAnalysis.DoesNotReturnIfAttribute.cs | 0 ...tics.CodeAnalysis.ExperimentalAttribute.cs | 0 ...nostics.CodeAnalysis.MaybeNullAttribute.cs | 0 ...ics.CodeAnalysis.MaybeNullWhenAttribute.cs | 0 ...ics.CodeAnalysis.MemberNotNullAttribute.cs | 0 ...CodeAnalysis.MemberNotNullWhenAttribute.cs | 0 ...agnostics.CodeAnalysis.NotNullAttribute.cs | 0 ....CodeAnalysis.NotNullIfNotNullAttribute.cs | 0 ...stics.CodeAnalysis.NotNullWhenAttribute.cs | 0 ...deAnalysis.SetsRequiredMembersAttribute.cs | 0 ...tics.CodeAnalysis.StringSyntaxAttribute.cs | 0 ...stics.CodeAnalysis.UnscopedRefAttribute.cs | 0 .../{ => LanguageSupport}/System.Index.cs | 0 .../{ => LanguageSupport}/System.Range.cs | 0 ...lerServices.AsyncMethodBuilderAttribute.cs | 0 ...vices.CallerArgumentExpressionAttribute.cs | 0 ...ilerServices.CollectionBuilderAttribute.cs | 0 ...rvices.CompilerFeatureRequiredAttribute.cs | 0 ...erpolatedStringHandlerArgumentAttribute.cs | 0 ...ices.InterpolatedStringHandlerAttribute.cs | 0 ...Runtime.CompilerServices.IsExternalInit.cs | 0 ...ilerServices.ModuleInitializerAttribute.cs | 0 ...ces.OverloadResolutionPriorityAttribute.cs | 0 ...mpilerServices.ParamCollectionAttribute.cs | 0 ...ompilerServices.RequiredMemberAttribute.cs | 0 ...pilerServices.RequiresLocationAttribute.cs | 0 ...ompilerServices.SkipLocalsInitAttribute.cs | 0 ...ioning.RequiresPreviewFeaturesAttribute.cs | 0 ...icrosoft.CodeAnalysis.EmbeddedAttribute.cs | 18 ++++++++ .../Extensions/AssemblyExtensions.cs | 28 +++++++++++++ .../PolyfillsGenerator.Polyfills.cs | 42 ++++++++++--------- .../PolyfillsGenerator.cs | 6 ++- .../PrivatePolyfills/EmbeddedAttribute.cs | 12 ------ 37 files changed, 73 insertions(+), 33 deletions(-) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Index.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Range.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.IsExternalInit.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.ParamCollectionAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.RequiredMemberAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.RequiresLocationAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs (100%) rename src/PolySharp.SourceGenerators/EmbeddedResources/{ => LanguageSupport}/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs (100%) create mode 100644 src/PolySharp.SourceGenerators/EmbeddedResources/RoslynSupported/Microsoft.CodeAnalysis.EmbeddedAttribute.cs create mode 100644 src/PolySharp.SourceGenerators/Extensions/AssemblyExtensions.cs delete mode 100644 src/PolySharp.SourceGenerators/PrivatePolyfills/EmbeddedAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.AllowNullAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.DisallowNullAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.ExperimentalAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.MaybeNullAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.MemberNotNullAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.NotNullAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.StringSyntaxAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Diagnostics.CodeAnalysis.UnscopedRefAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Index.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Index.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Index.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Index.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Range.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Range.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Range.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Range.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.AsyncMethodBuilderAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.CallerArgumentExpressionAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.CollectionBuilderAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.InterpolatedStringHandlerArgumentAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.InterpolatedStringHandlerAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.IsExternalInit.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.IsExternalInit.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.IsExternalInit.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.IsExternalInit.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.ModuleInitializerAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ParamCollectionAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.ParamCollectionAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.ParamCollectionAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.ParamCollectionAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiredMemberAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.RequiredMemberAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiredMemberAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.RequiredMemberAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiresLocationAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.RequiresLocationAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.RequiresLocationAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.RequiresLocationAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.CompilerServices.SkipLocalsInitAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs similarity index 100% rename from src/PolySharp.SourceGenerators/EmbeddedResources/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs rename to src/PolySharp.SourceGenerators/EmbeddedResources/LanguageSupport/System.Runtime.Versioning.RequiresPreviewFeaturesAttribute.cs diff --git a/src/PolySharp.SourceGenerators/EmbeddedResources/RoslynSupported/Microsoft.CodeAnalysis.EmbeddedAttribute.cs b/src/PolySharp.SourceGenerators/EmbeddedResources/RoslynSupported/Microsoft.CodeAnalysis.EmbeddedAttribute.cs new file mode 100644 index 0000000..5c3492c --- /dev/null +++ b/src/PolySharp.SourceGenerators/EmbeddedResources/RoslynSupported/Microsoft.CodeAnalysis.EmbeddedAttribute.cs @@ -0,0 +1,18 @@ +// +#pragma warning disable +#nullable enable annotations + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.CodeAnalysis +{ + /// + /// A special attribute recognized by Roslyn, that marks a type as "embedded", meaning it won't ever be visible from other assemblies. + /// + [global::System.AttributeUsage(global::System.AttributeTargets.All)] + [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + internal sealed partial class EmbeddedAttribute : global::System.Attribute + { + } +} \ No newline at end of file diff --git a/src/PolySharp.SourceGenerators/Extensions/AssemblyExtensions.cs b/src/PolySharp.SourceGenerators/Extensions/AssemblyExtensions.cs new file mode 100644 index 0000000..497c4cc --- /dev/null +++ b/src/PolySharp.SourceGenerators/Extensions/AssemblyExtensions.cs @@ -0,0 +1,28 @@ +// 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. + +using System.IO; +using System.Reflection; + +namespace PolySharp.SourceGenerators.Extensions; + +/// +/// Extension methods for the type. +/// +internal static class AssemblyExtensions +{ + /// + /// Reads a manifest resue from the specified assembly and returns its content as a . + /// + /// The assemlby to read from. + /// The name of the resource to read. + /// The resource contents. + public static string ReadManifestResource(this Assembly assembly, string resourceName) + { + using Stream stream = typeof(PolyfillsGenerator).Assembly.GetManifestResourceStream(resourceName); + using StreamReader reader = new(stream); + + return reader.ReadToEnd(); + } +} \ No newline at end of file diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index 24235e6..c9533d6 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -23,7 +23,7 @@ partial class PolyfillsGenerator /// /// A regex to extract the fully qualified type name of a type from its embedded resource name. /// - private const string EmbeddedResourceNameToFullyQualifiedTypeNameRegex = @"^PolySharp\.SourceGenerators\.EmbeddedResources(?:\.RuntimeSupported)?\.(System(?:\.\w+)+)\.cs$"; + private const string EmbeddedResourceNameToFullyQualifiedTypeNameRegex = @"^PolySharp\.SourceGenerators\.EmbeddedResources\.\w+\.(\w+(?:\.\w+)+)\.cs$"; /// /// The mapping of fully qualified type names to embedded resource names. @@ -35,16 +35,18 @@ from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResou /// /// The collection of fully qualified type names for language support types. /// - private static readonly ImmutableArray LanguageSupportTypeNames = [.. from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResourceNames() - where !resourceName.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.RuntimeSupported.") - select Regex.Match(resourceName, EmbeddedResourceNameToFullyQualifiedTypeNameRegex).Groups[1].Value]; + private static readonly ImmutableArray LanguageSupportTypeNames = [.. + from KeyValuePair resource in FullyQualifiedTypeNamesToResourceNames + where resource.Value.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.LanguageSupport.") + select resource.Key]; /// /// The collection of fully qualified type names for runtime supported types. /// - private static readonly ImmutableArray RuntimeSupportedTypeNames = [.. from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResourceNames() - where resourceName.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.RuntimeSupported.") - select Regex.Match(resourceName, EmbeddedResourceNameToFullyQualifiedTypeNameRegex).Groups[1].Value]; + private static readonly ImmutableArray RuntimeSupportedTypeNames = [.. + from KeyValuePair resource in FullyQualifiedTypeNamesToResourceNames + where resource.Value.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.RuntimeSupported.") + select resource.Key]; /// /// The collection of all fully qualified type names for available polyfill types. @@ -71,18 +73,6 @@ where resourceName.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.Runt /// private readonly ConcurrentDictionary manifestSources = new(); - /// - /// Emits any sources that are needed right after initialization. - /// - /// The input value to use. - private static void EmitPostInitializationSources(IncrementalGeneratorPostInitializationContext context) - { - // Emit the '[Embedded]' definition, which is used by all polyfill types. This is needed to avoid - // conflicts when multiple polyfills are transitively visible in scenarios such as '[InternalsVisibleTo]'. - // When '[Embedded]' is used, Roslyn will instead just pick one of the accessible copies, with no errors. - context.AddEmbeddedAttributeDefinition(); - } - /// /// Extracts the value for the current generation. /// @@ -256,6 +246,20 @@ static SyntaxFixupType GetSyntaxFixupType(AvailableType availableType, Generatio return new(info.AvailableType.FullyQualifiedMetadataName, info.Options.UsePublicAccessibilityForGeneratedTypes, fixupType); } + /// + /// Emits the source for . + /// + /// The input instance to use to emit code. + private static void EmitEmbeddedAttribute(IncrementalGeneratorPostInitializationContext context) + { + string resourceName = FullyQualifiedTypeNamesToResourceNames["Microsoft.CodeAnalysis.EmbeddedAttribute"]; + + // We don't need any adjustments for this attribute, we just read it directly from the embedded resource + string sourceText = typeof(PolyfillsGenerator).Assembly.ReadManifestResource(resourceName); + + context.AddSource("Microsoft.CodeAnalysis.EmbeddedAttribute.g.cs", sourceText); + } + /// /// Emits the source for a given object. /// diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs index 1ef2d43..a06fca4 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs @@ -13,8 +13,10 @@ public sealed partial class PolyfillsGenerator : IIncrementalGenerator /// public void Initialize(IncrementalGeneratorInitializationContext context) { - // Emit any sources that are needed right after initialization - context.RegisterPostInitializationOutput(EmitPostInitializationSources); + // Emit the '[Embedded]' definition, which is used by all polyfill types. This is needed to avoid + // conflicts when multiple polyfills are transitively visible in scenarios such as '[InternalsVisibleTo]'. + // When '[Embedded]' is used, Roslyn will instead just pick one of the accessible copies, with no errors. + context.RegisterPostInitializationOutput(EmitEmbeddedAttribute); // Prepare all the generation options in a single incremental model IncrementalValueProvider generationOptions = diff --git a/src/PolySharp.SourceGenerators/PrivatePolyfills/EmbeddedAttribute.cs b/src/PolySharp.SourceGenerators/PrivatePolyfills/EmbeddedAttribute.cs deleted file mode 100644 index 7ee6b9d..0000000 --- a/src/PolySharp.SourceGenerators/PrivatePolyfills/EmbeddedAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; - -namespace Microsoft.CodeAnalysis; - -/// -/// Marks a type as "embedded", meaning it won't ever be visible from other assemblies. -/// -[AttributeUsage(AttributeTargets.All)] -internal sealed class EmbeddedAttribute : Attribute; \ No newline at end of file From 42930740661032293b3b0c425f4650659221b10b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 18 Jun 2025 23:22:31 -0700 Subject: [PATCH 06/12] Add 'UsePublicAccessibility' unit test --- PolySharp.slnx | 1 + ...ySharp.Tests.UsePublicAccessibility.csproj | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/PolySharp.Tests.UsePublicAccessibility/PolySharp.Tests.UsePublicAccessibility.csproj diff --git a/PolySharp.slnx b/PolySharp.slnx index ffda3b4..3b5474c 100644 --- a/PolySharp.slnx +++ b/PolySharp.slnx @@ -8,6 +8,7 @@ + diff --git a/tests/PolySharp.Tests.UsePublicAccessibility/PolySharp.Tests.UsePublicAccessibility.csproj b/tests/PolySharp.Tests.UsePublicAccessibility/PolySharp.Tests.UsePublicAccessibility.csproj new file mode 100644 index 0000000..1a5d5e0 --- /dev/null +++ b/tests/PolySharp.Tests.UsePublicAccessibility/PolySharp.Tests.UsePublicAccessibility.csproj @@ -0,0 +1,32 @@ + + + + + net472;net48;net481;netstandard2.0;netstandard2.1;net8.0;net9.0 + true + true + + + + + + + + + + + + + + + + + + + + + From 98771325a2a7f8948fb8c8b2d4dbee4933e6f165 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 18 Jun 2025 23:24:21 -0700 Subject: [PATCH 07/12] Revert Roslyn to '4.3.0' --- .../UnsupportedCSharpLanguageVersionAnalyzer.cs | 2 +- .../Diagnostics/DiagnosticDescriptors.cs | 11 ++++++----- .../AnalyzerConfigOptionsProviderExtensions.cs | 2 +- .../Extensions/DiagnosticsExtensions.cs | 2 +- .../PolySharp.SourceGenerators.csproj | 4 ++-- src/PolySharp.SourceGenerators/PolySharp.targets | 8 ++++---- .../PolyfillsGenerator.Polyfills.cs | 12 ++++++------ .../PolyfillsGenerator.TypeForwards.cs | 8 +++----- 8 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/PolySharp.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs b/src/PolySharp.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs index 4130853..e934a80 100644 --- a/src/PolySharp.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs +++ b/src/PolySharp.SourceGenerators/Diagnostics/Analyzers/UnsupportedCSharpLanguageVersionAnalyzer.cs @@ -18,7 +18,7 @@ namespace PolySharp.SourceGenerators; public sealed partial class UnsupportedCSharpLanguageVersionAnalyzer : DiagnosticAnalyzer { /// - public override ImmutableArray SupportedDiagnostics { get; } = [UnsupportedCSharpLanguageVersionError]; + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(UnsupportedCSharpLanguageVersionError); /// public override void Initialize(AnalysisContext context) diff --git a/src/PolySharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/PolySharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 4d6f6d1..61ca921 100644 --- a/src/PolySharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/PolySharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -5,6 +5,8 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; +#pragma warning disable IDE0090 // Use 'new DiagnosticDescriptor(...)' + namespace PolySharp.SourceGenerators.Diagnostics; /// @@ -18,7 +20,7 @@ internal static class DiagnosticDescriptors /// Format: "The value "{0}" is not valid for property "{1}" (it has to be a valid MSBuild bool value)". /// /// - public static readonly DiagnosticDescriptor InvalidBoolMSBuildProperty = new( + public static readonly DiagnosticDescriptor InvalidBoolMSBuildProperty = new DiagnosticDescriptor( id: "POLYSP0001", title: "Invalid PolySharp bool MSBuild property", messageFormat: "The value \"{0}\" is not valid for property \"{1}\" (it has to be a valid MSBuild bool value)", @@ -34,7 +36,7 @@ internal static class DiagnosticDescriptors /// Format: "The fully qualified metadata name "{0}" used in property "{1}" is not valid, and it does not match any available polyfill type". /// /// - public static readonly DiagnosticDescriptor InvalidPolyfillFullyQualifiedMetadataName = new( + public static readonly DiagnosticDescriptor InvalidPolyfillFullyQualifiedMetadataName = new DiagnosticDescriptor( id: "POLYSP0002", title: "Invalid fully qualified metadata name for polyfill", messageFormat: "The fully qualified metadata name \"{0}\" used in property \"{1}\" is not a valid fully qualified type name, or it does not match any available polyfill type", @@ -47,7 +49,7 @@ internal static class DiagnosticDescriptors /// /// Gets a indicating when an unsupported C# language version is being used. /// - public static readonly DiagnosticDescriptor UnsupportedCSharpLanguageVersionError = new( + public static readonly DiagnosticDescriptor UnsupportedCSharpLanguageVersionError = new DiagnosticDescriptor( id: "POLYSP0003", title: "Unsupported C# language version", messageFormat: "The source generator features from PolySharp require consuming projects to set the C# language version to at least C# 8.0", @@ -55,6 +57,5 @@ internal static class DiagnosticDescriptors defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true, description: "The source generator features from PolySharp require consuming projects to set the C# language version to at least C# 8.0. Make sure to add 8.0 (or above) to your .csproj file.", - helpLinkUri: "https://github.com/Sergio0694/PolySharp", - customTags: WellKnownDiagnosticTags.CompilationEnd); + helpLinkUri: "https://github.com/Sergio0694/PolySharp"); } diff --git a/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs b/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs index 65fe757..d4521af 100644 --- a/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs +++ b/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs @@ -71,6 +71,6 @@ public static ImmutableArray GetStringArrayMSBuildProperty(this Analyzer return builder.ToImmutable(); } - return []; + return ImmutableArray.Empty; } } \ No newline at end of file diff --git a/src/PolySharp.SourceGenerators/Extensions/DiagnosticsExtensions.cs b/src/PolySharp.SourceGenerators/Extensions/DiagnosticsExtensions.cs index 1be9b5a..3cd9f7b 100644 --- a/src/PolySharp.SourceGenerators/Extensions/DiagnosticsExtensions.cs +++ b/src/PolySharp.SourceGenerators/Extensions/DiagnosticsExtensions.cs @@ -5,7 +5,7 @@ namespace PolySharp.SourceGenerators.Extensions; /// -/// Extension methods for , in various scenarios. +/// Extension methods for , specifically for reporting diagnostics. /// internal static class DiagnosticsExtensions { diff --git a/src/PolySharp.SourceGenerators/PolySharp.SourceGenerators.csproj b/src/PolySharp.SourceGenerators/PolySharp.SourceGenerators.csproj index 26d6116..4be0497 100644 --- a/src/PolySharp.SourceGenerators/PolySharp.SourceGenerators.csproj +++ b/src/PolySharp.SourceGenerators/PolySharp.SourceGenerators.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -7,7 +7,7 @@ - + diff --git a/src/PolySharp.SourceGenerators/PolySharp.targets b/src/PolySharp.SourceGenerators/PolySharp.targets index 532bcba..e9f4075 100644 --- a/src/PolySharp.SourceGenerators/PolySharp.targets +++ b/src/PolySharp.SourceGenerators/PolySharp.targets @@ -7,7 +7,7 @@ - + @(PolySharpCurrentCompilerAssemblyIdentity->'%(Version)') - true + true - + @@ -44,7 +44,7 @@ --> + Text="The PolySharp source generators have been disabled on the current configuration, as they need Roslyn 4.3 in order to work. PolySharp requires the source generators to run in order to generate polyfills, so the library cannot be used without a more up to date IDE (eg. VS 2022 17.3 or greater) or .NET SDK version (.NET 6.0.400 SDK or greater)."/> diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index c9533d6..1d6c159 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -35,23 +35,23 @@ from string resourceName in typeof(PolyfillsGenerator).Assembly.GetManifestResou /// /// The collection of fully qualified type names for language support types. /// - private static readonly ImmutableArray LanguageSupportTypeNames = [.. + private static readonly ImmutableArray LanguageSupportTypeNames = ImmutableArray.CreateRange( from KeyValuePair resource in FullyQualifiedTypeNamesToResourceNames where resource.Value.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.LanguageSupport.") - select resource.Key]; + select resource.Key); /// /// The collection of fully qualified type names for runtime supported types. /// - private static readonly ImmutableArray RuntimeSupportedTypeNames = [.. + private static readonly ImmutableArray RuntimeSupportedTypeNames = ImmutableArray.CreateRange( from KeyValuePair resource in FullyQualifiedTypeNamesToResourceNames where resource.Value.StartsWith("PolySharp.SourceGenerators.EmbeddedResources.RuntimeSupported.") - select resource.Key]; + select resource.Key); /// /// The collection of all fully qualified type names for available polyfill types. /// - private static readonly ImmutableArray AllSupportTypeNames = [.. LanguageSupportTypeNames.Concat(RuntimeSupportedTypeNames)]; + private static readonly ImmutableArray AllSupportTypeNames = ImmutableArray.CreateRange(LanguageSupportTypeNames.Concat(RuntimeSupportedTypeNames)); /// /// The to find all uses. @@ -117,7 +117,7 @@ private static ImmutableArray GetAvailableTypes(Compilation compi // A minimum of C# 8.0 is required to benefit from the polyfills if (!compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp8)) { - return []; + return ImmutableArray.Empty; } // Helper function to check whether a type is available diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.TypeForwards.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.TypeForwards.cs index d4097a8..afb6f35 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.TypeForwards.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.TypeForwards.cs @@ -14,13 +14,11 @@ partial class PolyfillsGenerator /// /// The collection of fully qualified type names for types that could require a modreq. /// - private static readonly ImmutableArray ModreqCandidateFullyQualifiedTypeNames = - [ + private static readonly ImmutableArray ModreqCandidateFullyQualifiedTypeNames = ImmutableArray.Create( "System.Index", "System.Range", "System.Runtime.CompilerServices.IsExternalInit", - "System.Runtime.CompilerServices.RequiresLocationAttribute", - ]; + "System.Runtime.CompilerServices.RequiresLocationAttribute"); /// /// Gets the types from the BCL that should potentially receive type forwards. @@ -33,7 +31,7 @@ private static ImmutableArray GetCoreLibTypes(Compilation compilation, C // Same check as when generating polyfills (if none can be generated, there's no need for type forwards) if (!compilation.HasLanguageVersionAtLeastEqualTo(LanguageVersion.CSharp8)) { - return []; + return ImmutableArray.Empty; } IAssemblySymbol coreLibAssemblySymbol = compilation.GetSpecialType(SpecialType.System_Object).ContainingAssembly; From 399da2e21b1ffada2e253141d18fac97661f462d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 3 Sep 2025 15:44:03 -0700 Subject: [PATCH 08/12] Fix a comment for '[Embedded]' fixups --- src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index 1d6c159..2ca585c 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -292,7 +292,7 @@ private void EmitGeneratedType(SourceProductionContext context, GeneratedType ty // change is so minimal, it can very well just be done this way to keep things simple, that's fine in this case. adjustedSource = adjustedSource.Replace(" internal ", " public "); - // If types are public, we also need to strip the '[Embedded]' attributes, as it's only allowed on public types + // If types are public, we also need to strip the '[Embedded]' attributes, as it's not allowed on public types adjustedSource = EmbeddedAttributeRegex.Replace(adjustedSource, ""); } From 7e4d58229728e0b13fa775f44e2624c49aa41ccd Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 15 Nov 2025 12:50:26 -0800 Subject: [PATCH 09/12] Add support for EmbeddedAttribute emission via MSBuild property Introduces a new MSBuild property 'PolySharpUseEmbeddedAttributeForGeneratedTypes' and corresponding generation option to control whether the [Embedded] attribute is emitted and applied to generated types. Refactors the generator to emit the EmbeddedAttribute only when this option is enabled, improving flexibility and reducing unnecessary code emission. --- .../Constants/PolySharpMSBuildProperties.cs | 5 ++++ .../Models/GenerationOptions.cs | 2 ++ .../PolyfillsGenerator.Polyfills.cs | 25 +++++++++++++------ .../PolyfillsGenerator.cs | 8 +++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/PolySharp.SourceGenerators/Constants/PolySharpMSBuildProperties.cs b/src/PolySharp.SourceGenerators/Constants/PolySharpMSBuildProperties.cs index 13eb25c..039e6b2 100644 --- a/src/PolySharp.SourceGenerators/Constants/PolySharpMSBuildProperties.cs +++ b/src/PolySharp.SourceGenerators/Constants/PolySharpMSBuildProperties.cs @@ -10,6 +10,11 @@ internal static class PolySharpMSBuildProperties /// public const string UsePublicAccessibilityForGeneratedTypes = "PolySharpUsePublicAccessibilityForGeneratedTypes"; + /// + /// The MSBuild property for . + /// + public const string UseEmbeddedAttributeForGeneratedTypes = "PolySharpUseEmbeddedAttributeForGeneratedTypes"; + /// /// The MSBuild property for . /// diff --git a/src/PolySharp.SourceGenerators/Models/GenerationOptions.cs b/src/PolySharp.SourceGenerators/Models/GenerationOptions.cs index f436b69..f6233ab 100644 --- a/src/PolySharp.SourceGenerators/Models/GenerationOptions.cs +++ b/src/PolySharp.SourceGenerators/Models/GenerationOptions.cs @@ -6,6 +6,7 @@ namespace PolySharp.SourceGenerators.Models; /// A model to hold all generation options for the source generator. /// /// Whether to use public accessibility for the generated types. +/// Whether to emit the [Embedded] attribute and apply it to generated types. /// Whether to also generated dummy runtime supported attributes. /// Whether to move the [UnmanagedCallersOnly] type to a dummy InteropServices2 namespace. /// Whether to never generate any [TypeForwardedTo] declarations automatically. @@ -13,6 +14,7 @@ namespace PolySharp.SourceGenerators.Models; /// The collection of fully qualified type names of types to include in the generation. internal sealed record GenerationOptions( bool UsePublicAccessibilityForGeneratedTypes, + bool UseEmbeddedAttributeForGeneratedTypes, bool IncludeRuntimeSupportedAttributes, bool UseInteropServices2NamespaceForUnmanagedCallersOnlyAttribute, bool ExcludeTypeForwardedToDeclarations, diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index 2ca585c..5ab9b01 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -85,6 +85,9 @@ private static GenerationOptions GetGenerationOptions(AnalyzerConfigOptionsProvi // $(PolySharpUsePublicAccessibilityForGeneratedTypes) MSBuild property to configure this however they need. bool usePublicAccessibilityForGeneratedTypes = options.GetBoolMSBuildProperty(PolySharpMSBuildProperties.UsePublicAccessibilityForGeneratedTypes); + // Check whether to emit the '[Embedded]' attribute and apply it to generated types + bool useEmbeddedAttributeForGeneratedTypes = options.GetBoolMSBuildProperty(PolySharpMSBuildProperties.UseEmbeddedAttributeForGeneratedTypes); + // Do the same as above for all other available boolean properties bool includeRuntimeSupportedAttributes = options.GetBoolMSBuildProperty(PolySharpMSBuildProperties.IncludeRuntimeSupportedAttributes); bool useInteropServices2NamespaceForUnmanagedCallersOnlyAttribute = options.GetBoolMSBuildProperty(PolySharpMSBuildProperties.UseInteropServices2NamespaceForUnmanagedCallersOnlyAttribute); @@ -99,6 +102,7 @@ private static GenerationOptions GetGenerationOptions(AnalyzerConfigOptionsProvi return new( usePublicAccessibilityForGeneratedTypes, + useEmbeddedAttributeForGeneratedTypes, includeRuntimeSupportedAttributes, useInteropServices2NamespaceForUnmanagedCallersOnlyAttribute, excludeTypeForwardedToDeclarations, @@ -247,17 +251,24 @@ static SyntaxFixupType GetSyntaxFixupType(AvailableType availableType, Generatio } /// - /// Emits the source for . + /// Emits all requested "pre-initialization" types (but as an output step, so we can handle conditions). /// - /// The input instance to use to emit code. - private static void EmitEmbeddedAttribute(IncrementalGeneratorPostInitializationContext context) + /// The input instance to use to emit code. + /// The input instance to use to emit code. + private static void EmitPreInitializationTypes(SourceProductionContext context, GenerationOptions options) { - string resourceName = FullyQualifiedTypeNamesToResourceNames["Microsoft.CodeAnalysis.EmbeddedAttribute"]; + // Emit the '[Embedded]' definition, which is used by all polyfill types. This is needed to avoid + // conflicts when multiple polyfills are transitively visible in scenarios such as '[InternalsVisibleTo]'. + // When '[Embedded]' is used, Roslyn will instead just pick one of the accessible copies, with no errors. + if (options.UseEmbeddedAttributeForGeneratedTypes) + { + string resourceName = FullyQualifiedTypeNamesToResourceNames["Microsoft.CodeAnalysis.EmbeddedAttribute"]; - // We don't need any adjustments for this attribute, we just read it directly from the embedded resource - string sourceText = typeof(PolyfillsGenerator).Assembly.ReadManifestResource(resourceName); + // We don't need any adjustments for this attribute, we just read it directly from the embedded resource + string sourceText = typeof(PolyfillsGenerator).Assembly.ReadManifestResource(resourceName); - context.AddSource("Microsoft.CodeAnalysis.EmbeddedAttribute.g.cs", sourceText); + context.AddSource("Microsoft.CodeAnalysis.EmbeddedAttribute.g.cs", sourceText); + } } /// diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs index a06fca4..d2c4e5e 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.cs @@ -13,16 +13,14 @@ public sealed partial class PolyfillsGenerator : IIncrementalGenerator /// public void Initialize(IncrementalGeneratorInitializationContext context) { - // Emit the '[Embedded]' definition, which is used by all polyfill types. This is needed to avoid - // conflicts when multiple polyfills are transitively visible in scenarios such as '[InternalsVisibleTo]'. - // When '[Embedded]' is used, Roslyn will instead just pick one of the accessible copies, with no errors. - context.RegisterPostInitializationOutput(EmitEmbeddedAttribute); - // Prepare all the generation options in a single incremental model IncrementalValueProvider generationOptions = context.AnalyzerConfigOptionsProvider .Select(GetGenerationOptions); + // Generate sources that only depend on the options in use + context.RegisterSourceOutput(generationOptions, EmitPreInitializationTypes); + // Get the sequence of all available types that could be generated IncrementalValuesProvider availableTypes = context.CompilationProvider From 1d7b2632c33bfa5fa4cbdfc0d5c568e350f32d62 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 15 Nov 2025 12:51:33 -0800 Subject: [PATCH 10/12] Add PolySharpUseEmbeddedAttributeForGeneratedTypes option Document and expose the new PolySharpUseEmbeddedAttributeForGeneratedTypes property in both READMEs and PolySharp.targets. This option allows generated polyfill types to be marked with the [Embedded] attribute. --- README.md | 1 + src/PolySharp.Package/README.md | 1 + src/PolySharp.SourceGenerators/PolySharp.targets | 1 + 3 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 3e65b86..f0014cd 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ It also includes the following optional runtime-supported polyfills: The following properties are available: - "PolySharpUsePublicAccessibilityForGeneratedTypes": makes all generated types public. +- "PolySharpUseEmbeddedAttributeForGeneratedTypes": adds the `[Embedded]` attributes to generated pofylill types. - "PolySharpIncludeRuntimeSupportedAttributes": enables polyfills for (dummy) runtime-supported attributes too. - "PolySharpUseInteropServices2NamespaceForUnmanagedCallersOnlyAttribute": moves `[UnmanagedCallersOnly]`. - "PolySharpExcludeGeneratedTypes": excludes specific types from generation (';' or ',' separated type names). diff --git a/src/PolySharp.Package/README.md b/src/PolySharp.Package/README.md index 0cacf88..0e55fcf 100644 --- a/src/PolySharp.Package/README.md +++ b/src/PolySharp.Package/README.md @@ -89,6 +89,7 @@ It also includes the following optional runtime-supported polyfills: The following properties are available: - "PolySharpUsePublicAccessibilityForGeneratedTypes": makes all generated types public. +- "PolySharpUseEmbeddedAttributeForGeneratedTypes": adds the `[Embedded]` attributes to generated pofylill types. - "PolySharpIncludeRuntimeSupportedAttributes": enables polyfills for (dummy) runtime-supported attributes too. - "PolySharpUseInteropServices2NamespaceForUnmanagedCallersOnlyAttribute": moves `[UnmanagedCallersOnly]`. - "PolySharpExcludeGeneratedTypes": excludes specific types from generation (';' or ',' separated type names). diff --git a/src/PolySharp.SourceGenerators/PolySharp.targets b/src/PolySharp.SourceGenerators/PolySharp.targets index e9f4075..b8c2496 100644 --- a/src/PolySharp.SourceGenerators/PolySharp.targets +++ b/src/PolySharp.SourceGenerators/PolySharp.targets @@ -109,6 +109,7 @@ + From 1080617a9388db22db281c099a3e2569cdcd1afb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Dec 2025 14:48:03 -0800 Subject: [PATCH 11/12] Refactor syntax fixup handling and GeneratedType model Removed IsPublicAccessibilityRequired from GeneratedType and moved accessibility and embedded attribute handling to SyntaxFixupType flags. Updated PolyfillsGenerator to use new flags for source adjustments, improving flexibility and maintainability of syntax fixup logic. --- .../Models/GeneratedType.cs | 6 +----- .../Models/SyntaxFixupType.cs | 18 +++++++++++++---- .../PolyfillsGenerator.Polyfills.cs | 20 ++++++++++++++----- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/PolySharp.SourceGenerators/Models/GeneratedType.cs b/src/PolySharp.SourceGenerators/Models/GeneratedType.cs index 9fd4111..e0f770a 100644 --- a/src/PolySharp.SourceGenerators/Models/GeneratedType.cs +++ b/src/PolySharp.SourceGenerators/Models/GeneratedType.cs @@ -4,9 +4,5 @@ namespace PolySharp.SourceGenerators.Models; /// A model to hold information on a type to generate. /// /// The fully qualified type name of the type to generate. -/// Whether to use public accessibility for the generated type. /// The types of syntax fixups to apply. -internal sealed record GeneratedType( - string FullyQualifiedMetadataName, - bool IsPublicAccessibilityRequired, - SyntaxFixupType FixupType); +internal sealed record GeneratedType(string FullyQualifiedMetadataName, SyntaxFixupType FixupType); diff --git a/src/PolySharp.SourceGenerators/Models/SyntaxFixupType.cs b/src/PolySharp.SourceGenerators/Models/SyntaxFixupType.cs index bc37406..b0e6490 100644 --- a/src/PolySharp.SourceGenerators/Models/SyntaxFixupType.cs +++ b/src/PolySharp.SourceGenerators/Models/SyntaxFixupType.cs @@ -13,25 +13,35 @@ internal enum SyntaxFixupType /// None = 0, + /// + /// Uses the accessibility modifier (instead of ). + /// + UsePublicAccessibilityModifier = 1 << 0, + + /// + /// Remove all [Embedded] attributes. + /// + RemoveEmbeddedAttributes = 1 << 1, + /// /// Remove all [MethodImpl] attributes. /// - RemoveMethodImplAttributes = 1 << 0, + RemoveMethodImplAttributes = 1 << 2, /// /// Remove all [ExcludeFromCodeCoverage] attributes. /// - RemoveExcludeFromCodeCoverageAttributes = 1 << 1, + RemoveExcludeFromCodeCoverageAttributes = 1 << 3, /// /// Generates the [UnmanagedCallersOnly] type in the InteropServices2 dummy namespace. /// /// This is needed when methods annotated with the attribute have to be assigned to delegates, which Roslyn will otherwise block. - UseInteropServices2ForUnmanagedCallersOnlyAttribute = 1 << 2, + UseInteropServices2ForUnmanagedCallersOnlyAttribute = 1 << 4, /// /// Generates a global using for the [InlineArray] type in the dummy namespace. /// /// This is always needed when the type is used, as the usage is entirely blocked in the normal namespace. - EmitGlobalUsingForInlineArrayAttribute = 1 << 3 + EmitGlobalUsingForInlineArrayAttribute = 1 << 5 } diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index 5ab9b01..be109af 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -247,7 +247,11 @@ static SyntaxFixupType GetSyntaxFixupType(AvailableType availableType, Generatio // Combine the syntax type with any analyzer options SyntaxFixupType fixupType = info.AvailableType.FixupType | GetSyntaxFixupType(info.AvailableType, info.Options); - return new(info.AvailableType.FullyQualifiedMetadataName, info.Options.UsePublicAccessibilityForGeneratedTypes, fixupType); + // Also combine additional flags from project settings + fixupType |= info.Options.UsePublicAccessibilityForGeneratedTypes ? SyntaxFixupType.UsePublicAccessibilityModifier : SyntaxFixupType.None; + fixupType |= !info.Options.UseEmbeddedAttributeForGeneratedTypes ? SyntaxFixupType.RemoveEmbeddedAttributes : SyntaxFixupType.None; + + return new(info.AvailableType.FullyQualifiedMetadataName, fixupType); } /// @@ -285,8 +289,8 @@ private void EmitGeneratedType(SourceProductionContext context, GeneratedType ty using Stream stream = typeof(PolyfillsGenerator).Assembly.GetManifestResourceStream(resourceName); - // If public accessibility has been requested or a syntax fixup is needed, we need to update the loaded source files - if (type is { IsPublicAccessibilityRequired: true } or { FixupType: not SyntaxFixupType.None }) + // If a syntax fixup is needed, we need to update the loaded source files + if (type is { FixupType: not SyntaxFixupType.None }) { string adjustedSource; @@ -295,7 +299,7 @@ private void EmitGeneratedType(SourceProductionContext context, GeneratedType ty adjustedSource = reader.ReadToEnd(); } - if (type.IsPublicAccessibilityRequired) + if ((type.FixupType & SyntaxFixupType.UsePublicAccessibilityModifier) != 0) { // After reading the file, replace all internal keywords with public. Use a space before and after the identifier // to avoid potential false positives. This could also be done by loading the source tree and using a syntax @@ -306,6 +310,12 @@ private void EmitGeneratedType(SourceProductionContext context, GeneratedType ty // If types are public, we also need to strip the '[Embedded]' attributes, as it's not allowed on public types adjustedSource = EmbeddedAttributeRegex.Replace(adjustedSource, ""); } + else if ((type.FixupType & SyntaxFixupType.RemoveEmbeddedAttributes) != 0) + { + // Remove the '[Embedded]' attributes as above, if requested. We only need this check if types + // are not public, or these attributes would've already been stripped by the previous branch. + adjustedSource = EmbeddedAttributeRegex.Replace(adjustedSource, ""); + } if ((type.FixupType & SyntaxFixupType.RemoveMethodImplAttributes) != 0) { @@ -344,7 +354,7 @@ namespace System.Runtime.CompilerServices2 } else { - // If the default accessibility is used, we can load the source directly + // Otherwise if no fixups are needed, we can load the source directly sourceText = SourceText.From(stream, Encoding.UTF8, canBeEmbedded: true); } From 9b8c417a1170e1709373962c4f327ff0476bc921 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Dec 2025 14:58:02 -0800 Subject: [PATCH 12/12] Add overload for GetBoolMSBuildProperty with default value Introduces a new overload of GetBoolMSBuildProperty in AnalyzerConfigOptionsProviderExtensions to allow specifying a default value if the property is missing or empty. Updates PolyfillsGenerator to use this overload for UseEmbeddedAttributeForGeneratedTypes, defaulting to true. --- ...AnalyzerConfigOptionsProviderExtensions.cs | 22 +++++++++++++++++++ .../PolyfillsGenerator.Polyfills.cs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs b/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs index d4521af..92dd486 100644 --- a/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs +++ b/src/PolySharp.SourceGenerators/Extensions/AnalyzerConfigOptionsProviderExtensions.cs @@ -46,6 +46,28 @@ public static bool GetBoolMSBuildProperty(this AnalyzerConfigOptionsProvider opt string.Equals(propertyValue, bool.TrueString, StringComparison.OrdinalIgnoreCase); } + /// + /// Gets the value of a MSBuild property. + /// + /// The input instance. + /// The MSBuild property name. + /// The default value for the property, if missing. + /// The value of the specified MSBuild property, or . + public static bool GetBoolMSBuildProperty(this AnalyzerConfigOptionsProvider options, string propertyName, bool defaultValue = false) + { + if (!options.GlobalOptions.TryGetValue($"build_property.{propertyName}", out string? propertyValue)) + { + return defaultValue; + } + + if (string.IsNullOrEmpty(propertyValue)) + { + return defaultValue; + } + + return string.Equals(propertyValue, bool.TrueString, StringComparison.OrdinalIgnoreCase); + } + /// /// Gets the value of an MSBuild property representing a semicolon-separated list of -s. /// diff --git a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs index be109af..8bfd582 100644 --- a/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs +++ b/src/PolySharp.SourceGenerators/PolyfillsGenerator.Polyfills.cs @@ -86,7 +86,7 @@ private static GenerationOptions GetGenerationOptions(AnalyzerConfigOptionsProvi bool usePublicAccessibilityForGeneratedTypes = options.GetBoolMSBuildProperty(PolySharpMSBuildProperties.UsePublicAccessibilityForGeneratedTypes); // Check whether to emit the '[Embedded]' attribute and apply it to generated types - bool useEmbeddedAttributeForGeneratedTypes = options.GetBoolMSBuildProperty(PolySharpMSBuildProperties.UseEmbeddedAttributeForGeneratedTypes); + bool useEmbeddedAttributeForGeneratedTypes = options.GetBoolMSBuildProperty(PolySharpMSBuildProperties.UseEmbeddedAttributeForGeneratedTypes, defaultValue: true); // Do the same as above for all other available boolean properties bool includeRuntimeSupportedAttributes = options.GetBoolMSBuildProperty(PolySharpMSBuildProperties.IncludeRuntimeSupportedAttributes);