Skip to content

LINQ in the compiler #13474

Description

@SeeminglyScience

Not really a bug but:

private IEnumerable<Expression> CompileInvocationArguments(IEnumerable<ExpressionAst> arguments)
{
return arguments == null ? Array.Empty<Expression>() : arguments.Select(CompileExpressionOperand);
}

And the method in the select:

internal Expression CompileExpressionOperand(ExpressionAst exprAst)
{
var result = Compile(exprAst);
if (result.Type == typeof(void))
{
result = Expression.Block(result, ExpressionCache.NullConstant);
}
return result;
}

That method is used to compile method arguments, the result is then enumerated twice (once in the first highlighted line, one is the last):

var callInfo = new CallInfo(args.Count());
var classScope = _memberFunctionType != null ? _memberFunctionType.Type : null;
var binder = name.Equals("new", StringComparison.OrdinalIgnoreCase) && @static
? (CallSiteBinder)PSCreateInstanceBinder.Get(callInfo, constraints, publicTypeOnly: true)
: PSInvokeMemberBinder.Get(name, callInfo, @static, propertySet, constraints, classScope);
var dynamicExprFromBinder = DynamicExpression.Dynamic(binder, typeof(object), args.Prepend(target));

This causes all method arguments to be compiled twice due to multiple enumeration. I'm not aware of any bugs due to this behavior, but it probably negatively impacts compile time for complicated member invocations. Also the method supplied to Select is not done in such a way that the delegate can be cached per instance by roslyn.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-Engine-Performancecore PowerShell engine, interpreter, and runtime performance

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions