-
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
Implement support for UnsafeAccessor
in the trimmer
#88268
Conversation
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsThe core of the change is that Implementation choices:
The guiding reason to keep the implementation simple is that we don't expect the unsafe accessor to be used by developers directly, instead we assume that vast majority of its usages will be from source generators. So, developer UX is not as important. Test changes:
Fixes in CoreCLR/NativeAOT: Part of #86161.
|
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.
NativeAOT/VM changes and new runtime tests LGTM.
Thank you!
Parameter overload resolution is very problematic in Cecil - would have to reimplement it effectively.
Fixes a bug in CoreCLR and NativeAOT which would allow non-ref this for value instance method accessors. This leads to asserts from JIT.
Parameter overload resolution is very problematic in Cecil - would have to reimplement it effectively.
Fixes a bug in CoreCLR and NativeAOT which would allow non-ref this for value instance method accessors. This leads to asserts from JIT.
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@vitek-karas I resolved the merge conflict |
…s/runtime into TrimmerUnsafeAccessor
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.
ILLink changes LGTM!
src/tools/illink/src/linker/Linker.Steps/UnsafeAccessorMarker.cs
Outdated
Show resolved
Hide resolved
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
// Copy of the enum from CoreLib - once that is merged this should be deleted. |
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.
Based on the build failures I think this can be removed now
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.
Yes - I'm testing this locally - there are also some merge conflicts in the runtime test. I need to test it on all 3 runtimes now :-)
Co-authored-by: Sven Boemer <sbomer@gmail.com>
Test failures are unrelated. |
The core of the change is that
UnsafeAccessor
creates a code dependency from the accessor method to the target specified by the attribute. The trimmer needs to follow this dependency and preserve the target. Additionally, because the trimmer operates at the IL level, it needs to make sure that the target will keep its name and some other properties intact (so that the runtime implementation of theUnsafeAccessor
can still work).Implementation choices:
The guiding reason to keep the implementation simple is that we don't expect the unsafe accessor to be used by developers directly, instead we assume that vast majority of its usages will be from source generators. So, developer UX is not as important.
Test changes:
Requires*
attributes behave correctlyFixes in CoreCLR/NativeAOT:
This change fixes one bug in the CoreCLR/NativeAOT implementation, unsafe accessor on a instance method of a value type must use "by-ref" parameter for the
this
parameter. Without the "by-ref" the accessor is considered invalid and will throw.This change also adds some tests to the CoreCLR/NativeAOT test suite.
Part of #86161.
Related to #86438.
Feature design in #81741.