-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add design usage notes to TypeMapAttribute and TypeMapAssociationAttribute documentation #12107
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
base: main
Are you sure you want to change the base?
Conversation
…ute documentation Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
| Types used in a managed-to-unmanaged interop operation can use `TypeMapAssociationAttribute` to define a conditional link between the source and proxy type. If the source is kept, so is the proxy type. If trimming observes an explicit allocation of the source type, the entry is inserted into the map. | ||
| When an application is trimmed, an entry in the Proxy Type Map is included when the "source type" is referenced in one of the following ways in reachable code: |
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 of this below is incorrect, it only applies to the type map, not the proxy map.
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.
@Sergio0694 This is directly from the design document. What is incorrect about it?
See https://github.com/dotnet/runtime/blob/main/docs/design/features/typemap.md#proxy-type-map
| - The argument to the `mkrefany` instruction. | ||
| - The argument to the `refanyval` instruction. | ||
| If the type is an interface type and the user could possibly see a `RuntimeTypeHandle` for the type as part of a casting or virtual method resolution operation (such as with <xref:System.Runtime.InteropServices.IDynamicInterfaceCastable>), then the following cases also apply: |
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.
| If the type is an interface type and the user could possibly see a `RuntimeTypeHandle` for the type as part of a casting or virtual method resolution operation (such as with <xref:System.Runtime.InteropServices.IDynamicInterfaceCastable>), then the following cases also apply: | |
| If the type is an interface type and the user could possibly see a <xref:System.RuntimeTypeHandle> for the type as part of a casting or virtual method resolution operation (such as with <xref:System.Runtime.InteropServices.IDynamicInterfaceCastable>), then the following cases also apply: |
| > Conflicting key/value mappings are not allowed. | ||
| > [!NOTE] | ||
| > The underlying format of the produced maps is implementation-defined. Different .NET form factors might use different formats. Additionally, it's not guaranteed that the `TypeMapAttribute`, `TypeMapAssociationAttribute`, and `TypeMapAssemblyTargetAttribute` attributes are present in the final image after a trimming tool has been run. |
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.
| > The underlying format of the produced maps is implementation-defined. Different .NET form factors might use different formats. Additionally, it's not guaranteed that the `TypeMapAttribute`, `TypeMapAssociationAttribute`, and `TypeMapAssemblyTargetAttribute` attributes are present in the final image after a trimming tool has been run. | |
| > The underlying format of the produced maps is implementation-defined. Different .NET form factors might use different formats. Additionally, it's not guaranteed that the <xref:System.Runtime.InteropServices.TypeMapAttribute%60%601>, <xref:System.Runtime.InteropServices.TypeMapAssociationAttribute%60%601>, and <xref:System.Runtime.InteropServices.TypeMapAssemblyTarget%60%601> attributes are present in the final image after a trimming tool has been run. |
| > Conflicting key/value mappings are not allowed. | ||
| > [!NOTE] | ||
| > The underlying format of the produced maps is implementation-defined. Different .NET form factors might use different formats. Additionally, it's not guaranteed that the `TypeMapAttribute`, `TypeMapAssociationAttribute`, and `TypeMapAssemblyTargetAttribute` attributes are present in the final image after a trimming tool has been run. |
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.
| > The underlying format of the produced maps is implementation-defined. Different .NET form factors might use different formats. Additionally, it's not guaranteed that the `TypeMapAttribute`, `TypeMapAssociationAttribute`, and `TypeMapAssemblyTargetAttribute` attributes are present in the final image after a trimming tool has been run. | |
| > The underlying format of the produced maps is implementation-defined. Different .NET form factors might use different formats. Additionally, it's not guaranteed that the <xref:System.Runtime.InteropServices.TypeMapAttribute%60%601>, <xref:System.Runtime.InteropServices.TypeMapAssociationAttribute%60%601>, and <xref:System.Runtime.InteropServices.TypeMapAssemblyTarget%60%601> attributes are present in the final image after a trimming tool has been run. |
| ## Remarks | ||
| Types used in a managed-to-unmanaged interop operation can use `TypeMapAssociationAttribute` to define a conditional link between the source and proxy type. If the source is kept, so is the proxy type. If trimming observes an explicit allocation of the source type, the entry is inserted into the map. |
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.
| Types used in a managed-to-unmanaged interop operation can use `TypeMapAssociationAttribute` to define a conditional link between the source and proxy type. If the source is kept, so is the proxy type. If trimming observes an explicit allocation of the source type, the entry is inserted into the map. | |
| Types used in a managed-to-unmanaged interop operation can use <xref:System.Runtime.InteropServices.TypeMapAssociationAttribute%60%601> to define a conditional link between the source and proxy type. If the source is kept, so is the proxy type. If trimming observes an explicit allocation of the source type, the entry is inserted into the map. |
| ## Remarks | ||
| Types involved in unmanaged-to-managed interop operations can be referenced in a `TypeMapAttribute` assembly attribute that declares the external type system name, a target type, and optionally a "trim target" to determine if the target type should be included in the map. If the constructor that doesn't take a trim target is used, the entry is always emitted into the type map. |
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.
| Types involved in unmanaged-to-managed interop operations can be referenced in a `TypeMapAttribute` assembly attribute that declares the external type system name, a target type, and optionally a "trim target" to determine if the target type should be included in the map. If the constructor that doesn't take a trim target is used, the entry is always emitted into the type map. | |
| Types involved in unmanaged-to-managed interop operations can be referenced in a <xref:System.Runtime.InteropServices.TypeMapAttribute%60%601> assembly attribute that declares the external type system name, a target type, and optionally a "trim target" to determine if the target type should be included in the map. If the constructor that doesn't take a trim target is used, the entry is always emitted into the type map. |
Summary
Adds detailed Remarks sections to
TypeMapAttribute<TTypeMapGroup>andTypeMapAssociationAttribute<TTypeMapGroup>documenting the trimming behavior from the runtime design doc.TypeMapAttribute
ldtoken,unbox,isinst,castclass,box,newarr,newobj, etc.)TypeMapAssociationAttribute
IDynamicInterfaceCastableAlso fixes pre-existing typo ("kthe" → "the") in TypeMapAttribute constructor parameter description.
Original prompt
TypeMapAttribute/TypeMapAssociationAttributeAdd design usage notes to documentation #12102✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.