Skip to content

Use An AOT-friendly Linq implementation #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../../external/corefx/src/System.Linq/src/System/Linq/*.cs
2 changes: 2 additions & 0 deletions mcs/class/System.Core/unityaot_System.Core.dll.sources
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#include winaot_System.Core.dll.sources
../referencesource/System.Core/System/Linq/Enumerable.cs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We exclude all of Linq directory and only add Enumerable.cs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that everything we need is in Enumerable.cs. In the corefx code, everything is broken up into smaller files in a partial class. I did test this code with our .NET Standard 2.0 compliance tests, and it passes. So I think this is correct.

corefx/SR.cs
49 changes: 49 additions & 0 deletions mcs/class/referencesource/System.Core/System/Linq/Enumerable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,11 @@ public string Empty
{
get
{
#if UNITY_AOT
return SR.EmptyEnumerable;
#else
return Strings.EmptyEnumerable;
#endif
}
}
}
Expand Down Expand Up @@ -2829,4 +2833,49 @@ public object[] Items
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private int count;
}

#if UNITY_AOT
// <summary>
/// An iterator that can produce an array or <see cref="List{TElement}"/> through an optimized path.
/// </summary>
internal interface IIListProvider<TElement> : IEnumerable<TElement>
{
/// <summary>
/// Produce an array of the sequence through an optimized path.
/// </summary>
/// <returns>The array.</returns>
TElement[] ToArray();

/// <summary>
/// Produce a <see cref="List{TElement}"/> of the sequence through an optimized path.
/// </summary>
/// <returns>The <see cref="List{TElement}"/>.</returns>
List<TElement> ToList();

/// <summary>
/// Returns the count of elements in the sequence.
/// </summary>
/// <param name="onlyIfCheap">If true then the count should only be calculated if doing
/// so is quick (sure or likely to be constant time), otherwise -1 should be returned.</param>
/// <returns>The number of elements.</returns>
int GetCount(bool onlyIfCheap);
}

internal static partial class Error
{
internal static Exception ArgumentNull(string s) => new ArgumentNullException(s);

internal static Exception ArgumentOutOfRange(string s) => new ArgumentOutOfRangeException(s);

internal static Exception MoreThanOneElement() => new InvalidOperationException(SR.MoreThanOneElement);

internal static Exception MoreThanOneMatch() => new InvalidOperationException(SR.MoreThanOneMatch);

internal static Exception NoElements() => new InvalidOperationException(SR.NoElements);

internal static Exception NoMatch() => new InvalidOperationException(SR.NoMatch);

internal static Exception NotSupported() => new NotSupportedException();
}
#endif
}