未验证 提交 dfe08b3b 编写于 作者: L Lakshan Fernando 提交者: GitHub

Native aot trim annotations experiment (#65816)

* Add nativeaot trim annotations experiment

* Fix mono libraries

* Update src/libraries/System.Reflection.Emit.Lightweight/ref/System.Reflection.Emit.Lightweight.cs
Co-authored-by: NEric Erhardt <eric.erhardt@microsoft.com>

* FB on attribute message

* FB

* missed nativeaot message change
Co-authored-by: NEric Erhardt <eric.erhardt@microsoft.com>
上级 1665aca8
T:System.CLSCompliantAttribute
T:System.Diagnostics.CodeAnalysis.MemberNotNullAttribute
T:System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute
T:System.Diagnostics.DebuggerGuidedStepThroughAttribute
T:System.Runtime.CompilerServices.EagerStaticClassConstructionAttribute
......@@ -4,6 +4,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
......@@ -15,6 +16,7 @@ namespace System
public abstract partial class Array : ICloneable, IList, IStructuralComparable, IStructuralEquatable
{
// Create instance will create an array
[RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static unsafe Array CreateInstance(Type elementType, int length)
{
if (elementType is null)
......@@ -67,6 +69,7 @@ public static unsafe Array CreateInstance(Type elementType, int length1, int len
return InternalCreate((void*)t.TypeHandle.Value, 3, pLengths, null);
}
[RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static unsafe Array CreateInstance(Type elementType, params int[] lengths)
{
if (elementType is null)
......@@ -92,6 +95,7 @@ public static unsafe Array CreateInstance(Type elementType, params int[] lengths
return InternalCreate((void*)t.TypeHandle.Value, lengths.Length, pLengths, null);
}
[RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static unsafe Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds)
{
if (elementType == null)
......
......@@ -139,6 +139,7 @@ private void InitManifestModule()
#region DefineDynamicAssembly
[RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
[DynamicSecurityMethod] // Required to make Assembly.GetCallingAssembly reliable.
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
{
......@@ -149,6 +150,7 @@ public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyB
null);
}
[RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
[DynamicSecurityMethod] // Required to make Assembly.GetCallingAssembly reliable.
public static AssemblyBuilder DefineDynamicAssembly(
AssemblyName name,
......
......@@ -49,6 +49,7 @@ public sealed class DynamicMethod : MethodInfo
// class initialization (ctor and init)
//
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name,
Type? returnType,
Type[]? parameterTypes)
......@@ -64,6 +65,7 @@ public sealed class DynamicMethod : MethodInfo
true);
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name,
Type? returnType,
Type[]? parameterTypes,
......@@ -80,6 +82,7 @@ public sealed class DynamicMethod : MethodInfo
true);
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name,
Type? returnType,
Type[]? parameterTypes,
......@@ -96,6 +99,7 @@ public sealed class DynamicMethod : MethodInfo
false);
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name,
Type? returnType,
Type[]? parameterTypes,
......@@ -113,6 +117,7 @@ public sealed class DynamicMethod : MethodInfo
false);
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name,
MethodAttributes attributes,
CallingConventions callingConvention,
......@@ -132,6 +137,7 @@ public sealed class DynamicMethod : MethodInfo
false);
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name,
Type? returnType,
Type[]? parameterTypes,
......@@ -148,6 +154,7 @@ public sealed class DynamicMethod : MethodInfo
false);
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name,
Type? returnType,
Type[]? parameterTypes,
......@@ -165,6 +172,7 @@ public sealed class DynamicMethod : MethodInfo
false);
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name,
MethodAttributes attributes,
CallingConventions callingConvention,
......
......@@ -507,6 +507,7 @@ public override bool IsDefined(Type attributeType, bool inherit)
public override Type[] GetGenericArguments() => m_inst ?? Type.EmptyTypes;
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
{
......
......@@ -48,21 +48,25 @@ public static IntPtr OffsetOf(Type t!!, string fieldName)
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr OffsetOfHelper(IRuntimeFieldInfo f);
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static byte ReadByte(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadByte(nativeHome, offset));
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static short ReadInt16(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt16(nativeHome, offset));
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static int ReadInt32(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt32(nativeHome, offset));
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static long ReadInt64([MarshalAs(UnmanagedType.AsAny), In] object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt64(nativeHome, offset));
......@@ -102,21 +106,25 @@ private static unsafe T ReadValueSlow<T>(object ptr, int ofs, Func<IntPtr, int,
}
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteByte(object ptr, int ofs, byte val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, byte value) => WriteByte(nativeHome, offset, value));
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt16(object ptr, int ofs, short val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, short value) => Marshal.WriteInt16(nativeHome, offset, value));
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt32(object ptr, int ofs, int val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, int value) => Marshal.WriteInt32(nativeHome, offset, value));
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt64(object ptr, int ofs, long val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, long value) => Marshal.WriteInt64(nativeHome, offset, value));
......@@ -201,6 +209,7 @@ private static void PrelinkCore(MethodInfo m)
/// structure contains pointers to allocated blocks and "fDeleteOld" is
/// true, this routine will call DestroyStructure() first.
/// </summary>
[RequiresDynamicCode("Marshalling code for the object might not be available. Use the StructureToPtr<T> overload instead.")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld);
......@@ -214,6 +223,7 @@ private static void PrelinkCore(MethodInfo m)
/// Frees all substructures pointed to by the native memory block.
/// "structuretype" is used to provide layout information.
/// </summary>
[RequiresDynamicCode("Marshalling code for the object might not be available. Use the DestroyStructure<T> overload instead.")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void DestroyStructure(IntPtr ptr, Type structuretype);
......
......@@ -30,14 +30,14 @@ public override Module ManifestModule
}
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
return default;
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
......
......@@ -8,49 +8,49 @@ namespace System.Reflection.Emit
{
public sealed class DynamicMethod : MethodInfo
{
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Module m, bool skipVisibility)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type returnType, Type[] parameterTypes)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type returnType, Type[] parameterTypes, bool restrictedSkipVisibility)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type returnType, Type[] parameterTypes, Module m)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type returnType, Type[] parameterTypes, Module m, bool skipVisibility)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type returnType, Type[] parameterTypes, Type owner)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
}
[RequiresDynamicCode("Generating new code at runtime is not supported with native AOT.")]
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility)
{
ReflectionEmitThrower.ThrowPlatformNotSupportedException();
......
......@@ -114,6 +114,7 @@ public override string[] GetEnumNames()
return new ReadOnlySpan<string>(ret).ToArray();
}
[RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the GetValues<TEnum> overload instead.")]
public override Array GetEnumValues()
{
if (!IsEnum)
......
......@@ -30,13 +30,21 @@ public sealed partial class DynamicILInfo
}
public sealed partial class DynamicMethod : System.Reflection.MethodInfo
{
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? parameterTypes, System.Reflection.Module m, bool skipVisibility) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type? returnType, System.Type[]? parameterTypes, System.Type owner, bool skipVisibility) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, System.Type? returnType, System.Type[]? parameterTypes) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, System.Type? returnType, System.Type[]? parameterTypes, bool restrictedSkipVisibility) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, System.Type? returnType, System.Type[]? parameterTypes, System.Reflection.Module m) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, System.Type? returnType, System.Type[]? parameterTypes, System.Reflection.Module m, bool skipVisibility) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, System.Type? returnType, System.Type[]? parameterTypes, System.Type owner) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, System.Type? returnType, System.Type[]? parameterTypes, System.Type owner, bool skipVisibility) { }
public override System.Reflection.MethodAttributes Attributes { get { throw null; } }
public override System.Reflection.CallingConventions CallingConvention { get { throw null; } }
......
......@@ -19,7 +19,9 @@ public sealed partial class AssemblyBuilder : System.Reflection.Assembly
public override string Location { get { throw null; } }
public override System.Reflection.Module ManifestModule { get { throw null; } }
public override bool ReflectionOnly { get { throw null; } }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
public static System.Reflection.Emit.AssemblyBuilder DefineDynamicAssembly(System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
public static System.Reflection.Emit.AssemblyBuilder DefineDynamicAssembly(System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access, System.Collections.Generic.IEnumerable<System.Reflection.Emit.CustomAttributeBuilder>? assemblyAttributes) { throw null; }
public System.Reflection.Emit.ModuleBuilder DefineDynamicModule(string name) { throw null; }
public override bool Equals(object? obj) { throw null; }
......@@ -333,6 +335,7 @@ public sealed partial class MethodBuilder : System.Reflection.MethodInfo
public override System.Reflection.ParameterInfo[] GetParameters() { throw null; }
public override object Invoke(object? obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object?[]? parameters, System.Globalization.CultureInfo? culture) { throw null; }
public override bool IsDefined(System.Type attributeType, bool inherit) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
public override System.Reflection.MethodInfo MakeGenericMethod(params System.Type[] typeArguments) { throw null; }
public void SetCustomAttribute(System.Reflection.ConstructorInfo con, byte[] binaryAttribute) { }
......
......@@ -533,6 +533,7 @@ public static partial class Marshal
public static object? CreateWrapperOfType(object? o, System.Type t) { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static TWrapper CreateWrapperOfType<T, TWrapper>(T? o) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the DestroyStructure<T> overload instead.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static void DestroyStructure(System.IntPtr ptr, System.Type structuretype) { }
public static void DestroyStructure<T>(System.IntPtr ptr) { }
......@@ -553,6 +554,7 @@ public static partial class Marshal
public static System.IntPtr GetComInterfaceForObject<T, TInterface>([System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T o) { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static object? GetComObjectData(object obj, object key) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the delegate might not be available. Use the GetDelegateForFunctionPointer<TDelegate> overload instead.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static System.Delegate GetDelegateForFunctionPointer(System.IntPtr ptr, System.Type t) { throw null; }
public static TDelegate GetDelegateForFunctionPointer<TDelegate>(System.IntPtr ptr) { throw null; }
......@@ -564,6 +566,7 @@ public static partial class Marshal
public static System.Exception? GetExceptionForHR(int errorCode) { throw null; }
public static System.Exception? GetExceptionForHR(int errorCode, System.IntPtr errorInfo) { throw null; }
public static System.IntPtr GetExceptionPointers() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the delegate might not be available. Use the GetFunctionPointerForDelegate<TDelegate> overload instead.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static System.IntPtr GetFunctionPointerForDelegate(System.Delegate d) { throw null; }
public static System.IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d) where TDelegate : notnull { throw null; }
......@@ -624,8 +627,10 @@ public static partial class Marshal
public static string PtrToStringUni(System.IntPtr ptr, int len) { throw null; }
public static string? PtrToStringUTF8(System.IntPtr ptr) { throw null; }
public static string PtrToStringUTF8(System.IntPtr ptr, int byteLen) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static void PtrToStructure(System.IntPtr ptr, object structure) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static object? PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors| System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type structureType) { throw null; }
public static T? PtrToStructure<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]T>(System.IntPtr ptr) { throw null; }
......@@ -633,26 +638,31 @@ public static partial class Marshal
public static int QueryInterface(System.IntPtr pUnk, ref System.Guid iid, out System.IntPtr ppv) { throw null; }
public static byte ReadByte(System.IntPtr ptr) { throw null; }
public static byte ReadByte(System.IntPtr ptr, int ofs) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("ReadByte(Object, Int32) may be unavailable in future releases.")]
public static byte ReadByte(object ptr, int ofs) { throw null; }
public static short ReadInt16(System.IntPtr ptr) { throw null; }
public static short ReadInt16(System.IntPtr ptr, int ofs) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("ReadInt16(Object, Int32) may be unavailable in future releases.")]
public static short ReadInt16(object ptr, int ofs) { throw null; }
public static int ReadInt32(System.IntPtr ptr) { throw null; }
public static int ReadInt32(System.IntPtr ptr, int ofs) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("ReadInt32(Object, Int32) may be unavailable in future releases.")]
public static int ReadInt32(object ptr, int ofs) { throw null; }
public static long ReadInt64(System.IntPtr ptr) { throw null; }
public static long ReadInt64(System.IntPtr ptr, int ofs) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("ReadInt64(Object, Int32) may be unavailable in future releases.")]
public static long ReadInt64(object ptr, int ofs) { throw null; }
public static System.IntPtr ReadIntPtr(System.IntPtr ptr) { throw null; }
public static System.IntPtr ReadIntPtr(System.IntPtr ptr, int ofs) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("ReadIntPtr(Object, Int32) may be unavailable in future releases.")]
public static System.IntPtr ReadIntPtr(object ptr, int ofs) { throw null; }
......@@ -670,8 +680,10 @@ public static partial class Marshal
public static bool SetComObjectData(object obj, object key, object? data) { throw null; }
public static void SetLastPInvokeError(int error) { throw null; }
public static void SetLastSystemError(int error) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static int SizeOf(object structure) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the SizeOf<T> overload instead.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static int SizeOf(System.Type t) { throw null; }
public static int SizeOf<T>() { throw null; }
......@@ -684,6 +696,7 @@ public static partial class Marshal
public static System.IntPtr StringToHGlobalAnsi(string? s) { throw null; }
public static System.IntPtr StringToHGlobalAuto(string? s) { throw null; }
public static System.IntPtr StringToHGlobalUni(string? s) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available. Use the StructureToPtr<T> overload instead.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public static void StructureToPtr(object structure, System.IntPtr ptr, bool fDeleteOld) { }
public static void StructureToPtr<T>([System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T structure, System.IntPtr ptr, bool fDeleteOld) { }
......@@ -694,6 +707,7 @@ public static partial class Marshal
public static System.IntPtr UnsafeAddrOfPinnedArrayElement<T>(T[] arr, int index) { throw null; }
public static void WriteByte(System.IntPtr ptr, byte val) { }
public static void WriteByte(System.IntPtr ptr, int ofs, byte val) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")]
public static void WriteByte(object ptr, int ofs, byte val) { }
......@@ -701,24 +715,29 @@ public static partial class Marshal
public static void WriteInt16(System.IntPtr ptr, short val) { }
public static void WriteInt16(System.IntPtr ptr, int ofs, char val) { }
public static void WriteInt16(System.IntPtr ptr, int ofs, short val) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("WriteInt16(Object, Int32, Char) may be unavailable in future releases.")]
public static void WriteInt16(object ptr, int ofs, char val) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
public static void WriteInt16(object ptr, int ofs, short val) { }
public static void WriteInt32(System.IntPtr ptr, int val) { }
public static void WriteInt32(System.IntPtr ptr, int ofs, int val) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("WriteInt32(Object, Int32, Int32) may be unavailable in future releases.")]
public static void WriteInt32(object ptr, int ofs, int val) { }
public static void WriteInt64(System.IntPtr ptr, int ofs, long val) { }
public static void WriteInt64(System.IntPtr ptr, long val) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("WriteInt64(Object, Int32, Int64) may be unavailable in future releases.")]
public static void WriteInt64(object ptr, int ofs, long val) { }
public static void WriteIntPtr(System.IntPtr ptr, int ofs, System.IntPtr val) { }
public static void WriteIntPtr(System.IntPtr ptr, System.IntPtr val) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the object might not be available")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("WriteIntPtr(Object, Int32, IntPtr) may be unavailable in future releases.")]
public static void WriteIntPtr(object ptr, int ofs, System.IntPtr val) { }
......
......@@ -342,11 +342,15 @@ public abstract partial class Array : System.Collections.ICollection, System.Col
public static void Copy(System.Array sourceArray, long sourceIndex, System.Array destinationArray, long destinationIndex, long length) { }
public void CopyTo(System.Array array, int index) { }
public void CopyTo(System.Array array, long index) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static System.Array CreateInstance(System.Type elementType, int length) { throw null; }
public static System.Array CreateInstance(System.Type elementType, int length1, int length2) { throw null; }
public static System.Array CreateInstance(System.Type elementType, int length1, int length2, int length3) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static System.Array CreateInstance(System.Type elementType, params int[] lengths) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static System.Array CreateInstance(System.Type elementType, int[] lengths, int[] lowerBounds) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static System.Array CreateInstance(System.Type elementType, params long[] lengths) { throw null; }
public static T[] Empty<T>() { throw null; }
public static bool Exists<T>(T[] array, System.Predicate<T> match) { throw null; }
......@@ -2662,6 +2666,7 @@ public abstract partial class Enum : System.ValueType, System.IComparable, Syste
public static string[] GetNames<TEnum>() where TEnum: struct, System.Enum { throw null; }
public System.TypeCode GetTypeCode() { throw null; }
public static System.Type GetUnderlyingType(System.Type enumType) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use the GetValues<TEnum> overload instead.")]
public static System.Array GetValues(System.Type enumType) { throw null; }
public static TEnum[] GetValues<TEnum>() where TEnum : struct, System.Enum { throw null; }
public bool HasFlag(System.Enum flag) { throw null; }
......@@ -6744,6 +6749,7 @@ public abstract partial class Type : System.Reflection.MemberInfo, System.Reflec
public virtual string? GetEnumName(object value) { throw null; }
public virtual string[] GetEnumNames() { throw null; }
public virtual System.Type GetEnumUnderlyingType() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("It might not be possible to create an array of the enum type at runtime. Use Enum.GetValues<TEnum> instead.")]
public virtual System.Array GetEnumValues() { throw null; }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicEvents)]
public System.Reflection.EventInfo? GetEvent(string name) { throw null; }
......@@ -6898,11 +6904,14 @@ public abstract partial class Type : System.Reflection.MemberInfo, System.Reflec
protected abstract bool IsPrimitiveImpl();
public virtual bool IsSubclassOf(System.Type c) { throw null; }
protected virtual bool IsValueTypeImpl() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public virtual System.Type MakeArrayType() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public virtual System.Type MakeArrayType(int rank) { throw null; }
public virtual System.Type MakeByRefType() { throw null; }
public static System.Type MakeGenericMethodParameter(int position) { throw null; }
public static System.Type MakeGenericSignatureType(System.Type genericTypeDefinition, params System.Type[] typeArguments) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
public virtual System.Type MakeGenericType(params System.Type[] typeArguments) { throw null; }
public virtual System.Type MakePointerType() { throw null; }
......@@ -8328,6 +8337,7 @@ public partial class ArrayList : System.Collections.ICollection, System.Collecti
public static System.Collections.ArrayList Synchronized(System.Collections.ArrayList list) { throw null; }
public static System.Collections.IList Synchronized(System.Collections.IList list) { throw null; }
public virtual object?[] ToArray() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public virtual System.Array ToArray(System.Type type) { throw null; }
public virtual void TrimToSize() { }
}
......@@ -12063,6 +12073,7 @@ public abstract partial class MethodInfo : System.Reflection.MethodBase
public override System.Type[] GetGenericArguments() { throw null; }
public virtual System.Reflection.MethodInfo GetGenericMethodDefinition() { throw null; }
public override int GetHashCode() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
public virtual System.Reflection.MethodInfo MakeGenericMethod(params System.Type[] typeArguments) { throw null; }
public static bool operator ==(System.Reflection.MethodInfo? left, System.Reflection.MethodInfo? right) { throw null; }
......@@ -282,6 +282,7 @@ private static bool CanAssignArrayElement(Type source, Type target)
return false;
}
[RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static unsafe Array CreateInstance(Type elementType, int length)
{
if (elementType is null)
......@@ -341,6 +342,7 @@ public static unsafe Array CreateInstance(Type elementType, int length1, int len
return array;
}
[RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static unsafe Array CreateInstance(Type elementType, params int[] lengths)
{
if (elementType is null)
......@@ -365,6 +367,7 @@ public static unsafe Array CreateInstance(Type elementType, params int[] lengths
return array;
}
[RequiresDynamicCode("The native code for the array might not be available at runtime.")]
public static unsafe Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds)
{
if (elementType == null)
......
......@@ -236,6 +236,7 @@ public override bool ReflectionOnly
get { return base.ReflectionOnly; }
}
[RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
{
if (name == null)
......@@ -244,6 +245,7 @@ public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyB
return new AssemblyBuilder(name, access);
}
[RequiresDynamicCode("Defining a dynamic assembly requires dynamic code.")]
public static AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder>? assemblyAttributes)
{
AssemblyBuilder ab = DefineDynamicAssembly(name, access);
......
......@@ -72,40 +72,49 @@ public sealed class DynamicMethod : MethodInfo
internal bool creating;
private DynamicILInfo? il_info;
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type? returnType, Type[]? parameterTypes, Module m) : this(name, returnType, parameterTypes, m, false)
{
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type? returnType, Type[]? parameterTypes, Type owner) : this(name, returnType, parameterTypes, owner, false)
{
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type? returnType, Type[]? parameterTypes, Module m, bool skipVisibility) : this(name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, m, skipVisibility)
{
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type? returnType, Type[]? parameterTypes, Type owner, bool skipVisibility) : this(name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, owner, skipVisibility)
{
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, Type owner, bool skipVisibility) : this(name, attributes, callingConvention, returnType, parameterTypes, owner, owner?.Module, skipVisibility, false, true)
{
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, Module m, bool skipVisibility) : this(name, attributes, callingConvention, returnType, parameterTypes, null, m, skipVisibility, false, false)
{
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type? returnType, Type[]? parameterTypes) : this(name, returnType, parameterTypes, false)
{
}
// FIXME: "Visibility is not restricted"
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
public DynamicMethod(string name, Type? returnType, Type[]? parameterTypes, bool restrictedSkipVisibility)
: this(name, MethodAttributes.Public | MethodAttributes.Static, CallingConventions.Standard, returnType, parameterTypes, null, null, restrictedSkipVisibility, true, false)
{
}
[RequiresDynamicCode("Creating a DynamicMethod requires dynamic code.")]
[DynamicDependency(nameof(owner))] // Automatically keeps all previous fields too due to StructLayout
private DynamicMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, Type? owner, Module? m, bool skipVisibility, bool anonHosted, bool typeOwner)
{
......
......@@ -541,6 +541,7 @@ private static Exception NotSupported()
return new NotSupportedException("The invoked member is not supported in a dynamic module.");
}
[RequiresDynamicCode("The native code for this instantiation might not be available at runtime.")]
[RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")]
public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
{
......
......@@ -29,12 +29,14 @@ public partial class Marshal
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void SetLastPInvokeError(int error);
[RequiresDynamicCode("Marshalling code for the object might not be available. Use the DestroyStructure<T> overload instead.")]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void DestroyStructure(IntPtr ptr, Type structuretype);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern IntPtr OffsetOf(Type t, string fieldName);
[RequiresDynamicCode("Marshalling code for the object might not be available. Use the StructureToPtr<T> overload instead.")]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld);
......@@ -193,48 +195,56 @@ public static int GetExceptionCode()
throw new PlatformNotSupportedException();
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static byte ReadByte(object ptr, int ofs)
{
// Obsolete
throw new PlatformNotSupportedException();
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static short ReadInt16(object ptr, int ofs)
{
// Obsolete
throw new PlatformNotSupportedException();
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static int ReadInt32(object ptr, int ofs)
{
// Obsolete
throw new PlatformNotSupportedException();
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static long ReadInt64(object ptr, int ofs)
{
// Obsolete
throw new PlatformNotSupportedException();
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteByte(object ptr, int ofs, byte val)
{
// Obsolete
throw new PlatformNotSupportedException();
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt16(object ptr, int ofs, short val)
{
// Obsolete
throw new PlatformNotSupportedException();
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt32(object ptr, int ofs, int val)
{
// Obsolete
throw new PlatformNotSupportedException();
}
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt64(object ptr, int ofs, long val)
{
// Obsolete
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册