Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
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
23 changes: 23 additions & 0 deletions src/System.Linq.Expressions/tests/CompilerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using System.Threading;
using Xunit;

namespace System.Linq.Expressions.Tests
Expand All @@ -26,6 +27,28 @@ public static void CompileDeepTree_NoStackOverflow(bool useInterpreter)
Assert.Equal(n, f());
}

[Theory, ClassData(typeof(CompilationTypes))]
public static void CompileDeepTree_NoStackOverflowFast(bool useInterpreter)
{
Expression e = Expression.Constant(0);

int n = 100;

for (int i = 0; i < n; i++)
e = Expression.Add(e, Expression.Constant(1));

Func<int> f = null;
// Request a stack size of 1 to get the minimum size allowed.
// This reduces the size of tree needed to risk a stack overflow.
// This though will only risk overflow once, so the outerloop test
// above is still needed.
Thread t = new Thread(() => f = Expression.Lambda<Func<int>>(e).Compile(useInterpreter), 1);
t.Start();
t.Join();
Copy link
Member

Choose a reason for hiding this comment

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

Did the previous code overflow more than once? Presumably this new version won't, so maybe we still need the old test as outerloop in addition to the new one as inner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.


Assert.Equal(n, f());
}

#if FEATURE_COMPILE
[Fact]
public static void EmitConstantsToIL_NonNullableValueTypes()
Expand Down