Skip to content

Conversation

@jtschuster
Copy link
Member

Adds xml schema for ILLink.LinkAttributes.xml, and a more general schema that encompasses all of ILLink.LinkAttributes.xml, ILLink.Descriptors.xml, and ILLink.Substittutions.xml. In test xml files there are relative paths to the relevant schema to enable linting.

Also fixes where the preserve attribute was sometimes "none" and sometimes "nothing".

Copy link
Member

@vitek-karas vitek-karas left a 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

@@ -0,0 +1,193 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

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).

Copy link
Member Author

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";
Copy link
Contributor

@tlakollo tlakollo Jan 13, 2022

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

Copy link
Member

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.

Copy link
Contributor

@tlakollo tlakollo Jan 13, 2022

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

@@ -0,0 +1,193 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Member

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).

<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" />
Copy link
Member

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

<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" />
Copy link
Member

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.

<xsd:element name="resource">
<xsd:complexType>
<xsd:attribute name="name" use="required" />
<xsd:attribute name="action" use="required" />
Copy link
Member

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?

<xsd:element ref="type" />
</xsd:choice>
<xsd:attribute name="fullname" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

@jtschuster jtschuster Jan 20, 2022

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

<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" />
Copy link
Member

Choose a reason for hiding this comment

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

Add featuredefault?

@jtschuster jtschuster merged commit 3a06cc8 into dotnet:main Jan 22, 2022
jtschuster added a commit to jtschuster/linker that referenced this pull request Jan 24, 2022
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.
@jtschuster jtschuster deleted the XmlSchema branch February 17, 2022 17:25
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
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
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.

4 participants