Annotate MS.CA and MS.CA.C# for trimming#66519
Conversation
96947e8 to
d10d229
Compare
73a219e to
c78e67c
Compare
|
@dotnet/roslyn-compiler for review |
src/Compilers/CSharp/Portable/Microsoft.CodeAnalysis.CSharp.csproj
Outdated
Show resolved
Hide resolved
| static LocalizableResourceString() | ||
| { | ||
| ObjectBinder.RegisterTypeReader(typeof(LocalizableResourceString), reader => new LocalizableResourceString(reader)); | ||
| } |
There was a problem hiding this comment.
Need an explanation on why this was removed.
There was a problem hiding this comment.
This is fundamentally untrimmable, but the only usage I found was in tests.
There was a problem hiding this comment.
Are we sure this isn't used for diagnostics being serialized across processes?
There was a problem hiding this comment.
I tried and couldn't find a place where it was used. The integration tests are also passing. I'm not sure how else to verify this.
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerAssemblyLoader.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/InternalUtilities/ReflectionUtilities.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerAssemblyLoader.cs
Show resolved
Hide resolved
|
Not sure what's up with roslyn-ci here. |
|
Looks like the integration-corehost tests are a bit of a disaster. I'm going to ignore them unless someone has specific suggestions. |
|
FYI we're bringing the first version of the COMWrapper source generator online, which will fix the trim issues in Emit, but I'm not going to include that work in this PR. |
| </PropertyGroup> | ||
|
|
||
| <!-- Enable trimming/AOT compat --> | ||
| <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' >= '6.0'"> |
There was a problem hiding this comment.
$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0')) ?
|
@agocke What's the next step for this PR? We can mark it as draft if it still needs some work to figure out (not quite ready for another look yet), to make room in our review queue. |
|
Jared's review is stale. This is ready. Next steps are on your side. |
| AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Method | | ||
| AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct, | ||
| Inherited = false)] | ||
| internal sealed class DynamicallyAccessedMembersAttribute : Attribute |
There was a problem hiding this comment.
Not sure whether Roslyn has special rules/policies for NuGet dependencies, but would it make sense to leverage PolySharp here rather than manually adding polyfills with ifdefs on new targets? PolySharp handles that automatically, and if size is a concern you can also configure it to only ever polyfill the exact types you need, rather than all available ones. It would also make it simpler to extend this in the future when/if more polyfills were needed.
For instance, for the changes in this PR you'd just need:
<ItemGroup>
<PackageReference Include="PolySharp" Version="1.13.1" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
<PolySharpIncludeGeneratedTypes>
System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute;
System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes;
System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute;
System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute;
</PolySharpIncludeGeneratedTypes>
</PropertyGroup>| internal static class TrimWarningMessages | ||
| { | ||
| internal const string AnalyzerReflectionLoadMessage = "Loading analyzers via reflection is not supported when trimming."; | ||
| internal const string NativePdbsNotSupported = "Native PDBs use built-in COM, which is not supported when trimming."; |
There was a problem hiding this comment.
Fixed link: dotnet/symreader#340
Should we file a roslyn issue to revisit the annotations once that PR is merged?
| /// <see cref="ConditionalAttribute"/>. So it is always preserved in the compiled assembly. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)] | ||
| internal sealed class UnconditionalSuppressMessageAttribute : Attribute |
There was a problem hiding this comment.
Should use TypeForwardedTo on NET like so: https://github.com/dotnet/roslyn/blob/main/src/Dependencies/Contracts/IsExternalInit.cs
There was a problem hiding this comment.
I don't think it's necessary here. IsExternalInit needs type forwarding to maintain binary compatibility because it gets used in modreqs, while tooling matches this attribute by name (99% sure).
There was a problem hiding this comment.
But as seen in https://patch-diff.githubusercontent.com/raw/dotnet/roslyn/pull/66519.diff, this file is unused, so maybe we can just delete it.
There was a problem hiding this comment.
Even if it's not necessary here I prefer we follow a single pattern.
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Diagnostics.CodeAnalysis; |
| TestRoundTripType(typeof(int)); | ||
| TestRoundTripType(typeof(string)); | ||
| TestRoundTripType(typeof(ObjectSerializationTests)); | ||
| } |
There was a problem hiding this comment.
@agocke General question: could you share a bit about the overall flow/story? In particular, when/where do the messages in the annotations surface to users?
Also, what is the approach you use to find all the methods that need to be instrumented? (how do we know the annotations are complete?)
|
@agocke Marked as draft since looks stale. Please un-draft and ping when ready for another look. Thanks |
|
Just for context we hit this in CsWinRT 3.0 as well, as we are shipping a new build tool as a Native AOT binary, which uses the Roslyn APIs to compile Windows Runtime projections from sources at publish time. For now we've had to just suppress all trimming warnings (see here), which seems to still work, but isn't ideal. We'd love to see this merged 🙂 |
Brief description of trimming analysis: when trimming an application, the libraries should be annotated to be trim-compatible or, if that's not possible, to alert the user which APIs will not be compatible with trimming.
Almost all of MS.CA and MS.CA.CSharp are already trimming compatible, it is only native PDB writing which has problems (because it uses built-in COM support, which is basically reflection). The native PDB writing could eventually be moved to use COM wrappers and be made trim-compatible, but right now I've simply marked the APIs incompatible. There are still plenty of useful APIs for consumers, including all the syntax and binding APIs, that don't use PDB emit.