-
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
Suppress linker warnings properly #84272
Conversation
Tagging subscribers to this area: @dotnet/area-system-reflection-emit Issue DetailsThe Linker warnings were incorrectly suppressed in #83554 and causing a build failure in dotnet/sdk#31571 (comment) The method will be referenced for loading all .NET primitive types from user provided In order to unblock build failure caused by this raising this PR with the quick fix. Will reiterate the handling of other primitive types separately
|
What is the build configuration where this is causing a build failure? I would expect that the new Reflection.Emit implementation is always going to be trimmed for now, and thus it should not produce any warnings. The warning can be a symptom of some more fundamental problem. |
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/MethodBuilderImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/TypeBuilderImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Show resolved
Hide resolved
|
||
default: throw new NotSupportedException(SR.Format(SR.NotSupported_Signature, type.FullName)); | ||
// We need to translate from Reflection.Type to SignatureTypeEncoder. | ||
if (id > -1) |
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 the extra if?
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.
module.GetTypeIdFromCoreTypes(type)
returns -1 in case it is not core type or the type not found
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.
Right but why do you optimizing for exception code path?
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.
For now we only support core types, eventually that path will be updated to support other types
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.
Yep but even in that case they would better be handled via default:
than this if
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.
Not sure how, seems there is no default
signature option in SignatureTypeEncoder
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/Encoding/BlobEncoders.cs#L888-L1145
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.
What would a default
signature option do?
The existing PrimitiveTypeCode
defined by System.Reflection.Metadata looks very similar for the CoreTypeId. Maybe we should just use PrimitiveTypeCode
.
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.
we should just use PrimitiveTypeCode.
Thoughts about this one?
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.
Thoughts about this one?
Tried, PrimitiveTypeCode
uses SignatureTypeCode values that are not matching by the index, specifically the value of IntPtr is 24, UIntPtr is 25, Object value is 28, leaving a gap in the array indexes
Line 11 in bc887b3
Boolean = SignatureTypeCode.Boolean, |
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Show resolved
Hide resolved
I checked why the warnings were not caught by the runtime build originally. In this case, the offending code is not connected to any public API (yet I assume), so in the "library" mode it gets trimmed away. But SDK will still see it. @sbomer for ideas - the SDK is effectively testing "more" than runtime. I create #84297 to track the "infra" issue. |
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Outdated
Show resolved
Hide resolved
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.
Hope the suggested edits make sense
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs
Show resolved
Hide resolved
Yes, it makes sense, thank you! |
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs
Outdated
Show resolved
Hide resolved
…t/SignatureHelper.cs
The failure unrelated and known, merging |
The Linker warnings were incorrectly suppressed in #83554 and causing a build failure in dotnet/sdk#31571 (comment)
The method will be referenced for loading all .NET primitive types from user provided
Core
assembly. I assumed core primitive types are trimmer safe, but it seems unreferenced primitive type could be trimmed, therefore propagating the linker warning for the method. And suppressing the warning for the usages as I think it is safe to suppress these warnings forSystem.Object
andSystem.Void
types.In order to unblock build failure caused by this raising this PR with the quick fix. Will reiterate the handling of other primitive types separately