-
Notifications
You must be signed in to change notification settings - Fork 5k
AssemblyBuilder.Save add custom attributes handling. #84580
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
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsThis PR include following updates:
|
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/FieldBuilderImpl.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/CustomAttributeWrapper.cs
Outdated
Show resolved
Hide resolved
281549c
to
79dad59
Compare
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/FieldBuilderImpl.cs
Outdated
Show resolved
Hide resolved
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/MethodBuilderImpl.cs
Outdated
Show resolved
Hide resolved
5d2ca10
to
3385596
Compare
Co-authored-by: Aaron Robinson <[email protected]>
|
||
m_con = con; | ||
m_binaryAttribute = binaryAttribute; | ||
m_binaryAttribute = binaryAttribute.ToArray(); |
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.
This is introducing an extra array copy. Do you remember whether this regression was considered during the API review discussion that proposed changing the argument type to ReadOnlySpan?
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.
Do you remember whether this regression was considered during the API review discussion that proposed changing the argument type to ReadOnlySpan?
No, I don't think so, there were not much discussion about this change, quickly agreed for this update. Would you suggest to keep the SetCustomAttributeCore(ConstructorInfo con, byte[] binaryAttribute)
for 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.
I think that the extra copy is fine, it is just something that I have noticed and that I did not expect. I do not have a strong opinion about it. What do you think?
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.
I think this path would be used rarely (attributes for generic type parameter) so probably fine, but for the new assembly builder implementation we are creating this copy for each attribute:
runtime/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/CustomAttributeWrapper.cs
Line 16 in 02536ba
_binaryAttribute = binaryAttribute.ToArray(); |
I think I can workaround that to keep the
BlobHandle
of the ReadOnlySpan<byte>
instead of byte[]
in CustomAttributeWrapper
. But that needs #81059 merged and a public API for ReadOnlySpan<byte>
overload is added
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.
Added TODO for using BlobHandle
instead of byte[]
.
There is similar allocation added in mono:
runtime/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs
Line 85 in a7ed5ce
data = binaryAttribute.ToArray(); |
SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
overload used directly as previously it was also cloning the byte array runtime/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs
Line 86 in 2087ceb
data = (byte[])binaryAttribute.Clone(); |
SetCustomAttribute(CustomAttributeBuilder customBuilder)
overload is used it will call SetCustomAttributeCore(customBuilder.Ctor, customBuilder.Data)
and going to create another copy ...
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/CustomAttributeWrapper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/CustomAttributeWrapper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/CustomAttributeWrapper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/CustomAttributeWrapper.cs
Outdated
Show resolved
Hide resolved
…s for some values
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/FieldBuilderImpl.cs
Outdated
Show resolved
Hide resolved
.../System.Reflection.Emit/tests/PersistableAssemblyBuilder/AssemblySaveCustomAttributeTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/CustomAttributeWrapper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/CustomAttributeWrapper.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/CustomAttributeWrapper.cs
Show resolved
Hide resolved
0ea2bb4
to
0d56695
Compare
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.
Thanks
Thank you for review! Failures unrelated and |
Contributes to #62956
This PR include following updates:
ConstructorInfo Ctor
,byte[] Data
properties fromCustomAttributeBuilder
and use them forSetCustomAttribute(CustomAttributeBuilder customBuilder)
in shared*Builder
types. (initially was planning to make the fields internal, but Mono using properties).protected override void SetCustomAttributeCore(CustomAttributeBuilder customBuilder)
implementations and convertbyte[] binaryAttribute
parameter ofSetCustomAttributeCore(ConstructorInfo con, byte[] binaryAttribute)
intoReadOnlySpan<byte> binaryAttribute
for all runtime*Builder
types