-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable trimmer analysis warnings #348
Comments
Here are the current warnings as of 88f0c89:
|
Hmm... with #350 in place, we get rid of that particular commit ac5f898f6d0deb64be91f76eb12bfa032f222478
Author: Per Lundberg <[email protected]>
Date: Thu Oct 20 20:56:30 2022 +0300
(many) Enable trimmer warnings
diff --git Directory.Build.props Directory.Build.props
index 2ecb570..44182a1 100644
--- Directory.Build.props
+++ Directory.Build.props
@@ -3,7 +3,7 @@
<PropertyGroup>
<CodeAnalysisRuleSet>$(SolutionDir)global.ruleset</CodeAnalysisRuleSet>
<TargetFramework>net7.0</TargetFramework>
- <SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
+ <SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
diff --git src/Perlang.Common/ITypeReference.cs src/Perlang.Common/ITypeReference.cs
index 2d9669a..8553eb1 100644
--- src/Perlang.Common/ITypeReference.cs
+++ src/Perlang.Common/ITypeReference.cs
@@ -1,6 +1,7 @@
#nullable enable
using System;
+using System.Diagnostics.CodeAnalysis;
namespace Perlang
{
@@ -9,6 +10,7 @@ namespace Perlang
Token? TypeSpecifier { get; }
// TODO: Remove setter to make this interface and class be fully immutable, for debuggability.
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
Type? ClrType { get; set; }
/// <summary>
diff --git src/Perlang.Common/TypeReference.cs src/Perlang.Common/TypeReference.cs
index 349564d..70d9135 100644
--- src/Perlang.Common/TypeReference.cs
+++ src/Perlang.Common/TypeReference.cs
@@ -1,5 +1,6 @@
#nullable enable
using System;
+using System.Diagnostics.CodeAnalysis;
namespace Perlang
{
@@ -15,6 +16,7 @@ namespace Perlang
public Type? ClrType
{
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
get => clrType;
set
{
diff --git src/Perlang.Interpreter/PerlangInterpreter.cs src/Perlang.Interpreter/PerlangInterpreter.cs
index e087512..8c0a3dc 100644
--- src/Perlang.Interpreter/PerlangInterpreter.cs
+++ src/Perlang.Interpreter/PerlangInterpreter.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Numerics;
@@ -116,6 +117,7 @@ namespace Perlang.Interpreter
/// Registers global classes defined in native .NET code.
/// </summary>
/// <exception cref="PerlangInterpreterException">Multiple classes with the same name was encountered.</exception>
+ [UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
private void RegisterGlobalClasses()
{
var globalClassesQueryable = AppDomain.CurrentDomain.GetAssemblies()
diff --git src/Perlang.Interpreter/Typing/TypeResolver.cs src/Perlang.Interpreter/Typing/TypeResolver.cs
index fccdc6b..104320f 100644
--- src/Perlang.Interpreter/Typing/TypeResolver.cs
+++ src/Perlang.Interpreter/Typing/TypeResolver.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
using Humanizer;
@@ -457,6 +458,7 @@ namespace Perlang.Interpreter.Typing
return VoidObject.Void;
}
+ [UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "Everything referenced in the loaded assembly is manually preserved, so it's safe")]
public override VoidObject VisitGetExpr(Expr.Get expr)
{
base.VisitGetExpr(expr); ...causes the following link-time warnings:
|
Reported the |
I think we're still not ready for this. It seems nontrivial to get this done, especially in that it's hard to annotate property getters only (and not setters). As mentioned in the issue description, I have changed my mind since #223 (comment) but let's postpone it until next year or so. 🙂 |
Moved to GitLab
Please continue to the new version of this issue here: https://gitlab.perlang.org/perlang/perlang/-/issues/348. The GitHub page you are currently reading will not contain the latest information on this issue.
At the moment, we suppress trimmer warnings via
SuppressTrimAnalysisWarnings
set here:perlang/Directory.Build.props
Lines 3 to 7 in 88f0c89
However, suppressing the trimmer warnings is not really the way to go. When we upgraded to .NET 6, we reasoned like this
This hit us when trying to upgrade to .NET 7 (#347 (comment)), since it hid these trimming warnings. This together with the changes in .NET 7 (https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-7/#trimming-and-nativeaot-all-assemblies-trimmed-by-default) turned out to be disastrous.
It was also hard to fully resolve this at the time of the .NET 6 upgrade, because it essentially requires (I think) all dependencies to also properly be trimmer-annotated, and this is not really something fully under our control. This used to be a problem with
System.CommandLine
, but I'm not sure this is the case any more since dotnet/command-line-api#1465 has been resolved.Suggested steps
System.CommandLine
to a more recent version if it might help.The text was updated successfully, but these errors were encountered: