Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public SymbolTable SymbolTable
set => _symbolTable = value;
}

// Remove this: https://github.com/microsoft/Power-Fx/issues/2821
internal readonly Dictionary<TexlFunction, IAsyncTexlFunction> AdditionalFunctions = new ();

[Obsolete("Use Config.EnumStore or symboltable directly")]
internal EnumStoreBuilder EnumStoreBuilder => InternalConfigSymbols.EnumStoreBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ public static void EnableRegExFunctions(this PowerFxConfig config, TimeSpan regE
{
RegexTypeCache regexTypeCache = new (regexCacheSize);

foreach (KeyValuePair<TexlFunction, IAsyncTexlFunction> func in Library.RegexFunctions(regExTimeout, regexTypeCache))
foreach (TexlFunction func in Library.RegexFunctions(regExTimeout, regexTypeCache))
{
if (config.ComposedConfigSymbols.Functions.AnyWithName(func.Key.Name))
if (config.ComposedConfigSymbols.Functions.AnyWithName(func.Name))
{
throw new InvalidOperationException("Cannot add RegEx functions more than once.");
}

config.InternalConfigSymbols.AddFunction(func.Key);
config.AdditionalFunctions.Add(func.Key, func.Value);
config.InternalConfigSymbols.AddFunction(func);
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/libraries/Microsoft.PowerFx.Interpreter/EvalVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,6 @@ public override async ValueTask<FormulaValue> Visit(CallNode node, EvalVisitorCo

FormulaValue result;

// Remove this: https://github.com/microsoft/Power-Fx/issues/2821
IReadOnlyDictionary<TexlFunction, IAsyncTexlFunction> extraFunctions = _services.GetService<IReadOnlyDictionary<TexlFunction, IAsyncTexlFunction>>();

try
{
IFunctionInvoker invoker = GetInvoker(func);
Expand All @@ -430,10 +427,6 @@ public override async ValueTask<FormulaValue> Visit(CallNode node, EvalVisitorCo
{
result = await asyncFunc.InvokeAsync(args, _cancellationToken).ConfigureAwait(false);
}
else if (extraFunctions?.TryGetValue(func, out asyncFunc) == true)
{
result = await asyncFunc.InvokeAsync(args, _cancellationToken).ConfigureAwait(false);
}
else if (func is IAsyncTexlFunction4 asyncFunc4)
{
// https://github.com/microsoft/Power-Fx/issues/2818
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static partial class Library
/// <param name="regexTimeout">Timeout duration for regular expression execution. Default is 1 second.</param>
/// <param name="regexCache">Regular expression type cache.</param>
/// <returns></returns>
internal static Dictionary<TexlFunction, IAsyncTexlFunction> RegexFunctions(TimeSpan regexTimeout, RegexTypeCache regexCache)
internal static IEnumerable<TexlFunction> RegexFunctions(TimeSpan regexTimeout, RegexTypeCache regexCache)
{
if (regexTimeout == TimeSpan.Zero)
{
Expand All @@ -43,14 +43,47 @@ internal static Dictionary<TexlFunction, IAsyncTexlFunction> RegexFunctions(Time
throw new ArgumentOutOfRangeException(nameof(regexTimeout), "Timeout duration for regular expression execution must be positive.");
}

return new Dictionary<TexlFunction, IAsyncTexlFunction>()
return new TexlFunction[]
{
{ new IsMatchFunction(regexCache), new IsMatchImplementation(regexTimeout) },
{ new MatchFunction(regexCache), new MatchImplementation(regexTimeout) },
{ new MatchAllFunction(regexCache), new MatchAllImplementation(regexTimeout) }
new IsMatchImpl(regexCache, new IsMatchImplementation(regexTimeout)),
new MatchImpl(regexCache, new MatchImplementation(regexTimeout)),
new MatchAllImpl(regexCache, new MatchAllImplementation(regexTimeout)),
};
}

internal sealed class IsMatchImpl : IsMatchFunction, IAsyncTexlFunction
{
private readonly IAsyncTexlFunction _inner;

public IsMatchImpl(RegexTypeCache regexCache, IAsyncTexlFunction inner)
: base(regexCache) => _inner = inner;

public Task<FormulaValue> InvokeAsync(FormulaValue[] args, CancellationToken cancellationToken)
=> _inner.InvokeAsync(args, cancellationToken);
}

internal sealed class MatchImpl : MatchFunction, IAsyncTexlFunction
{
private readonly IAsyncTexlFunction _inner;

public MatchImpl(RegexTypeCache regexCache, IAsyncTexlFunction inner)
: base(regexCache) => _inner = inner;

public Task<FormulaValue> InvokeAsync(FormulaValue[] args, CancellationToken cancellationToken)
=> _inner.InvokeAsync(args, cancellationToken);
}

internal sealed class MatchAllImpl : MatchAllFunction, IAsyncTexlFunction
{
private readonly IAsyncTexlFunction _inner;

public MatchAllImpl(RegexTypeCache regexCache, IAsyncTexlFunction inner)
: base(regexCache) => _inner = inner;

public Task<FormulaValue> InvokeAsync(FormulaValue[] args, CancellationToken cancellationToken)
=> _inner.InvokeAsync(args, cancellationToken);
}

internal class IsMatchImplementation : RegexCommonImplementation
{
private readonly TimeSpan _regexTimeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ internal static IExpressionEvaluator GetEvaluator(this CheckResult result, Stack
_globals = globals,
_allSymbols = result.Symbols,
_parameterSymbolTable = result.Parameters,
_additionalFunctions = result.Engine.Config.AdditionalFunctions
};

return expr;
Expand Down Expand Up @@ -126,7 +125,6 @@ internal class ParsedExpression : IExpressionEvaluator
internal ReadOnlySymbolValues _globals;
internal ReadOnlySymbolTable _allSymbols;
internal ReadOnlySymbolTable _parameterSymbolTable;
internal IReadOnlyDictionary<TexlFunction, IAsyncTexlFunction> _additionalFunctions;

internal ParsedExpression(IntermediateNode irnode, ScopeSymbol topScope, StackDepthCounter stackMarker, CultureInfo cultureInfo = null)
{
Expand All @@ -150,12 +148,6 @@ public async Task<FormulaValue> EvalAsync(CancellationToken cancellationToken, I
hasInnerServices = true;
}

if (_additionalFunctions != null && _additionalFunctions.Any())
{
innerServices.AddService(_additionalFunctions);
hasInnerServices = true;
}

RuntimeConfig runtimeConfig2 = new RuntimeConfig
{
Values = symbolValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@ public static void EnableRegExFunctions(PowerFxConfig config, TimeSpan regExTime
{
RegexTypeCache regexTypeCache = new (regexCacheSize);

foreach (KeyValuePair<TexlFunction, IAsyncTexlFunction> func in RegexFunctions(regExTimeout, regexTypeCache, includeDotNet, includeNode, includePCRE2))
foreach (TexlFunction func in RegexFunctions(regExTimeout, regexTypeCache, includeDotNet, includeNode, includePCRE2))
{
if (config.ComposedConfigSymbols.Functions.AnyWithName(func.Key.Name))
if (config.ComposedConfigSymbols.Functions.AnyWithName(func.Name))
{
throw new InvalidOperationException("Cannot add RegEx functions more than once.");
}

config.InternalConfigSymbols.AddFunction(func.Key);
config.AdditionalFunctions.Add(func.Key, func.Value);
config.InternalConfigSymbols.AddFunction(func);
}
}

internal static Dictionary<TexlFunction, IAsyncTexlFunction> RegexFunctions(TimeSpan regexTimeout, RegexTypeCache regexCache, bool includeDotNet, bool includeNode, bool includePCRE2)
internal static IEnumerable<TexlFunction> RegexFunctions(TimeSpan regexTimeout, RegexTypeCache regexCache, bool includeDotNet, bool includeNode, bool includePCRE2)
{
if (regexTimeout == TimeSpan.Zero)
{
Expand All @@ -49,11 +48,11 @@ internal static Dictionary<TexlFunction, IAsyncTexlFunction> RegexFunctions(Time
throw new ArgumentOutOfRangeException(nameof(regexTimeout), "Timeout duration for regular expression execution must be positive.");
}

return new Dictionary<TexlFunction, IAsyncTexlFunction>()
return new TexlFunction[]
{
{ new IsMatchFunction(regexCache), new Compare_IsMatchImplementation(regexTimeout, includeDotNet, includeNode, includePCRE2) },
{ new MatchFunction(regexCache), new Compare_MatchImplementation(regexTimeout, includeDotNet, includeNode, includePCRE2) },
{ new MatchAllFunction(regexCache), new Compare_MatchAllImplementation(regexTimeout, includeDotNet, includeNode, includePCRE2) }
new Library.IsMatchImpl(regexCache, new Compare_IsMatchImplementation(regexTimeout, includeDotNet, includeNode, includePCRE2)),
new Library.MatchImpl(regexCache, new Compare_MatchImplementation(regexTimeout, includeDotNet, includeNode, includePCRE2)),
new Library.MatchAllImpl(regexCache, new Compare_MatchAllImplementation(regexTimeout, includeDotNet, includeNode, includePCRE2)),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,18 @@ public static void EnableRegExFunctions(PowerFxConfig config, TimeSpan regExTime
{
RegexTypeCache regexTypeCache = new (regexCacheSize);

foreach (KeyValuePair<TexlFunction, IAsyncTexlFunction> func in RegexFunctions(regExTimeout, regexTypeCache))
foreach (TexlFunction func in RegexFunctions(regExTimeout, regexTypeCache))
{
if (config.SymbolTable.Functions.AnyWithName(func.Key.Name))
if (config.SymbolTable.Functions.AnyWithName(func.Name))
{
throw new InvalidOperationException("Cannot add RegEx functions more than once.");
}

config.SymbolTable.AddFunction(func.Key);
config.AdditionalFunctions.Add(func.Key, func.Value);
config.SymbolTable.AddFunction(func);
}
}

internal static Dictionary<TexlFunction, IAsyncTexlFunction> RegexFunctions(TimeSpan regexTimeout, RegexTypeCache regexCache)
internal static IEnumerable<TexlFunction> RegexFunctions(TimeSpan regexTimeout, RegexTypeCache regexCache)
{
if (regexTimeout == TimeSpan.Zero)
{
Expand All @@ -266,11 +265,11 @@ internal static Dictionary<TexlFunction, IAsyncTexlFunction> RegexFunctions(Time
throw new ArgumentOutOfRangeException(nameof(regexTimeout), "Timeout duration for regular expression execution must be positive.");
}

return new Dictionary<TexlFunction, IAsyncTexlFunction>()
return new TexlFunction[]
{
{ new IsMatchFunction(regexCache), new NodeJS_IsMatchImplementation(regexTimeout) },
{ new MatchFunction(regexCache), new NodeJS_MatchImplementation(regexTimeout) },
{ new MatchAllFunction(regexCache), new NodeJS_MatchAllImplementation(regexTimeout) }
new Library.IsMatchImpl(regexCache, new NodeJS_IsMatchImplementation(regexTimeout)),
new Library.MatchImpl(regexCache, new NodeJS_MatchImplementation(regexTimeout)),
new Library.MatchAllImpl(regexCache, new NodeJS_MatchAllImplementation(regexTimeout)),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,18 @@ public static void EnableRegExFunctions(PowerFxConfig config, TimeSpan regExTime
{
RegexTypeCache regexTypeCache = new (regexCacheSize);

foreach (KeyValuePair<TexlFunction, IAsyncTexlFunction> func in RegexFunctions(regExTimeout, regexTypeCache))
foreach (TexlFunction func in RegexFunctions(regExTimeout, regexTypeCache))
{
if (config.SymbolTable.Functions.AnyWithName(func.Key.Name))
if (config.SymbolTable.Functions.AnyWithName(func.Name))
{
throw new InvalidOperationException("Cannot add RegEx functions more than once.");
}

config.SymbolTable.AddFunction(func.Key);
config.AdditionalFunctions.Add(func.Key, func.Value);
config.SymbolTable.AddFunction(func);
}
}

internal static Dictionary<TexlFunction, IAsyncTexlFunction> RegexFunctions(TimeSpan regexTimeout, RegexTypeCache regexCache)
internal static IEnumerable<TexlFunction> RegexFunctions(TimeSpan regexTimeout, RegexTypeCache regexCache)
{
if (regexTimeout == TimeSpan.Zero)
{
Expand All @@ -461,11 +460,11 @@ internal static Dictionary<TexlFunction, IAsyncTexlFunction> RegexFunctions(Time
throw new ArgumentOutOfRangeException(nameof(regexTimeout), "Timeout duration for regular expression execution must be positive.");
}

return new Dictionary<TexlFunction, IAsyncTexlFunction>()
return new TexlFunction[]
{
{ new IsMatchFunction(regexCache), new PCRE2_IsMatchImplementation(regexTimeout) },
{ new MatchFunction(regexCache), new PCRE2_MatchImplementation(regexTimeout) },
{ new MatchAllFunction(regexCache), new PCRE2_MatchAllImplementation(regexTimeout) }
new Library.IsMatchImpl(regexCache, new PCRE2_IsMatchImplementation(regexTimeout)),
new Library.MatchImpl(regexCache, new PCRE2_MatchImplementation(regexTimeout)),
new Library.MatchAllImpl(regexCache, new PCRE2_MatchAllImplementation(regexTimeout)),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void TextCatchIllegalFormatException()
_allSymbols = symbols,
_parameterSymbolTable = symbols,
_globals = values,
_additionalFunctions = new Dictionary<TexlFunction, IAsyncTexlFunction>(),
};

// This test
Expand Down
Loading