Skip to content
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

Warn on message formatting failure instead of crash, and fix Native AOT MakeGenericType failure #110330

Merged
merged 9 commits into from
Jan 2, 2025

Conversation

jtschuster
Copy link
Member

@jtschuster jtschuster commented Dec 2, 2024

The tests in #110229 exposed an issue in NativeAOT around MakeGenericType/Method. ILC doesn't make sure that an instantiation from MakeGenericType/Method fulfills the constraints of the generic type/method, which can create to nonsense types that fail asserts in other places. The fix is to ensure that the constraints are valid before determining the dependencies of the instantiated generic.

This PR also includes the formatting try/catch in #110229 so that the tests that expose the issue can run without crashing the trimmer.

Fixes #109536

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Dec 2, 2024
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Dec 2, 2024
@jtschuster jtschuster added NO-REVIEW Experimental/testing PR, do NOT review it and removed linkable-framework Issues associated with delivering a linker friendly framework area-Tools-ILLink .NET linker development as well as trimming analyzers labels Dec 2, 2024
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Dec 2, 2024
- Wrap message formatting in try/catch and give warning if format fails
- Guard MakeGenericMethodSite dependency creation with call to
  CheckConstraints
@jtschuster jtschuster changed the title Update tests to see if NativeAOT failure is related to other PR Warn on message formatting failure instead of crash, and fix Native AOT MakeGenericType failure Dec 3, 2024
Comment on lines 43 to 55
string formattedString;
try
{
formattedString = string.Format(format, args);
}
catch (FormatException)
{
#pragma warning disable RS1035 // Do not use APIs banned for analyzers - We just need a newline
formattedString = "Internal error formatting diagnostic. Please report the issue at https://aka.ms/report-illink" + Environment.NewLine
+ $"'{format}', " + $"[{string.Join(", ", args)}]";
#pragma warning restore RS1035 // Do not use APIs banned for analyzers
}
return formattedString;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do resource string formatting all over the product but I haven't seen a place that would have a try/catch to transform internal errors to different internal errors. Is there more context on this?

Unhandled exceptions are often logged in various crash telemetries (not that I know of anyone actually looking at it in the past years, but in principle). This will swallow the possible telemetry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string formatting caused errors since the number of arguments expected and provided don't always match for DAM warnings when Nullable is the source of the value. The proper fix to avoid the exception is in #110229, after which we could remove this try/catch. It still hits this exception in this PR because I wanted to separate the NativeAOT fix MakeGenericType fix and the DAM warning/arguments mismatch fix.

We could remove the tests and the try/catch from #110229 before merging this PR if you'd rather avoid merging the try/catch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this PR can just be about the HandleCallAction, it's fine without test since we'll get the test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the test and formatting changes.

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jtschuster jtschuster merged commit d75c745 into dotnet:main Jan 2, 2025
85 of 88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[area-Tools-ILLink]: dotnet publish crashing when using PublishTrimmed option
2 participants