Skip to content

NativeAOT: Consider enabling trim/AOT/single-file warnings by default #18571

Closed

Description

@ivanpovazan

Since NativeAOT is much more restrictive in terms of trimming and AOT compatibility of compiled applications (and used frameworks) compared to Mono, we should enable trimming, AOT and single-file warnings by default. Especially for the fact that NativeAOT does not have a safety - fallback mechanism like Mono's interpreter.

Additionally, since we will release NativeAOT on iOS as an experimental feature, enabling these warnings (and treating them as errors) would let us detect issues with our frameworks and compiled applications, which will enable us to address them early and improve the AOT experience for our customers.

Activity

  1. changed the title [-]Enable trim/aot warnings by default[/-] [+]NativeAOT: Consider enabling trim and aot warnings by default[/+] on Jul 21, 2023
  2. changed the title [-]NativeAOT: Consider enabling trim and aot warnings by default[/-] [+]NativeAOT: Consider enabling trim and AOT warnings by default[/+] on Jul 21, 2023
  3. added this to the .NET 8 milestone on Jul 21, 2023
  4. changed the title [-]NativeAOT: Consider enabling trim and AOT warnings by default[/-] [+]NativeAOT: Consider enabling trim/AOT/single file warnings by default[/+] on Jul 21, 2023
  5. changed the title [-]NativeAOT: Consider enabling trim/AOT/single file warnings by default[/-] [+]NativeAOT: Consider enabling trim/AOT/single-file warnings by default[/+] on Jul 21, 2023
  6. MichalStrehovsky commented on Jul 25, 2023

    @MichalStrehovsky
    Member

    If we don't do anything to break this, adding <PublishAot>true</PublishAot> to the project should already enable these analyzers (we should validate).

    To validate, one should be able to create a new MAUI project in VS and add:

    public class Class1
    {
        static Type t;
    
        static void Frob()
            => t.MakeGenericType(Array.Empty<Type>());
    }

    To the .cs somewhere. You should see IL3050 and IL2055 warnings when you build (and green squiggles in VS).

  7. ivanpovazan commented on Jul 25, 2023

    @ivanpovazan
    MemberAuthor

    If we don't do anything to break this, adding true to the project should already enable these analyzers (we should validate).

    If I did not miss anything, there are two places/properties which affect what can be currently seen in the build output:

    Building a MAUI template application with how the analysers are currently configured (from above) the build log does not include precise information:

    /Users/ivan/repos/xamarin/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.7.23360.1/MauiTest/obj/Release/net8.0-ios/ios-arm64/linked/Microsoft.iOS.dll : warning IL3053: Assembly 'Microsoft.iOS' produced AOT analysis warnings. [/Users/ivan/repos/xamarin/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.7.23360.1/MauiTest/MauiTest.csproj]
    /Users/ivan/repos/xamarin/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.7.23360.1/MauiTest/obj/Release/net8.0-ios/ios-arm64/linked/Microsoft.Maui.Controls.Xaml.dll : warning IL3053: Assembly 'Microsoft.Maui.Controls.Xaml' produced AOT analysis warnings. [/Users/ivan/repos/xamarin/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.7.23360.1/MauiTest/MauiTest.csproj]
    /Users/ivan/repos/xamarin/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.7.23360.1/MauiTest/obj/Release/net8.0-ios/ios-arm64/linked/Microsoft.Maui.dll : warning IL3053: Assembly 'Microsoft.Maui' produced AOT analysis warnings. [/Users/ivan/repos/xamarin/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.7.23360.1/MauiTest/MauiTest.csproj]
    /Users/ivan/repos/xamarin/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.7.23360.1/MauiTest/obj/Release/net8.0-ios/ios-arm64/linked/System.Linq.Expressions.dll : warning IL3053: Assembly 'System.Linq.Expressions' produced AOT analysis warnings. [/Users/ivan/repos/xamarin/xamarin-macios/builds/downloads/dotnet-sdk-8.0.100-preview.7.23360.1/MauiTest/MauiTest.csproj]
    

    To get the full analysis log, we would have to pass -p:SuppressTrimAnalysisWarnings=false -p:TrimmerSingleWarn=false

    Another thing worth considering is enabling these properties only for the ILC pass, and not for ILLink, to avoid getting duplicate warnings from the two trimming tools, or even incorrect warnings due to ILLink-ILC compatibility and difference in trimming capabilities.

    /cc: @vitek-karas

  8. MichalStrehovsky commented on Jul 25, 2023

    @MichalStrehovsky
    Member

    Would it be possible to at least address the ones in new ios?

    MAUI is probably a lost cause for .NET 8 and there will be warnings to tell people they're not getting a great experience. It would be nice if we could address at least those that are in an empty app but I don't know if it's possible.

    To get the full analysis log, we would have to pass -p:SuppressTrimAnalysisWarnings=false -p:TrimmerSingleWarn=false

    We should disable warning suppression in the SDK. TrimmerSingleWarn is useful to turn off for us, but brings no value to customers (customer knowing a MAUI assembly is not trim safe is better than spamming them with a dozen warnings they can do nothing about because they don't have MAUI source code they can edit).

  9. vitek-karas commented on Jul 25, 2023

    @vitek-karas
    Member

    +1 on leaving TrimmerSingleWarn=true, it's a much better experience.
    +10 for trying to make the default template for ios warning free, but it might be too difficult

    In general I think it would make sense to suppress all trim analysis warnings from the linker, not only due to duplicates but also due to possible differences (the tools will run with different input and settings). For correctness those from the NativeAOT should be sufficient (and more precise).

  10. added
    dotnet
    on Jul 30, 2023
  11. rolfbjarne commented on Aug 3, 2023

    @rolfbjarne
    Member
  12. rolfbjarne commented on Aug 3, 2023

    @rolfbjarne
    Member

    I've added an issue to fix the warnings, with a list of all the warnings: #18629

    Once they're fixed, and the warnings enabled by default, we should also add tests to ensure we don't regress.

  13. ivanpovazan commented on Aug 18, 2023

    @ivanpovazan
    MemberAuthor

    Fixed with 90cc165

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnet

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions