Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorium committed Aug 30, 2016
1 parent 8684657 commit cb1ff05
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 1.0.3 - 30/08/2016
* Constant evaluation.

### 1.0.2 - 30/08/2016
* Better support of C# anonymous types

Expand Down
8 changes: 4 additions & 4 deletions src/Linq.Expression.Optimizer.net35/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("Linq.Expression.Optimizer.net35")>]
[<assembly: AssemblyProductAttribute("Linq.Expression.Optimizer")>]
[<assembly: AssemblyDescriptionAttribute("Lightweight optimizer of System.Linq.Expression expressions. Just basic boolean algebra and reductions, constant and tuple/anonymous type eliminations.")>]
[<assembly: AssemblyVersionAttribute("1.0.2")>]
[<assembly: AssemblyFileVersionAttribute("1.0.2")>]
[<assembly: AssemblyVersionAttribute("1.0.3")>]
[<assembly: AssemblyFileVersionAttribute("1.0.3")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] Version = "1.0.2"
let [<Literal>] InformationalVersion = "1.0.2"
let [<Literal>] Version = "1.0.3"
let [<Literal>] InformationalVersion = "1.0.3"
8 changes: 4 additions & 4 deletions src/Linq.Expression.Optimizer/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("Linq.Expression.Optimizer")>]
[<assembly: AssemblyProductAttribute("Linq.Expression.Optimizer")>]
[<assembly: AssemblyDescriptionAttribute("Lightweight optimizer of System.Linq.Expression expressions. Just basic boolean algebra and reductions, constant and tuple/anonymous type eliminations.")>]
[<assembly: AssemblyVersionAttribute("1.0.2")>]
[<assembly: AssemblyFileVersionAttribute("1.0.2")>]
[<assembly: AssemblyVersionAttribute("1.0.3")>]
[<assembly: AssemblyFileVersionAttribute("1.0.3")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] Version = "1.0.2"
let [<Literal>] InformationalVersion = "1.0.2"
let [<Literal>] Version = "1.0.3"
let [<Literal>] InformationalVersion = "1.0.3"
27 changes: 16 additions & 11 deletions src/Linq.Expression.Optimizer/ExpressionOptimizer.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// This is just a light-weight expression optimizer.
/// It won't Compile() or do any heavy stuff.
/// It won't do any heavy stuff...
module ExpressionOptimizer

open System.Linq.Expressions
Expand Down Expand Up @@ -225,23 +225,28 @@ let internal deMorgan = function
| noHit -> noHit

// ------------------------------------- //
#if NET45
/// This is just helping to work with FSI:
let internal ``evaluate FSI constants`` (e:Expression) =
/// Evaluating constants to not mess with our expressions:
let internal ``evaluate constants`` (e:Expression) =
match e.NodeType, e with
// Also we don't want FSharp interactive debugging to mess our expressions:
| ExpressionType.MemberAccess, ( :? MemberExpression as me)
when me <> null && me.Expression=null && me.Member.DeclaringType.Name.ToUpper().StartsWith("FSI_") ->
when me <> null && me.Expression<>null ->
match me.Expression with
| :? ConstantExpression ->
//Constant expression. Can be evaluated.
Expression.Constant(Expression.Lambda(me).Compile().DynamicInvoke(null), me.Type) :> Expression
| _ -> e
| ExpressionType.MemberAccess, ( :? MemberExpression as me)
when me <> null && me.Expression=null &&
(me.Member.DeclaringType.Name.ToUpper().StartsWith("FSI_")
|| me.Member.DeclaringType.Name.ToUpper().StartsWith("<>C__DISPLAYCLASS") ) ->
match me.Member with
| :? PropertyInfo as p when p.PropertyType.IsValueType -> Expression.Constant(p.GetValue(p) :?> IComparable, p.PropertyType) :> Expression
| :? PropertyInfo as p when p.GetType().FullName.StartsWith("System") ->
Expression.Constant(Expression.Lambda(me).Compile().DynamicInvoke(null), me.Type) :> Expression
| _ -> e
| _ -> e
#endif
// ------------------------------------- //
let internal reductionMethods = [
#if NET45
``evaluate FSI constants``;
#endif
``evaluate constants``;
``replace constant comparison``; ``remove AnonymousType``; ``cut not used condition``; ``not false is true``;
(*associate;*) commute; (*distribute;*) gather; identity; annihilate; absorb; idempotence; complement; doubleNegation; deMorgan]

Expand Down
3 changes: 2 additions & 1 deletion src/Linq.Expression.Optimizer/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ open System.Linq.Expressions

let xs = [1;2;3;4;5].AsQueryable()

let cons = 8
let qry =
query{
for x in xs do
select (not(not(not(x>3))) && true)
select (not(not(not(x>3))) && true && cons>2)
}

let optimized = ExpressionOptimizer.visit(qry.Expression)
Expand Down

0 comments on commit cb1ff05

Please sign in to comment.