FastExpressionCompiler

Fast Compiler for C# Expression Trees and the lightweight LightExpression alternative. Diagnostic and code generation tools for the expressions.

MIT License

Stars
1.1K
Committers
24

Bot releases are visible (Hide)

FastExpressionCompiler - v4.2.0 Feature and bug-fix release Latest Release

Published by dadhi 6 months ago

v4.2.0 Feature and bug-fix release

  • feat: #133 Optimize Switch Expression

  • feat: #393 Support ToCSharpString of the block in the ternary expression

  • feat: #396 Optimize conditional expressions with the DefaultExpression left or right operand the same way as ConstantExpression

  • fix: #390 System.AccessViolationException when mapping using Mapster

  • fix: #391 ToCSharpString outputs ? for Nullable which does not produce the compile-able code

  • fix: #392 ToExpressionString wrongly declares Label instead of LabelTarget array

  • fix: #394 Calling a user defined == operator runs into a CLR invalid program exception

  • fix: #397 Fix and optimize the Switch support

  • fix: #399 Coalesce nullable with 0 is not working

  • fix: #400 Fix the direct assignment of Try to Member expression because indirect assignment through tmp var works

  • fix: #401 Invoke inlining is not working with collections in AutoMapper tests

  • fix: #404 An expression with a single parameter concatenated to a string causes 'Exception has been thrown by the target of an invocation' during delegate invocation

  • fix: #405 NullReferenceException with V4.X when using long?[]

  • fix: #406 NullReferenceException with V4.X

  • fix: #407 NullReferenceException when setting the Enum field

  • fix: #408 Dictionary mapping failing when the InvocationExpression inlining is involved

FastExpressionCompiler - v4.1.0 Small feature and bug release

Published by dadhi 9 months ago

v4.1.0 Small feature and bug release

  • added: #379 Add direct net8.0 target as soon as Appveyor CI will support it
  • fixed: #380 Comparisons with nullable types
  • fixed: #381 NullReferenceException with V4.X when trying to map
  • fixed: #386 Value can not be null(parametr 'meth')
FastExpressionCompiler - v4.0.1 Bug-fix release

Published by dadhi 11 months ago

v4.0.1 Bug-fix release

  • fixed: #374 CompileFast doesn't work with HasFlag
FastExpressionCompiler - v4.0.0 Major release

Published by dadhi 11 months ago

v4.0.0 Major release

  • fixed: #352 xxxAssign doesn't work with MemberAccess

  • fixed: #353 NullReferenceException when calling CompileFast() results

  • fixed: #357 Invalid program exception

  • fixed: #366 FastExpressionCompiler[v3.3.4] gives incorrect results in some linq operations

  • fixed: #368 Fix duplicate nested lambda compilation

  • fixed: #374 CompileFast doesn't work with HasFlag

  • added: #264 Optimize the array index emit to emit specific Ldelem_ code instead of generic Ldelem

  • added: #273 Implement IArgumentProvider for the BlockExpression to minimize the consumed memory

  • added: #346 Is it possible to implement ref local variables?

  • added: #359 Improve the performance of variable lookup

  • added: #367 Better diagnostics and debugging with error codes from Collect and Compile rounds

  • added: #369 Decrease memory occupied by the LightExpression Block by storing Expression in SmallList (partly on stack)

  • added: #370 Optimize any nested lambda compilation (LINQ) by compiling right after collect one-by-one

  • added: #372 Support LightExpression.Expression.TryConvertDelegateIntrinsic for converting one type of delegate to another

  • added: #373 Support custom C# printing for the LightExpression.Expression

FastExpressionCompiler - v3.3.4 Bug-fix release

Published by dadhi almost 2 years ago

v3.3.4 Bug-fix release

  • fixed: #345 EmitCall is for the varargs method and should not be used for normal convention

  • fixed: #347 InvalidProgramException on compiling an expression that returns a record which implements IList

  • fixed: #349 Error when loading struct parameters closed by the nested lambda e.g. predicate in Linq

  • fixed: #355 Error with converting to/from signed/unsigned integers (Thanks to @TYoungSL for the PR!)

  • fixed: the C# output for if-else test condition, and inc/dec operations; and for label at the end of the lambda

  • fixed: ref assignment C# output

  • perf: Replace ILGenerator.Emit(OpCodes.Call, ..) with EmitMethodCall performance

FastExpressionCompiler - v3.3.3 Bug-fix release

Published by dadhi about 2 years ago

v3.3.3 Bug-fix release

  • fixed: #336 Method TryCompileBoundToFirstClosureParam is returning passed Type array to pool may cause undefined behavior
  • fixed: #337 Switch LightExpression.Expression.ToString from System.Expression.ToString pseudo-code to ToCSharpString
  • fixed: #338 InvocationExpression is not properly converted to System Expression via ToExpression for non-lambda expression
  • fixed: #341 Equality comparison between nullable and null inside Any produces incorrect compiled expression
FastExpressionCompiler - v3.3.2 Bug-fix release

Published by dadhi over 2 years ago

v3.3.2 Bug-fix release

  • fixed: #335 FastExpressionCompiler.LightExpressions - MemberInit has recursive calls
FastExpressionCompiler - v3.3.1 Optimization and bug-fix release

Published by dadhi over 2 years ago

v3.3.1 Optimization and bug-fix release

  • fixed: #333 AccessViolationException and other suspicious behaviour on invoking result of CompileFast()
  • optim: LightExpression.Parameter consumes less memory for the common standard types.
FastExpressionCompiler - v3.3.0 Feature and bug-fix release

Published by dadhi over 2 years ago

v3.3.0 Feature and bug-fix release

  • added: #235 [GodMode] Expression to IL intrinsic
  • added: #325 Add LightExpression.NewNoByRefArgs overloads for performance
  • added: #327 Replace direct il.Emit(OpCodes.Call, ...) with EmitMethodCall
  • added: #329 Optimize special case compilation for New and Call with no arguments
  • added: #330 Optimize nested lambda ClosureInfo memory footprint
  • fixed: #324 The LightExpression.New of IEnumerable is recursive
  • fixed: #328 Fix the performance of TryEmitConvert to String
FastExpressionCompiler - v3.2.2 Bug-fix release

Published by dadhi over 2 years ago

v3.2.2 Bug-fix release

  • fixed: #284 Invalid Program after Coalesce
  • fixed: #308 Wrong delegate type returned (with closure)
  • fixed: #310 InvalidProgramException when nullable result is ignored
  • fixed: #316 in parameter
  • fixed: #319 NRE in IndexExpression.get_ArgumentCount
  • fixed: #320 "Bad label content in ILGenerator" when creating through DynamicModule
  • fixed: #321 Call with out parameter to field type that is not value type fails
FastExpressionCompiler - v3.2.1 Bug-fix release

Published by dadhi about 3 years ago

v3.2.1 Bug-fix release

  • fixed: #307 Switch with fall through throws "System.InvalidProgramException: 'Common Language Runtime detected an invalid program.'"
FastExpressionCompiler - v3.2.0 Bug-fix and optimization release

Published by dadhi over 3 years ago

v3.2.0 Bug-fix and optimization release

  • fixed: #305 CompileFast generates incorrect code with arrays and printing
  • fixed: added missing Expression.MakeCatchBlock
  • optimized: memory of Expression of T
  • optimized: for the custom MethodCallExpression
  • optimized: adding the ConstantInt and ConstantOf without boxing and null constant with the less space
FastExpressionCompiler - v3.1.0 Feature and bug-fix release

Published by dadhi over 3 years ago

v3.1.0 Feature and bug-fix release

  • added: #297 Add custom Constant to string output in the ToCSharpString and ToExpressionString
  • added: #303 Add CompilerFlags.ThrowOnNotSupportedException and throw NotSupportedExpressionException when the flag is passed to CompileFast
  • fixed: #301 Another case of the InvalidOperationException in the Mapster
  • fixed: ListInit compilation for the Dictionary
  • fixed: the lookup for the non-public property setter
FastExpressionCompiler - v3.0.5 Bug-fix release

Published by dadhi over 3 years ago

v3.0.5 Bug-fix release

  • fixed: another case in #301 InvalidOperationException in the Mapster
  • fixed: multiple problems with the TryCatch C# and Expression string output
FastExpressionCompiler - v3.0.4 Bug-fix release

Published by dadhi over 3 years ago

v3.0.4 Bug-fix release

  • fixed: #302 Error compiling expression with array access
FastExpressionCompiler - v3.0.3 Bug-fix release

Published by dadhi over 3 years ago

v3.0.3 Bug-fix release

  • fixed: #301 InvalidOperationException in the Mapster
  • fixed: small bugs in the Lambda ToCSharpString output
FastExpressionCompiler - ## v3.0.2 Bug-fix release

Published by dadhi over 3 years ago

v3.0.2 Bug-fix release

  • fixed: #300 Bad label content in ILGenerator in the Mapster benchmark with FEC V3
  • fixed: Small issues with the ToCSharpString(), specifically in the TryCatch, and the Goto, and the Label expressions
FastExpressionCompiler - v3.0.1 Bug-fix release

Published by dadhi over 3 years ago

v3.0.1 Bug-fix release

fixed: #298 LightExpression with the NewExpression of 4 arguments has ArgumentCount = 3

FastExpressionCompiler - v3.0.0 - Major feature release

Published by dadhi over 3 years ago

v3.0.0 - Major feature release

This version contains a lot of fixes and improvements and as-little-as-possible breaking changes.

FastExpressionCompiler and FastExpressionCompiler.LightExpression

  • Performance and memory consumption are improved, especially for the expressions with the closure and for expressions with the nested lambdas.
  • More expression types are supported.
  • Many fixes in the IL Emit.
  • Added ToCSharpString() extension method to output the compile-able C# code described by the expression (tries hard).
  • Added ToExpressionString() extension method to output the valid expression construction syntax, so given an expression object you'll get e.g. Lambda(New(...)).
  • Added optional enum CompilerFlags { Default, NoInvocationLambdaInlining, EnableDelegateDebugInfo} parameter for the compilation
  • EnableDelegateDebugInfo adds the diagnostic info into the compiled delegate including its source Expression and C# code. Can be used as following:
    var f = e.CompileFast(true, CompilerFlags.EnableDelegateDebugInfo);
    var di = f.Target as IDelegateDebugInfo;
    Assert.IsNotNull(di.Expression);
    Assert.IsNotNull(di.ExpressionString);
    Assert.IsNotNull(di.CSharpString);

FastExpressionCompiler.LightExpression

  • Now includes the ExpressionVisitor.
  • Improves the compatibility (the drop-in replacement) between the FastExpressionCompiler.LightExpression.Expression and the System.Linq.Expression.
  • Decreasing the memory consumed by the created expressions partially via implementing the IArgumentProvider and IParameterProvider for some expressions.

The full list of the closed issues

Milestone v3.0.0

FastExpressionCompiler - v2.0.0

Published by dadhi over 5 years ago

Major release

Contains breaking changes, but likely or lucky you'll need to re-compile only.

Thanks

V2 was developed with a strong help of @jogibear9988, @dzmitry-lahoda, @MaceWindu,
and other contributors - kudos to all of them!

The main change

FEC package now is split in two: [FastExpressionCompiler (FEC)] and [FastExpressionCompiler.LightExpression (FEC.LE)]. The packages are not dependent on each other and may be used together.

FEC.LightExpression allows a drop-in replacement for manually created expression, the only change is different namespace using. LE.Expression is "lighter" because it is faster created and consumes less memory. It does it by avoiding most of compatibility and verification checks. But it does not mean it is not safe! You can convert it to System Expression as easy as calling ToExpression or ToLambdaExpression and it will run the usual verification. This conversation also enables fallback to Expression.Compile inside the CompileFast.

  • ExpressionInfo and supporting logic is moved from FEC to FEC.LE
  • ExpressionInfo is renamed to Expression but moved into new namespace FastExpressionCompiler.LightExpression
  • FastExpressionCompiler.cs stripped from ExpressionInfo noise and now is much simpler and lost 33% LOC.
  • FastExpressionCompiler.cs is shared between FEC and FEC.LE with LIGHT_EXPRESSION build variable controlling what to compile: System.Linq.Expressions.Expression or FastExpressionCompiler.LightExpression

Features

  • added: #57 Consider signed package version!
  • added: #59 Support compiling delegates with ref and out parameters
  • added: #78 Lambda<Func>(Block(Label(Label(typeof(int)), Constant(7)))) is not supported
  • added: #88 Lambda<Func>(Block(Constant(IntPtr.Zero)))
  • added: #91 Support for MultiplyAssign, AddAsiggn, DivideAssign
  • added: #98 % and bit operators are not supported
  • added: #101 Some Assign Modes are not yet supported
  • added: #102 Label and Goto Expression not yet implemented
  • added: #105 Bit Expression Types are not yet supported
  • added: #106 ExpressionType.Power not supported
  • added: #107 Check if xxxAssigns also work with Variables
  • added: #118 Support for Expression.Variable (in a Expression.Block)
  • added: #127 Switch is not supported
  • added: #130 Net Framework Expression compiler generates perfromanter Code for isNull check
  • added: #138 Optimize Compilation of nested Lambdas

Fixes

  • fixed: #83 Issues with linq2db tests
  • fixed: #92 Expression not compilable
  • fixed: #93 Comparison to "null" does not work when not Typed
  • fixed: #95 Ref support not yet working completely
  • fixed: #124 LightExpression wrong Type
  • fixed: #131 Linq2db - Test for JIT compiler internal limitation
  • fixed: #137 Problem with Reading & Writing of Struct Fields.
  • fixed: #146 Boolean parameter value changed from false to true
  • fixed: #147 'Common Language Runtime detected an invalid program' with int.TryParse
  • fixed: #151 'Attempt to read protected memory'
  • fixed: #152 int.MinValue access throws 'Method not supported'
  • fixed: #154 Equals Expression does not call "Equals" of class (in MS Code)
  • fixed: #156 Invoking an Action constant fails with 'Common Language Runtime detected an invalid program'
  • fixed: #159 Condition with converted numeric comparisons gives unexpected result
  • fixed: #162 Float - short numeric comparisons with conversions gives unexpected result
  • fixed: #163 Add of Nullable Int, etc does not work correctly
  • fixed: #165 Int and Decimal to Double conversion issues
  • fixed: #170 Problems with ref parameters
  • fixed: #172 Using FEC to compile a property setter with an enum value sets the property to random values