Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PowerShell.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.3</RuntimeFrameworkVersion>
<LangVersion>Latest</LangVersion>
<TieredCompilation>true</TieredCompilation>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
2 changes: 2 additions & 0 deletions src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,8 @@ public static class InternalTestHooks

internal static bool ShowMarkdownOutputBypass;

internal static bool ExpressionCompile;

/// <summary>This member is used for internal test purposes.</summary>
public static void SetTestHook(string property, object value)
{
Expand Down
33 changes: 23 additions & 10 deletions src/System.Management.Automation/engine/parser/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ private static RuntimeDefinedParameter GetRuntimeDefinedParameter(ParameterAst p

if (attribute is ExperimentalAttribute expAttribute)
{
// Only honor the first seen experimental attribute, ignore the others.
// Only honor the first seen experimental attribute, ignore the others.
if (!hasSeenExpAttribute && expAttribute.ToHide) { return null; }

// Do not add experimental attributes to the attribute list.
Expand Down Expand Up @@ -1763,19 +1763,32 @@ internal void Compile(CompiledScriptBlockData scriptBlock, bool optimize)
private Action<FunctionContext> CompileTree(Expression<Action<FunctionContext>> lambda, CompileInterpretChoice compileInterpretChoice)
{
if (lambda == null)
{
return null;
}

if (compileInterpretChoice == CompileInterpretChoice.AlwaysCompile)
switch (compileInterpretChoice)
{
return lambda.Compile();
}
case CompileInterpretChoice.AlwaysCompile:

return lambda.Compile(preferInterpretation: false);

// threshold is # of times the script must run before we decide to compile
// NeverCompile sets the threshold to int.MaxValue, so theoretically we might compile
// at some point, but it's very unlikely.
int threshold = (compileInterpretChoice == CompileInterpretChoice.NeverCompile) ? int.MaxValue : -1;
var deleg = new LightCompiler(threshold).CompileTop(lambda).CreateDelegate();
return (Action<FunctionContext>)deleg;
case CompileInterpretChoice.NeverCompile:

return lambda.Compile(preferInterpretation: true);

default:
// Here compileInterpretChoice == CompileInterpretChoice.CompileOnDemand
//
if (Internal.InternalTestHooks.ExpressionCompile)
{
return lambda.Compile(preferInterpretation: false);
}
else
{
return lambda.Compile(preferInterpretation: true);
}
}
}

internal static object GetExpressionValue(ExpressionAst expressionAst, bool isTrustedInput, ExecutionContext context, IDictionary usingValues = null)
Expand Down