Show / Hide Table of Contents

Class ShortcircuitExpressions

Remove operations when knowledge about the nullity of Expression nodes allows this.

Inheritance
Object
ChangeDag<Expression, Table, IExpressionVisitor>
ChangeExpressions
ShortcircuitExpressions
Implements
IGenericExpressionVisitor<IEnumerable<Expression>>
IExpressionVisitor
IGenericVisitor<IEnumerable<Expression>>
Inherited Members
ChangeExpressions.CreatedExpressions
ChangeExpressions.Result
ChangeExpressions.Identifier(Expression)
ChangeExpressions.ChangeIdentifier(Expression)
ChangeExpressions.Change(Aggregand)
ChangeExpressions.Change(BinaryAggregation)
ChangeExpressions.Change(ColumnReference)
ChangeExpressions.Change(DataSourceColumn)
ChangeExpressions.Change(Extern)
ChangeExpressions.Change(Filter)
ChangeExpressions.Change(JoinKey)
ChangeExpressions.Change(Literal)
ChangeExpressions.Change(RuntimeVariable)
ChangeExpressions.Change(UnaryAggregation)
ChangeExpressions.Change(UnionExpression)
ChangeExpressions.Change(VectorOperation)
ChangeExpressions.Change(UnaryWindowFunction)
ChangeExpressions.Visit(Aggregand)
ChangeExpressions.Visit(BinaryAggregation)
ChangeExpressions.Visit(BinaryOperation)
ChangeExpressions.Visit(ColumnReference)
ChangeExpressions.Visit(DataSourceColumn)
ChangeExpressions.Visit(Extern)
ChangeExpressions.Visit(Filter)
ChangeExpressions.Visit(JoinKey)
ChangeExpressions.Visit(Literal)
ChangeExpressions.Visit(RuntimeVariable)
ChangeExpressions.Visit(TernaryOperation)
ChangeExpressions.Visit(UnaryAggregation)
ChangeExpressions.Visit(UnaryOperation)
ChangeExpressions.Visit(UnionExpression)
ChangeExpressions.Visit(VectorOperation)
ChangeExpressions.Visit(UnaryWindowFunction)
ChangeDag<Expression, Table, IExpressionVisitor>.Mapping
ChangeDag<Expression, Table, IExpressionVisitor>.Reset()
ChangeDag<Expression, Table, IExpressionVisitor>.Identifier(Expression)
ChangeDag<Expression, Table, IExpressionVisitor>.ChangeIdentifier(Expression)
ChangeDag<Expression, Table, IExpressionVisitor>.ReplaceParent(Expression, Expression, Expression)
ChangeDag<Expression, Table, IExpressionVisitor>.UberVisit<TSubnode>(TSubnode, Func<TSubnode, Expression>)
ChangeDag<Expression, Table, IExpressionVisitor>.UberVisit<TSubnode, TSubidentifier>(TSubnode, Func<TSubnode, Expression>)
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Mangrove.MetricSetTransformers.Normalization
Assembly: MetricSetTransformers.dll
Syntax
public class ShortcircuitExpressions : ChangeExpressions, IGenericExpressionVisitor<IEnumerable<Expression>>, IExpressionVisitor, IGenericVisitor<IEnumerable<Expression>>
Remarks

Why is this needed? It is an artifact of a construct called "generic templates" and how they are handled by the MDL Compiler as of now (2019-04-15). Generic templates are essentially C# functions whose definitions are inlined after Roslyn validates the metric set. However, there can be valid C# code which no longer compiles after function inlining, see for example:

int x = 0;
double foo(double? y) => y ?? 0;
foo(x);

Here, the inlined function definition x ?? 0 will cause the C# compiler to complain.

In addition, we replace any tautological comparisons, like

  1. for non-nullable x, we replace x != null ---> true x == null ---> false null != x ---> true null == x ---> false IsNull(x) ---> false IsNotNull(x) ---> true
  2. we replace tautological literal comparisons 1 != 2 ---> true 5 == 5 ---> true true == false ---> false
  3. for any boolean ternary operation with the left operand tautologically true of false, we replace that with the corresponding value, i.e. true ? a : b ---> a false ? a : b ---> b
  4. for And and Or

true && true ---> true true || true ---> true true && false ---> false true || false ---> true

In particular, expression

x != null ? 1 : 0 for non-nullable x

would be simply replaced with the literal 1.

Methods

View Source

Change(BinaryOperation)

Declaration
protected override Expression Change(BinaryOperation expr)
Parameters
Type Name Description
BinaryOperation expr
Returns
Type Description
Expression
Overrides
ChangeExpressions.Change(BinaryOperation)
View Source

Change(TernaryOperation)

Declaration
protected override Expression Change(TernaryOperation expr)
Parameters
Type Name Description
TernaryOperation expr
Returns
Type Description
Expression
Overrides
ChangeExpressions.Change(TernaryOperation)
View Source

Change(UnaryOperation)

Declaration
protected override Expression Change(UnaryOperation expr)
Parameters
Type Name Description
UnaryOperation expr
Returns
Type Description
Expression
Overrides
ChangeExpressions.Change(UnaryOperation)

Implements

IGenericExpressionVisitor<T>
IExpressionVisitor
IGenericVisitor<T>

Extension Methods

ObjectExtensions.EventId(Object)
  • View Source
Back to top Generated by DocFX