dadhi / FastExpressionCompiler

Fast Compiler for C# Expression Trees and the lightweight LightExpression alternative. Diagnostic and code generation tools for the expressions.
MIT License
1.16k stars 82 forks source link

Some form of compile time branch elimination #402

Open dadhi opened 6 months ago

dadhi commented 6 months ago

Sometimes when composing the final expression, the parts are the Lambdas and Invocations (e.g. AutoMapper does this a lot). The more generic lambda may take the null constant or default expression as invocation of a special kind. After inlining the Invocation contains the conditions Test like Constant(null) == Default(typeof(X)) or similar. Knowing that we may eliminate the false branch during Collect and Emit phase, and substitute the whole condition with the true branch body.