Skip to content

Commit 61aaabe

Browse files
committed
Use An AOT-friendly Linq implementation
The corefx implementation of Linq is not AOT-friendly, and won't work with IL2CPP until IL2CPP gets full generic sharing support. So use the Linq implementation from reference source for the unityaot profile. This implementation is AOT-friendly. This change addresses case 1013854 in Unity.
1 parent 2fb0286 commit 61aaabe

7 files changed

+61
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../external/corefx/src/System.Linq/src/System/Linq/*.cs

mcs/class/System.Core/linux_unityaot_System.Core.dll.sources

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ System.Security.Cryptography/SHA512Cng.cs
1313
../referencesource/System.Core/System/Security/Cryptography/AesManaged.cs
1414
../referencesource/System.Core/System/Security/Cryptography/ECDiffieHellman.cs
1515
../referencesource/System.Core/System/Security/Cryptography/ECKeyXmlFormat.cs
16+
17+
../referencesource/System.Core/System/Linq/Enumerable.cs
18+
corefx/SR.cs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../external/corefx/src/System.Linq/src/System/Linq/*.cs

mcs/class/System.Core/macos_unityaot_System.Core.dll.sources

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ System.Security.Cryptography/SHA512Cng.cs
1313
../referencesource/System.Core/System/Security/Cryptography/AesManaged.cs
1414
../referencesource/System.Core/System/Security/Cryptography/ECDiffieHellman.cs
1515
../referencesource/System.Core/System/Security/Cryptography/ECKeyXmlFormat.cs
16+
17+
../referencesource/System.Core/System/Linq/Enumerable.cs
18+
corefx/SR.cs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
../../../external/corefx/src/System.Net.Sockets/src/System/Net/Sockets/UnixDomainSocketEndPoint.Unix.cs
22
../../../external/corefx/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs
33
../../../external/corefx/src/Common/src/Interop/Unix/Interop.Libraries.cs
4+
../../../external/corefx/src/System.Linq/src/System/Linq/*.cs
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include orbis_System.Core.dll.sources
22

33
../../../external/corefx/src/System.Net.Sockets/src/System/Net/Sockets/UnixDomainSocketEndPoint.Windows.cs
4+
../referencesource/System.Core/System/Linq/Enumerable.cs
5+
corefx/SR.cs

mcs/class/referencesource/System.Core/System/Linq/Enumerable.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,11 @@ public string Empty
27762776
{
27772777
get
27782778
{
2779+
#if UNITY_AOT
2780+
return SR.EmptyEnumerable;
2781+
#else
27792782
return Strings.EmptyEnumerable;
2783+
#endif
27802784
}
27812785
}
27822786
}
@@ -2829,4 +2833,50 @@ public object[] Items
28292833
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
28302834
private int count;
28312835
}
2836+
2837+
2838+
#if UNITY_AOT
2839+
// <summary>
2840+
/// An iterator that can produce an array or <see cref="List{TElement}"/> through an optimized path.
2841+
/// </summary>
2842+
internal interface IIListProvider<TElement> : IEnumerable<TElement>
2843+
{
2844+
/// <summary>
2845+
/// Produce an array of the sequence through an optimized path.
2846+
/// </summary>
2847+
/// <returns>The array.</returns>
2848+
TElement[] ToArray();
2849+
2850+
/// <summary>
2851+
/// Produce a <see cref="List{TElement}"/> of the sequence through an optimized path.
2852+
/// </summary>
2853+
/// <returns>The <see cref="List{TElement}"/>.</returns>
2854+
List<TElement> ToList();
2855+
2856+
/// <summary>
2857+
/// Returns the count of elements in the sequence.
2858+
/// </summary>
2859+
/// <param name="onlyIfCheap">If true then the count should only be calculated if doing
2860+
/// so is quick (sure or likely to be constant time), otherwise -1 should be returned.</param>
2861+
/// <returns>The number of elements.</returns>
2862+
int GetCount(bool onlyIfCheap);
2863+
}
2864+
2865+
internal static partial class Error
2866+
{
2867+
internal static Exception ArgumentNull(string s) => new ArgumentNullException(s);
2868+
2869+
internal static Exception ArgumentOutOfRange(string s) => new ArgumentOutOfRangeException(s);
2870+
2871+
internal static Exception MoreThanOneElement() => new InvalidOperationException(SR.MoreThanOneElement);
2872+
2873+
internal static Exception MoreThanOneMatch() => new InvalidOperationException(SR.MoreThanOneMatch);
2874+
2875+
internal static Exception NoElements() => new InvalidOperationException(SR.NoElements);
2876+
2877+
internal static Exception NoMatch() => new InvalidOperationException(SR.NoMatch);
2878+
2879+
internal static Exception NotSupported() => new NotSupportedException();
2880+
}
2881+
#endif
28322882
}

0 commit comments

Comments
 (0)