Skip to content

Conversation

@roji
Copy link
Member

@roji roji commented Aug 2, 2021

This is only a first step, more work is needed. Based on work by @NinoFloris in #3830 (thanks!)

After this, the following issues still remain in Npgsql (for a trivial "hello world"-like program):

/home/roji/projects/npgsql/src/Npgsql/Internal/TypeHandlers/ArrayHandler.cs(258,21): Trim analysis error IL2060: Npgsql.Internal.TypeHandlers.ArrayHandler.ArrayTypeInfo<TArrayOrList>..cctor(): Call to 'System.Reflection.MethodInfo System.Reflection.MethodInfo::MakeGenericMethod(System.Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
/home/roji/projects/npgsql/src/Npgsql/Internal/TypeHandlers/ArrayHandler.cs(246,21): Trim analysis error IL2060: Npgsql.Internal.TypeHandlers.ArrayHandler.ArrayTypeInfo<TArrayOrList>..cctor(): Call to 'System.Reflection.MethodInfo System.Reflection.MethodInfo::MakeGenericMethod(System.Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
/home/roji/projects/npgsql/src/Npgsql/TypeMapping/ConnectorTypeMapper.cs(247,13): Trim analysis error IL2070: Npgsql.TypeMapping.ConnectorTypeMapper.GetArrayElementType(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Reflection.TypeInfo.ImplementedInterfaces.get'. The parameter 'type' of method 'Npgsql.TypeMapping.ConnectorTypeMapper.GetArrayElementType(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
/home/roji/projects/npgsql/src/Npgsql/Internal/TypeHandling/NullableHandler.cs(68,16): Trim analysis error IL2060: Npgsql.Internal.TypeHandling.NullableHandler.CreateDelegate<TDelegate>(Type,MethodInfo): Call to 'System.Reflection.MethodInfo System.Reflection.MethodInfo::MakeGenericMethod(System.Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]

These are related to array/nullable handling, which currently heavily relies on reflection and is being explored by @NinoFloris (see #3813).

Apart from this the following external linker warnings are generated (especially from System.Data), not sure if the plan is to handle those in .NET 6.0:

External linker warnings
ILLink : Trim analysis error IL2026: System.Data.ColumnTypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,Object,Type): Using method 'System.Type.GetType(String,Func<AssemblyName,Assembly>,Func<Assembly,String,Boolean,Type>,Boolean,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type might be removed. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.ColumnTypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,Object,Type): Using method 'System.Type.GetType(String,Func<AssemblyName,Assembly>,Func<Assembly,String,Boolean,Type>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type might be removed. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.ColumnTypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,Object,Type): Using method 'System.Type.GetType(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type might be removed. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.ColumnTypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,Object,Type): Using method 'System.Type.GetType(String,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type might be removed. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.ColumnTypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,Object,Type): Using method 'System.Type.GetType(String,Boolean,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type might be removed. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.ColumnTypeConverter.ConvertTo(ITypeDescriptorContext,CultureInfo,Object,Type): Using method 'System.Type.GetType(String,Func<AssemblyName,Assembly>,Func<Assembly,String,Boolean,Type>,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The type might be removed. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataSet.GetObjectData(SerializationInfo,StreamingContext): Using method 'System.Data.DataSet.SerializeDataSet(SerializationInfo,StreamingContext,SerializationFormat)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using method 'System.Data.XmlTreeGen.Save(DataSet,XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using method 'System.Data.DataSet.DataSet(SerializationInfo,StreamingContext,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using method 'System.Data.DataSet.DataSet(SerializationInfo,StreamingContext)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using method 'System.Data.DataSet.ReadXmlSerializable(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using method 'System.Data.DataSet.WriteXml(XmlWriter,XmlWriteMode)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using method 'System.Data.DataSet.WriteXmlSchema(XmlWriter,SchemaFormat,Converter<Type,String>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.GetObjectData(SerializationInfo,StreamingContext): Using method 'System.Data.DataTable.SerializeDataTable(SerializationInfo,StreamingContext,Boolean,SerializationFormat)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.GetSchema(): Using method 'System.Data.XmlTreeGen.Save(DataTable,XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.ReadXml(XmlReader,XmlReadMode,Boolean): Using method 'System.Data.XmlDataLoader.LoadData(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.ReadXml(XmlReader,XmlReadMode,Boolean): Using method 'System.Data.DataTable.ReadXmlDiffgram(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.ReadXml(XmlReader,XmlReadMode,Boolean): Using method 'System.Data.DataTable.ReadXmlDiffgram(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.ReadXml(XmlReader,XmlReadMode,Boolean): Using method 'System.Data.DataTable.ReadXmlSchema(XmlReader,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.ReadXml(XmlReader,XmlReadMode,Boolean): Using method 'System.Data.DataTable.ReadXmlSchema(XmlReader,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.WriteXmlCore(XmlWriter): Using method 'System.Data.DataTable.WriteXmlSchema(XmlWriter,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.DataTable.WriteXmlCore(XmlWriter): Using method 'System.Data.DataTable.WriteXml(XmlWriter,XmlWriteMode,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.Common.DbConnectionStringBuilder.GetProperties(Hashtable): Using method 'System.ComponentModel.TypeDescriptor.GetProperties(Object,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. PropertyDescriptor's PropertyType cannot be statically discovered. The Type of component cannot be statically discovered. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Data.Common.DbConnectionStringBuilder.System.ComponentModel.ICustomTypeDescriptor.GetAttributes(): Using method 'System.ComponentModel.TypeDescriptor.GetAttributes(Object,Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The Type of component cannot be statically discovered. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Linq.Expressions.Expression.Convert(Expression,Type): Using method 'System.Linq.Expressions.Expression.Convert(Expression,Type,MethodInfo)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Creating Expressions requires unreferenced code because the members being referenced by the Expression may be trimmed. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]
ILLink : Trim analysis error IL2026: System.Text.Json.Nodes.JsonNode.System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(Expression): Using method 'System.Text.Json.Nodes.JsonNode.CreateDynamicObject(Expression,JsonNode)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using JsonNode instances as dynamic types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. [/home/roji/projects/npgsql/test/Npgsql.TrimmingTests/Npgsql.TrimmingTests.csproj]

Part of #3300
Part of #3820

@roji roji requested a review from NinoFloris August 2, 2021 11:19
@roji roji requested a review from vonzshik as a code owner August 2, 2021 11:19
* Annotate composite types as incompatible with trimming, while
  suppressing warnings for applications which don't use them.
* Create a very basic console test program for testing (#3820). We'll
  eventually run this in CI.

Part of #3300
Part of #3820
@roji
Copy link
Member Author

roji commented Aug 2, 2021

Will wait in case @NinoFloris has any input here (though remember it's just a first thing).

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.

2 participants