Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/FastExpressionCompiler/FastExpressionCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3157,7 +3157,7 @@ private static bool TryEmitIndexOperands(Expression objExpr, IndexExpression ind
if (objVar != -1)
EmitLoadLocalVariable(il, objVar);
for (var i = 0; i < count; ++i)
EmitLoadLocalVariable(il, argVars[i]);
EmitLoadLocalVariable(il, argVars.GetSurePresentRef(i));
}
return true;
}
Expand Down Expand Up @@ -4826,7 +4826,7 @@ private static bool EmitNewArrayBounds(NewArrayExpression expr, ILGenerator il,
}
if (spillBounds)
for (var i = 0; i < boundCount; ++i)
EmitLoadLocalVariable(il, boundVars[i]);
EmitLoadLocalVariable(il, boundVars.GetSurePresentRef(i));
if (boundCount == 1)
{
var elemType = expr.Type.GetElementType();
Expand Down
2 changes: 2 additions & 0 deletions test/FastExpressionCompiler.TestsRunner.Net472/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static void RunLightExpressionTests(object state)
t.Run(new LightExpression.UnitTests.RuntimeTypeConstantRegressionTests());
t.Run(new LightExpression.UnitTests.MemberConstructorExceptionTests());
t.Run(new LightExpression.UnitTests.MethodBasedNotRegressionTests());
t.Run(new LightExpression.UnitTests.SpillMetadataBoundsTests());
t.Run(new LightExpression.UnitTests.ExtensionReductionIdentityRegressionTests());
t.Run(new LightExpression.UnitTests.LiftedOperandEvaluationRegressionTests());
t.Run(new LightExpression.UnitTests.StringReferenceIdentityTests());
Expand Down Expand Up @@ -222,6 +223,7 @@ static void RunLightExpressionTests(object state)
fecTests.Run(new RuntimeTypeConstantRegressionTests());
fecTests.Run(new MemberConstructorExceptionTests());
fecTests.Run(new MethodBasedNotRegressionTests());
fecTests.Run(new SpillMetadataBoundsTests());
fecTests.Run(new CustomReducibleNodeRegressionTests());
fecTests.Run(new ExtensionReductionIdentityRegressionTests());
fecTests.Run(new LiftedOperandEvaluationRegressionTests());
Expand Down
2 changes: 2 additions & 0 deletions test/FastExpressionCompiler.TestsRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static void Main(string[] args)
lt.Run(new LightExpression.UnitTests.RuntimeTypeConstantRegressionTests());
lt.Run(new LightExpression.UnitTests.MemberConstructorExceptionTests());
lt.Run(new LightExpression.UnitTests.MethodBasedNotRegressionTests());
lt.Run(new LightExpression.UnitTests.SpillMetadataBoundsTests());
lt.Run(new LightExpression.UnitTests.ExtensionReductionIdentityRegressionTests());
lt.Run(new LightExpression.UnitTests.LiftedOperandEvaluationRegressionTests());
lt.Run(new LightExpression.UnitTests.StringReferenceIdentityTests());
Expand Down Expand Up @@ -241,6 +242,7 @@ public static void Main(string[] args)
st.Run(new RuntimeTypeConstantRegressionTests());
st.Run(new MemberConstructorExceptionTests());
st.Run(new MethodBasedNotRegressionTests());
st.Run(new SpillMetadataBoundsTests());
st.Run(new CustomReducibleNodeRegressionTests());
st.Run(new ExtensionReductionIdentityRegressionTests());
st.Run(new LiftedOperandEvaluationRegressionTests());
Expand Down
28 changes: 28 additions & 0 deletions test/FastExpressionCompiler.UnitTests/SpillMetadataBoundsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using S = System.Linq.Expressions.Expression;
#if LIGHT_EXPRESSION
namespace FastExpressionCompiler.LightExpression.UnitTests;
#else
namespace FastExpressionCompiler.UnitTests;
#endif

public struct SpillMetadataBoundsTests : ITestX
{
public sealed class Cell { public int this[int a,int b,int c,int d]=>a+b+c+d; }
public void Run(TestRun t) { Array_bounds_cover_inline_and_overflow_metadata(t); All_index_operands_are_restored(t); }
public void Array_bounds_cover_inline_and_overflow_metadata(TestContext t)
{
foreach(var rank in new[]{1,4,8,12})
{
var bounds=new System.Linq.Expressions.Expression[rank];for(var i=0;i<rank;++i)bounds[i]=S.TryFinally(S.Constant(1),S.Empty());
var tree=S.Lambda<Func<Array>>(S.Convert(S.NewArrayBounds(typeof(int),bounds),typeof(Array)));
var fast=tree.FromSysExpression().CompileFast(true);if(!t.IsNotNull(fast))return;var result=fast();t.AreEqual(rank,result.Rank);t.AreEqual(1L,result.LongLength);
t.AreEqual(tree.Compile()().LongLength,result.LongLength);
}
}
public void All_index_operands_are_restored(TestContext t)
{
var cell=S.Parameter(typeof(Cell));var args=new System.Linq.Expressions.Expression[4];for(var i=0;i<4;++i)args[i]=S.TryFinally(S.Constant(i+1),S.Empty());
var tree=S.Lambda<Func<Cell,int>>(S.MakeIndex(cell,typeof(Cell).GetProperty("Item"),args),cell);var fast=tree.FromSysExpression().CompileFast(true);if(t.IsNotNull(fast))t.AreEqual(tree.Compile()(new Cell()),fast(new Cell()));
}
}
Loading