Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/data-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The `required` attribute specifies that if the type is not marked, during the ma
<type fullname="Assembly.B" />

<!-- Preserve the type declaration only -->
<type fullname="Assembly.C" preserve="nothing" />
<type fullname="Assembly.C" preserve="none" />

<!-- Preserve a nested type -->
<type fullname="Assembly.D/Nested" preserve="all" />
Expand Down
124 changes: 124 additions & 0 deletions src/ILLink.Shared/ILLink.LinkAttributes.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified"
elementFormDefault="unqualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:complexType name="membertype">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="attribute" type="attribute" />
</xsd:choice>
<xsd:attribute name="feature" />
<xsd:attribute name="featurevalue" type="xsd:boolean" />
<xsd:attribute name="featuredefault" type="xsd:boolean" />
<xsd:attribute name="name" />
<xsd:attribute name="signature" />
</xsd:complexType>

<xsd:complexType name="method">
<xsd:complexContent>
<xsd:extension base="membertype">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="parameter">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="attribute" type="attribute" />
</xsd:choice>
<xsd:attribute name="name" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:choice maxOccurs="1" minOccurs="0">
<xsd:element name="return">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="attribute" type="attribute" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:choice>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="argument" mixed="true">
<xsd:choice minOccurs="0" maxOccurs="1">
<xsd:element name="argument">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="type" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:attribute name="type" />
</xsd:complexType>

<xsd:complexType name="attribute">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="argument" type="argument" />
<xsd:element name="property">
<xsd:complexType mixed="true">
<xsd:attribute name="name" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:attribute name="internal" />
<xsd:attribute name="fullname" />
<xsd:attribute name="assembly" />
</xsd:complexType>

<xsd:complexType name="assembly">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="attribute" type="attribute" />
<xsd:element name="type" type="type" />
</xsd:choice>
<xsd:attribute name="fullname" use="required" />
<xsd:attribute name="feature" />
<xsd:attribute name="featurevalue" type="xsd:boolean" />
<xsd:attribute name="featuredefault" type="xsd:boolean" />
</xsd:complexType>

<xsd:complexType name ="nestedtype">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="event" type="membertype" />
<xsd:element name="method" type="method" />
<xsd:element name="field" type="membertype" />
<xsd:element name="property" type="membertype" />
<xsd:element name="attribute" type="attribute" />
<xsd:element name="type" type="nestedtype" />
</xsd:choice>
<xsd:attribute name="name" use="required"/>
<xsd:attribute name="feature" />
<xsd:attribute name="featurevalue" type="xsd:boolean" />
<xsd:attribute name="featuredefault" type="xsd:boolean" />
</xsd:complexType>

<xsd:complexType name="type">
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="attribute" type="attribute" />
<xsd:element name="event" type="membertype" />
<xsd:element name="method" type="method" />
<xsd:element name="field" type="membertype" />
<xsd:element name="property" type="membertype" />
<xsd:element name="type" type="nestedtype"/>
</xsd:choice>
<xsd:attribute name="feature" />
<xsd:attribute name="featurevalue" type="xsd:boolean" />
<xsd:attribute name="featuredefault" type="xsd:boolean" />
<xsd:attribute name="fullname" use="required"/>
</xsd:complexType>

<xsd:element name="linker">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded" minOccurs="0">
<xsd:element name="assembly" type="assembly" />
<xsd:element name="type" type="type" />
</xsd:choice>
</xsd:complexType>
</xsd:element>

</xsd:schema>
6 changes: 6 additions & 0 deletions src/ILLink.Shared/ILLink.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)ILLink.LinkAttributes.xsd">
<SubType>Designer</SubType>
</None>
<None Include="$(MSBuildThisFileDirectory)ILLink.xsd" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/ILLink.Tasks/CreateRuntimeRootDescriptorFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static void AddXmlTypeNode (XmlDocument doc, XmlNode assemblyNode, string typeNa
typeNode.Attributes.Append (preserve);
} else if ((members.fields == null) && (members.methods == null)) {
XmlAttribute preserve = doc.CreateAttribute ("preserve");
preserve.Value = "nothing";
preserve.Value = "none";

@tlakollo tlakollo Jan 13, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

@tlakollo tlakollo Jan 13, 2022

Copy link
Copy Markdown
Contributor

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

typeNode.Attributes.Append (preserve);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<linker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../src/ILLink.Shared/ILLink.LinkAttributes.xsd">
<assembly fullname="*">
<type fullname="System.Diagnostics.DebuggerTypeProxyAttribute">
<attribute internal="RemoveAttributeInstances"/>
Expand All @@ -8,4 +8,4 @@
<attribute internal="RemoveAttributeInstances"/>
</type>
</assembly>
</linker>
</linker>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<linker>
<linker>
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<type fullname="Mono.Linker.Tests.Cases.Attributes.OnlyKeepUsed.UnusedAttributePreservedViaLinkXmlIsKept/FooAttribute" preserve="all">
</type>
</assembly>
</linker>
</linker>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<?xml version="1.0" encoding="utf-8" ?>
<linker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../src/ILLink.Shared/ILLink.LinkAttributes.xsd">
<assembly fullname="Test">
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>Test</argument>
Expand All @@ -16,4 +16,4 @@
</field>
</type>
</assembly>
</linker>
</linker>
132 changes: 66 additions & 66 deletions test/Mono.Linker.Tests.Cases/DataFlow/XmlAnnotations.xml
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="Test">
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2067</argument>
<property name="Scope">member</property>
<property name="Target">M:Mono.Linker.Tests.Cases.DataFlow.XmlAnnotations.ReadFromInstanceField</property>
</attribute>
<type fullname="Mono.Linker.Tests.Cases.DataFlow.XmlAnnotations">
<field name="_typeWithPublicParameterlessConstructor">
<attribute fullname="System.DoesNotExistAttribute" assembly="Mono.Linker.Tests.Cases.Expectations">
<argument>0</argument>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</field>
<method signature="System.Void TwoAnnotatedParameters(System.Type,System.Type)">
<parameter name="type">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</parameter>
<parameter name="type2">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicConstructors</argument>
</attribute>
</parameter>
</method>
<method signature="SpacesBetweenParametersWrongArgument (System.Type, System.Boolean)">
<parameter name="type">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">0</argument>
</attribute>
</parameter>
</method>
<method signature="GenericMethod&lt;T&gt;(T,System.Type)">
<parameter name="type">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</parameter>
</method>
<method name="ReturnConstructorsFailure">
<return>
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</return>
</method>
<property name="PropertyWithPublicParameterlessConstructor">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</property>
<type name="NestedType">
<field name="_typeWithPublicParameterlessConstructor">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</field>
</type>
</type>
</assembly>
</linker>
<?xml version="1.0" encoding="utf-8"?>
<linker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../src/ILLink.Shared/ILLink.LinkAttributes.xsd">
<assembly fullname="Test">
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2067</argument>
<property name="Scope">member</property>
<property name="Target">M:Mono.Linker.Tests.Cases.DataFlow.XmlAnnotations.ReadFromInstanceField</property>
</attribute>
<type fullname="Mono.Linker.Tests.Cases.DataFlow.XmlAnnotations">
<field name="_typeWithPublicParameterlessConstructor">
<attribute fullname="System.DoesNotExistAttribute" assembly="Mono.Linker.Tests.Cases.Expectations">
<argument>0</argument>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</field>
<method signature="System.Void TwoAnnotatedParameters(System.Type,System.Type)">
<parameter name="type">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</parameter>
<parameter name="type2">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicConstructors</argument>
</attribute>
</parameter>
</method>
<method signature="SpacesBetweenParametersWrongArgument (System.Type, System.Boolean)">
<parameter name="type">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">0</argument>
</attribute>
</parameter>
</method>
<method signature="GenericMethod&lt;T&gt;(T,System.Type)">
<parameter name="type">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</parameter>
</method>
<method name="ReturnConstructorsFailure">
<return>
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</return>
</method>
<property name="PropertyWithPublicParameterlessConstructor">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</property>
<type name="NestedType">
<field name="_typeWithPublicParameterlessConstructor">
<attribute fullname="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute">
<argument type="System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes">PublicParameterlessConstructor</argument>
</attribute>
</field>
</type>
</type>
</assembly>
</linker>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<linker>
<linker>
<assembly fullname="DynamicDependencyMethodInNonReferencedAssemblyLibrary, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<type fullname="Mono.Linker.Tests.Cases.DynamicDependencies.Dependencies.DynamicDependencyMethodInNonReferencedAssemblyLibrary" preserve="all" />
</assembly>
</linker>
</linker>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<type fullname="Mono.Linker.Tests.Cases.DynamicDependencies.DynamicDependencyFromAttributeXml">
Expand All @@ -15,4 +15,4 @@
</method>
</type>
</assembly>
</linker>
</linker>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<?xml version="1.0" encoding="utf-8" ?>
<linker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../src/ILLink.Shared/ILLink.LinkAttributes.xsd">
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<type fullname="Mono.Linker.Tests.Cases.DynamicDependencies.DynamicDependencyFromAttributeXml">
<method name="DependencyToUnusedMethod">
Expand All @@ -15,4 +15,4 @@
</method>
</type>
</assembly>
</linker>
</linker>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<type fullname="Mono.Linker.Tests.Cases.DynamicDependencies.DynamicDependencyFromAttributeXmlOnNonReferencedAssembly">
Expand All @@ -18,4 +18,4 @@
</field>
</type>
</assembly>
</linker>
</linker>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<?xml version="1.0" encoding="utf-8" ?>
<linker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../src/ILLink.Shared/ILLink.LinkAttributes.xsd">
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<type fullname="Mono.Linker.Tests.Cases.DynamicDependencies.DynamicDependencyFromAttributeXmlOnNonReferencedAssembly">
<method name="MethodWithDependencyInXml">
Expand All @@ -18,4 +18,4 @@
</field>
</type>
</assembly>
</linker>
</linker>
Loading