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

Annotate FSharp.Core for trimmability #15980

Closed
charlesroddie opened this issue Sep 14, 2023 · 5 comments
Closed

Annotate FSharp.Core for trimmability #15980

charlesroddie opened this issue Sep 14, 2023 · 5 comments
Assignees
Labels
Area-AOT Everything related to AOT Feature Request
Milestone

Comments

@charlesroddie
Copy link
Contributor

Compile an F# app with NativeAOT

Set <TrimmerSingleWarn>false</TrimmerSingleWarn> to see detailed logs.

Many warnings result. These are mostly from FSharp.Core but some are from a "Compiler" namespace and presumably leak from there into FSharp.Core.

F# should be annotated for trimming so that users who do not use problematic constructs will not get warnings. Problematic code should be annotated with DynamicallyAccessedMemberTypes etc.. The aim of the trimming annotations is to give users full confidence that, if there are no warnings, then AOT compilation will work.

The code warned about should not be actually called if users are careful, and if they set --reflectionfree they will be given help in avoiding problematic code (like sprintf used explicitly), and the compiler will also not generate problematic code (like sprintf generated from DUs).

However --reflectionfree doesn't catch all uses of reflection (although it could and should be extended to do that), so there are currently false negatives, and there are also a lot of false positives as seen below. So this is complementary to the standard dotnet trimming annotation approach.

FSharp.Core\seq.fs(333): Trim analysis warning IL2091: Microsoft.FSharp.Collections.Internal.IEnumerator.upto<TResult>(FSharpOption`1<Int32>,FSharpFunc`2<Int32,!!0>): 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicParameterlessConstructor' in 'System.Lazy`1'. The generic parameter 'TResult' of 'Microsoft.FSharp.Collections.Internal.IEnumerator.upto<TResult>(FSharpOption`1<Int32>,FSharpFunc`2<Int32,!!0>)' 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.
FSharp.Core\printf.fs(1283): AOT analysis warning IL3050: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.parseAndCreateFunctionFactory(): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
FSharp.Core\printf.fs(1291): AOT analysis warning IL3050: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.parseAndCreateFunctionFactory(): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
FSharp.Core\printf.fs(1107): AOT analysis warning IL3050: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.buildCaptureFunc<a>(PrintfImpl.FormatSpecifier,a,Type[],Type,Tuple`5<Object,Boolean,Type[],Type,FSharpOption`1<Object>>): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
FSharp.Core\printf.fs(1119): Trim analysis warning IL2060: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.buildCaptureFunc<a>(PrintfImpl.FormatSpecifier,a,Type[],Type,Tuple`5<Object,Boolean,Type[],Type,FSharpOption`1<Object>>): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method.
FSharp.Core\printf.fs(1119): AOT analysis warning IL3050: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.buildCaptureFunc<a>(PrintfImpl.FormatSpecifier,a,Type[],Type,Tuple`5<Object,Boolean,Type[],Type,FSharpOption`1<Object>>): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
FSharp.Core\printf.fs(1125): Trim analysis warning IL2060: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.buildCaptureFunc<a>(PrintfImpl.FormatSpecifier,a,Type[],Type,Tuple`5<Object,Boolean,Type[],Type,FSharpOption`1<Object>>): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method.
FSharp.Core\printf.fs(1125): AOT analysis warning IL3050: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.buildCaptureFunc<a>(PrintfImpl.FormatSpecifier,a,Type[],Type,Tuple`5<Object,Boolean,Type[],Type,FSharpOption`1<Object>>): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
FSharp.Core\printf.fs(1132): Trim analysis warning IL2060: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.buildCaptureFunc<a>(PrintfImpl.FormatSpecifier,a,Type[],Type,Tuple`5<Object,Boolean,Type[],Type,FSharpOption`1<Object>>): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method.
FSharp.Core\printf.fs(1132): AOT analysis warning IL3050: Microsoft.FSharp.Core.PrintfImpl.FormatParser`4.buildCaptureFunc<a>(PrintfImpl.FormatSpecifier,a,Type[],Type,Tuple`5<Object,Boolean,Type[],Type,FSharpOption`1<Object>>): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
FSharp.Core\printf.fs(1005): Trim analysis warning IL2060: Microsoft.FSharp.Core.PrintfImpl.getValueConverter(Type,PrintfImpl.FormatSpecifier): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method.
FSharp.Core\printf.fs(1005): AOT analysis warning IL3050: Microsoft.FSharp.Core.PrintfImpl.getValueConverter(Type,PrintfImpl.FormatSpecifier): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
FSharp.Core\printf.fs(1163): Trim analysis warning IL2060: Microsoft.FSharp.Core.PrintfImpl.convFunc@1163-1.Invoke(a,Type): Call to 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic method.
FSharp.Core\printf.fs(1163): AOT analysis warning IL3050: Microsoft.FSharp.Core.PrintfImpl.convFunc@1163-1.Invoke(a,Type): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
Compiler\Utilities\sformat.fs(571): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfo<a>(BindingFlags,a,Type): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(Type,FSharpOption`1<BindingFlags>)'. The parameter '#2' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfo<a>(BindingFlags,a,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.
Compiler\Utilities\sformat.fs(1356): Trim analysis warning IL2075: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.sequenceValueL(Display.ShowMode,Int32,Display.Precedence,IEnumerable): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The return value of method 'System.Object.GetType()' 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.
Compiler\Utilities\sformat.fs(1365): Trim analysis warning IL2075: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.sequenceValueL(Display.ShowMode,Int32,Display.Precedence,IEnumerable): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'. The return value of method 'System.Object.GetType()' 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.
Compiler\Utilities\sformat.fs(589): Trim analysis warning IL2070: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.typeUsesSystemObjectToString(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String,BindingFlags,Binder,Type[],ParameterModifier[])'. The parameter '#0' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.Display.typeUsesSystemObjectToString(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.
Compiler\Utilities\sformat.fs(1408): Trim analysis warning IL2070: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.objectValueWithPropertiesL(Int32,Type,Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The parameter '#1' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.objectValueWithPropertiesL(Int32,Type,Object)' 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.
Compiler\Utilities\sformat.fs(1412): Trim analysis warning IL2070: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.objectValueWithPropertiesL(Int32,Type,Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter '#1' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.objectValueWithPropertiesL(Int32,Type,Object)' 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.
Compiler\Utilities\sformat.fs(1448): Trim analysis warning IL2070: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.objectValueWithPropertiesL(Int32,Type,Object): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.Type.InvokeMember(String,BindingFlags,Binder,Object,Object[],CultureInfo)'. The parameter '#1' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.Display.ObjectGraphFormatter.objectValueWithPropertiesL(Int32,Type,Object)' 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.
Compiler\Utilities\sformat.fs(470): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.isListType(Type): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.IsUnion(Type,FSharpOption`1<BindingFlags>)'. The parameter '#0' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.isListType(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.
Compiler\Utilities\sformat.fs(471): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.isListType(Type): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(Type,FSharpOption`1<BindingFlags>)'. The parameter '#0' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.isListType(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.
Compiler\Utilities\sformat.fs(504): Trim analysis warning IL2072: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject(BindingFlags,Object): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.IsTuple(Type)'. The return value of method 'System.Object.GetType()' 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.
Compiler\Utilities\sformat.fs(505): Trim analysis warning IL2072: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject(BindingFlags,Object): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.GetTupleElements(Type)'. The return value of method 'System.Object.GetType()' 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.
Compiler\Utilities\sformat.fs(518): Trim analysis warning IL2072: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject(BindingFlags,Object): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.IsFunction(Type)'. The return value of method 'System.Object.GetType()' 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.
Compiler\Utilities\sformat.fs(526): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.IsUnion(Type,FSharpOption`1<BindingFlags>)'. The parameter '#2' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit)' 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.
Compiler\Utilities\sformat.fs(527): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpValue.GetUnionFields(Object,Type,FSharpOption`1<BindingFlags>)'. The parameter '#2' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit)' 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.
Compiler\Utilities\sformat.fs(535): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.IsExceptionRepresentation(Type,FSharpOption`1<BindingFlags>)'. The parameter '#2' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit)' 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.
Compiler\Utilities\sformat.fs(536): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.GetExceptionFields(Type,FSharpOption`1<BindingFlags>)'. The parameter '#2' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit)' 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.
Compiler\Utilities\sformat.fs(544): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.IsRecord(Type,FSharpOption`1<BindingFlags>)'. The parameter '#2' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit)' 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.
Compiler\Utilities\sformat.fs(545): Trim analysis warning IL2067: Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit): '' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'Microsoft.FSharp.Reflection.FSharpType.GetRecordFields(Type,FSharpOption`1<BindingFlags>)'. The parameter '#2' of method 'Microsoft.FSharp.Text.StructuredPrintfImpl.ReflectUtils.Value.GetValueInfoOfObject$cont@526(BindingFlags,Object,Type,Unit)' 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.
FSharp.Core\reflect.fs(389): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.getUnionTypeTagNameMap(Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicNestedTypes', 'DynamicallyAccessedMemberTypes.NonPublicNestedTypes' in call to 'System.Type.GetNestedType(String,BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.getUnionTypeTagNameMap(Type,BindingFlags)' 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.
FSharp.Core\reflect.fs(393): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.getUnionTypeTagNameMap(Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetMethods(BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.getUnionTypeTagNameMap(Type,BindingFlags)' 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.
FSharp.Core\reflect.fs(416): Trim analysis warning IL2075: Microsoft.FSharp.Reflection.Impl.getUnionTypeTagNameMap(Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields', 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The return value of method 'System.Type.GetNestedType(String,BindingFlags)' 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.
Compiler\Utilities\sformat.fs(1082): Trim analysis warning IL2080: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.buildObjMessageL@1082-2.Invoke(Unit): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.Type.InvokeMember(String,BindingFlags,Binder,Object,Object[],CultureInfo)'. The field 'Microsoft.FSharp.Text.StructuredPrintfImpl.Display.buildObjMessageL@1082-2.ty' 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.
Compiler\Utilities\sformat.fs(1327): Trim analysis warning IL2075: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.possibleKeyValueL@1317-1.Invoke(!0): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' 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.
Compiler\Utilities\sformat.fs(1327): Trim analysis warning IL2075: Microsoft.FSharp.Text.StructuredPrintfImpl.Display.possibleKeyValueL@1317-1.Invoke(!0): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' 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.
FSharp.Core\reflect.fs(853): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.getTupleElementAccessors(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'System.Type.GetFields(BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.getTupleElementAccessors(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.
FSharp.Core\reflect.fs(855): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.getTupleElementAccessors(Type): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.getTupleElementAccessors(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.
FSharp.Core\reflect.fs(972): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.fieldPropsOfRecordType(Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.fieldPropsOfRecordType(Type,BindingFlags)' 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.
FSharp.Core\reflect.fs(558): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.getUnionTagReader(Type,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetMethod(String,BindingFlags,Binder,Type[],ParameterModifier[])'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.getUnionTagReader(Type,BindingFlags)' 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.
FSharp.Core\reflect.fs(525): Trim analysis warning IL2075: Microsoft.FSharp.Reflection.Impl.fieldsPropsOfUnionCase(Type,Int32,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The return value of method 'Microsoft.FSharp.Reflection.Impl.getUnionCaseTyp(Type,Int32,BindingFlags)' 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.
FSharp.Core\reflect.fs(525): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.fieldsPropsOfUnionCase(Type,Int32,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperties(BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.fieldsPropsOfUnionCase(Type,Int32,BindingFlags)' 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.
FSharp.Core\reflect.fs(73): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.getInstancePropertyInfos(Type,String[],BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperty(String,BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.getInstancePropertyInfos(Type,String[],BindingFlags)' 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.
FSharp.Core\reflect.fs(445): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.getUnionCaseTyp(Type,Int32,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicNestedTypes', 'DynamicallyAccessedMemberTypes.NonPublicNestedTypes' in call to 'System.Type.GetNestedType(String,BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.getUnionCaseTyp(Type,Int32,BindingFlags)' 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.
FSharp.Core\reflect.fs(449): Trim analysis warning IL2055: Microsoft.FSharp.Reflection.Impl.getUnionCaseTyp(Type,Int32,BindingFlags): Call to 'System.Type.MakeGenericType(Type[])' can not be statically analyzed. It's not possible to guarantee the availability of requirements of the generic type.
FSharp.Core\reflect.fs(449): AOT analysis warning IL3050: Microsoft.FSharp.Reflection.Impl.getUnionCaseTyp(Type,Int32,BindingFlags): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime.
FSharp.Core\reflect.fs(76): Trim analysis warning IL2070: Microsoft.FSharp.Reflection.Impl.getInstancePropertyReader(Type,String,BindingFlags): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperty(String,BindingFlags)'. The parameter '#0' of method 'Microsoft.FSharp.Reflection.Impl.getInstancePropertyReader(Type,String,BindingFlags)' 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.
@charlesroddie
Copy link
Contributor Author

@0101 0101 added Area-AOT Everything related to AOT and removed Needs-Triage labels Oct 2, 2023
@KevinRansom
Copy link
Member

KevinRansom commented Oct 3, 2023

@charlesroddie :
We have these tests here: https://github.com/dotnet/fsharp/blob/main/tests/AheadOfTime/Trimming/SelfContained_Trimming_Test/SelfContained_Trimming_Test.fsproj

That verify trimming now works correctly for %A, unions, records etc, but we have not yet done the work to enable F# apps to work when AOT reflection is disabled.

It is the next sizable job I will be working on unless priorities change.

@KevinRansom
Copy link
Member

@charlesroddie , I think we are in a pretty decent place now for trimmabilty.

We have %A support for all F# types. We do need to do a lot of work to enable F# AOT when reflection is disabled in the runtime.

We have these tests here: https://github.com/dotnet/fsharp/tree/main/tests/AheadOfTime/Trimming

We will manage reflection disabled AOT with this PR: #16663

If there are any Apis that need Annotation we will handle them as issues.

Before I close this, let me know if there are any specific APIs you have in mind for additional annotation.

Thanks

Kevin

@charlesroddie
Copy link
Contributor Author

Great. Is there a released version of F# or the dotnet sdk with these annotations in? We have dotnet sdk 8.0.101 in the pipeline but can try 8.0.201.

@KevinRansom KevinRansom modified the milestones: Backlog, March-2024 Mar 7, 2024
@charlesroddie
Copy link
Contributor Author

I can confirm that when building from VS 17.9.2, there are no trim warnings coming from FSharp.Core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AOT Everything related to AOT Feature Request
Projects
Archived in project
Development

No branches or pull requests

3 participants