Skip to content

Commit a0a6992

Browse files
committed
Fixed AOT compatibility attributes (#254)
1 parent e896dbb commit a0a6992

File tree

20 files changed

+88
-34
lines changed

20 files changed

+88
-34
lines changed

src/DotNext.IO/DotNext.IO.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<LangVersion>latest</LangVersion>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>true</ImplicitUsings>
8-
<IsTrimmable>true</IsTrimmable>
8+
<IsAotCompatible>true</IsAotCompatible>
99
<Features>nullablePublicOnly</Features>
1010
<RootNamespace>DotNext</RootNamespace>
1111
<Authors>.NET Foundation and Contributors</Authors>
1212
<Company />
1313
<Product>.NEXT Family of Libraries</Product>
14-
<VersionPrefix>5.16.1</VersionPrefix>
14+
<VersionPrefix>5.17.0</VersionPrefix>
1515
<VersionSuffix></VersionSuffix>
1616
<AssemblyName>DotNext.IO</AssemblyName>
1717
<PackageLicenseExpression>MIT</PackageLicenseExpression>

src/DotNext.MaintenanceServices/DotNext.MaintenanceServices.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<LangVersion>latest</LangVersion>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>true</ImplicitUsings>
8-
<IsTrimmable>true</IsTrimmable>
8+
<IsAotCompatible>true</IsAotCompatible>
99
<Features>nullablePublicOnly</Features>
1010
<RootNamespace>DotNext</RootNamespace>
1111
<Authors>.NET Foundation and Contributors</Authors>
1212
<Company />
1313
<Product>.NEXT Family of Libraries</Product>
14-
<VersionPrefix>0.4.0</VersionPrefix>
14+
<VersionPrefix>0.5.0</VersionPrefix>
1515
<VersionSuffix></VersionSuffix>
1616
<AssemblyName>DotNext.MaintenanceServices</AssemblyName>
1717
<PackageLicenseExpression>MIT</PackageLicenseExpression>

src/DotNext.Metaprogramming/DotNext.Metaprogramming.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<LangVersion>latest</LangVersion>
77
<Nullable>enable</Nullable>
88
<ImplicitUsings>true</ImplicitUsings>
9-
<IsTrimmable>false</IsTrimmable>
9+
<IsAotCompatible>false</IsAotCompatible>
1010
<Features>nullablePublicOnly</Features>
11-
<VersionPrefix>5.16.1</VersionPrefix>
11+
<VersionPrefix>5.17.0</VersionPrefix>
1212
<VersionSuffix></VersionSuffix>
1313
<Authors>.NET Foundation</Authors>
1414
<Product>.NEXT Family of Libraries</Product>

src/DotNext.Threading/DotNext.Threading.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<LangVersion>latest</LangVersion>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>true</ImplicitUsings>
8-
<IsTrimmable>true</IsTrimmable>
8+
<IsAotCompatible>true</IsAotCompatible>
99
<Features>nullablePublicOnly</Features>
10-
<VersionPrefix>5.16.1</VersionPrefix>
10+
<VersionPrefix>5.17.0</VersionPrefix>
1111
<VersionSuffix></VersionSuffix>
1212
<Authors>.NET Foundation and Contributors</Authors>
1313
<Product>.NEXT Family of Libraries</Product>

src/DotNext.Threading/Threading/AsyncReaderWriterLock.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ private enum LockType : byte
3636

3737
// describes internal state of reader/writer lock
3838
[StructLayout(LayoutKind.Auto)]
39+
[SuppressMessage("Usage", "CA1001", Justification = "The disposable field is disposed in the Dispose() method")]
3940
internal struct State : IDisposable
4041
{
4142
private ulong version; // version of write lock

src/DotNext.Unsafe/DotNext.Unsafe.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<LangVersion>latest</LangVersion>
77
<Nullable>enable</Nullable>
88
<ImplicitUsings>true</ImplicitUsings>
9-
<IsTrimmable>true</IsTrimmable>
10-
<VersionPrefix>5.16.1</VersionPrefix>
9+
<IsAotCompatible>true</IsAotCompatible>
10+
<VersionPrefix>5.17.0</VersionPrefix>
1111
<Features>nullablePublicOnly</Features>
1212
<VersionSuffix></VersionSuffix>
1313
<Authors>.NET Foundation and Contributors</Authors>

src/DotNext/DotNext.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<LangVersion>latest</LangVersion>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>true</ImplicitUsings>
8-
<IsTrimmable>true</IsTrimmable>
8+
<IsAotCompatible>true</IsAotCompatible>
99
<Features>nullablePublicOnly</Features>
1010
<RootNamespace>DotNext</RootNamespace>
1111
<Authors>.NET Foundation and Contributors</Authors>
1212
<Company />
1313
<Product>.NEXT Family of Libraries</Product>
14-
<VersionPrefix>5.16.1</VersionPrefix>
14+
<VersionPrefix>5.17.0</VersionPrefix>
1515
<VersionSuffix></VersionSuffix>
1616
<AssemblyName>DotNext</AssemblyName>
1717
<PackageLicenseExpression>MIT</PackageLicenseExpression>

src/DotNext/Dynamic/TaskResultBinder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace DotNext.Dynamic;
99

1010
[RequiresDynamicCode("DLR is required to resolve underlying task type at runtime")]
11+
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
1112
internal sealed class TaskResultBinder : CallSiteBinder
1213
{
1314
private static Expression BindProperty(PropertyInfo resultProperty, Expression target, out Expression restrictions)

src/DotNext/EqualityComparerBuilder.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ internal ConstructedEqualityComparer(Func<T?, T?, bool> equality, Func<T, int> h
6464
}
6565

6666
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
67+
[RequiresDynamicCode("Dynamic code generation may be incompatible with AOT")]
6768
private static PropertyInfo? GetDefaultEqualityComparer(Type target)
6869
=> typeof(EqualityComparer<>)
6970
.MakeGenericType(target)
7071
.GetProperty(nameof(EqualityComparer<int>.Default), PublicStaticFlags);
7172

7273
private static FieldInfo? HashSaltField => typeof(RandomExtensions).GetField(nameof(RandomExtensions.BitwiseHashSalt), BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);
7374

75+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
7476
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
7577
private static MethodCallExpression EqualsMethodForValueType(MemberExpression first, MemberExpression second)
7678
{
@@ -97,6 +99,7 @@ private static MethodCallExpression EqualsMethodForValueType(MemberExpression fi
9799
return Expression.Call(Expression.Property(null, defaultProperty), method, first, second);
98100
}
99101

102+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
100103
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
101104
private static Expression HashCodeMethodForValueType(Expression expr, ConstantExpression salted)
102105
{
@@ -130,6 +133,7 @@ private static Expression HashCodeMethodForValueType(Expression expr, ConstantEx
130133
return expr;
131134
}
132135

136+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
133137
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
134138
private static MethodInfo EqualsMethodForArrayElementType(Type itemType)
135139
{
@@ -151,6 +155,7 @@ private static MethodInfo EqualsMethodForArrayElementType(Type itemType)
151155
return new Func<IEnumerable<object>?, IEnumerable<object>?, bool>(Collection.SequenceEqual).Method;
152156
}
153157

158+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
154159
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
155160
private static MethodCallExpression EqualsMethodForArrayElementType(MemberExpression fieldX, MemberExpression fieldY)
156161
{
@@ -159,6 +164,7 @@ private static MethodCallExpression EqualsMethodForArrayElementType(MemberExpres
159164
return Expression.Call(method, fieldX, fieldY);
160165
}
161166

167+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
162168
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
163169
private static MethodInfo HashCodeMethodForArrayElementType(Type itemType)
164170
{
@@ -174,6 +180,7 @@ private static MethodInfo HashCodeMethodForArrayElementType(Type itemType)
174180
.MakeGenericMethod(itemType);
175181
}
176182

183+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
177184
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
178185
private static MethodCallExpression HashCodeMethodForArrayElementType(Expression expr, ConstantExpression salted)
179186
{
@@ -192,11 +199,10 @@ private static IEnumerable<FieldInfo> GetAllFields(Type type)
192199
}
193200
}
194201

202+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
195203
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
196204
private Func<T?, T?, bool> BuildEquals()
197205
{
198-
if (!RuntimeFeature.IsDynamicCodeSupported)
199-
throw new PlatformNotSupportedException();
200206
var x = Expression.Parameter(typeof(T));
201207
if (x.Type.IsPrimitive)
202208
return EqualityComparer<T?>.Default.Equals;
@@ -238,11 +244,10 @@ private static IEnumerable<FieldInfo> GetAllFields(Type type)
238244
return Expression.Lambda<Func<T?, T?, bool>>(expr, false, x, y).Compile();
239245
}
240246

247+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
241248
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
242249
private Func<T, int> BuildGetHashCode()
243250
{
244-
if (!RuntimeFeature.IsDynamicCodeSupported)
245-
throw new PlatformNotSupportedException();
246251
Expression expr;
247252
var inputParam = Expression.Parameter(typeof(T));
248253
if (inputParam.Type.IsPrimitive)
@@ -291,6 +296,7 @@ private Func<T, int> BuildGetHashCode()
291296
/// <param name="equals">The implementation of equality check.</param>
292297
/// <param name="hashCode">The implementation of hash code.</param>
293298
/// <exception cref="PlatformNotSupportedException">Dynamic code generation is not supported by underlying CLR implementation.</exception>
299+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
294300
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
295301
public void Build(out Func<T?, T?, bool> equals, out Func<T, int> hashCode)
296302
{
@@ -303,6 +309,7 @@ public void Build(out Func<T?, T?, bool> equals, out Func<T, int> hashCode)
303309
/// </summary>
304310
/// <returns>The generated equality comparer.</returns>
305311
/// <exception cref="PlatformNotSupportedException">Dynamic code generation is not supported by underlying CLR implementation.</exception>
312+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
306313
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
307314
public IEqualityComparer<T> Build()
308315
{

src/DotNext/Reflection/TaskType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ static TaskType()
5151
/// <seealso cref="Task{TResult}"/>
5252
/// <seealso cref="ValueTask"/>
5353
/// <seealso cref="ValueTask{TResult}"/>
54-
[RequiresUnreferencedCode("Runtime generic instantiation may be incompatible with IL trimming")]
54+
[RequiresDynamicCode("Runtime binding requires dynamic code compilation")]
55+
[RequiresUnreferencedCode("Dynamic code generation may be incompatible with IL trimming")]
5556
public static Type MakeTaskType(this Type taskResult, bool valueTask = false)
5657
{
5758
if (taskResult == typeof(void))

0 commit comments

Comments
 (0)