From ea07f3e2b704c68016613b7400ed49fedd184569 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 7 Apr 2025 11:12:02 -0700 Subject: [PATCH] Annotate Microsoft.CSharp with RequiresDynamicCode The public API surface looks exactly like RequiresUnreferencedCode, but the private implementation details vary slightly. I don't think there's a meaningful difference in the annotations for RDC vs RUC. --- .../Microsoft.CSharp/ref/Microsoft.CSharp.cs | 11 +++ .../src/Microsoft.CSharp.csproj | 2 +- .../Microsoft/CSharp/RuntimeBinder/Binder.cs | 12 ++++ .../CSharp/RuntimeBinder/BinderHelper.cs | 2 + .../CSharpBinaryOperationBinder.cs | 1 + .../RuntimeBinder/CSharpConvertBinder.cs | 1 + .../RuntimeBinder/CSharpGetIndexBinder.cs | 1 + .../RuntimeBinder/CSharpGetMemberBinder.cs | 1 + .../RuntimeBinder/CSharpInvokeBinder.cs | 1 + .../CSharpInvokeConstructorBinder.cs | 1 + .../RuntimeBinder/CSharpInvokeMemberBinder.cs | 1 + .../RuntimeBinder/CSharpIsEventBinder.cs | 1 + .../RuntimeBinder/CSharpSetIndexBinder.cs | 1 + .../RuntimeBinder/CSharpSetMemberBinder.cs | 1 + .../CSharpUnaryOperationBinder.cs | 1 + .../ComInterop/BoundDispEvent.cs | 1 + .../RuntimeBinder/ComInterop/ComBinder.cs | 11 +++ .../ComInterop/ComEventSinksContainer.cs | 2 + .../ComInterop/ComEventsSink.Extended.cs | 1 + .../ComInterop/ComInvokeAction.cs | 2 + .../ComInterop/ComInvokeBinder.cs | 1 + .../RuntimeBinder/ComInterop/ComObject.cs | 3 + .../ComInterop/ComRuntimeHelpers.cs | 4 ++ .../RuntimeBinder/ComInterop/DispCallable.cs | 1 + .../ComInterop/DispCallableMetaObject.cs | 1 + .../ComInterop/IDispatchComObject.cs | 1 + .../ComInterop/IDispatchMetaObject.cs | 1 + .../RuntimeBinder/ComInterop/SplatCallSite.cs | 1 + .../RuntimeBinder/ComInterop/VariantArray.cs | 2 + .../RuntimeBinder/DynamicDebuggerProxy.cs | 13 ++++ .../RuntimeBinder/Errors/ErrorHandling.cs | 2 + .../RuntimeBinder/Errors/UserStringBuilder.cs | 13 ++++ .../ExpressionTreeCallRewriter.cs | 1 + .../CSharp/RuntimeBinder/RuntimeBinder.cs | 30 ++++++++ .../RuntimeBinder/Semantics/BinOpSig.cs | 1 + .../RuntimeBinder/Semantics/Binding/Better.cs | 5 ++ .../RuntimeBinder/Semantics/Conversion.cs | 35 +++++++++ .../RuntimeBinder/Semantics/Conversions.cs | 4 ++ .../Semantics/ExplicitConversion.cs | 2 + .../RuntimeBinder/Semantics/ExprFactory.cs | 19 +++++ .../Semantics/ExpressionBinder.cs | 29 ++++++++ .../Semantics/GroupToArgsBinder.cs | 1 + .../Semantics/ImplicitConversion.cs | 3 + .../RuntimeBinder/Semantics/MemberLookup.cs | 1 + .../Semantics/MemberLookupResults.cs | 2 + .../RuntimeBinder/Semantics/MethodIterator.cs | 1 + .../Semantics/MethodTypeInferrer.cs | 1 + .../RuntimeBinder/Semantics/Nullable.cs | 2 + .../RuntimeBinder/Semantics/Operators.cs | 72 ++++++++++++++++++- .../Semantics/PredefinedMembers.cs | 10 +++ .../Semantics/SemanticChecker.cs | 6 ++ .../Semantics/Symbols/AggregateSymbol.cs | 2 +- .../Semantics/Symbols/SymFactory.cs | 13 ++++ .../Semantics/Symbols/SymbolLoader.cs | 15 ++++ .../Semantics/Tree/MethodInfo.cs | 1 + .../Semantics/Tree/PropertyInfo.cs | 1 + .../Tree/Visitors/ExpressionTreeRewriter.cs | 1 + .../RuntimeBinder/Semantics/TypeBind.cs | 5 ++ .../Semantics/Types/AggregateType.cs | 2 +- .../Semantics/Types/ArrayType.cs | 2 +- .../Semantics/Types/NullableType.cs | 2 +- .../Semantics/Types/PredefinedTypes.cs | 2 + .../Semantics/Types/TypeManager.cs | 28 ++++++++ .../RuntimeBinder/Semantics/UnaOpSig.cs | 1 + .../CSharp/RuntimeBinder/SymbolTable.cs | 35 +++++++++ 65 files changed, 426 insertions(+), 7 deletions(-) diff --git a/src/libraries/Microsoft.CSharp/ref/Microsoft.CSharp.cs b/src/libraries/Microsoft.CSharp/ref/Microsoft.CSharp.cs index 619bb40feb9d36..24ae1ab00a281c 100644 --- a/src/libraries/Microsoft.CSharp/ref/Microsoft.CSharp.cs +++ b/src/libraries/Microsoft.CSharp/ref/Microsoft.CSharp.cs @@ -10,26 +10,37 @@ namespace Microsoft.CSharp.RuntimeBinder public static partial class Binder { [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder BinaryOperation(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Linq.Expressions.ExpressionType operation, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder Convert(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type type, System.Type? context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder GetIndex(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder GetMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder Invoke(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder InvokeConstructor(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Collections.Generic.IEnumerable? typeArguments, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder IsEvent(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type? context) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder SetIndex(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder SetMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, string name, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Using dynamic types might cause types or members to be removed by trimmer.")] + [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT.")] public static System.Runtime.CompilerServices.CallSiteBinder UnaryOperation(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags flags, System.Linq.Expressions.ExpressionType operation, System.Type? context, System.Collections.Generic.IEnumerable? argumentInfo) { throw null; } } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft.CSharp.csproj b/src/libraries/Microsoft.CSharp/src/Microsoft.CSharp.csproj index d286f621f43c1e..7a2b989d927840 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft.CSharp.csproj +++ b/src/libraries/Microsoft.CSharp/src/Microsoft.CSharp.csproj @@ -13,7 +13,7 @@ $(DefineConstants);ENABLECOMBINDER true $(DefineConstants);LEGACY_GETRESOURCESTRING_USER - false + true diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Binder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Binder.cs index beec176cb19c60..168223f6795660 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Binder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Binder.cs @@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder public static class Binder { internal const string TrimmerWarning = "Using dynamic types might cause types or members to be removed by trimmer."; + internal const string DynamicCodeWarning = "The 'dynamic' feature requires runtime-code generation, which is incompatible with AOT."; ////////////////////////////////////////////////////////////////////// /// @@ -28,6 +29,7 @@ public static class Binder /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp binary operation binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder BinaryOperation( CSharpBinderFlags flags, ExpressionType operation, @@ -56,6 +58,7 @@ public static CallSiteBinder BinaryOperation( /// The that indicates where this operation is used. /// Returns a new CSharp convert binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder Convert( CSharpBinderFlags flags, Type type, @@ -83,6 +86,7 @@ public static CallSiteBinder Convert( /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp get index binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder GetIndex( CSharpBinderFlags flags, Type? context, @@ -102,6 +106,7 @@ public static CallSiteBinder GetIndex( /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp get member binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder GetMember( CSharpBinderFlags flags, string name, @@ -122,6 +127,7 @@ public static CallSiteBinder GetMember( /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp invoke binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder Invoke( CSharpBinderFlags flags, Type? context, @@ -150,6 +156,7 @@ public static CallSiteBinder Invoke( /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp invoke member binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder InvokeMember( CSharpBinderFlags flags, string name, @@ -188,6 +195,7 @@ public static CallSiteBinder InvokeMember( /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp invoke constructor binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder InvokeConstructor( CSharpBinderFlags flags, Type? context, @@ -206,6 +214,7 @@ public static CallSiteBinder InvokeConstructor( /// The that indicates where this operation is used. /// Returns a new CSharp is event binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder IsEvent( CSharpBinderFlags flags, string name, @@ -224,6 +233,7 @@ public static CallSiteBinder IsEvent( /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp set index binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder SetIndex( CSharpBinderFlags flags, Type? context, @@ -245,6 +255,7 @@ public static CallSiteBinder SetIndex( /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp set member binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder SetMember( CSharpBinderFlags flags, string name, @@ -267,6 +278,7 @@ public static CallSiteBinder SetMember( /// The sequence of instances for the arguments to this operation. /// Returns a new CSharp unary operation binder. [RequiresUnreferencedCode(TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CallSiteBinder UnaryOperation( CSharpBinderFlags flags, ExpressionType operation, diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs index cc35f5c8be47e2..b3ea3f98592293 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/BinderHelper.cs @@ -21,6 +21,7 @@ internal static class BinderHelper private static MethodInfo s_SingleIsNaN; [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static DynamicMetaObject Bind( ICSharpBinder action, RuntimeBinder binder, @@ -474,6 +475,7 @@ internal static bool CompareArgInfos(CSharpArgumentInfo[] argInfos, CSharpArgume } #if !ENABLECOMBINDER + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static void ThrowIfUsingDynamicCom(DynamicMetaObject target) { if (target.LimitType.IsCOMObject) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpBinaryOperationBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpBinaryOperationBinder.cs index 4320ce948a4779..1426e1b26ecbd9 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpBinaryOperationBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpBinaryOperationBinder.cs @@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Instances of this class are generated by the C# compiler. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpBinaryOperationBinder : BinaryOperationBinder, ICSharpBinder { [ExcludeFromCodeCoverage(Justification = "Name should not be called for this binder")] diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpConvertBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpConvertBinder.cs index 7cca8a6ebe9aaf..ee29098777dc2e 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpConvertBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpConvertBinder.cs @@ -16,6 +16,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Instances of this class are generated by the C# compiler. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpConvertBinder : ConvertBinder, ICSharpBinder { [ExcludeFromCodeCoverage(Justification = "Name should not be called for this binder")] diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetIndexBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetIndexBinder.cs index 6211ee1ec71901..db83488e9d313e 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetIndexBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetIndexBinder.cs @@ -15,6 +15,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Instances of this class are generated by the C# compiler. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpGetIndexBinder : GetIndexBinder, ICSharpBinder { public string Name => SpecialNames.Indexer; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetMemberBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetMemberBinder.cs index c8643be6c4d955..cbb721563053d5 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetMemberBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpGetMemberBinder.cs @@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Instances of this class are generated by the C# compiler. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpGetMemberBinder : GetMemberBinder, IInvokeOnGetBinder, ICSharpBinder { public BindingFlag BindingFlags => BindingFlag.BIND_RVALUEREQUIRED; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeBinder.cs index 5a15ed533db767..49578c6a455380 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeBinder.cs @@ -15,6 +15,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Represents a dynamic delegate-like call in C#, providing the binding semantics and the details about the operation. /// Instances of this class are generated by the C# compiler. /// + [RequiresDynamicCode(Binder.DynamicCodeWarning)] [RequiresUnreferencedCode(Binder.TrimmerWarning)] internal sealed class CSharpInvokeBinder : InvokeBinder, ICSharpInvokeOrInvokeMemberBinder { diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeConstructorBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeConstructorBinder.cs index ef3753c3378ce3..2bf01477eb14ce 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeConstructorBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeConstructorBinder.cs @@ -11,6 +11,7 @@ namespace Microsoft.CSharp.RuntimeBinder { [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpInvokeConstructorBinder : DynamicMetaObjectBinder, ICSharpInvokeOrInvokeMemberBinder { public BindingFlag BindingFlags => 0; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeMemberBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeMemberBinder.cs index 785457031cf9bf..b2c0cf6daff4db 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeMemberBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpInvokeMemberBinder.cs @@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Instances of this class are generated by the C# compiler. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpInvokeMemberBinder : InvokeMemberBinder, ICSharpInvokeOrInvokeMemberBinder { public BindingFlag BindingFlags => 0; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpIsEventBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpIsEventBinder.cs index b3cf6415742d59..2026d14b9c1489 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpIsEventBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpIsEventBinder.cs @@ -13,6 +13,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Used to test whether a dynamic member over which += or -= is used is an event member. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpIsEventBinder : DynamicMetaObjectBinder, ICSharpBinder { public BindingFlag BindingFlags => 0; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetIndexBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetIndexBinder.cs index 3d7c948d97bc3b..3965d489bd56fe 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetIndexBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetIndexBinder.cs @@ -16,6 +16,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Instances of this class are generated by the C# compiler. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpSetIndexBinder : SetIndexBinder, ICSharpBinder { public string Name => SpecialNames.Indexer; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetMemberBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetMemberBinder.cs index 91e8dad955896f..ded45203119dd1 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetMemberBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpSetMemberBinder.cs @@ -16,6 +16,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Instances of this class are generated by the C# compiler. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpSetMemberBinder : SetMemberBinder, ICSharpBinder { public BindingFlag BindingFlags => 0; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpUnaryOperationBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpUnaryOperationBinder.cs index 5f35fd25222f8b..d50665055fdb50 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpUnaryOperationBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/CSharpUnaryOperationBinder.cs @@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder /// Instances of this class are generated by the C# compiler. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class CSharpUnaryOperationBinder : UnaryOperationBinder, ICSharpBinder { [ExcludeFromCodeCoverage(Justification = "Name should not be called for this binder")] diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/BoundDispEvent.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/BoundDispEvent.cs index e7e95859e77bf2..6f1c94a5d019fc 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/BoundDispEvent.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/BoundDispEvent.cs @@ -10,6 +10,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop { [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class BoundDispEvent : DynamicObject { private readonly object _rcw; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComBinder.cs index 584f40662185ce..ce87bd45073605 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComBinder.cs @@ -33,6 +33,7 @@ public static bool IsComObject(object value) /// true if member evaluation may be delayed. /// true if operation was bound successfully; otherwise, false. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool TryBindGetMember(GetMemberBinder binder, DynamicMetaObject instance, out DynamicMetaObject result, bool delayInvocation) { Requires.NotNull(binder); @@ -65,6 +66,7 @@ public static bool TryBindGetMember(GetMemberBinder binder, DynamicMetaObject in /// The new representing the result of the binding. /// true if operation was bound successfully; otherwise, false. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool TryBindSetMember(SetMemberBinder binder, DynamicMetaObject instance, DynamicMetaObject value, out DynamicMetaObject result) { Requires.NotNull(binder); @@ -90,6 +92,7 @@ public static bool TryBindSetMember(SetMemberBinder binder, DynamicMetaObject in /// The new representing the result of the binding. /// true if operation was bound successfully; otherwise, false. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool TryBindInvoke(InvokeBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) { Requires.NotNull(binder); @@ -115,6 +118,7 @@ public static bool TryBindInvoke(InvokeBinder binder, DynamicMetaObject instance /// The new representing the result of the binding. /// true if operation was bound successfully; otherwise, false. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool TryBindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) { Requires.NotNull(binder); @@ -140,6 +144,7 @@ public static bool TryBindInvokeMember(InvokeMemberBinder binder, DynamicMetaObj /// The new representing the result of the binding. /// true if operation was bound successfully; otherwise, false. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) { Requires.NotNull(binder); @@ -166,6 +171,7 @@ public static bool TryBindGetIndex(GetIndexBinder binder, DynamicMetaObject inst /// The new representing the result of the binding. /// true if operation was bound successfully; otherwise, false. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool TryBindSetIndex(SetIndexBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, DynamicMetaObject value, out DynamicMetaObject result) { Requires.NotNull(binder); @@ -228,6 +234,7 @@ public static bool TryConvert(ConvertBinder binder, DynamicMetaObject instance, /// The object for which member names are requested. /// The collection of member names. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static IList GetDynamicDataMemberNames(object value) { Requires.NotNull(value); @@ -244,6 +251,7 @@ internal static IList GetDynamicDataMemberNames(object value) /// The enumeration of names of data members for which to retrieve values. /// The collection of pairs that represent data member's names and their data. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static IList> GetDynamicDataMembers(object value, IEnumerable names) { Requires.NotNull(value); @@ -253,6 +261,7 @@ internal static IList> GetDynamicDataMembers(object } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool TryGetMetaObject(ref DynamicMetaObject instance) { // If we're already a COM MO don't make a new one @@ -272,6 +281,7 @@ private static bool TryGetMetaObject(ref DynamicMetaObject instance) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool TryGetMetaObjectInvoke(ref DynamicMetaObject instance) { // If we're already a COM MO don't make a new one @@ -293,6 +303,7 @@ private static bool TryGetMetaObjectInvoke(ref DynamicMetaObject instance) /// /// Special binder that indicates special semantics for COM GetMember operation. /// + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class ComGetMemberBinder : GetMemberBinder { private readonly GetMemberBinder _originalBinder; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComEventSinksContainer.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComEventSinksContainer.cs index 9c06e6cdf311f3..79eb0ab02f6374 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComEventSinksContainer.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComEventSinksContainer.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; using System.Runtime.InteropServices; @@ -12,6 +13,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop /// This list is usually attached as a custom data for RCW object and /// is finalized whenever RCW is finalized. /// + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class ComEventSinksContainer : List, IDisposable { private ComEventSinksContainer() diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComEventsSink.Extended.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComEventsSink.Extended.cs index 7c000b14a9b5f3..8f8f4b9c48ed0f 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComEventsSink.Extended.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComEventsSink.Extended.cs @@ -9,6 +9,7 @@ namespace System.Runtime.InteropServices { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed partial class ComEventsSink { private void Initialize(object rcw, Guid iid) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComInvokeAction.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComInvokeAction.cs index 9a6a6272f67f8f..f6e715884a6db5 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComInvokeAction.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComInvokeAction.cs @@ -14,6 +14,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop /// /// Invokes the object. If it falls back, just produce an error. /// + [RequiresDynamicCode(Binder.DynamicCodeWarning)] [RequiresUnreferencedCode(Binder.TrimmerWarning)] internal sealed class ComInvokeAction : InvokeBinder { @@ -46,6 +47,7 @@ public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, Dynam /// Splats the arguments to another nested dynamic site, which does the /// real invocation of the IDynamicMetaObjectProvider. /// + [RequiresDynamicCode(Binder.DynamicCodeWarning)] [RequiresUnreferencedCode(Binder.TrimmerWarning)] internal sealed class SplatInvokeBinder : CallSiteBinder { diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComInvokeBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComInvokeBinder.cs index ff356ef08c96c8..22181857ce681b 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComInvokeBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComInvokeBinder.cs @@ -13,6 +13,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class ComInvokeBinder { private readonly ComMethodDesc _methodDesc; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComObject.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComObject.cs index fd4aa80ca23a7f..230d44a66d388d 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComObject.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComObject.cs @@ -32,6 +32,7 @@ internal ComObject(object rcw) /// /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ComObject ObjectToComObject(object rcw) { Debug.Assert(ComBinder.IsComObject(rcw)); @@ -82,6 +83,8 @@ internal static MethodCallExpression RcwToComObject(Expression rcw) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] + private static ComObject CreateComObject(object rcw) { if (rcw is IDispatch dispatchObject) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComRuntimeHelpers.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComRuntimeHelpers.cs index c1228bc1eade72..8a7ac723c9715b 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComRuntimeHelpers.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/ComRuntimeHelpers.cs @@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop internal static class ComRuntimeHelpers { [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static void CheckThrowException(int hresult, ref ExcepInfo excepInfo, uint argErr, string message) { if (ComHresults.IsSuccess(hresult)) @@ -209,11 +210,13 @@ internal static unsafe ComTypes.TYPELIBATTR GetTypeAttrForTypeLib(ComTypes.IType } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static BoundDispEvent CreateComEvent(object rcw, Guid sourceIid, int dispid) { return new BoundDispEvent(rcw, sourceIid, dispid); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static DispCallable CreateDispCallable(IDispatchComObject dispatch, ComMethodDesc method) { return new DispCallable(dispatch, method.Name, method.DispId); @@ -350,6 +353,7 @@ public static IntPtr GetIdsOfNamedParameters(IDispatch dispatch, string[] names, internal static ModuleBuilder DynamicModule { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] get { if (s_dynamicModule != null) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallable.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallable.cs index 3a0b4678f4ebab..ca6187e6473973 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallable.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallable.cs @@ -11,6 +11,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop /// /// This represents a bound dispmember on a IDispatch object. /// + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class DispCallable : IPseudoComObject { internal DispCallable(IDispatchComObject dispatch, string memberName, int dispId) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallableMetaObject.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallableMetaObject.cs index c94a7e0f389865..41a994efc65812 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallableMetaObject.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/DispCallableMetaObject.cs @@ -8,6 +8,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop { [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class DispCallableMetaObject : DynamicMetaObject { private readonly DispCallable _callable; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchComObject.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchComObject.cs index babcf60eb20e42..b696ac139e8a7d 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchComObject.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchComObject.cs @@ -75,6 +75,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop /// dispid. /// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class IDispatchComObject : ComObject, IDynamicMetaObjectProvider { private ComTypeDesc _comTypeDesc; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchMetaObject.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchMetaObject.cs index 589c63da54f947..376d6d73a83e58 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchMetaObject.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/IDispatchMetaObject.cs @@ -9,6 +9,7 @@ namespace Microsoft.CSharp.RuntimeBinder.ComInterop { [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class IDispatchMetaObject : ComFallbackMetaObject { private readonly IDispatchComObject _self; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/SplatCallSite.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/SplatCallSite.cs index 354da7bd4caf29..1b291286c6673a 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/SplatCallSite.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/SplatCallSite.cs @@ -27,6 +27,7 @@ internal SplatCallSite(object callable) public delegate object InvokeDelegate(object[] args); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal object Invoke(object[] args) { Debug.Assert(args != null); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/VariantArray.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/VariantArray.cs index 559b9e92c01b1e..816f549d9ecdb3 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/VariantArray.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ComInterop/VariantArray.cs @@ -62,6 +62,7 @@ internal static MemberExpression GetStructField(ParameterExpression variantArray return Expression.Field(variantArray, "Element" + field); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static Type GetStructType(int args) { Debug.Assert(args >= 0); @@ -95,6 +96,7 @@ internal static Type GetStructType(int args) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Type CreateCustomType(int size) { TypeAttributes attrs = TypeAttributes.NotPublic | TypeAttributes.SequentialLayout; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/DynamicDebuggerProxy.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/DynamicDebuggerProxy.cs index 049ae14924c3b9..b0d9238b4b974c 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/DynamicDebuggerProxy.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/DynamicDebuggerProxy.cs @@ -30,6 +30,7 @@ private DynamicBindingFailedException(SerializationInfo info, StreamingContext c } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class GetMemberValueBinder : GetMemberBinder { public GetMemberValueBinder(string name, bool ignoreCase) @@ -82,6 +83,7 @@ public DynamicProperty(string name, object value) internal DynamicProperty[] Items { [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] get { if (results == null || results.Count == 0) @@ -110,6 +112,7 @@ public DynamicMetaObjectProviderDebugView(object arg) private static readonly ParameterExpression parameter = Expression.Parameter(typeof(object), "debug"); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static object TryEvalBinaryOperators( T1 arg1, T2 arg2, @@ -133,6 +136,7 @@ public static object TryEvalBinaryOperators( } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static object TryEvalUnaryOperators(T obj, ExpressionType oper, Type accessibilityContext) { if (oper == ExpressionType.IsTrue || oper == ExpressionType.IsFalse) @@ -154,6 +158,7 @@ public static object TryEvalUnaryOperators(T obj, ExpressionType oper, Type a } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static K TryEvalCast(T obj, Type type, CSharpBinderFlags kind, Type accessibilityContext) { var site = CallSite>.Create(Binder.Convert(kind, type, accessibilityContext)); @@ -205,6 +210,7 @@ private static void CreateDelegateSignatureAndArgumentInfos( /// /// Result of invoking the delegate. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static object CreateDelegateAndInvoke(Type[] delegateSignatureTypes, CallSiteBinder binder, object[] args) { Type delegateType = Expression.GetDelegateType(delegateSignatureTypes); @@ -231,6 +237,7 @@ private static object CreateDelegateAndInvoke(Type[] delegateSignatureTypes, Cal /// Generic type arguments if there are any. /// Result of method invocation. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static object TryEvalMethodVarArgs( object[] methodArgs, Type[] argTypes, @@ -282,6 +289,7 @@ public static object TryEvalMethodVarArgs( /// Determines if COM binder should return a callable object. /// Result of property invocation. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static object TryGetMemberValue(T obj, string propName, Type accessibilityContext, bool isResultIndexed) { // In most cases it's ok to use CSharpArgumentInfoFlags.None since target of property call is dynamic. @@ -310,6 +318,7 @@ public static object TryGetMemberValue(T obj, string propName, Type accessibi /// Type that determines context in which method should be called. /// Result of property invocation. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static object TryGetMemberValueVarArgs( object[] propArgs, Type[] argTypes, @@ -344,6 +353,7 @@ public static object TryGetMemberValueVarArgs( /// Type that determines context in which method should be called. /// Result of property invocation. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static object TrySetMemberValue( TObject obj, string propName, @@ -376,6 +386,7 @@ public static object TrySetMemberValue( /// Type that determines context in which method should be called. /// Result of property invocation. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static object TrySetMemberValueVarArgs( object[] propArgs, Type[] argTypes, @@ -398,6 +409,7 @@ public static object TrySetMemberValueVarArgs( } //Called when we don't know if the member is a property or a method + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static object TryGetMemberValue(object obj, string name, bool ignoreException) { // if you want to ignore case for VB, this is how you set it .. make it a member and add a ctor to init it @@ -433,6 +445,7 @@ internal static object TryGetMemberValue(object obj, string name, bool ignoreExc #endif [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static IList> QueryDynamicObject(object obj) { IDynamicMetaObjectProvider ido = obj as IDynamicMetaObjectProvider; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs index fcd9aeeb33f4ea..bea28d7db482c7 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using Microsoft.CSharp.RuntimeBinder.Semantics; @@ -10,6 +11,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Errors { internal static class ErrorHandling { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static RuntimeBinderException Error(ErrorCode id, params ErrArg[] args) { // Create an argument array manually using the type information in the ErrArgs. diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/UserStringBuilder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/UserStringBuilder.cs index 3a0e6ae67d63cd..b73d8fcfdc75a4 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/UserStringBuilder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/UserStringBuilder.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text; using Microsoft.CSharp.RuntimeBinder.Semantics; @@ -69,6 +70,7 @@ private static string ErrSK(SYMKIND sk) * Does NOT include () */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendParamList(TypeArray @params, bool isParamArray) { if (null == @params) @@ -117,11 +119,13 @@ private void ErrAppendName(Name name) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendParentSym(Symbol sym, SubstContext pctx) { ErrAppendParentCore(sym.parent, pctx); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendParentCore(Symbol parent, SubstContext pctx) { if (parent == null || parent == NamespaceSymbol.Root) @@ -141,6 +145,7 @@ private void ErrAppendParentCore(Symbol parent, SubstContext pctx) ErrAppendChar('.'); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendTypeParameters(TypeArray @params, SubstContext pctx) { if (@params != null && @params.Count != 0) @@ -156,6 +161,7 @@ private void ErrAppendTypeParameters(TypeArray @params, SubstContext pctx) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendMethod(MethodSymbol meth, SubstContext pctx, bool fArgs) { if (meth.IsExpImpl() && meth.swtSlot) @@ -269,12 +275,15 @@ private void ErrAppendMethod(MethodSymbol meth, SubstContext pctx, bool fArgs) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendIndexer(IndexerSymbol indexer, SubstContext pctx) { ErrAppendString("this["); ErrAppendParamList(TypeManager.SubstTypeArray(indexer.Params, pctx), indexer.isParamArray); ErrAppendChar(']'); } + + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendProperty(PropertySymbol prop, SubstContext pctx) { ErrAppendParentSym(prop, pctx); @@ -306,11 +315,13 @@ private void ErrAppendProperty(PropertySymbol prop, SubstContext pctx) /* * Create a fill-in string describing a symbol. */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendSym(Symbol sym, SubstContext pctx) { ErrAppendSym(sym, pctx, true); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendSym(Symbol sym, SubstContext pctx, bool fArgs) { switch (sym.getKind()) @@ -388,6 +399,7 @@ private void ErrAppendSym(Symbol sym, SubstContext pctx, bool fArgs) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ErrAppendType(CType pType, SubstContext pctx) { if (pctx != null && !pctx.IsNop) @@ -535,6 +547,7 @@ private void ErrAppendType(CType pType, SubstContext pctx) } // Returns true if the argument could be converted to a string. + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public bool ErrArgToString(out string psz, ErrArg parg, out bool fUserStrings) { fUserStrings = false; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ExpressionTreeCallRewriter.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ExpressionTreeCallRewriter.cs index b9f3fab762f382..f3aad7f75b57a1 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ExpressionTreeCallRewriter.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/ExpressionTreeCallRewriter.cs @@ -11,6 +11,7 @@ namespace Microsoft.CSharp.RuntimeBinder { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class ExpressionTreeCallRewriter : ExprVisitorBase { ///////////////////////////////////////////////////////////////////////////////// diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinder.cs index ffc141a89d4f73..4aaf894cab1f4c 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinder.cs @@ -22,6 +22,7 @@ internal readonly struct RuntimeBinder internal bool IsChecked => _binder.Context.Checked; [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public RuntimeBinder(Type contextType, bool isChecked = false) { AggregateSymbol context; @@ -41,6 +42,7 @@ public RuntimeBinder(Type contextType, bool isChecked = false) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public Expression Bind(ICSharpBinder payload, Expression[] parameters, DynamicMetaObject[] args, out DynamicMetaObject deferredBinding) { // The lock is here to protect this instance of the binder from itself @@ -67,6 +69,7 @@ public Expression Bind(ICSharpBinder payload, Expression[] parameters, DynamicMe } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expression BindCore( ICSharpBinder payload, Expression[] parameters, @@ -130,6 +133,7 @@ internal static void EnsureLockIsTaken() } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool DeferBinding( ICSharpBinder payload, ArgumentObject[] arguments, @@ -186,6 +190,7 @@ private bool DeferBinding( } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Expression CreateExpressionTreeFromResult(Expression[] parameters, Scope pScope, Expr pResult) { // (3) - Place the result in a return statement and create the ExprBoundLambda. @@ -200,6 +205,7 @@ private static Expression CreateExpressionTreeFromResult(Expression[] parameters } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Type GetArgumentType(ICSharpBinder p, CSharpArgumentInfo argInfo, Expression param, DynamicMetaObject arg, int index) { Type t = argInfo.UseCompileTimeType ? param.Type : arg.LimitType; @@ -240,6 +246,7 @@ private Type GetArgumentType(ICSharpBinder p, CSharpArgumentInfo argInfo, Expres ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ArgumentObject[] CreateArgumentArray( ICSharpBinder payload, Expression[] parameters, @@ -263,6 +270,7 @@ private ArgumentObject[] CreateArgumentArray( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static void PopulateSymbolTableWithPayloadInformation( ICSharpInvokeOrInvokeMemberBinder callOrInvoke, Type callingType, ArgumentObject[] arguments) { @@ -302,6 +310,7 @@ internal static void PopulateSymbolTableWithPayloadInformation( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void AddConversionsForArguments(ArgumentObject[] arguments) { foreach (ArgumentObject arg in arguments) @@ -313,6 +322,7 @@ private static void AddConversionsForArguments(ArgumentObject[] arguments) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal ExprWithArgs DispatchPayload(ICSharpInvokeOrInvokeMemberBinder payload, ArgumentObject[] arguments, LocalVariableSymbol[] locals) => BindCall(payload, CreateCallingObjectForCall(payload, arguments, locals), arguments, locals); @@ -324,6 +334,7 @@ internal ExprWithArgs DispatchPayload(ICSharpInvokeOrInvokeMemberBinder payload, // local as a ref type. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static LocalVariableSymbol[] PopulateLocalScope( ICSharpBinder payload, Scope pScope, @@ -368,6 +379,7 @@ private static LocalVariableSymbol[] PopulateLocalScope( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprBoundLambda GenerateBoundLambda(Scope pScope, Expr call) { // We don't actually need the real delegate type here - we just need SOME delegate type. @@ -381,6 +393,7 @@ private static ExprBoundLambda GenerateBoundLambda(Scope pScope, Expr call) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr CreateLocal(Type type, bool isOut, LocalVariableSymbol local) { CType ctype; @@ -408,6 +421,7 @@ private Expr CreateLocal(Type type, bool isOut, LocalVariableSymbol local) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr CreateArgumentListEXPR( ArgumentObject[] arguments, LocalVariableSymbol[] locals, @@ -442,6 +456,7 @@ internal Expr CreateArgumentListEXPR( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr CreateArgumentEXPR(ArgumentObject argument, LocalVariableSymbol local) { Expr arg; @@ -512,6 +527,7 @@ private Expr CreateArgumentEXPR(ArgumentObject argument, LocalVariableSymbol loc ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprMemberGroup CreateMemberGroupExpr( string Name, Type[] typeArguments, @@ -615,6 +631,7 @@ private static ExprMemberGroup CreateMemberGroupExpr( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr CreateProperty( SymWithType swt, Expr callingObject, @@ -635,6 +652,7 @@ private Expr CreateProperty( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprWithArgs CreateIndexer(SymWithType swt, Expr callingObject, Expr arguments, BindingFlag bindFlags) { IndexerSymbol index = swt.Sym as IndexerSymbol; @@ -647,6 +665,7 @@ private ExprWithArgs CreateIndexer(SymWithType swt, Expr callingObject, Expr arg ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr CreateArray(Expr callingObject, Expr optionalIndexerArguments) { return _binder.BindArrayIndexCore(callingObject, optionalIndexerArguments); @@ -655,6 +674,7 @@ private Expr CreateArray(Expr callingObject, Expr optionalIndexerArguments) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr CreateField( SymWithType swt, Expr callingObject) @@ -679,6 +699,7 @@ private Expr CreateField( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr CreateCallingObjectForCall( ICSharpInvokeOrInvokeMemberBinder payload, ArgumentObject[] arguments, @@ -718,6 +739,7 @@ private Expr CreateCallingObjectForCall( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprWithArgs BindCall( ICSharpInvokeOrInvokeMemberBinder payload, Expr callingObject, @@ -836,6 +858,7 @@ private static void CheckForConditionalMethodError(ExprCall call) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void ReorderArgumentsForNamedAndOptional(Expr callingObject, ExprWithArgs result) { Expr arguments = result.OptionalArguments; @@ -937,6 +960,7 @@ private Expr StripNamedArguments(Expr pArg) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindUnaryOperation( CSharpUnaryOperationBinder payload, ArgumentObject[] arguments, @@ -977,6 +1001,7 @@ internal Expr BindUnaryOperation( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindBinaryOperation( CSharpBinaryOperationBinder payload, ArgumentObject[] arguments, @@ -1100,6 +1125,7 @@ private static OperatorKind GetOperatorKind(ExpressionType p, bool bIsLogical) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindProperty( ICSharpBinder payload, ArgumentObject argument, @@ -1184,6 +1210,7 @@ internal Expr BindProperty( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindImplicitConversion( ArgumentObject[] arguments, Type returnType, @@ -1223,6 +1250,7 @@ internal Expr BindImplicitConversion( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindExplicitConversion(ArgumentObject[] arguments, Type returnType, LocalVariableSymbol[] locals) { Debug.Assert(arguments.Length == 1); @@ -1243,6 +1271,7 @@ internal Expr BindExplicitConversion(ArgumentObject[] arguments, Type returnType ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindAssignment( ICSharpBinder payload, ArgumentObject[] arguments, @@ -1283,6 +1312,7 @@ internal Expr BindAssignment( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindIsEvent( CSharpIsEventBinder binder, ArgumentObject[] arguments, diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/BinOpSig.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/BinOpSig.cs index 2fda0966078e72..428f1da0601eed 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/BinOpSig.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/BinOpSig.cs @@ -50,6 +50,7 @@ public bool AutoLift() } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private sealed class BinOpFullSig : BinOpSig { private readonly LiftFlags _grflt; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Binding/Better.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Binding/Better.cs index 9d85eb383732e4..29f7a6b43570ab 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Binding/Better.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Binding/Better.cs @@ -37,6 +37,7 @@ internal readonly partial struct ExpressionBinder new byte[] /* OBJECT*/ {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3} }; + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static BetterType WhichMethodIsBetterTieBreaker( CandidateFunctionMember node1, CandidateFunctionMember node2, @@ -198,6 +199,7 @@ private static int FindName(List names, Name name) // By rearranging the arguments as such we make sure that any specified named arguments appear in the same position for both // methods and we also maintain the relative order of the other parameters (the type long appears after int in the above example) + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static TypeArray RearrangeNamedArguments(TypeArray pta, MethPropWithInst mpwi, CType pTypeThrough, ArgInfos args) { #if DEBUG @@ -277,6 +279,7 @@ private static TypeArray RearrangeNamedArguments(TypeArray pta, MethPropWithInst // Returns Left if m1 is better, Right if m2 is better, or Neither/Same [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private BetterType WhichMethodIsBetter( CandidateFunctionMember node1, CandidateFunctionMember node2, @@ -395,6 +398,7 @@ private BetterType WhichMethodIsBetter( } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private BetterType WhichConversionIsBetter(CType argType, CType p1, CType p2) { Debug.Assert(argType != null); @@ -479,6 +483,7 @@ private BetterType WhichConversionIsBetter(CType argType, CType p1, CType p2) // Determine best method for overload resolution. Returns null if no best // method, in which case two tying methods are returned for error reporting. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private CandidateFunctionMember FindBestMethod( List list, CType pTypeThrough, diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Conversion.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Conversion.cs index faca677a332f73..ab1902e592592a 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Conversion.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Conversion.cs @@ -211,6 +211,7 @@ private static bool isUserDefinedConversion(PredefinedType ptSrc, PredefinedType private static volatile bool s_fCheckedBetter; [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void CheckBetterTable() { if (s_fCheckedBetter) @@ -240,6 +241,7 @@ private void CheckBetterTable() #pragma warning disable CA1822 [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private BetterType WhichSimpleConversionIsBetter(PredefinedType pt1, PredefinedType pt2) { #if DEBUG @@ -257,6 +259,7 @@ assumed that the given type is implicitly convertible to both of the predefined (possibly via a user defined conversion, method group conversion, etc). ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private BetterType WhichTypeIsBetter(PredefinedType pt1, PredefinedType pt2, CType typeGiven) { if (pt1 == pt2) @@ -293,6 +296,7 @@ Determined which conversion is better relative to a given type. It is assumed th a user defined conversion, method group conversion, etc). ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private BetterType WhichTypeIsBetter(CType type1, CType type2, CType typeGiven) { Debug.Assert(type1 != null && type2 != null); @@ -336,25 +340,31 @@ private BetterType WhichTypeIsBetter(CType type1, CType type2, CType typeGiven) // returns true if an implicit conversion exists from source type to dest type. flags is an optional parameter. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool canConvert(CType src, CType dest, CONVERTTYPE flags) => BindImplicitConversion(null, src, dest, flags); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public bool canConvert(CType src, CType dest) => canConvert(src, dest, 0); // returns true if a implicit conversion exists from source expr to dest type. flags is an optional parameter. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool canConvert(Expr expr, CType dest) => canConvert(expr, dest, 0); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool canConvert(Expr expr, CType dest, CONVERTTYPE flags) => BindImplicitConversion(expr, expr.Type, dest, flags); // performs an implicit conversion if it's possible. otherwise displays an error. flags is an optional parameter. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr mustConvertCore(Expr expr, CType destExpr) => mustConvertCore(expr, destExpr, 0); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr mustConvertCore(Expr expr, CType dest, CONVERTTYPE flags) { Debug.Assert(!(expr is ExprMemberGroup)); @@ -403,12 +413,14 @@ private Expr mustConvertCore(Expr expr, CType dest, CONVERTTYPE flags) // future conversions. It will also produce possible binding errors for method groups. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public Expr tryConvert(Expr expr, CType dest) { return tryConvert(expr, dest, 0); } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr tryConvert(Expr expr, CType dest, CONVERTTYPE flags) { if (BindImplicitConversion(expr, expr.Type, dest, out Expr exprResult, flags)) @@ -423,9 +435,11 @@ private Expr tryConvert(Expr expr, CType dest, CONVERTTYPE flags) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public Expr mustConvert(Expr expr, CType dest) => mustConvert(expr, dest, (CONVERTTYPE)0); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr mustConvert(Expr expr, CType dest, CONVERTTYPE flags) => mustConvertCore(expr, dest, flags); // public bool canCast(Expr expr, CType dest) @@ -436,6 +450,7 @@ private Expr tryConvert(Expr expr, CType dest, CONVERTTYPE flags) // performs an explicit conversion if its possible. otherwise displays an error. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr mustCastCore(Expr expr, CType dest, CONVERTTYPE flags) { Debug.Assert(!(expr is ExprMemberGroup)); @@ -511,6 +526,7 @@ private Expr mustCastCore(Expr expr, CType dest, CONVERTTYPE flags) throw CantConvert(expr, dest); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static RuntimeBinderException CantConvert(Expr expr, CType dest) { // Generic "can't convert" error. @@ -519,20 +535,25 @@ private static RuntimeBinderException CantConvert(Expr expr, CType dest) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public Expr mustCast(Expr expr, CType dest) => mustCast(expr, dest, 0); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public Expr mustCast(Expr expr, CType dest, CONVERTTYPE flags) => mustCastCore(expr, dest, flags); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr MustCastInUncheckedContext(Expr expr, CType dest, CONVERTTYPE flags) => new ExpressionBinder(new BindingContext(Context)).mustCast(expr, dest, flags); // returns true if an explicit conversion exists from source type to dest type. flags is an optional parameter. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool canCast(CType src, CType dest, CONVERTTYPE flags) => BindExplicitConversion(null, src, dest, flags); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool BindImplicitConversion(Expr pSourceExpr, CType pSourceType, CType destinationType, CONVERTTYPE flags) { ImplicitConversion binder = new ImplicitConversion(this, pSourceExpr, pSourceType, destinationType, false, flags); @@ -540,6 +561,7 @@ private bool BindImplicitConversion(Expr pSourceExpr, CType pSourceType, CType d } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool BindImplicitConversion(Expr pSourceExpr, CType pSourceType, CType destinationType, out Expr ppDestinationExpr, CONVERTTYPE flags) { ImplicitConversion binder = new ImplicitConversion(this, pSourceExpr, pSourceType, destinationType, true, flags); @@ -549,6 +571,7 @@ private bool BindImplicitConversion(Expr pSourceExpr, CType pSourceType, CType d } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool BindImplicitConversion(Expr pSourceExpr, CType pSourceType, CType destinationType, bool needsExprDest, out Expr ppDestinationExpr, CONVERTTYPE flags) { ImplicitConversion binder = new ImplicitConversion(this, pSourceExpr, pSourceType, destinationType, needsExprDest, flags); @@ -558,6 +581,7 @@ private bool BindImplicitConversion(Expr pSourceExpr, CType pSourceType, CType d } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool BindExplicitConversion(Expr pSourceExpr, CType pSourceType, CType destinationType, bool needsExprDest, out Expr ppDestinationExpr, CONVERTTYPE flags) { ExplicitConversion binder = new ExplicitConversion(this, pSourceExpr, pSourceType, destinationType, needsExprDest, flags); @@ -567,6 +591,7 @@ private bool BindExplicitConversion(Expr pSourceExpr, CType pSourceType, CType d } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool BindExplicitConversion(Expr pSourceExpr, CType pSourceType, CType destinationType, out Expr ppDestinationExpr, CONVERTTYPE flags) { ExplicitConversion binder = new ExplicitConversion(this, pSourceExpr, pSourceType, destinationType, true, flags); @@ -576,6 +601,7 @@ private bool BindExplicitConversion(Expr pSourceExpr, CType pSourceType, CType d } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool BindExplicitConversion(Expr pSourceExpr, CType pSourceType, CType destinationType, CONVERTTYPE flags) { ExplicitConversion binder = new ExplicitConversion(this, pSourceExpr, pSourceType, destinationType, false, flags); @@ -623,6 +649,7 @@ A conversion that needs fewer lifts is better than one that requires more (if th forms have identical signatures). ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool bindUserDefinedConversion(Expr exprSrc, CType typeSrc, CType typeDst, bool needExprDest, out Expr pexprDst, bool fImplicitOnly) { pexprDst = null; @@ -1052,6 +1079,7 @@ private bool bindUserDefinedConversion(Expr exprSrc, CType typeSrc, CType typeDs return true; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static RuntimeBinderException HandleAmbiguity(CType typeSrc, CType typeDst, List prguci, int iuciBestSrc, int iuciBestDst) { Debug.Assert(0 <= iuciBestSrc && iuciBestSrc < prguci.Count); @@ -1090,12 +1118,14 @@ private static void MarkAsIntermediateConversion(Expr pExpr) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr BindUDConversionCore(Expr pFrom, CType pTypeFrom, CType pTypeTo, CType pTypeDestination, MethWithInst mwiBest) { return BindUDConversionCore(pFrom, pTypeFrom, pTypeTo, pTypeDestination, mwiBest, out _); } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr BindUDConversionCore(Expr pFrom, CType pTypeFrom, CType pTypeTo, CType pTypeDestination, MethWithInst mwiBest, out Expr ppTransformedArgument) { Expr pTransformedArgument = mustCastCore(pFrom, pTypeFrom, CONVERTTYPE.NOUDC); @@ -1112,6 +1142,7 @@ private Expr BindUDConversionCore(Expr pFrom, CType pTypeFrom, CType pTypeTo, CT * Fold a constant cast. Returns true if the constant could be folded. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ConstCastResult bindConstantCast(Expr exprSrc, CType typeDest, bool needExprDest, out Expr pexprDest, bool explicitConversion) { pexprDest = null; @@ -1322,6 +1353,7 @@ is closer. The return value is -1 if type1 is closer, +1 if type2 is closer and 0 if neither is closer. ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private int CompareSrcTypesBased(CType type1, bool fImplicit1, CType type2, bool fImplicit2) { Debug.Assert(type1 != type2); @@ -1356,6 +1388,7 @@ is closer. The return value is -1 if type1 is closer, +1 if type2 is closer and 0 if neither is closer. ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private int CompareDstTypesBased(CType type1, bool fImplicit1, CType type2, bool fImplicit2) { Debug.Assert(type1 != type2); @@ -1372,6 +1405,7 @@ private int CompareDstTypesBased(CType type1, bool fImplicit1, CType type2, bool * Bind a constant cast to or from decimal. Return null if cast can't be done. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Expr BindDecimalConstCast(CType destType, CType srcType, ExprConstant src) { CType typeDecimal = SymbolLoader.GetPredefindType(PredefinedType.PT_DECIMAL); @@ -1482,6 +1516,7 @@ private static Expr BindDecimalConstCast(CType destType, CType srcType, ExprCons } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool CanExplicitConversionBeBoundInUncheckedContext(Expr exprSrc, CType typeSrc, CType typeDest, CONVERTTYPE flags) { Debug.Assert(typeDest != null); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Conversions.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Conversions.cs index 8e6519fbfffca3..220c6c76428286 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Conversions.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Conversions.cs @@ -25,6 +25,7 @@ when the source is a reference type and the destination is a base type of the so that typeDst.IsRefType() may still return false (when both are type parameters). ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool FImpRefConv(CType typeSrc, CType typeDst) => typeSrc.IsReferenceType && SymbolLoader.HasIdentityOrImplicitReferenceConversion(typeSrc, typeDst); @@ -73,6 +74,7 @@ The latter two cases can happen with type variables even though the other type v a reference type. ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool FExpRefConv(CType typeSrc, CType typeDst) { Debug.Assert(typeSrc != null); @@ -219,10 +221,12 @@ o If type parameter Xi is declared to be contravariant ("in") then either Si mus or Si and Ti must both be reference types. ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool HasGenericDelegateExplicitReferenceConversion(CType source, CType target) => target is AggregateType aggTarget && HasGenericDelegateExplicitReferenceConversion(source, aggTarget); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool HasGenericDelegateExplicitReferenceConversion(CType pSource, AggregateType pTarget) { if (!(pSource is AggregateType aggSrc) || diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExplicitConversion.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExplicitConversion.cs index 620206fb6d99fa..d8a6dc3e751b15 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExplicitConversion.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExplicitConversion.cs @@ -13,6 +13,7 @@ internal readonly partial struct ExpressionBinder // BindExplicitConversion // ---------------------------------------------------------------------------- + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private sealed class ExplicitConversion { private readonly ExpressionBinder _binder; @@ -592,6 +593,7 @@ private AggCastResult bindExplicitConversionToEnum(AggregateType aggTypeDest) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private AggCastResult bindExplicitConversionBetweenSimpleTypes(AggregateType aggTypeDest) { // 13.2.1 diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExprFactory.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExprFactory.cs index a9eb6ee419931b..8d6ab793576db4 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExprFactory.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExprFactory.cs @@ -25,6 +25,7 @@ public static ExprProperty CreateProperty(CType type, Expr optionalObjectThrough public static ExprMemberGroup CreateMemGroup(EXPRFLAG flags, Name name, TypeArray typeArgs, SYMKIND symKind, CType parentType, Expr obj, CMemberLookupResults memberLookupResults) => new ExprMemberGroup(flags, name, typeArgs, symKind, parentType, obj, memberLookupResults); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprMemberGroup CreateMemGroup(Expr obj, MethPropWithInst method) { Name name = method.Sym?.name; @@ -34,60 +35,75 @@ public static ExprMemberGroup CreateMemGroup(Expr obj, MethPropWithInst method) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprUserDefinedConversion CreateUserDefinedConversion(Expr arg, Expr call, MethWithInst method) => new ExprUserDefinedConversion(arg, call, method); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprCast CreateCast(CType type, Expr argument) => CreateCast(0, type, argument); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprCast CreateCast(EXPRFLAG flags, CType type, Expr argument) => new ExprCast(flags, type, argument); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprLocal CreateLocal(LocalVariableSymbol local) => new ExprLocal(local); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprBoundLambda CreateAnonymousMethod(AggregateType delegateType, Scope argumentScope, Expr expression) => new ExprBoundLambda(delegateType, argumentScope, expression); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprMethodInfo CreateMethodInfo(MethPropWithInst mwi) => CreateMethodInfo(mwi.Meth(), mwi.GetType(), mwi.TypeArgs); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprMethodInfo CreateMethodInfo(MethodSymbol method, AggregateType methodType, TypeArray methodParameters) => new ExprMethodInfo( TypeManager.GetPredefAgg(method.IsConstructor() ? PredefinedType.PT_CONSTRUCTORINFO : PredefinedType.PT_METHODINFO).getThisType(), method, methodType, methodParameters); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprPropertyInfo CreatePropertyInfo(PropertySymbol prop, AggregateType propertyType) => new ExprPropertyInfo(TypeManager.GetPredefAgg(PredefinedType.PT_PROPERTYINFO).getThisType(), prop, propertyType); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprFieldInfo CreateFieldInfo(FieldSymbol field, AggregateType fieldType) => new ExprFieldInfo(field, fieldType, TypeManager.GetPredefAgg(PredefinedType.PT_FIELDINFO).getThisType()); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprTypeOf CreateTypeOf(CType sourceType) => new ExprTypeOf(TypeManager.GetPredefAgg(PredefinedType.PT_TYPE).getThisType(), sourceType); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprUserLogicalOp CreateUserLogOp(CType type, Expr trueFalseCall, ExprCall operatorCall) => new ExprUserLogicalOp(type, trueFalseCall, operatorCall); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprConcat CreateConcat(Expr first, Expr second) => new ExprConcat(first, second); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprConstant CreateStringConstant(string str) => CreateConstant(TypeManager.GetPredefAgg(PredefinedType.PT_STRING).getThisType(), ConstVal.Get(str)); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprMultiGet CreateMultiGet(EXPRFLAG flags, CType type, ExprMulti multi) => new ExprMultiGet(type, flags, multi); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprMulti CreateMulti(EXPRFLAG flags, CType type, Expr left, Expr op) => new ExprMulti(type, flags, left, op); @@ -99,6 +115,7 @@ public static ExprMulti CreateMulti(EXPRFLAG flags, CType type, Expr left, Expr // // This returns a null for reference types and an EXPRZEROINIT for all others. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static Expr CreateZeroInit(CType type) { Debug.Assert(type != null); @@ -139,10 +156,12 @@ public static Expr CreateZeroInit(CType type) public static ExprConstant CreateConstant(CType type, ConstVal constVal) => new ExprConstant(type, constVal); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprConstant CreateIntegerConstant(int x) => CreateConstant(TypeManager.GetPredefAgg(PredefinedType.PT_INT).getThisType(), ConstVal.Get(x)); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ExprConstant CreateBoolConstant(bool b) => CreateConstant(TypeManager.GetPredefAgg(PredefinedType.PT_BOOL).getThisType(), ConstVal.Get(b)); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExpressionBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExpressionBinder.cs index b179fe3f02d74d..2f7457ba42ddd8 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExpressionBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ExpressionBinder.cs @@ -270,6 +270,7 @@ public ExpressionBinder(BindingContext context) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static AggregateType GetPredefindType(PredefinedType pt) { Debug.Assert(pt != PredefinedType.PT_VOID); // use getVoidType() @@ -278,6 +279,7 @@ private static AggregateType GetPredefindType(PredefinedType pt) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr GenerateAssignmentConversion(Expr op1, Expr op2, bool allowExplicit) => allowExplicit ? mustCastCore(op2, op1.Type, 0) : mustConvertCore(op2, op1.Type); @@ -285,6 +287,7 @@ private Expr GenerateAssignmentConversion(Expr op1, Expr op2, bool allowExplicit // Bind the simple assignment operator =. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public Expr BindAssignment(Expr op1, Expr op2, bool allowExplicit) { Debug.Assert(op1 is ExprCast @@ -300,6 +303,7 @@ public Expr BindAssignment(Expr op1, Expr op2, bool allowExplicit) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindArrayIndexCore(Expr pOp1, Expr pOp2) { CType pIntType = GetPredefindType(PredefinedType.PT_INT); @@ -329,21 +333,25 @@ internal Expr BindArrayIndexCore(Expr pOp1, Expr pOp2) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Workarounds https://github.com/mono/linker/issues/1416. All usages are marked as unsafe.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr MustConvertWithSuppressedMessage(Expr x, CType pDestType) => mustConvert(x, pDestType); [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Workarounds https://github.com/mono/linker/issues/1416. All usages are marked as unsafe.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprCast ExprFactoryCreateCastWithSuppressedMessage(EXPRFLAG flags, CType type, Expr argument) => ExprFactory.CreateCast(flags, type, argument); //////////////////////////////////////////////////////////////////////////////// // Create a cast node with the given expression flags. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void bindSimpleCast(Expr exprSrc, CType typeDest, out Expr pexprDest) => bindSimpleCast(exprSrc, typeDest, out pexprDest, 0); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void bindSimpleCast(Expr exprSrc, CType typeDest, out Expr pexprDest, EXPRFLAG exprFlags) { Debug.Assert(typeDest != null); @@ -387,6 +395,7 @@ private void bindSimpleCast(Expr exprSrc, CType typeDest, out Expr pexprDest, EX // exprFlags - Flags to put on the generated expr [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprCall BindToMethod(MethWithInst mwi, Expr pArguments, ExprMemberGroup pMemGroup, MemLookFlags flags) { Debug.Assert(mwi.Sym is MethodSymbol && (!mwi.Meth().isOverride || mwi.Meth().isHideByName)); @@ -432,6 +441,7 @@ private ExprCall BindToMethod(MethWithInst mwi, Expr pArguments, ExprMemberGroup // for a given field and pObject pointer. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr BindToField(Expr pOptionalObject, FieldWithType fwt, BindingFlag bindFlags) { Debug.Assert(fwt.GetType() != null && fwt.Field().getClass() == fwt.GetType().OwningAggregate); @@ -458,6 +468,7 @@ internal Expr BindToField(Expr pOptionalObject, FieldWithType fwt, BindingFlag b //////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal ExprProperty BindToProperty(Expr pObject, PropWithType pwt, BindingFlag bindFlags, Expr args, ExprMemberGroup pMemGroup) { Debug.Assert(pwt.Sym is PropertySymbol && @@ -534,6 +545,7 @@ internal ExprProperty BindToProperty(Expr pObject, PropWithType pwt, BindingFlag } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal Expr bindUDUnop(ExpressionKind ek, Expr arg) { Name pName = ExpressionKindName(ek); @@ -649,6 +661,7 @@ internal Expr bindUDUnop(ExpressionKind ek, Expr arg) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprCall BindLiftedUDUnop(Expr arg, CType typeArg, MethPropWithInst mpwi) { CType typeRaw = typeArg.StripNubs(); @@ -678,6 +691,7 @@ private ExprCall BindLiftedUDUnop(Expr arg, CType typeArg, MethPropWithInst mpwi } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprCall BindUDUnopCall(Expr arg, CType typeArg, MethPropWithInst mpwi) { CType typeRet = TypeManager.SubstType(mpwi.Meth().RetType, mpwi.GetType()); @@ -693,6 +707,7 @@ private ExprCall BindUDUnopCall(Expr arg, CType typeArg, MethPropWithInst mpwi) // Given a method group or indexer group, bind it to the arguments for an // invocation. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private GroupToArgsBinderResult BindMethodGroupToArgumentsCore(BindingFlag bindFlags, ExprMemberGroup grp, Expr args, int carg, NamedArgumentsKind namedArgumentsKind) { ArgInfos pargInfo = new ArgInfos { carg = carg }; @@ -711,6 +726,7 @@ private GroupToArgsBinderResult BindMethodGroupToArgumentsCore(BindingFlag bindF // Given a method group or indexer group, bind it to the arguments for an // invocation. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal ExprWithArgs BindMethodGroupToArguments(BindingFlag bindFlags, ExprMemberGroup grp, Expr args) { Debug.Assert(grp.SymKind == SYMKIND.SK_MethodSymbol || grp.SymKind == SYMKIND.SK_PropertySymbol && ((grp.Flags & EXPRFLAG.EXF_INDEXER) != 0)); @@ -791,6 +807,7 @@ private static NamedArgumentsKind FindNamedArgumentsType(Expr args) //////////////////////////////////////////////////////////////////////////////// // Report a bad operator types error to the user. + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static RuntimeBinderException BadOperatorTypesError(Expr pOperand1, Expr pOperand2) { Debug.Assert(pOperand1 != null); @@ -818,6 +835,7 @@ private static ErrorCode GetStandardLvalueError(CheckLvalueKind kind) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void CheckLvalueProp(ExprProperty prop) { Debug.Assert(prop != null); @@ -835,6 +853,7 @@ private void CheckLvalueProp(ExprProperty prop) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void CheckPropertyAccess(MethWithType mwt, PropWithType pwtSlot, CType type) { switch (CSemanticChecker.CheckAccess2(mwt.Meth(), mwt.GetType(), ContextForMemberLookup, type)) @@ -850,6 +869,7 @@ private void CheckPropertyAccess(MethWithType mwt, PropWithType pwtSlot, CType t // A false return means not to process the expr any further - it's totally out // of place. For example - a method group or an anonymous method. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void CheckLvalue(Expr expr, CheckLvalueKind kind) { if (expr.isLvalue()) @@ -908,6 +928,7 @@ private void CheckLvalue(Expr expr, CheckLvalueKind kind) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void PostBindMethod(MethWithInst pMWI) { MethodSymbol meth = pMWI.Meth(); @@ -923,6 +944,7 @@ private static void PostBindMethod(MethWithInst pMWI) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void PostBindProperty(PropWithType pwt, out MethWithType pmwtGet, out MethWithType pmwtSet) { PropertySymbol prop = pwt.Prop(); @@ -942,6 +964,7 @@ private static void PostBindProperty(PropWithType pwt, out MethWithType pmwtGet, } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr AdjustMemberObject(SymWithType swt, Expr pObject) { // Assert that the type is present and is an instantiation of the member's parent. @@ -1059,6 +1082,7 @@ private static void AssertObjectIsLvalue(Expr pObject) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void verifyMethodArgs(ExprWithArgs call, CType callingObjectType) { Debug.Assert(call != null); @@ -1072,6 +1096,7 @@ private void verifyMethodArgs(ExprWithArgs call, CType callingObjectType) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void AdjustCallArgumentsForParams(CType callingObjectType, CType type, MethodOrPropertySymbol mp, TypeArray pTypeArgs, Expr argsPtr, out Expr newArgs) { Debug.Assert(mp != null); @@ -1284,6 +1309,7 @@ private void AdjustCallArgumentsForParams(CType callingObjectType, CType type, M ]; [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal CType ChooseArrayIndexType(Expr args) { // first, select the allowable types @@ -1406,12 +1432,14 @@ private static bool IsConvInTable(List convTable, MethodSymbol meth, // Check to see if an integral constant is within range of a integral // destination type. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool isConstantInRange(ExprConstant exprSrc, CType typeDest) { return isConstantInRange(exprSrc, typeDest, false); } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool isConstantInRange(ExprConstant exprSrc, CType typeDest, bool realsOk) { FUNDTYPE ftSrc = exprSrc.Type.FundamentalType; @@ -1608,6 +1636,7 @@ private static Name ExpressionKindName(ExpressionKind ek) return NameManager.GetPredefinedName(EK2NAME[ek - ExpressionKind.FirstOp]); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void CheckUnsafe(CType type) { if (type == null || type.IsUnsafe()) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/GroupToArgsBinder.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/GroupToArgsBinder.cs index aa17e639acc9a7..6fd4483e6d73fd 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/GroupToArgsBinder.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/GroupToArgsBinder.cs @@ -17,6 +17,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics internal readonly partial struct ExpressionBinder { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class GroupToArgsBinder { private enum Result diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ImplicitConversion.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ImplicitConversion.cs index 04eb44a564634a..485b9e648e6af8 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ImplicitConversion.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/ImplicitConversion.cs @@ -13,6 +13,7 @@ internal readonly partial struct ExpressionBinder // BindImplicitConversion // ---------------------------------------------------------------------------- + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private sealed class ImplicitConversion { public ImplicitConversion(ExpressionBinder binder, Expr exprSrc, CType typeSrc, CType typeDest, bool needsExprDest, CONVERTTYPE flags) @@ -261,6 +262,7 @@ of times. (Handled by BindExplicitConversion.) then S? => T is not standard. Similarly if S => T is not implicit then S => T? is not standard. ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool BindNubConversion(NullableType nubDst) { // This code assumes that STANDARD and ISEXPLICIT are never both set. @@ -665,6 +667,7 @@ private bool bindImplicitConversionToEnum(AggregateType aggTypeSrc) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool bindImplicitConversionBetweenSimpleTypes(AggregateType aggTypeSrc) { AggregateSymbol aggSrc = aggTypeSrc.OwningAggregate; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MemberLookup.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MemberLookup.cs index e060dee7e21c7a..3648b9237f5daf 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MemberLookup.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MemberLookup.cs @@ -34,6 +34,7 @@ internal enum MemLookFlags : uint // // Lookup must be called before any other methods. + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class MemberLookup { // The inputs to Lookup. diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MemberLookupResults.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MemberLookupResults.cs index 4d3538a495686f..61810f853eeda0 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MemberLookupResults.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MemberLookupResults.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using Microsoft.CSharp.RuntimeBinder.Syntax; namespace Microsoft.CSharp.RuntimeBinder.Semantics @@ -11,6 +12,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics // to get at the inaccessible symbols, bogus symbols, and validly bound symbols. // ---------------------------------------------------------------------------- + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed partial class CMemberLookupResults { private TypeArray ContainingTypes { get; }// Types that contain the member we're looking for. diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MethodIterator.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MethodIterator.cs index f8243f5733e1ff..69920a519fedff 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MethodIterator.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MethodIterator.cs @@ -10,6 +10,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics { internal sealed partial class CMemberLookupResults { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public sealed class CMethodIterator { // Inputs. diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MethodTypeInferrer.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MethodTypeInferrer.cs index 39cbc4479a66a7..cb9091130d4418 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MethodTypeInferrer.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/MethodTypeInferrer.cs @@ -9,6 +9,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class MethodTypeInferrer { private enum NewInferenceResult diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Nullable.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Nullable.cs index ccdd55c5d632e0..fe03e124c3f0c0 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Nullable.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Nullable.cs @@ -36,6 +36,7 @@ private static Expr StripNullableConstructor(Expr pExpr) // Create an expr for exprSrc.Value where exprSrc.type is a NullableType. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Expr BindNubValue(Expr exprSrc) { Debug.Assert(exprSrc != null && exprSrc.Type is NullableType); @@ -60,6 +61,7 @@ private static Expr BindNubValue(Expr exprSrc) // Create an expr for new T?(exprSrc) where T is exprSrc.type. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprCall BindNubNew(Expr exprSrc) { Debug.Assert(exprSrc != null); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Operators.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Operators.cs index 97f2815c7f3797..615fcab9d74e1a 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Operators.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Operators.cs @@ -80,7 +80,11 @@ Note that pointer operators cannot be lifted over nullable and are not callable // Method pointers must be in the order of the corresponding enums. We check this when the full signature is set. // When the binding method is looked up in these arrays we ASSERT // if the array is out of bounds of the corresponding array. - private static readonly BinOpSig[] s_binopSignatures = + private static readonly BinOpSig[] s_binopSignatures = InitBinopSignatures(); + + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL3050:RequiresDynamicCode", + Justification = "We can't annotate static constructors on structs, but everything else in this type is annotated.")] + private static BinOpSig[] InitBinopSignatures() => new[] { new BinOpSig (PredefinedType.PT_INT, PredefinedType.PT_INT, BinOpMask.Integer, 8, BindIntBinOp, OpSigFlags.Value, BinOpFuncKind.IntBinOp ), new BinOpSig (PredefinedType.PT_UINT, PredefinedType.PT_UINT, BinOpMask.Integer, 7, BindIntBinOp, OpSigFlags.Value, BinOpFuncKind.IntBinOp ), @@ -113,7 +117,11 @@ Note that pointer operators cannot be lifted over nullable and are not callable // since they lose precision. See the language spec. // Increment and decrement operators are special. - private static readonly UnaOpSig[] s_rguos = + private static readonly UnaOpSig[] s_rguos = InitUnaOpSignatures(); + + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL3050:RequiresDynamicCode", + Justification = "We can't annotate static constructors on structs, but everything else in this type is annotated.")] + private static UnaOpSig[] InitUnaOpSignatures() => new[] { new UnaOpSig( PredefinedType.PT_INT, UnaOpMask.Signed, 7, BindIntUnaOp, UnaOpFuncKind.IntUnaOp ), new UnaOpSig( PredefinedType.PT_UINT, UnaOpMask.Unsigned, 6, BindIntUnaOp, UnaOpFuncKind.IntUnaOp ), @@ -135,6 +143,7 @@ Note that pointer operators cannot be lifted over nullable and are not callable }; [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprBinOp BindUserDefinedBinOp(ExpressionKind ek, BinOpArgInfo info) { MethPropWithInst pmpwi; @@ -172,6 +181,7 @@ private ExprBinOp BindUserDefinedBinOp(ExpressionKind ek, BinOpArgInfo info) // Adds special signatures to the candidate list. If we find an exact match // then it will be the last item on the list and we return true. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool GetSpecialBinopSignatures(List prgbofs, BinOpArgInfo info) { Debug.Assert(prgbofs != null); @@ -188,6 +198,7 @@ private bool GetSpecialBinopSignatures(List prgbofs, BinOpArgInfo // then it will be the last item on the list and we return true. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool GetStandardAndLiftedBinopSignatures(List rgbofs, BinOpArgInfo info) { Debug.Assert(rgbofs != null); @@ -392,6 +403,7 @@ private bool GetStandardAndLiftedBinopSignatures(List rgbofs, BinO // Returns the index of the best match, or -1 if there is no best match. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private int FindBestSignatureInList( List binopSignatures, BinOpArgInfo info) @@ -449,6 +461,7 @@ private int FindBestSignatureInList( } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprBinOp BindNullEqualityComparison(ExpressionKind ek, BinOpArgInfo info) { Expr arg1 = info.arg1; @@ -483,6 +496,7 @@ applying overload resolution to the predefined operators. It handles lifting ove */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public Expr BindStandardBinop(ExpressionKind ek, Expr arg1, Expr arg2) { Debug.Assert(arg1 != null); @@ -558,6 +572,7 @@ public Expr BindStandardBinop(ExpressionKind ek, Expr arg1, Expr arg2) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr BindStandardBinopCore(BinOpArgInfo info, BinOpFullSig bofs, ExpressionKind ek, EXPRFLAG flags) { if (bofs.pfn == null) @@ -600,6 +615,7 @@ private Expr BindStandardBinopCore(BinOpArgInfo info, BinOpFullSig bofs, Express } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprBinOp BindLiftedStandardBinOp(BinOpArgInfo info, BinOpFullSig bofs, ExpressionKind ek, EXPRFLAG flags) { Debug.Assert(bofs.Type1() is NullableType || bofs.Type2() is NullableType); @@ -654,6 +670,7 @@ private ExprBinOp BindLiftedStandardBinOp(BinOpArgInfo info, BinOpFullSig bofs, ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private void LiftArgument(Expr pArgument, CType pParameterType, bool bConvertBeforeLift, out Expr ppLiftedArgument, out Expr ppNonLiftedArgument) { @@ -689,6 +706,7 @@ Get the special signatures when at least one of the args is a delegate instance. Returns true iff an exact signature match is found. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool GetDelBinOpSigs(List prgbofs, BinOpArgInfo info) { if (!info.ValidForDelegate() || !info.type1.IsDelegateType && !info.type2.IsDelegateType) @@ -729,6 +747,7 @@ private bool GetDelBinOpSigs(List prgbofs, BinOpArgInfo info) scenario or lifted scenario. Sets pgrflt, ptypeSig1 and ptypeSig2 accordingly. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool CanConvertArg1(BinOpArgInfo info, CType typeDst, out LiftFlags pgrflt, out CType ptypeSig1, out CType ptypeSig2) { @@ -764,6 +783,7 @@ private bool CanConvertArg1(BinOpArgInfo info, CType typeDst, out LiftFlags pgrf Same as CanConvertArg1 but with the indices interchanged! */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool CanConvertArg2(BinOpArgInfo info, CType typeDst, out LiftFlags pgrflt, out CType ptypeSig1, out CType ptypeSig2) { @@ -800,6 +820,7 @@ Record the appropriate binary operator full signature from the given BinOpArgInf that any NullableType valued args should be lifted. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void RecordBinOpSigFromArgs(List prgbofs, BinOpArgInfo info) { LiftFlags grflt = LiftFlags.None; @@ -836,6 +857,7 @@ private static void RecordBinOpSigFromArgs(List prgbofs, BinOpArgI we find an exact match. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool GetEnumBinOpSigs(List prgbofs, BinOpArgInfo info) { if (!info.typeRaw1.IsEnumType && !info.typeRaw2.IsEnumType) @@ -908,6 +930,7 @@ may be applicable and better (or ambiguous)! This also handles == on System.Dele it has special rules as well. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool GetRefEqualSigs(List prgbofs, BinOpArgInfo info) { if (info.mask != BinOpMask.Equal) @@ -1029,6 +1052,7 @@ Because of user defined conversion operators this relation is not transitive. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private int WhichBofsIsBetter(BinOpFullSig bofs1, BinOpFullSig bofs2, CType type1, CType type2) { BetterType bt1; @@ -1151,6 +1175,7 @@ private static (ExpressionKind, UnaOpKind, EXPRFLAG) CalculateExprAndUnaryOpKind } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public Expr BindStandardUnaryOperator(OperatorKind op, Expr pArgument) { Debug.Assert(pArgument != null); @@ -1293,6 +1318,7 @@ public Expr BindStandardUnaryOperator(OperatorKind op, Expr pArgument) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private UnaryOperatorSignatureFindResult PopulateSignatureList(Expr pArgument, UnaOpKind unaryOpKind, UnaOpMask unaryOpMask, ExpressionKind exprKind, EXPRFLAG flags, List pSignatures, out Expr ppResult) { // We should have already checked argument != null and argument.type != null. @@ -1384,6 +1410,7 @@ private UnaryOperatorSignatureFindResult PopulateSignatureList(Expr pArgument, U ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool FindApplicableSignatures( Expr pArgument, UnaOpMask unaryOpMask, @@ -1510,6 +1537,7 @@ private bool FindApplicableSignatures( } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprOperator BindLiftedStandardUnop(ExpressionKind ek, EXPRFLAG flags, Expr arg, UnaOpFullSig uofs) { NullableType type = uofs.GetType() as NullableType; @@ -1536,6 +1564,7 @@ private ExprOperator BindLiftedStandardUnop(ExpressionKind ek, EXPRFLAG flags, E Returns negative if iuos1 is better, positive if iuos2 is better, 0 if neither. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private int WhichUofsIsBetter(UnaOpFullSig uofs1, UnaOpFullSig uofs2, CType typeArg) { BetterType bt; @@ -1562,6 +1591,7 @@ private int WhichUofsIsBetter(UnaOpFullSig uofs1, UnaOpFullSig uofs2, CType type /* Handles standard binary integer based operators. */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprOperator BindIntBinOp(ExpressionBinder binder, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(arg1.Type.IsPredefined && arg2.Type.IsPredefined && arg1.Type.PredefinedType == arg2.Type.PredefinedType); @@ -1572,6 +1602,7 @@ private static ExprOperator BindIntBinOp(ExpressionBinder binder, ExpressionKind /* Handles standard unary integer based operators. */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprOperator BindIntUnaOp(ExpressionBinder binder, ExpressionKind ek, EXPRFLAG flags, Expr arg) { Debug.Assert(arg.Type.IsPredefined); @@ -1582,6 +1613,7 @@ private static ExprOperator BindIntUnaOp(ExpressionBinder binder, ExpressionKind /* Handles standard binary floating point (float, double) based operators. */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprOperator BindRealBinOp(ExpressionBinder binder, ExpressionKind ek, EXPRFLAG _, Expr arg1, Expr arg2) { Debug.Assert(arg1.Type.IsPredefined && arg2.Type.IsPredefined && arg1.Type.PredefinedType == arg2.Type.PredefinedType); @@ -1592,6 +1624,7 @@ private static ExprOperator BindRealBinOp(ExpressionBinder binder, ExpressionKin /* Handles standard unary floating point (float, double) based operators. */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprOperator BindRealUnaOp(ExpressionBinder binder, ExpressionKind ek, EXPRFLAG _, Expr arg) { Debug.Assert(arg.Type.IsPredefined); @@ -1603,6 +1636,7 @@ private static ExprOperator BindRealUnaOp(ExpressionBinder binder, ExpressionKin Handles standard increment and decrement operators. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr BindIncOp(ExpressionKind ek, EXPRFLAG flags, Expr arg, UnaOpFullSig uofs) { Debug.Assert(ek == ExpressionKind.Add || ek == ExpressionKind.Subtract); @@ -1627,6 +1661,7 @@ private Expr BindIncOp(ExpressionKind ek, EXPRFLAG flags, Expr arg, UnaOpFullSig } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr BindIncOpCore(ExpressionKind ek, EXPRFLAG flags, Expr exprVal, CType type) { Debug.Assert(ek == ExpressionKind.Add || ek == ExpressionKind.Subtract); @@ -1685,6 +1720,7 @@ private Expr BindIncOpCore(ExpressionKind ek, EXPRFLAG flags, Expr exprVal, CTyp } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr LScalar(ExpressionKind ek, EXPRFLAG flags, Expr exprVal, CType type, ConstVal cv, CType typeTmp) { CType typeOne = type; @@ -1699,6 +1735,7 @@ private Expr LScalar(ExpressionKind ek, EXPRFLAG flags, Expr exprVal, CType type } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprMulti BindNonliftedIncOp(ExpressionKind ek, EXPRFLAG flags, Expr arg, UnaOpFullSig uofs) { Debug.Assert(ek == ExpressionKind.Add || ek == ExpressionKind.Subtract); @@ -1726,6 +1763,7 @@ private ExprMulti BindNonliftedIncOp(ExpressionKind ek, EXPRFLAG flags, Expr arg } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprMulti BindLiftedIncOp(ExpressionKind ek, EXPRFLAG flags, Expr arg, UnaOpFullSig uofs) { Debug.Assert(ek == ExpressionKind.Add || ek == ExpressionKind.Subtract); @@ -1760,6 +1798,7 @@ Here is how it works. */ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprBinOp BindDecBinOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(arg1.Type.IsPredefType(PredefinedType.PT_DECIMAL) && arg2.Type.IsPredefType(PredefinedType.PT_DECIMAL)); @@ -1802,6 +1841,7 @@ Handles standard unary decimal based operators. [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprUnaryOp BindDecUnaOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg) { Debug.Assert(arg.Type.IsPredefType(PredefinedType.PT_DECIMAL)); @@ -1822,6 +1862,7 @@ private static ExprUnaryOp BindDecUnaOp(ExpressionBinder _, ExpressionKind ek, E /* Handles string concatenation. */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Expr BindStrBinOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(ek == ExpressionKind.Add); @@ -1834,6 +1875,7 @@ private static Expr BindStrBinOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG Bind a shift operator: <<, >>. These can have integer or long first operands, and second operand must be int. */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprBinOp BindShiftOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(ek == ExpressionKind.LeftShirt || ek == ExpressionKind.RightShift); @@ -1852,6 +1894,7 @@ result will be a constant also. */ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprBinOp BindBoolBinOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(arg1 != null); @@ -1863,6 +1906,7 @@ private static ExprBinOp BindBoolBinOp(ExpressionBinder _, ExpressionKind ek, EX } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprOperator BindBoolBitwiseOp(ExpressionKind ek, EXPRFLAG flags, Expr expr1, Expr expr2) { Debug.Assert(ek == ExpressionKind.BitwiseAnd || ek == ExpressionKind.BitwiseOr); @@ -1907,6 +1951,7 @@ Handles boolean unary operator (!). */ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Expr BindBoolUnaOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg) { Debug.Assert(arg.Type.IsPredefType(PredefinedType.PT_BOOL)); @@ -1932,6 +1977,7 @@ Handles string equality. */ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprBinOp BindStrCmpOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(ek == ExpressionKind.Eq || ek == ExpressionKind.NotEq); @@ -1950,6 +1996,7 @@ private static ExprBinOp BindStrCmpOp(ExpressionBinder _, ExpressionKind ek, EXP Handles reference equality operators. Type variables come through here. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprBinOp BindRefCmpOp(ExpressionBinder binder, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(ek == ExpressionKind.Eq || ek == ExpressionKind.NotEq); @@ -1966,6 +2013,7 @@ private static ExprBinOp BindRefCmpOp(ExpressionBinder binder, ExpressionKind ek Handles delegate binary operators. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Expr BindDelBinOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(ek == ExpressionKind.Add || ek == ExpressionKind.Subtract || ek == ExpressionKind.Eq || ek == ExpressionKind.NotEq); @@ -2007,6 +2055,7 @@ private static Expr BindDelBinOp(ExpressionBinder _, ExpressionKind ek, EXPRFLAG Handles enum binary operators. */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Expr BindEnumBinOp(ExpressionBinder binder, ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { AggregateType typeDst = GetEnumBinOpType(ek, arg1.Type, arg2.Type, out AggregateType typeEnum); @@ -2036,6 +2085,7 @@ private static Expr BindEnumBinOp(ExpressionBinder binder, ExpressionKind ek, EX } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr BindLiftedEnumArithmeticBinOp(ExpressionKind ek, EXPRFLAG flags, Expr arg1, Expr arg2) { Debug.Assert(ek == ExpressionKind.Add || ek == ExpressionKind.Subtract); @@ -2083,6 +2133,7 @@ private Expr BindLiftedEnumArithmeticBinOp(ExpressionKind ek, EXPRFLAG flags, Ex Handles enum unary operator (~). */ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Expr BindEnumUnaOp(ExpressionBinder binder, ExpressionKind ek, EXPRFLAG flags, Expr arg) { Debug.Assert(ek == ExpressionKind.BitwiseNot); @@ -2184,6 +2235,7 @@ assumed to be already converted to the correct types. */ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprOperator BindIntOp(ExpressionKind kind, EXPRFLAG flags, Expr op1, Expr op2, PredefinedType ptOp) { //Debug.Assert(kind.isRelational() || kind.isArithmetic() || kind.isBitwise()); @@ -2209,6 +2261,7 @@ private ExprOperator BindIntOp(ExpressionKind kind, EXPRFLAG flags, Expr op1, Ex [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprOperator BindIntegerNeg(EXPRFLAG flags, Expr op, PredefinedType ptOp) { // 14.6.2 Unary minus operator @@ -2269,6 +2322,7 @@ to be already converted to the correct type. [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprOperator BindFloatOp(ExpressionKind kind, Expr op1, Expr op2) { //Debug.Assert(kind.isRelational() || kind.isArithmetic()); @@ -2286,6 +2340,7 @@ private static ExprOperator BindFloatOp(ExpressionKind kind, Expr op1, Expr op2) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "All types used here are builtin and will not be trimmed.")] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprConcat BindStringConcat(Expr op1, Expr op2) { // If the concatenation consists solely of two constants then we must @@ -2312,6 +2367,7 @@ private static ExprConcat BindStringConcat(Expr op1, Expr op2) /* Report an ambiguous operator types error. */ + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static RuntimeBinderException AmbiguousOperatorError(Expr op1, Expr op2) { Debug.Assert(op1 != null); @@ -2327,6 +2383,7 @@ private static RuntimeBinderException AmbiguousOperatorError(Expr op1, Expr op2) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private Expr BindUserBoolOp(ExpressionKind kind, ExprCall pCall) { Debug.Assert(pCall != null); @@ -2382,6 +2439,7 @@ private static AggregateType GetUserDefinedBinopArgumentType(CType type) return null; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static int GetUserDefinedBinopArgumentTypes(CType type1, CType type2, AggregateType[] rgats) { int cats = 0; @@ -2403,6 +2461,7 @@ private static int GetUserDefinedBinopArgumentTypes(CType type1, CType type2, Ag return cats; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool UserDefinedBinaryOperatorCanBeLifted(ExpressionKind ek, MethodSymbol method, AggregateType ats, TypeArray Params) { @@ -2447,6 +2506,7 @@ private static bool UserDefinedBinaryOperatorCanBeLifted(ExpressionKind ek, Meth // If the operator is applicable in either its regular or lifted forms, // add it to the candidate set and return true, otherwise return false. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool UserDefinedBinaryOperatorIsApplicable(List candidateList, ExpressionKind ek, MethodSymbol method, AggregateType ats, Expr arg1, Expr arg2, bool fDontLift) { @@ -2485,6 +2545,7 @@ private bool UserDefinedBinaryOperatorIsApplicable(List } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private bool GetApplicableUserDefinedBinaryOperatorCandidates( List candidateList, ExpressionKind ek, AggregateType type, Expr arg1, Expr arg2, bool fDontLift) @@ -2505,6 +2566,7 @@ private bool GetApplicableUserDefinedBinaryOperatorCandidates( } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private AggregateType GetApplicableUserDefinedBinaryOperatorCandidatesInBaseTypes( List candidateList, ExpressionKind ek, AggregateType type, Expr arg1, Expr arg2, bool fDontLift, AggregateType atsStop) @@ -2521,6 +2583,7 @@ private AggregateType GetApplicableUserDefinedBinaryOperatorCandidatesInBaseType } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprCall BindUDBinop(ExpressionKind ek, Expr arg1, Expr arg2, bool fDontLift, out MethPropWithInst ppmpwi) { List methFirst = new List(); @@ -2580,6 +2643,7 @@ private ExprCall BindUDBinop(ExpressionKind ek, Expr arg1, Expr arg2, bool fDont } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprCall BindUDBinopCall(Expr arg1, Expr arg2, TypeArray Params, CType typeRet, MethPropWithInst mpwi) { arg1 = mustConvert(arg1, Params[0]); @@ -2599,6 +2663,7 @@ private ExprCall BindUDBinopCall(Expr arg1, Expr arg2, TypeArray Params, CType t } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private ExprCall BindLiftedUDBinop(ExpressionKind ek, Expr arg1, Expr arg2, TypeArray Params, MethPropWithInst mpwi) { Expr exprVal1 = arg1; @@ -2677,6 +2742,7 @@ private ExprCall BindLiftedUDBinop(ExpressionKind ek, Expr arg1, Expr arg2, Type } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static AggregateType GetEnumBinOpType(ExpressionKind ek, CType argType1, CType argType2, out AggregateType ppEnumType) { Debug.Assert(argType1.IsEnumType || argType2.IsEnumType); @@ -2719,6 +2785,7 @@ private static AggregateType GetEnumBinOpType(ExpressionKind ek, CType argType1, } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprBinOp CreateBinopForPredefMethodCall(ExpressionKind ek, PREDEFMETH predefMeth, CType RetType, Expr arg1, Expr arg2) { MethodSymbol methSym = PredefinedMembers.GetMethod(predefMeth); @@ -2734,6 +2801,7 @@ private static ExprBinOp CreateBinopForPredefMethodCall(ExpressionKind ek, PREDE } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ExprUnaryOp CreateUnaryOpForPredefMethodCall(ExpressionKind ek, PREDEFMETH predefMeth, CType pRetType, Expr pArg) { MethodSymbol methSym = PredefinedMembers.GetMethod(predefMeth); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/PredefinedMembers.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/PredefinedMembers.cs index 6f6ad506e5ef44..bfc3fdb96ca38f 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/PredefinedMembers.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/PredefinedMembers.cs @@ -199,6 +199,7 @@ internal static class PredefinedMembers private static readonly PropertySymbol[] _properties = new PropertySymbol[(int)PREDEFPROP.PP_COUNT]; [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static PropertySymbol LoadProperty(PREDEFPROP property) { PredefinedPropertyInfo info = GetPropInfo(property); @@ -206,6 +207,7 @@ private static PropertySymbol LoadProperty(PREDEFPROP property) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static PropertySymbol LoadProperty( PREDEFPROP predefProp, Name propertyName, @@ -225,9 +227,11 @@ private static PropertySymbol LoadProperty( } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static AggregateSymbol GetPredefAgg(PredefinedType pt) => SymbolLoader.GetPredefAgg(pt); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static CType LoadTypeFromSignature(int[] signature, ref int indexIntoSignatures, TypeArray classTyVars) { Debug.Assert(signature != null); @@ -268,6 +272,7 @@ private static CType LoadTypeFromSignature(int[] signature, ref int indexIntoSig } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] [RequiresUnreferencedCode(Binder.TrimmerWarning)] private static TypeArray LoadTypeArrayFromSignature(int[] signature, ref int indexIntoSignatures, TypeArray classTyVars) { @@ -303,6 +308,7 @@ static PredefinedMembers() #endif [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static PropertySymbol GetProperty(PREDEFPROP property) { Debug.Assert(property >= 0 && property < PREDEFPROP.PP_COUNT); @@ -310,6 +316,7 @@ public static PropertySymbol GetProperty(PREDEFPROP property) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static MethodSymbol GetMethod(PREDEFMETH method) { Debug.Assert(method >= 0 && method < PREDEFMETH.PM_COUNT); @@ -317,6 +324,7 @@ public static MethodSymbol GetMethod(PREDEFMETH method) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static MethodSymbol LoadMethod( AggregateSymbol type, int[] signature, @@ -350,6 +358,7 @@ bool isVirtual return ret; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static MethodSymbol LookupMethodWhileLoading(AggregateSymbol type, int cMethodTyVars, Name methodName, ACCESS methodAccess, bool isStatic, bool isVirtual, CType returnType, TypeArray argumentTypes) { for (Symbol sym = SymbolLoader.LookupAggMember(methodName, type, symbmask_t.MASK_ALL); @@ -373,6 +382,7 @@ private static MethodSymbol LookupMethodWhileLoading(AggregateSymbol type, int c } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static MethodSymbol LoadMethod(PREDEFMETH method) { PredefinedMethodInfo info = GetMethInfo(method); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/SemanticChecker.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/SemanticChecker.cs index 620094db1ef9f9..73c386b49311ff 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/SemanticChecker.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/SemanticChecker.cs @@ -21,6 +21,7 @@ internal enum ACCESSERROR internal static class CSemanticChecker { // Generate an error if CType is static. + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static void CheckForStaticClass(CType type) { if (type.IsStaticClass) @@ -30,6 +31,7 @@ public static void CheckForStaticClass(CType type) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ACCESSERROR CheckAccess2(Symbol symCheck, AggregateType atsCheck, Symbol symWhere, CType typeThru) { Debug.Assert(symCheck != null); @@ -80,6 +82,7 @@ typeThru is ArrayType || } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool CheckTypeAccess(CType type, Symbol symWhere) { Debug.Assert(type != null); @@ -114,6 +117,7 @@ public static bool CheckTypeAccess(CType type, Symbol symWhere) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static ACCESSERROR CheckAccessCore(Symbol symCheck, AggregateType atsCheck, Symbol symWhere, CType typeThru) { Debug.Assert(symCheck != null); @@ -251,6 +255,7 @@ typeThru is ArrayType || public static bool CheckBogus(Symbol sym) => (sym as PropertySymbol)?.Bogus ?? false; [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static RuntimeBinderException ReportAccessError(SymWithType swtBad, Symbol symWhere, CType typeQual) { Debug.Assert(!CheckAccess(swtBad.Sym, swtBad.GetType(), symWhere, typeQual) || @@ -263,6 +268,7 @@ public static RuntimeBinderException ReportAccessError(SymWithType swtBad, Symbo } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool CheckAccess(Symbol symCheck, AggregateType atsCheck, Symbol symWhere, CType typeThru) => CheckAccess2(symCheck, atsCheck, symWhere, typeThru) == ACCESSERROR.ACCESSERROR_NOERROR; } diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/AggregateSymbol.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/AggregateSymbol.cs index b23ab911f297b0..7176c55673a3a4 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/AggregateSymbol.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/AggregateSymbol.cs @@ -14,7 +14,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics // AggregateSymbol - a symbol representing an aggregate type. These are classes, // interfaces, and structs. Parent is a namespace or class. Children are methods, // properties, and member variables, and types (including its own AGGTYPESYMs). - + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class AggregateSymbol : NamespaceOrAggregateSymbol { public Type AssociatedSystemType; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymFactory.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymFactory.cs index 98b8b18a297376..f4a566f12e15c3 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymFactory.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymFactory.cs @@ -2,12 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using Microsoft.CSharp.RuntimeBinder.Syntax; namespace Microsoft.CSharp.RuntimeBinder.Semantics { internal static class SymFactory { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static Symbol NewBasicSymbol( SYMKIND kind, Name name, @@ -73,6 +75,7 @@ private static Symbol NewBasicSymbol( } // Namespace + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static NamespaceSymbol CreateNamespace(Name name, NamespaceSymbol parent) { NamespaceSymbol sym = (NamespaceSymbol)NewBasicSymbol(SYMKIND.SK_NamespaceSymbol, name, parent); @@ -82,6 +85,7 @@ public static NamespaceSymbol CreateNamespace(Name name, NamespaceSymbol parent) } ///////////////////////////////////////////////////////////////////////////////// + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateSymbol CreateAggregate(Name name, NamespaceOrAggregateSymbol parent) { Debug.Assert(name != null); @@ -99,6 +103,7 @@ public static AggregateSymbol CreateAggregate(Name name, NamespaceOrAggregateSym } // Members of aggs + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static FieldSymbol CreateMemberVar(Name name, AggregateSymbol parent) { Debug.Assert(name != null); @@ -109,6 +114,7 @@ public static FieldSymbol CreateMemberVar(Name name, AggregateSymbol parent) return sym; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static LocalVariableSymbol CreateLocalVar(Name name, Scope parent, CType type) { LocalVariableSymbol sym = (LocalVariableSymbol)NewBasicSymbol(SYMKIND.SK_LocalVariableSymbol, name, parent); @@ -119,9 +125,11 @@ public static LocalVariableSymbol CreateLocalVar(Name name, Scope parent, CType return sym; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static MethodSymbol CreateMethod(Name name, AggregateSymbol parent) => NewBasicSymbol(SYMKIND.SK_MethodSymbol, name, parent) as MethodSymbol; + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static PropertySymbol CreateProperty(Name name, AggregateSymbol parent) { PropertySymbol sym = NewBasicSymbol(SYMKIND.SK_PropertySymbol, name, parent) as PropertySymbol; @@ -129,6 +137,7 @@ public static PropertySymbol CreateProperty(Name name, AggregateSymbol parent) return sym; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static EventSymbol CreateEvent(Name name, AggregateSymbol parent) { EventSymbol sym = NewBasicSymbol(SYMKIND.SK_EventSymbol, name, parent) as EventSymbol; @@ -137,6 +146,7 @@ public static EventSymbol CreateEvent(Name name, AggregateSymbol parent) return sym; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static TypeParameterSymbol CreateMethodTypeParameter(Name pName, MethodSymbol pParent, int index, int indexTotal) { TypeParameterSymbol pResult = (TypeParameterSymbol)NewBasicSymbol(SYMKIND.SK_TypeParameterSymbol, pName, pParent); @@ -149,6 +159,7 @@ public static TypeParameterSymbol CreateMethodTypeParameter(Name pName, MethodSy return pResult; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static TypeParameterSymbol CreateClassTypeParameter(Name pName, AggregateSymbol pParent, int index, int indexTotal) { TypeParameterSymbol pResult = (TypeParameterSymbol)NewBasicSymbol(SYMKIND.SK_TypeParameterSymbol, pName, pParent); @@ -161,8 +172,10 @@ public static TypeParameterSymbol CreateClassTypeParameter(Name pName, Aggregate return pResult; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static Scope CreateScope() => (Scope)NewBasicSymbol(SYMKIND.SK_Scope, null, null); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static IndexerSymbol CreateIndexer(Name name, ParentSymbol parent) { IndexerSymbol sym = (IndexerSymbol)NewBasicSymbol(SYMKIND.SK_IndexerSymbol, name, parent); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolLoader.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolLoader.cs index 7899c66348f63c..afdf1a32668114 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolLoader.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Symbols/SymbolLoader.cs @@ -10,14 +10,17 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics internal static class SymbolLoader { [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateSymbol GetPredefAgg(PredefinedType pt) => TypeManager.GetPredefAgg(pt); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateType GetPredefindType(PredefinedType pt) => GetPredefAgg(pt).getThisType(); public static Symbol LookupAggMember(Name name, AggregateSymbol agg, symbmask_t mask) => SymbolStore.LookupSym(name, agg, mask); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool IsBaseInterface(AggregateType atsDer, AggregateType pBase) { Debug.Assert(atsDer != null); @@ -42,6 +45,7 @@ private static bool IsBaseInterface(AggregateType atsDer, AggregateType pBase) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool IsBaseClassOfClass(CType pDerived, CType pBase) { Debug.Assert(pDerived != null); @@ -53,6 +57,7 @@ public static bool IsBaseClassOfClass(CType pDerived, CType pBase) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool IsBaseClass(CType pDerived, CType pBase) { Debug.Assert(pDerived != null); @@ -91,6 +96,7 @@ private static bool IsBaseClass(CType pDerived, CType pBase) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool HasCovariantArrayConversion(ArrayType pSource, ArrayType pDest) { Debug.Assert(pSource != null); @@ -103,6 +109,7 @@ private static bool HasCovariantArrayConversion(ArrayType pSource, ArrayType pDe } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool HasIdentityOrImplicitReferenceConversion(CType pSource, CType pDest) { Debug.Assert(pSource != null); @@ -118,6 +125,7 @@ public static bool HasIdentityOrImplicitReferenceConversion(CType pSource, CType private static bool AreTypesEqualForConversion(CType pType1, CType pType2) => pType1.Equals(pType2); [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool HasArrayConversionToInterface(ArrayType pSource, CType pDest) { Debug.Assert(pSource != null); @@ -160,6 +168,7 @@ private static bool HasArrayConversionToInterface(ArrayType pSource, CType pDest } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool HasImplicitReferenceConversion(CType pSource, CType pDest) { Debug.Assert(pSource != null); @@ -287,6 +296,7 @@ private static bool HasImplicitReferenceConversion(CType pSource, CType pDest) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool HasAnyBaseInterfaceConversion(CType pDerived, CType pBase) { if (!pBase.IsInterfaceType || !(pDerived is AggregateType atsDer)) @@ -325,6 +335,7 @@ private static bool HasAnyBaseInterfaceConversion(CType pDerived, CType pBase) // equal to Ti, or there is an implicit reference conversion from Ti to Si. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool HasInterfaceConversion(AggregateType pSource, AggregateType pDest) { Debug.Assert(pSource != null && pSource.IsInterfaceType); @@ -335,6 +346,7 @@ private static bool HasInterfaceConversion(AggregateType pSource, AggregateType ////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool HasDelegateConversion(AggregateType pSource, AggregateType pDest) { Debug.Assert(pSource != null && pSource.IsDelegateType); @@ -345,6 +357,7 @@ private static bool HasDelegateConversion(AggregateType pSource, AggregateType p ////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool HasVariantConversion(AggregateType pSource, AggregateType pDest) { Debug.Assert(pSource != null); @@ -400,6 +413,7 @@ private static bool HasVariantConversion(AggregateType pSource, AggregateType pD } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool HasImplicitBoxingConversion(CType pSource, CType pDest) { Debug.Assert(pSource != null); @@ -438,6 +452,7 @@ private static bool HasImplicitBoxingConversion(CType pSource, CType pDest) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool HasBaseConversion(CType pSource, CType pDest) { // By a "base conversion" we mean: diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/MethodInfo.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/MethodInfo.cs index ae36dd5e67d9fe..c5e2564816bc8f 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/MethodInfo.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/MethodInfo.cs @@ -8,6 +8,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class ExprMethodInfo : ExprWithType { public ExprMethodInfo(CType type, MethodSymbol method, AggregateType methodType, TypeArray methodParameters) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/PropertyInfo.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/PropertyInfo.cs index 5e1170bd080d98..51d8b7c251b2d9 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/PropertyInfo.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/PropertyInfo.cs @@ -23,6 +23,7 @@ public ExprPropertyInfo(CType type, PropertySymbol propertySymbol, AggregateType public PropertyInfo PropertyInfo { [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] get { // To do this, we need to construct a type array of the parameter types, diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/Visitors/ExpressionTreeRewriter.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/Visitors/ExpressionTreeRewriter.cs index 8ca065a59748fc..da06d01ca34d2e 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/Visitors/ExpressionTreeRewriter.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Tree/Visitors/ExpressionTreeRewriter.cs @@ -7,6 +7,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics { + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class ExpressionTreeRewriter : ExprVisitorBase { [RequiresUnreferencedCode(Binder.TrimmerWarning)] diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/TypeBind.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/TypeBind.cs index 1447c50e853d41..e0de4a45620831 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/TypeBind.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/TypeBind.cs @@ -33,6 +33,7 @@ internal static class TypeBind { // Check the constraints of any type arguments in the given Type. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool CheckConstraints(CType type, CheckConstraintsFlags flags) { type = type.GetNakedType(false); @@ -120,6 +121,7 @@ public static bool CheckConstraints(CType type, CheckConstraintsFlags flags) //////////////////////////////////////////////////////////////////////////////// // Check the constraints on the method instantiation. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static void CheckMethConstraints(MethWithInst mwi) { Debug.Assert(mwi.Meth() != null && mwi.GetType() != null && mwi.TypeArgs != null); @@ -137,6 +139,7 @@ public static void CheckMethConstraints(MethWithInst mwi) // typeArgsCls and typeArgsMeth are used for substitution on the bounds. The // tree and symErr are used for error reporting. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool CheckConstraintsCore(Symbol symErr, TypeArray typeVars, TypeArray typeArgs, TypeArray typeArgsCls, TypeArray typeArgsMeth, CheckConstraintsFlags flags) { Debug.Assert(typeVars.Count == typeArgs.Count); @@ -159,6 +162,7 @@ private static bool CheckConstraintsCore(Symbol symErr, TypeArray typeVars, Type } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool CheckSingleConstraint(Symbol symErr, TypeParameterType var, CType arg, TypeArray typeArgsCls, TypeArray typeArgsMeth, CheckConstraintsFlags flags) { Debug.Assert(!(arg is PointerType)); @@ -304,6 +308,7 @@ private static bool CheckSingleConstraint(Symbol symErr, TypeParameterType var, // constraints). [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool SatisfiesBound(CType arg, CType typeBnd) { if (typeBnd == arg) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/AggregateType.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/AggregateType.cs index e1f68f49e25988..12aabf321f012f 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/AggregateType.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/AggregateType.cs @@ -15,7 +15,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics // // Represents a generic constructed (or instantiated) type. Parent is the AggregateSymbol. // ---------------------------------------------------------------------------- - + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class AggregateType : CType { private AggregateType _baseType; // This is the result of calling SubstTypeArray on the aggregate's baseClass. diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/ArrayType.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/ArrayType.cs index e4a81400708a87..aa7b6d44fab158 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/ArrayType.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/ArrayType.cs @@ -10,7 +10,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics // ---------------------------------------------------------------------------- // ArrayType - a symbol representing an array. // ---------------------------------------------------------------------------- - + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class ArrayType : CType { public ArrayType(CType elementType, int rank, bool isSZArray) diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/NullableType.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/NullableType.cs index 5f127acddcb668..a9701907829d7d 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/NullableType.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/NullableType.cs @@ -14,7 +14,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics // A "derived" type representing Nullable. The base type T is the parent. // // ---------------------------------------------------------------------------- - + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal sealed class NullableType : CType { private AggregateType _ats; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/PredefinedTypes.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/PredefinedTypes.cs index 4e8750fb5109bc..b467ec244c5f18 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/PredefinedTypes.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/PredefinedTypes.cs @@ -15,6 +15,7 @@ internal static class PredefinedTypes // We want to delay load the predefined symbols as needed. [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static AggregateSymbol DelayLoadPredefSym(PredefinedType pt) { AggregateType type = (AggregateType)SymbolTable.GetCTypeFromType(PredefinedTypeFacts.GetAssociatedSystemType(pt)); @@ -32,6 +33,7 @@ internal static AggregateSymbol InitializePredefinedType(AggregateSymbol sym, Pr } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateSymbol GetPredefinedAggregate(PredefinedType pt) => s_predefSymbols[(int)pt] ??= DelayLoadPredefSym(pt); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/TypeManager.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/TypeManager.cs index df3805eea7a013..3da4c9012c8a22 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/TypeManager.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/TypeManager.cs @@ -64,6 +64,7 @@ public TypeParameterType GetTypeVarSym(int iv, bool fMeth) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static ArrayType GetArray(CType elementType, int args, bool isSZArray) { Debug.Assert(args > 0 && args < 32767); @@ -86,6 +87,7 @@ public static ArrayType GetArray(CType elementType, int args, bool isSZArray) return pArray; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateType GetAggregate(AggregateSymbol agg, AggregateType atsOuter, TypeArray typeArgs) { Debug.Assert(atsOuter == null || atsOuter.OwningAggregate == agg.Parent, ""); @@ -110,6 +112,7 @@ public static AggregateType GetAggregate(AggregateSymbol agg, AggregateType atsO return pAggregate; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateType GetAggregate(AggregateSymbol agg, TypeArray typeArgsAll) { Debug.Assert(typeArgsAll != null && typeArgsAll.Count == agg.GetTypeVarsAll().Count); @@ -132,6 +135,7 @@ public static AggregateType GetAggregate(AggregateSymbol agg, TypeArray typeArgs return GetAggregate(agg, atsOuter, typeArgsInner); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static PointerType GetPointer(CType baseType) { PointerType pPointer = TypeTable.LookupPointer(baseType); @@ -147,6 +151,7 @@ public static PointerType GetPointer(CType baseType) return pPointer; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static NullableType GetNullable(CType pUnderlyingType) { Debug.Assert(!(pUnderlyingType is NullableType), "Attempt to make nullable of nullable"); @@ -177,8 +182,10 @@ public static ParameterModifierType GetParameterModifier(CType paramType, bool i } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateSymbol GetNullable() => GetPredefAgg(PredefinedType.PT_G_OPTIONAL); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static CType SubstType(CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, bool denormMeth) { Debug.Assert(typeSrc != null); @@ -186,6 +193,7 @@ private static CType SubstType(CType typeSrc, TypeArray typeArgsCls, TypeArray t return ctx.IsNop ? typeSrc : SubstTypeCore(typeSrc, ctx); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateType SubstType(AggregateType typeSrc, TypeArray typeArgsCls) { Debug.Assert(typeSrc != null); @@ -194,9 +202,11 @@ public static AggregateType SubstType(AggregateType typeSrc, TypeArray typeArgsC return ctx.IsNop ? typeSrc : SubstTypeCore(typeSrc, ctx); } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static CType SubstType(CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth) => SubstType(typeSrc, typeArgsCls, typeArgsMeth, false); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static TypeArray SubstTypeArray(TypeArray taSrc, SubstContext ctx) { if (taSrc != null && taSrc.Count != 0 && ctx != null && !ctx.IsNop) @@ -224,13 +234,16 @@ public static TypeArray SubstTypeArray(TypeArray taSrc, SubstContext ctx) return taSrc; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static TypeArray SubstTypeArray(TypeArray taSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth) => taSrc == null || taSrc.Count == 0 ? taSrc : SubstTypeArray(taSrc, new SubstContext(typeArgsCls, typeArgsMeth, false)); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static TypeArray SubstTypeArray(TypeArray taSrc, TypeArray typeArgsCls) => SubstTypeArray(taSrc, typeArgsCls, null); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static AggregateType SubstTypeCore(AggregateType type, SubstContext ctx) { TypeArray args = type.TypeArgsAll; @@ -246,6 +259,7 @@ private static AggregateType SubstTypeCore(AggregateType type, SubstContext ctx) return type; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static CType SubstTypeCore(CType type, SubstContext pctx) { CType typeSrc; @@ -310,6 +324,7 @@ private static CType SubstTypeCore(CType type, SubstContext pctx) } } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool SubstEqualTypes(CType typeDst, CType typeSrc, TypeArray typeArgsCls, TypeArray typeArgsMeth, bool denormMeth) { if (typeDst.Equals(typeSrc)) @@ -544,30 +559,40 @@ public static bool TypeContainsTyVars(CType type, TypeArray typeVars) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateSymbol GetPredefAgg(PredefinedType pt) => PredefinedTypes.GetPredefinedAggregate(pt); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static AggregateType SubstType(AggregateType typeSrc, SubstContext ctx) => ctx == null || ctx.IsNop ? typeSrc : SubstTypeCore(typeSrc, ctx); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CType SubstType(CType typeSrc, SubstContext pctx) => pctx == null || pctx.IsNop ? typeSrc : SubstTypeCore(typeSrc, pctx); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CType SubstType(CType typeSrc, AggregateType atsCls) => SubstType(typeSrc, atsCls, null); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CType SubstType(CType typeSrc, AggregateType atsCls, TypeArray typeArgsMeth) => SubstType(typeSrc, atsCls?.TypeArgsAll, typeArgsMeth); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static CType SubstType(CType typeSrc, CType typeCls, TypeArray typeArgsMeth) => SubstType(typeSrc, (typeCls as AggregateType)?.TypeArgsAll, typeArgsMeth); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static TypeArray SubstTypeArray(TypeArray taSrc, AggregateType atsCls, TypeArray typeArgsMeth) => SubstTypeArray(taSrc, atsCls?.TypeArgsAll, typeArgsMeth); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static TypeArray SubstTypeArray(TypeArray taSrc, AggregateType atsCls) => SubstTypeArray(taSrc, atsCls, null); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool SubstEqualTypes(CType typeDst, CType typeSrc, CType typeCls, TypeArray typeArgsMeth) => SubstEqualTypes(typeDst, typeSrc, (typeCls as AggregateType)?.TypeArgsAll, typeArgsMeth, false); + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public static bool SubstEqualTypes(CType typeDst, CType typeSrc, CType typeCls) => SubstEqualTypes(typeDst, typeSrc, typeCls, null); public static TypeParameterType GetStdMethTypeVar(int iv) => s_stvcMethod.GetTypeVarSym(iv, true); @@ -584,6 +609,7 @@ public static TypeParameterType GetTypeParameter(TypeParameterSymbol pSymbol) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static CType GetBestAccessibleType(AggregateSymbol context, CType typeSrc) { // This method implements the "best accessible type" algorithm for determining the type @@ -661,6 +687,7 @@ internal static CType GetBestAccessibleType(AggregateSymbol context, CType typeS } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool TryVarianceAdjustmentToGetAccessibleType(AggregateSymbol context, AggregateType typeSrc, out CType typeDst) { Debug.Assert(typeSrc != null); @@ -722,6 +749,7 @@ private static bool TryVarianceAdjustmentToGetAccessibleType(AggregateSymbol con } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static bool TryArrayVarianceAdjustmentToGetAccessibleType(AggregateSymbol context, ArrayType typeSrc, out CType typeDst) { Debug.Assert(typeSrc != null); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/UnaOpSig.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/UnaOpSig.cs index 9c74f14f5c61c3..9fde98d55ed1c0 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/UnaOpSig.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/UnaOpSig.cs @@ -51,6 +51,7 @@ Set the values of the UnaOpFullSig from the given UnaOpSig. The ExpressionBinder the predefined type. Returns true iff the predef type is found. ***************************************************************************************************/ [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] public UnaOpFullSig(UnaOpSig uos) { this.pt = uos.pt; diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/SymbolTable.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/SymbolTable.cs index 451cdd5434697f..559fa6ffdb0bd8 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/SymbolTable.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/SymbolTable.cs @@ -46,6 +46,7 @@ public override bool Equals(object obj) } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static void PopulateSymbolTableWithName( string name, IEnumerable typeArguments, @@ -88,6 +89,7 @@ internal static void PopulateSymbolTableWithName( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static SymWithType LookupMember( string name, Expr callingObject, @@ -125,6 +127,7 @@ internal static SymWithType LookupMember( } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void AddParameterConversions(MethodBase method) { foreach (ParameterInfo param in method.GetParameters()) @@ -135,6 +138,7 @@ private static void AddParameterConversions(MethodBase method) #region InheritanceHierarchy [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void AddNamesOnType(NameHashKey key) { Debug.Assert(!s_namesLoadedForEachType.Contains(key)); @@ -149,6 +153,7 @@ private static void AddNamesOnType(NameHashKey key) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void AddNamesInInheritanceHierarchy(string name, List inheritance) { for (int i = inheritance.Count - 1; i >= 0; --i) @@ -231,6 +236,7 @@ private static void AddNamesInInheritanceHierarchy(string name, List inher ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static List CreateInheritanceHierarchyList(Type type) { List list; @@ -296,6 +302,7 @@ private static Name GetName(Type type) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static TypeArray GetMethodTypeParameters(MethodInfo method, MethodSymbol parent) { if (method.IsGenericMethod) @@ -324,6 +331,7 @@ private static TypeArray GetMethodTypeParameters(MethodInfo method, MethodSymbol ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static TypeArray GetAggregateTypeParameters(Type type, AggregateSymbol agg) { if (type.IsGenericType) @@ -382,6 +390,7 @@ private static TypeArray GetAggregateTypeParameters(Type type, AggregateSymbol a ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static TypeParameterType LoadClassTypeParameter(AggregateSymbol parent, Type t) { for (AggregateSymbol p = parent; p != null; p = p.parent as AggregateSymbol) @@ -496,6 +505,7 @@ private static Type GetOriginalTypeParameterType(Type t) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static TypeParameterType LoadMethodTypeParameter(MethodSymbol parent, Type t) { for (Symbol sym = parent.firstChild; sym != null; sym = sym.nextChild) @@ -515,6 +525,7 @@ private static TypeParameterType LoadMethodTypeParameter(MethodSymbol parent, Ty ///////////////////////////////////////////////////////////////////////////////// + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static TypeParameterType AddTypeParameterToSymbolTable( AggregateSymbol agg, MethodSymbol meth, @@ -578,6 +589,7 @@ private static TypeParameterType AddTypeParameterToSymbolTable( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static CType LoadSymbolsFromType(Type type) { List declarationChain = BuildDeclarationChain(type); @@ -643,6 +655,7 @@ private static CType LoadSymbolsFromType(Type type) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static TypeParameterType ProcessMethodTypeParameter(MethodInfo methinfo, Type t, AggregateSymbol parent) { MethodSymbol meth = FindMatchingMethod(methinfo, parent); @@ -663,6 +676,7 @@ private static TypeParameterType ProcessMethodTypeParameter(MethodInfo methinfo, ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static CType GetConstructedType(Type type, AggregateSymbol agg) { // We've found the one we want, so return it. @@ -686,6 +700,7 @@ private static CType GetConstructedType(Type type, AggregateSymbol agg) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static CType ProcessSpecialTypeInChain(NamespaceOrAggregateSymbol parent, Type t) { if (t.IsGenericParameter) @@ -717,6 +732,7 @@ private static CType ProcessSpecialTypeInChain(NamespaceOrAggregateSymbol parent ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static List BuildDeclarationChain(Type callingType) { // We need to build the parent chain of the calling type. Since we only @@ -794,6 +810,7 @@ private static AggregateSymbol FindSymForType(Symbol sym, Type t) return null; } + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static NamespaceSymbol AddNamespaceToSymbolTable(NamespaceOrAggregateSymbol parent, string sz) { Name name = GetName(sz); @@ -806,6 +823,7 @@ private static NamespaceSymbol AddNamespaceToSymbolTable(NamespaceOrAggregateSym ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static CType[] GetCTypeArrayFromTypes(Type[] types) { Debug.Assert(types != null); @@ -829,6 +847,7 @@ internal static CType[] GetCTypeArrayFromTypes(Type[] types) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static CType GetCTypeFromType(Type type) => type.IsByRef ? TypeManager.GetParameterModifier(LoadSymbolsFromType(type.GetElementType()), false) : LoadSymbolsFromType(type); @@ -839,6 +858,7 @@ internal static CType GetCTypeFromType(Type type) => type.IsByRef ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static AggregateSymbol AddAggregateToSymbolTable( NamespaceOrAggregateSymbol parent, Type type) @@ -992,6 +1012,7 @@ private static AggregateSymbol AddAggregateToSymbolTable( ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void SetInterfacesOnAggregate(AggregateSymbol aggregate, Type type) { if (type.IsGenericType) @@ -1017,6 +1038,7 @@ private static void SetInterfacesOnAggregate(AggregateSymbol aggregate, Type typ ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static FieldSymbol AddFieldToSymbolTable(FieldInfo fieldInfo, AggregateSymbol aggregate) { FieldSymbol field = SymbolStore.LookupSym( @@ -1072,6 +1094,7 @@ private static FieldSymbol AddFieldToSymbolTable(FieldInfo fieldInfo, AggregateS ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void AddEventToSymbolTable(EventInfo eventInfo, AggregateSymbol aggregate, FieldSymbol addedField) { EventSymbol ev = SymbolStore.LookupSym( @@ -1130,6 +1153,7 @@ private static void AddEventToSymbolTable(EventInfo eventInfo, AggregateSymbol a ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static void AddPredefinedPropertyToSymbolTable(AggregateSymbol type, Name property) { AggregateType aggtype = type.getThisType(); @@ -1147,6 +1171,7 @@ internal static void AddPredefinedPropertyToSymbolTable(AggregateSymbol type, Na ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void AddPropertyToSymbolTable(PropertyInfo property, AggregateSymbol aggregate) { Name name; @@ -1297,6 +1322,7 @@ private static void AddPropertyToSymbolTable(PropertyInfo property, AggregateSym ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static void AddPredefinedMethodToSymbolTable(AggregateSymbol type, Name methodName) { Type t = type.getThisType().AssociatedSystemType; @@ -1332,6 +1358,7 @@ internal static void AddPredefinedMethodToSymbolTable(AggregateSymbol type, Name ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static MethodSymbol AddMethodToSymbolTable(MethodBase member, AggregateSymbol callingAggregate, MethodKindEnum kind) { MethodInfo method = member as MethodInfo; @@ -1434,6 +1461,7 @@ private static MethodSymbol AddMethodToSymbolTable(MethodBase member, AggregateS ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void SetParameterDataForMethProp(MethodOrPropertySymbol methProp, ParameterInfo[] parameters) { if (parameters.Length > 0) @@ -1458,6 +1486,7 @@ private static void SetParameterDataForMethProp(MethodOrPropertySymbol methProp, ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void SetParameterAttributes(MethodOrPropertySymbol methProp, ParameterInfo[] parameters, int i) { ParameterInfo parameter = parameters[i]; @@ -1606,6 +1635,7 @@ private static MethodSymbol FindMatchingMethod(MemberInfo method, AggregateSymbo } [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static TypeArray CreateParameterArray(MemberInfo associatedInfo, ParameterInfo[] parameters) { bool isVarArg = associatedInfo is MethodBase mb && (mb.CallingConvention & CallingConventions.VarArgs) != 0; @@ -1627,6 +1657,7 @@ private static TypeArray CreateParameterArray(MemberInfo associatedInfo, Paramet ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static CType GetTypeOfParameter(ParameterInfo p, MemberInfo m) { Type t = p.ParameterType; @@ -1676,6 +1707,7 @@ private static bool DoesMethodHaveParameterArray(ParameterInfo[] parameters) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static SymWithType GetSlotForOverride(MethodInfo method) { if (method.IsVirtual && method.IsHideBySig) @@ -1704,6 +1736,7 @@ private static SymWithType GetSlotForOverride(MethodInfo method) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static MethodSymbol FindMethodFromMemberInfo(MemberInfo baseMemberInfo) { CType t = GetCTypeFromType(baseMemberInfo.DeclaringType); @@ -1734,6 +1767,7 @@ internal static bool AggregateContainsMethod(AggregateSymbol agg, string szName, ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] internal static void AddConversionsForType(Type type) { if (type.IsInterface) @@ -1749,6 +1783,7 @@ internal static void AddConversionsForType(Type type) ///////////////////////////////////////////////////////////////////////////////// [RequiresUnreferencedCode(Binder.TrimmerWarning)] + [RequiresDynamicCode(Binder.DynamicCodeWarning)] private static void AddConversionsForOneType(Type type) { if (type.IsGenericType)