-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[iOS] Fix trimming warnings in HttpClientHandler.AnyMobile #91520
[iOS] Fix trimming warnings in HttpClientHandler.AnyMobile #91520
Conversation
Tagging subscribers to this area: @dotnet/ncl Issue DetailsWhile testing NativeAOT on iOS, I started noticed this warning from ILC:
All the methods which call
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
…ient-handler-anymobile-suppress-ilc-warning
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar Issue DetailsWhile testing NativeAOT on iOS, I started noticed this warning from ILC:
All the methods which call
|
We typically write targeted trimming tests if there is a suppression. Suppressions are not great because someone could add a new callsite and forget to add DynamicDependency (or DynamicDependency the wrong thing). I think this can be rewritten to be correct by construction. All the text strings are there, they're just too far apart for analysis to figure them out. Basically, I'd do this:
|
@MichalStrehovsky thanks for the suggestion! |
src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs
Outdated
Show resolved
Hide resolved
/azp run runtime-ioslike |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! (Reviewing from the trimmability perspective only.)
Cc @AaronRobinsonMSFT - I think this is a nice candidate for #90081. We'll be able to simplify all of this and get rid of the reflection.
/azp run runtime-android |
Azure Pipelines successfully started running 1 pipeline(s). |
/backport to release/8.0-rc1 |
Started backporting to release/8.0-rc1: https://github.com/dotnet/runtime/actions/runs/6130417198 |
Was release/8.0-rc1 correct or should it have been release/8.0 instead? |
@stephentoub you're right, it shouldn't be RC1. I'll open a new backport. |
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6145796878 |
InvokeNativeHandlerMethod(getMethod, parameters: new object?[] { value }, cachingKey!); | ||
} | ||
|
||
private object InvokeNativeHandlerMethod(Func<MethodInfo> getMethod, object?[]? parameters, string cachingKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it not static?
|
||
private object InvokeNativeHandlerGetter(Func<MethodInfo> getMethod, [CallerMemberName] string? cachingKey = null) | ||
{ | ||
return InvokeNativeHandlerMethod(getMethod, parameters: null, cachingKey!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add Debug.Assert instead of only !
[DynamicDependency("set_Credentials", NativeHandlerType, AssemblyName)] | ||
private void SetCredentials(ICredentials? value) => InvokeNativeHandlerMethod("set_Credentials", value); | ||
private void SetCredentials(ICredentials? value) | ||
=> InvokeNativeHandlerSetter(() => Type.GetType(NativeHandlerType)!.GetMethod("set_Credentials")!, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps Type.GetType(NativeHandlerType)
could come as an argument to the lambda and you could cache it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand it, by keeping the GetType and GetMethod calls together with constant arguments will give the trimmer enough information to keep only the methods that are actually used. If we cached the type, I think it wouldn't be trimmable anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. We don't have a way to do this with caching the Type (without suppressing some warnings).
Once we have UnsafeAccessorType
then this can be rewritten to use that and it will not use any reflection and be faster.
[DynamicDependency("set_Credentials", NativeHandlerType, AssemblyName)] | ||
private void SetCredentials(ICredentials? value) => InvokeNativeHandlerMethod("set_Credentials", value); | ||
private void SetCredentials(ICredentials? value) | ||
=> InvokeNativeHandlerSetter(() => Type.GetType(NativeHandlerType)!.GetMethod("set_Credentials")!, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the lambdas should be static (not sure why the analyzer does not complain).
@@ -156,5 +153,36 @@ private static HttpMessageHandler CreateNativeHandler() | |||
|
|||
return (HttpMessageHandler)_nativeHandlerMethod!.Invoke(null, null)!; | |||
} | |||
|
|||
private object InvokeNativeHandlerGetter(Func<MethodInfo> getMethod, [CallerMemberName] string? cachingKey = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could use CallerLineNumberAttribute or some other key which is not a next string in the assembly
While testing NativeAOT on iOS, I started noticed this warning from ILC:
This PR fixes the warning.