Skip to content

Commit

Permalink
Only create one instance of Features.None/PFxV1 (#2740)
Browse files Browse the repository at this point in the history
  • Loading branch information
lesaltzm authored Nov 14, 2024
1 parent 9a9f71e commit ff22ee8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/libraries/Microsoft.PowerFx.Core/Public/CheckResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ public CheckContextSummary ApplyGetContextSummary()
var summary = new CheckContextSummary
{
AllowsSideEffects = allowSideEffects,
IsPreV1Semantics = isV1,
IsPreV1Semantics = !isV1,
ExpectedReturnType = this._expectedReturnTypes,
SuggestedSymbols = symbolEntries
};
Expand Down
45 changes: 23 additions & 22 deletions src/libraries/Microsoft.PowerFx.Core/Public/Config/Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,96 +9,92 @@

namespace Microsoft.PowerFx
{
[ThreadSafeImmutable]
public sealed class Features
{
/// <summary>
/// Enable Table syntax to not add "Value:" extra layer.
/// </summary>
internal bool TableSyntaxDoesntWrapRecords { get; set; }
internal bool TableSyntaxDoesntWrapRecords { get; init; }

/// <summary>
/// Enable functions to consistently return one dimension tables with
/// a "Value" column rather than some other name like "Result".
/// </summary>
internal bool ConsistentOneColumnTableResult { get; set; }
internal bool ConsistentOneColumnTableResult { get; init; }

/// <summary>
/// Disables support for row-scope disambiguation syntax.
/// Now,for example user would need to use Filter(A, ThisRecord.Value = 2) or Filter(A As Foo, Foo.Value = 2)
/// instead of
/// Filter(A, A[@Value] = 2).
/// </summary>
internal bool DisableRowScopeDisambiguationSyntax { get; set; }
internal bool DisableRowScopeDisambiguationSyntax { get; init; }

/// <summary>
/// Enable Identifier support for describing column names.
/// </summary>
internal bool SupportColumnNamesAsIdentifiers { get; set; }
internal bool SupportColumnNamesAsIdentifiers { get; init; }

/// <summary>
/// Enforces strong-typing for builtin enums, rather than treating
/// them as aliases for values of string/number/boolean types.
/// </summary>
internal bool StronglyTypedBuiltinEnums { get; set; }
internal bool StronglyTypedBuiltinEnums { get; init; }

/// <summary>
/// Updates the IsEmpty function to only allow table arguments, since it
/// does not work properly with other types of arguments.
/// </summary>
internal bool RestrictedIsEmptyArguments { get; set; }
internal bool RestrictedIsEmptyArguments { get; init; }

/// <summary>
/// Allow delegation for async calls (delegate using awaited call result).
/// </summary>
internal bool AllowAsyncDelegation { get; set; }
internal bool AllowAsyncDelegation { get; init; }

/// <summary>
/// Allow delegation for impure nodes.
/// </summary>
internal bool AllowImpureNodeDelegation { get; set; }
internal bool AllowImpureNodeDelegation { get; init; }

/// <summary>
/// Updates the FirstN/LastN functions to require a second argument, instead of
/// defaulting to 1.
/// </summary>
internal bool FirstLastNRequiresSecondArguments { get; set; }
internal bool FirstLastNRequiresSecondArguments { get; init; }

internal bool PowerFxV1CompatibilityRules { get; set; }
internal bool PowerFxV1CompatibilityRules { get; init; }

/// <summary>
/// This is required by AsType() in PA delegation analysis.
/// </summary>
internal bool AsTypeLegacyCheck { get; set; }

/// <summary>
/// This is required by AsType() in Legacy Analysis.
/// </summary>
internal bool IsLegacyAnalysis { get; set; }
internal bool AsTypeLegacyCheck { get; init; }

/// <summary>
/// Removes support for coercing a control to it's primary output property.
/// This only impacts PA Client scenarios, but some code still lives in PFx.
/// </summary>
internal bool PrimaryOutputPropertyCoercionDeprecated { get; set; }
internal bool PrimaryOutputPropertyCoercionDeprecated { get; init; }

/// <summary>
/// This is specific for PVA team and it is a temporary feature.
/// </summary>
internal bool JsonFunctionAcceptsLazyTypes { get; set; }
internal bool JsonFunctionAcceptsLazyTypes { get; init; }

/// <summary>
/// Enables more robust lookup reduction delegation.
/// </summary>
internal bool IsLookUpReductionDelegationEnabled { get; set; }
internal bool IsLookUpReductionDelegationEnabled { get; init; }

/// <summary>
/// Enables User-defined types functionality.
/// </summary>
internal bool IsUserDefinedTypesEnabled { get; set; } = false;
internal bool IsUserDefinedTypesEnabled { get; init; } = false;

internal static Features None => new Features();
internal static readonly Features None = new Features();

public static Features PowerFxV1 => new Features
public static readonly Features PowerFxV1 = new Features
{
TableSyntaxDoesntWrapRecords = true,
ConsistentOneColumnTableResult = true,
Expand Down Expand Up @@ -130,6 +126,11 @@ internal Features(Features other)
PowerFxV1CompatibilityRules = other.PowerFxV1CompatibilityRules;
PrimaryOutputPropertyCoercionDeprecated = other.PrimaryOutputPropertyCoercionDeprecated;
IsUserDefinedTypesEnabled = other.IsUserDefinedTypesEnabled;
AllowImpureNodeDelegation = other.AllowImpureNodeDelegation;
AllowAsyncDelegation = other.AllowAsyncDelegation;
AsTypeLegacyCheck = other.AsTypeLegacyCheck;
JsonFunctionAcceptsLazyTypes = other.JsonFunctionAcceptsLazyTypes;
IsLookUpReductionDelegationEnabled = other.IsLookUpReductionDelegationEnabled;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ public class AsTypeIsTypeParseJSONTests
{
private RecalcEngine SetupEngine(bool udtFeaturedEnabled = true)
{
var config = new PowerFxConfig();
var features = new Features(Features.PowerFxV1)
{
IsUserDefinedTypesEnabled = udtFeaturedEnabled,
};
var config = new PowerFxConfig(features);
config.EnableJsonFunctions();
config.Features.IsUserDefinedTypesEnabled = udtFeaturedEnabled;
return new RecalcEngine(config);
}

Expand Down

0 comments on commit ff22ee8

Please sign in to comment.