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

[main] Update dependencies from mono/linker #56593

Merged
merged 10 commits into from
Aug 3, 2021
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>f7e4c261815c66fde2c1e750b744f193e236c17e</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="6.0.100-preview.6.21378.1">
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="6.0.100-preview.6.21379.2">
<Uri>https://github.com/mono/linker</Uri>
<Sha>0cb9250a903cfc90cbac602ed79c0cbc588d8d3f</Sha>
<Sha>aec70d0ae5a5d304176bb9831f5ffdb6e13d3568</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.21370.1">
<Uri>https://github.com/dotnet/xharness</Uri>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<!-- Docs -->
<MicrosoftPrivateIntellisenseVersion>5.0.0-preview-20201009.2</MicrosoftPrivateIntellisenseVersion>
<!-- ILLink -->
<MicrosoftNETILLinkTasksVersion>6.0.100-preview.6.21378.1</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkTasksVersion>6.0.100-preview.6.21379.2</MicrosoftNETILLinkTasksVersion>
<MicrosoftNETILLinkAnalyzerPackageVersion>$(MicrosoftNETILLinkTasksVersion)</MicrosoftNETILLinkAnalyzerPackageVersion>
<!-- ICU -->
<MicrosoftNETCoreRuntimeICUTransportVersion>6.0.0-rc.1.21369.1</MicrosoftNETCoreRuntimeICUTransportVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ private sealed class LicenseClassFactory : IClassFactory2
private readonly LicenseInteropProxy _licenseProxy = new LicenseInteropProxy();
private readonly Guid _classId;

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors)]
private readonly Type _classType;

public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type classType)
public LicenseClassFactory(Guid clsid, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces | DynamicallyAccessedMemberTypes.PublicConstructors)] Type classType)
{
_classId = clsid;
_classType = classType;
Expand Down Expand Up @@ -627,6 +627,9 @@ internal sealed class LicenseInteropProxy
private object? _licContext;
private Type? _targetRcwType;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111",
sbomer marked this conversation as resolved.
Show resolved Hide resolved
Justification = "The type parameter to LicenseManager.CreateWithContext method has PublicConstructors annotation. We only invoke this method" +
"from AllocateAndValidateLicense which annotates the value passed in with the same annotation.")]
Copy link
Member

Choose a reason for hiding this comment

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

Yay for extra validation. Caught a bug here...

public LicenseInteropProxy()
{
Type licManager = Type.GetType("System.ComponentModel.LicenseManager, System.ComponentModel.TypeConverter", throwOnError: true)!;
Expand Down Expand Up @@ -742,7 +745,7 @@ public string RequestLicKey(Type type)
// If we are being entered because of a call to ICF::CreateInstanceLic(),
// "isDesignTime" will be "false" and "key" will point to a non-null
// license key.
public object AllocateAndValidateLicense(Type type, string? key, bool isDesignTime)
public object AllocateAndValidateLicense([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, string? key, bool isDesignTime)
{
object?[] parameters;
object? licContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,9 @@ Namespace Microsoft.VisualBasic.CompilerServices
MyBase.New(t, True)
End Sub

<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026",
Justification:=IDOBinder.SuppressionJustification)>
<UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111",
Justification:=IDOBinder.SuppressionJustification)>
Public Overrides Function FallbackConvert(
ByVal target As DynamicMetaObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@

namespace System.Data.Common
{
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
// https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "The use of GetType preserves members with RequiresUnreferencedCode, but the GetType callsites either "
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2113",
sbomer marked this conversation as resolved.
Show resolved Hide resolved
Justification = "The use of GetType preserves ICustomTypeDescriptor members with RequiresUnreferencedCode, but the GetType callsites either "
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public class DbConnectionStringBuilder : IDictionary, ICustomTypeDescriptor
Expand Down Expand Up @@ -393,6 +391,9 @@ internal Attribute[] GetAttributesFromCollection(AttributeCollection collection)
return attributes;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112",
sbomer marked this conversation as resolved.
Show resolved Hide resolved
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
private PropertyDescriptorCollection GetProperties()
{
Expand All @@ -419,6 +420,9 @@ private PropertyDescriptorCollection GetProperties()
return propertyDescriptors;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112",
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("PropertyDescriptor's PropertyType cannot be statically discovered.")]
protected virtual void GetProperties(Hashtable propertyDescriptors)
{
Expand Down Expand Up @@ -526,6 +530,9 @@ protected virtual void GetProperties(Hashtable propertyDescriptors)
}
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112",
Justification = "The use of GetType preserves this member with RequiresUnreferencedCode, but the GetType callsites either "
+ "occur in RequiresUnreferencedCode scopes, or have individually justified suppressions.")]
[RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
private PropertyDescriptorCollection GetProperties(Attribute[]? attributes)
{
Expand Down
8 changes: 4 additions & 4 deletions src/libraries/System.Data.Common/src/System/Data/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ namespace System.Data
[XmlSchemaProvider(nameof(GetDataSetSchema))]
[XmlRoot(nameof(DataSet))]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
// https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "CreateInstanceOfThisType's use of GetType uses only the parameterless constructor, but the annotations preserve all non-public constructors causing a warning for the serialization constructors. Those constructors won't be used here.")]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] // needed by Clone() to preserve derived ctors
public class DataSet : MarshalByValueComponent, IListSource, IXmlSerializable, ISupportInitializeNotification, ISerializable
{
Expand Down Expand Up @@ -231,11 +227,15 @@ protected void GetSerializationData(SerializationInfo info, StreamingContext con

// Deserialize all the tables schema and data of the dataset from binary/xml stream.
[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112",
Justification = "CreateInstanceOfThisType's use of GetType uses only the parameterless constructor, but the annotations preserve all non-public constructors causing a warning for the serialization constructors. Those constructors won't be used here.")]
protected DataSet(SerializationInfo info, StreamingContext context) : this(info, context, true)
{
}

[RequiresUnreferencedCode(RequiresUnreferencedCodeMessage)]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112",
Justification = "CreateInstanceOfThisType's use of GetType uses only the parameterless constructor, but the annotations preserve all non-public constructors causing a warning for the serialization constructors. Those constructors won't be used here.")]
protected DataSet(SerializationInfo info, StreamingContext context, bool ConstructSchema) : this()
{
SerializationFormat remotingFormat = SerializationFormat.Xml;
Expand Down
6 changes: 2 additions & 4 deletions src/libraries/System.Data.Common/src/System/Data/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ namespace System.Data
[XmlSchemaProvider(nameof(GetDataTableSchema))]
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
// https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
public class DataTable : MarshalByValueComponent, IListSource, ISupportInitializeNotification, ISerializable, IXmlSerializable
{
Expand Down Expand Up @@ -196,6 +192,8 @@ public DataTable(string? tableName, string? tableNamespace) : this(tableName)
}

// Deserialize the table from binary/xml stream.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112",
Justification = "CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
protected DataTable(SerializationInfo info, StreamingContext context) : this()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,16 @@ internal static DataTable GetSchemaTableFromDataTable(DataTable table)
DataColumn ColumnSize = new DataColumn(SchemaTableColumn.ColumnSize, typeof(int));
DataColumn NumericPrecision = new DataColumn(SchemaTableColumn.NumericPrecision, typeof(short));
DataColumn NumericScale = new DataColumn(SchemaTableColumn.NumericScale, typeof(short));
DataColumn DataType = new DataColumn(SchemaTableColumn.DataType, typeof(Type));
DataColumn DataType = GetSystemTypeDataColumn();

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2111",
Justification = "The problem is Type.TypeInitializer which requires constructors on the Type instance." +
"In this case the Type instance is about System.Type itself, so adding an explicit dependency on the same" +
"annotation here.")]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors, typeof(Type))]
Copy link
Member

Choose a reason for hiding this comment

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

Does the trimmer treat PublicConstructors | NonPublicConstructors as referencing static cctors?

I'm wondering if this DynamicDependency is truly necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, it does. Good question about DynamicDependency. I only found one place where the annotation was ultimately used:

PropertyInfo? propInfo = type.GetProperty("Null", BindingFlags.Public | BindingFlags.Static);
if (propInfo != null)
{
return propInfo.GetValue(null, null)!;
}
FieldInfo fieldInfo = type.GetField("Null", BindingFlags.Public | BindingFlags.Static)!;

If I didn't miss anything I think it's ok to remove.

static DataColumn GetSystemTypeDataColumn() =>
new DataColumn(SchemaTableColumn.DataType, typeof(Type));

DataColumn ProviderType = new DataColumn(SchemaTableColumn.ProviderType, typeof(int));
DataColumn IsLong = new DataColumn(SchemaTableColumn.IsLong, typeof(bool));
DataColumn AllowDBNull = new DataColumn(SchemaTableColumn.AllowDBNull, typeof(bool));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ namespace System.Data
/// This is the generic base class for TypedDataSet
/// </summary>
[Serializable]
// This coarse suppression silences all RequiresUnreferencedCode warnings in the class.
// https://github.com/mono/linker/issues/2136 tracks making it possible to add more granular suppressions at the member level, and with a different warning code.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "DataTable.CreateInstance's use of GetType uses only the parameterless constructor. Warnings are about serialization related constructors.")]
public abstract class TypedTableBase<T> : DataTable, IEnumerable<T> where T : DataRow
{

Expand All @@ -32,6 +28,8 @@ protected TypedTableBase() : base() { }
/// </summary>
/// <param name="info">SerializationInfo containing data to construct the object.</param>
/// <param name="context">The streaming context for the object being deserialized.</param>
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2112",
Justification = "DataTable.CreateInstance's use of GetType uses only the parameterless constructor, not this serialization related constructor.")]
[RequiresUnreferencedCode(DataSet.RequiresUnreferencedCodeMessage)]
protected TypedTableBase(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@
<property name="Scope">member</property>
<property name="Target">M:System.Data.OleDb.OleDbDataReader.GetFieldType(System.Int32)</property>
</attribute>
</assembly>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2111</argument>
<property name="Scope">member</property>
<property name="Target">M:System.Data.OleDb.OleDbDataReader.BuildSchemaTable(MetaData[])</property>
</attribute> </assembly>
</linker>
Loading