Skip to content
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

Strip the ILLinkTrim.xml file from the System.ComponentModel.TypeConverter assembly #37402

Merged
merged 5 commits into from
Jun 5, 2020

Conversation

layomia
Copy link
Contributor

@layomia layomia commented Jun 4, 2020

Contributes to #35199.

@layomia layomia added this to the 5.0 milestone Jun 4, 2020
@ghost
Copy link

ghost commented Jun 4, 2020

Tagging subscribers to this area: @safern
Notify danmosemsft if you want to be subscribed.

@safern
Copy link
Member

safern commented Jun 4, 2020

@layomia could you point me to the docs for the attributes?

@layomia layomia marked this pull request as ready for review June 4, 2020 17:59
@layomia layomia requested a review from eerhardt June 4, 2020 18:09
@eerhardt
Copy link
Member

eerhardt commented Jun 4, 2020

@layomia could you point me to the docs for the attributes?

There are docs in the class XML:

/// Indicates that certain members on a specified <see cref="Type"/> are accessed dynamically,
/// for example through <see cref="System.Reflection"/>.
/// </summary>
/// <remarks>
/// This allows tools to understand which members are being accessed during the execution
/// of a program.
///
/// This attribute is valid on members whose type is <see cref="Type"/> or <see cref="string"/>.
///
/// When this attribute is applied to a location of type <see cref="string"/>, the assumption is
/// that the string represents a fully qualified type name.
/// </remarks>

and also these docs:

@eerhardt
Copy link
Member

eerhardt commented Jun 4, 2020

Looks like you need to update to @MichalStrehovsky's latest change #37297

System/ComponentModel/TypeDescriptor.cs(2322,81): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'DynamicallyAccessedMemberTypes' does not contain a definition for 'DefaultConstructor'

@layomia
Copy link
Contributor Author

layomia commented Jun 4, 2020

Looks like you need to update to @MichalStrehovsky's latest change #37297

System/ComponentModel/TypeDescriptor.cs(2322,81): error CS0117: (NETCORE_ENGINEERING_TELEMETRY=Build) 'DynamicallyAccessedMemberTypes' does not contain a definition for 'DefaultConstructor'

Done

eerhardt
eerhardt previously approved these changes Jun 4, 2020
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have one question on the placement of the DynamicallyAccessedMembersAttribute on ComObjectType for @MichalStrehovsky (or @vitek-karas). Pending the answer of that question, this looks good to me.

@eerhardt eerhardt dismissed their stale review June 5, 2020 13:00

The ComObjectType property annotation needs to be fixed

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @layomia.

@@ -2319,7 +2319,7 @@ public static void Refresh(Assembly assembly)
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static Type ComObjectType
{
[DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) - this may be a preference thing, but IMO it feels more natural for this attribute to be applied to the property:

[EditorBrowsable(EditorBrowsableState.Advanced)]
[DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
public static Type ComObjectType
{
    get => typeof(TypeDescriptorComObject);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure linker will be able to handle this - the attribute on a property works for implicit getters/setters, but for those with explicit bodies it might not be reliable (since we need to detect the backing field if there's one to annotate it as well, and that detection is tricky/impossible for random properties).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if it doesn't work linker will not warn - TODO - I created dotnet/linker#1248 to get that fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure linker will be able to handle this - the attribute on a property works for implicit getters/setters, but for those with explicit bodies it might not be reliable (since we need to detect the backing field if there's one to annotate it as well, and that detection is tricky/impossible for random properties).

The behavior is that if the annotation is placed on the property, the annotation is propagated to the return value of the getter and the parameter of the setter. If this is an auto property, the annotation is also propagated to the backing field. Otherwise, this won't propagate to the backing field, even if it looks "obvious". One will get a warning and needs to annotate the backing field manually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this case where there is no backing field? Does the TypeDescriptorComObject type get annotated with [DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] if the attribute is applied to the property?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this case where there is no backing field?

This part applies always: "The behavior is that if the annotation is placed on the property, the annotation is propagated to the return value of the getter and the parameter of the setter"

Does the TypeDescriptorComObject type get annotated with

Yes, because it's a value that was returned from a method that has the return parameter annotated (because the annotation was propagated from the property).

@layomia layomia self-assigned this Jun 5, 2020
@layomia layomia merged commit e8264ca into dotnet:master Jun 5, 2020
@layomia layomia deleted the trim_xml_typeconverter branch June 5, 2020 19:11
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants