-
Notifications
You must be signed in to change notification settings - Fork 128
Create a schema for the LinkAttribute XML files #2500
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
test/Mono.Linker.Tests.Cases/Attributes.Debugger/DebuggerAttributesRemoved.xml
Outdated
Show resolved
Hide resolved
vitek-karas
left a comment
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.
Looks good - just couple of minor things
src/ILLink.Shared/ILLink.xsd
Outdated
| @@ -0,0 +1,193 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
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 would rename the file to ILLink.Descriptor.xsd
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 made this schema broad enough to cover ILLink.Substitutions.xml as well as ILLink.Descriptor.xml and ILLink.LinkAttributes.xml, so I don't want to name it just for descriptors, but if we don't like ILLink.xsd, maybe something like ILLink.General.xsd?
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.
Hmm - I didn't see it there - does the ILLink.Attributes.xsd "inherit/include" the ILLink.xsd then?
I would probably call it ILLink.Common.xsd, but ILLink.General.xsd works as well.
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.
What's the purpose of the schema? If we would like to give this to developers so that they have IntelliSense, having the schema suggest invalid values has potential to create harm (if there's no IntelliSense, one is forced to read docs; with IntelliSense, one relies on that for things that look "obvious").
Example: ILLink.Substitutions.xml will not look at name, only accepts signature for method. ILLink.Descriptors on the other hand will accept both name and signature and one can use it to preserve multiple methods (<method name="Foo" signature="System.Int32 Bar()"> will preserve all methods named Foo and the one Bar overload).
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 one I started as a form of documentation before I realized how different each xml file is. I think that's a good point, this schema is a little too general to provide any value. I'll remove this file and only do the more specific schema.
| } else if ((members.fields == null) && (members.methods == null)) { | ||
| XmlAttribute preserve = doc.CreateAttribute ("preserve"); | ||
| preserve.Value = "nothing"; | ||
| preserve.Value = "none"; |
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.
It's correct to have only one between the two, but just be aware that seems like runtime is using the 'nothing' notation since is what it was documented. See file.
The way I see it we either agreed on 'nothing' (and change only some linker tests) or agreed on 'none' and have to change other files outside the linker repo who may have used 'nothing' already
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 the guiding force should be what the linker actually recognizes - if it's both, then we should allow both in the schema as well.
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.
Seems like the code is looking for Nothing and if an invalid value is passed then it defaults to Nothing
https://github.com/dotnet/linker/blob/main/src/linker/Linker.Steps/DescriptorMarker.cs#L137-L146
src/ILLink.Shared/ILLink.xsd
Outdated
| @@ -0,0 +1,193 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
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.
What's the purpose of the schema? If we would like to give this to developers so that they have IntelliSense, having the schema suggest invalid values has potential to create harm (if there's no IntelliSense, one is forced to read docs; with IntelliSense, one relies on that for things that look "obvious").
Example: ILLink.Substitutions.xml will not look at name, only accepts signature for method. ILLink.Descriptors on the other hand will accept both name and signature and one can use it to preserve multiple methods (<method name="Foo" signature="System.Int32 Bar()"> will preserve all methods named Foo and the one Bar overload).
src/ILLink.Shared/ILLink.xsd
Outdated
| <xsd:attribute name="name" type="xsd:string" /> | ||
| <xsd:attribute name="signature" type="xsd:string" /> | ||
| <xsd:attribute name="required" type="xsd:boolean" /> | ||
| <xsd:attribute name="body" type="xsd:string" /> |
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.
Nit: We could restrict this to the two supported values
src/ILLink.Shared/ILLink.xsd
Outdated
| <xsd:attribute name="name" type="xsd:string" /> | ||
| <xsd:attribute name="signature" type="xsd:string" /> | ||
| <xsd:attribute name="value" type="xsd:string" /> | ||
| <xsd:attribute name="initialize" type="xsd:string" /> |
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.
Maybe make this bool?
In the parser, this has the same problem as preserve: value of true means "initialize", value of anything else means "don't initialize", but maybe we can cut that stuff off.
src/ILLink.Shared/ILLink.xsd
Outdated
| <xsd:element name="resource"> | ||
| <xsd:complexType> | ||
| <xsd:attribute name="name" use="required" /> | ||
| <xsd:attribute name="action" use="required" /> |
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.
Maybe add a type that restricts this to remove?
src/ILLink.Shared/ILLink.xsd
Outdated
| <xsd:element ref="type" /> | ||
| </xsd:choice> | ||
| <xsd:attribute name="fullname" type="xsd:string" /> | ||
| <xsd:attribute name="name" type="xsd:string" /> |
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 we support name on type?
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 documentation has name supported on nested types, but not on top level.
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.
What does the code do?
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.
Looks like it also allows name on nested types but not on top level.
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.
protected virtual void ProcessTypes (AssemblyDefinition assembly, XPathNavigator nav, bool warnOnUnresolvedTypes) in ProcessLinkerXmlBase.cs gets the fullname attribute, but in ProcessType in LinkAttributesParser.cs it will look for name, and doesn't look for fullname
src/ILLink.Shared/ILLink.xsd
Outdated
| <xsd:attribute name="required" type="xsd:boolean" /> | ||
| <xsd:attribute name="preserve" type="preservevalues" /> | ||
| <xsd:attribute name="feature" type="xsd:string" /> | ||
| <xsd:attribute name="featurevalue" type="xsd:boolean" /> |
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.
Add featuredefault?
Design proposal for DAM-on-type and RUC interactions (dotnet#2168) Co-authored-by: Sven Boemer <sbomer@gmail.com> Fix analyzer nullref on assembly attribute (dotnet#2534) The analyzer runs for property assignment operations, including those in attributes. To check whether the property assignment should warn, we look for RUC on the containing symbol. However, assembly-level attributes are contained in the global namespace, which has a null containing type. Create a schema for the LinkAttribute XML files (dotnet#2500) Adds xml schema for ILLink.LinkAttributes.xml, and adds relative paths to the schema in xml used in unit tests to enable linting. [main] Update dependencies from dotnet/runtime (dotnet#2539) [main] Update dependencies from dotnet/runtime Title and message resources should be enforced to exist to prevent printing empty messages (dotnet#2538) Currently, missing resources will default to an empty string printing an empty message for the diagnostics. Code should not try to gracefully handle errors. Included in this PR: - DiagnosticString should be able to locate a title and message resource strings otherwise it throws - Add title resource strings for all missing diagnostic Ids Update dependencies from https://github.com/dotnet/runtime build 20220123.5 (dotnet#2542) [main] Update dependencies from dotnet/runtime Update dependencies from https://github.com/dotnet/arcade build 20220121.6 (dotnet#2541) [main] Update dependencies from dotnet/arcade Analyzer warns when Requires... Attribute is on a static constructor (dotnet#2455) Adds warnings in the analyzer for IL2116 (RUC not allowed on static ctor) and adds IL2117 (RequiresDynamicCode not allowed on static ctor) and IL2118 (RequiresAssemblyFiles not allowed on static ctor). Fixes ExpectedWarning not having effects on constructors by adding a Visit override in the compilation tree walker in the test infra. Adds case in GetDisplayName to differentiate .cctor's and .ctor's. Linker doesn't seem to be checking ctors for calls to methods with RUC. This commit removes the check for the expected warnings in the linker until the bug is fixed.
Adds xml schema for ILLink.LinkAttributes.xml, and adds relative paths to the schema in xml used in unit tests to enable linting. Commit migrated from dotnet/linker@3a06cc8
Adds xml schema for
ILLink.LinkAttributes.xml, and a more general schema that encompasses all ofILLink.LinkAttributes.xml,ILLink.Descriptors.xml, andILLink.Substittutions.xml. In test xml files there are relative paths to the relevant schema to enable linting.Also fixes where the
preserveattribute was sometimes "none" and sometimes "nothing".