-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added: some initial improvements for #196: condition reduction, false…
… and true constants singletons; TBD: look to try catch upped language to 7.3
- Loading branch information
Showing
9 changed files
with
172 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
test/FastExpressionCompiler.IssueTests/FastExpressionCompiler.IssueTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...FastExpressionCompiler.IssueTests/Issue196_AutoMapper_tests_are_failing_when_using_FEC.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
| ||
|
||
using static System.Linq.Expressions.Expression; | ||
#if !LIGHT_EXPRESSION | ||
using System.Linq; | ||
using System.Reflection; | ||
using System; | ||
using System.Linq.Expressions; | ||
using AutoMapper; | ||
using NUnit.Framework; | ||
|
||
namespace FastExpressionCompiler.IssueTests | ||
{ | ||
[TestFixture] | ||
public class Issue196_AutoMapper_tests_are_failing_when_using_FEC | ||
{ | ||
public class FastExpressionCompilerBug | ||
{ | ||
[Test] | ||
public void ShouldWork() | ||
{ | ||
var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Dest>()); | ||
var mapper = config.CreateMapper(); | ||
var expression = mapper.ConfigurationProvider.ExpressionBuilder.CreateMapExpression(typeof(Source), typeof(Dest)); | ||
Assert.IsNotNull(((LambdaExpression)expression).CompileFast(true)); | ||
|
||
var source = new Source { Value = 5 }; | ||
var dest = mapper.Map<Dest>(source); | ||
|
||
Assert.AreEqual(source.Value, dest.Value); | ||
} | ||
|
||
public class Source | ||
{ | ||
public int Value { get; set; } | ||
} | ||
|
||
public class Dest | ||
{ | ||
public int Value { get; set; } | ||
} | ||
|
||
[Test] | ||
public void Comparison_with_null_should_produce_optimal_Brtrue_or_Brfalse_opcodes() | ||
{ | ||
var sourceParam = Parameter(typeof(Source), "source"); | ||
var body = Condition( | ||
Equal(sourceParam, Constant(null, typeof(Source))), | ||
Constant(null, typeof(Dest)), | ||
MemberInit(New(typeof(Dest).GetTypeInfo().DeclaredConstructors.First()), | ||
Bind(typeof(Dest).GetTypeInfo().DeclaredProperties.First(), | ||
Property(sourceParam, nameof(Source.Value))))); | ||
|
||
var expr = Lambda<Func<Source, Dest>>(body, sourceParam); | ||
|
||
//var fs = expr.Compile(); | ||
var ff = expr.CompileFast(true); | ||
|
||
var dest = ff(new Source {Value = 42}); | ||
Assert.AreEqual(42, dest.Value); | ||
} | ||
|
||
[Test] | ||
public void Logical_OrElse_should_be_reduced_if_one_of_operands_is_known_boolean_value() | ||
{ | ||
var sourceParam = Parameter(typeof(Source), "source"); | ||
var body = Condition( | ||
OrElse(Equal(sourceParam, Constant(null, typeof(Source))), Constant(false)), | ||
Constant(null, typeof(Dest)), | ||
MemberInit(New(typeof(Dest).GetTypeInfo().DeclaredConstructors.First()), | ||
Bind(typeof(Dest).GetTypeInfo().DeclaredProperties.First(), | ||
Property(sourceParam, nameof(Source.Value))))); | ||
|
||
var expr = Lambda<Func<Source, Dest>>(body, sourceParam); | ||
|
||
var fs = expr.Compile(); | ||
var ff = expr.CompileFast(true); | ||
|
||
var dest = ff(new Source { Value = 42 }); | ||
Assert.AreEqual(42, dest.Value); | ||
} | ||
|
||
[Test] | ||
public void Coalesce_should_produce_optimal_opcodes() | ||
{ | ||
var sourceParam = Parameter(typeof(Source), "source"); | ||
var body = Condition( | ||
Equal(sourceParam, Constant(null)), | ||
Constant(null, typeof(Dest)), | ||
Coalesce( | ||
Constant(new Dest { Value = 13 }), | ||
MemberInit(New(typeof(Dest).GetTypeInfo().DeclaredConstructors.First()), | ||
Bind(typeof(Dest).GetTypeInfo().DeclaredProperties.First(), | ||
Property(sourceParam, nameof(Source.Value)))))); | ||
|
||
var expr = Lambda<Func<Source, Dest>>(body, sourceParam); | ||
|
||
//var fs = expr.Compile(); | ||
var ff = expr.CompileFast(true); | ||
|
||
var dest = ff(new Source { Value = 42 }); | ||
Assert.AreEqual(13, dest.Value); | ||
} | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters