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

Change XmlFlowAnnotationSource implementation to expose CustomAttributes #1216

Merged
merged 6 commits into from
Jun 2, 2020

Conversation

tlakollo
Copy link
Contributor

  • Change XmlFlowAnnotationSource to expose CustomAttributes
  • Use ICustomAttributeProvider to simplify when asking for information
    about annotations
  • Use of assembly in the attribute is now mandatory
  • Assembly name now could be * either in the assembly element or in the
    assembly property inside the attribute element, leaving no assembly name is not
    supported
  • Added new error codes, swaped non used codes for new error codes
  • Changed documentation to reflect the way of use

@tlakollo tlakollo requested a review from vitek-karas May 27, 2020 06:09
@tlakollo tlakollo requested a review from marek-safar as a code owner May 27, 2020 06:09
@tlakollo tlakollo self-assigned this May 27, 2020
@tlakollo tlakollo force-pushed the XmlWithCustomAttributes branch 2 times, most recently from 87b8b53 to 0a7632d Compare May 28, 2020 00:09
Copy link
Contributor

@marek-safar marek-safar left a comment

Choose a reason for hiding this comment

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

Did first quick pass

_context.LogMessage (MessageContainer.CreateWarningMessage ($"DynamicallyAccessedMembers attribute was specified but no argument was proportioned", 2020));
} else if (attribute.ConstructorArguments.Count == 1) {
var arguments = attribute.ConstructorArguments.ToArray ();
return (DynamicallyAccessedMemberTypes) arguments[0].Value;
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot cast external value to local type

Copy link
Member

Choose a reason for hiding this comment

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

Same comment as in the previous PR - this is an enum type, this is basically the only case where it's "safe" since it's almost like a primitive type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's the case. If someone declares it's own type (we matching on names) then you cannot cast the enum type to "runtime" version of the type as they have different assembly identity.

Copy link
Member

Choose a reason for hiding this comment

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

You're right - we have to go through integer:

return (DynamicallyAccessedMemberTypes)(int)arguments[0].Value;

Then it should be correct - as we will simply map the number to the linker understanding of the flags.

Tlakollo and others added 5 commits June 2, 2020 04:24
- Use ICustomAttributeProvider to simplify when asking for information
about annotations
- Use of assembly in the attribute is now mandatory
- Assembly name now could be * either in the assembly element or in the
assembly property inside the attribute element, leaving no assembly name is not
supported
- Added new error codes, swaped non used codes for new error codes
- Changed documentation to reflect the way of use
- Fix review comments
@vitek-karas vitek-karas force-pushed the XmlWithCustomAttributes branch from 0629231 to e8e6f54 Compare June 2, 2020 12:09
@vitek-karas
Copy link
Member

I rebased to master and fixed any issues after that (mostly warning creation requiring context and location).
I moved the custom attribute source files to main linker namespace as they don't really belong to DataFlow anymore.
Small formatting fixes.

foreach (ParameterDefinition parameter in method.Parameters) {
if (paramName == parameter.Name) {
if (_attributes.ContainsKey (parameter))
_context.LogMessage (MessageContainer.CreateWarningMessage (_context, $"There are duplicate parameter names for '{paramName}' inside '{method.Name}' in '{_xmlDocumentLocation}'", 2024, _xmlDocumentLocation));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it warning?

Copy link
Member

Choose a reason for hiding this comment

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

We found two values for the same thing - we'll pick one of them, but drop the other. I think this should be a warning (since we're warning about other issues in the XML already)

Copy link
Contributor

Choose a reason for hiding this comment

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

What if we instead of warning we do something like _attributes[parameter].Add(attributes);

Copy link
Member

Choose a reason for hiding this comment

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

Sure - we could do that, but I would prefer not to. I don't want to encourage weird specifications. If there would be a good reason for this, then yes, but right now I don't see any. In my mind it's just adding complexity without much value.

if (attributes.Count () > 0)
_attributes[method.MethodReturnType] = attributes;
} else {
_context.LogMessage (MessageContainer.CreateWarningMessage (_context, $"There is more than one return parameter specified for '{method.Name}' in '{_xmlDocumentLocation}'", 2023, _xmlDocumentLocation));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it warning?

Copy link
Member

Choose a reason for hiding this comment

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

Same as above - two values for the same thing - we will intentionally drop data in this case so we should warn about it.

@tlakollo tlakollo merged commit 6c9263b into dotnet:master Jun 2, 2020
@tlakollo tlakollo deleted the XmlWithCustomAttributes branch February 19, 2021 02:21
tkapin pushed a commit to tkapin/runtime that referenced this pull request Jan 31, 2023
…tes (dotnet/linker#1216)

- Change XmlFlowAnnotationSource to expose CustomAttributes
- Use ICustomAttributeProvider to simplify when asking for information
about annotations
- Assembly name now could be '*' in the assembly element, there is a new assembly property inside the attribute element, leaving no assembly name in this property means to look for the type in all the loaded assemblies.
- Added new error codes, swapped non used codes for new error codes
- Changed documentation to reflect the new functionalities
- Move attribute sources to the main linker namespace

Co-authored-by: Tlakollo <[email protected]>
Co-authored-by: vitek-karas <[email protected]>

Commit migrated from dotnet/linker@6c9263b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants