From 650ba23fdb1bde9be08a7feb5e243a6441c5a8d8 Mon Sep 17 00:00:00 2001 From: "Rick Nguyen (from Dev Box)" Date: Tue, 22 Oct 2024 17:10:35 -0400 Subject: [PATCH] init --- .../Microsoft.PowerFx.Core/Binding/Binder.cs | 8 -- .../Binding/BindingConfig.cs | 5 +- .../UserDefinedTests.cs | 89 ------------------- 3 files changed, 1 insertion(+), 101 deletions(-) diff --git a/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs b/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs index 7b6bf28cce..1968c5ecb9 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs @@ -3071,14 +3071,6 @@ public override void Visit(FirstNameNode node) { _txb.ErrorContainer.EnsureError(node, TexlStrings.ErrInvalidControlReference); } - } - - if (_txb.BindingConfig.MarkAsAsyncOnLazilyLoadedControlRef && - lookupType.IsControl && - lookupInfo.Data is IExternalControl control && - !control.IsAppGlobalControl) - { - _txb.FlagPathAsAsync(_txb.Top); } // Update _usesGlobals, _usesResources, etc. diff --git a/src/libraries/Microsoft.PowerFx.Core/Binding/BindingConfig.cs b/src/libraries/Microsoft.PowerFx.Core/Binding/BindingConfig.cs index d8824d6397..edddc02bbd 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Binding/BindingConfig.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Binding/BindingConfig.cs @@ -23,17 +23,14 @@ internal class BindingConfig public bool AnalysisMode { get; } - public bool MarkAsAsyncOnLazilyLoadedControlRef { get; } = false; - public bool UserDefinitionsMode { get; } - public BindingConfig(bool allowsSideEffects = false, bool useThisRecordForRuleScope = false, bool numberIsFloat = false, bool analysisMode = false, bool markAsAsyncOnLazilyLoadedControlRef = false, bool userDefinitionsMode = false) + public BindingConfig(bool allowsSideEffects = false, bool useThisRecordForRuleScope = false, bool numberIsFloat = false, bool analysisMode = false, bool userDefinitionsMode = false) { AllowsSideEffects = allowsSideEffects; UseThisRecordForRuleScope = useThisRecordForRuleScope; NumberIsFloat = numberIsFloat; AnalysisMode = analysisMode; - MarkAsAsyncOnLazilyLoadedControlRef = markAsAsyncOnLazilyLoadedControlRef; UserDefinitionsMode = userDefinitionsMode; } } diff --git a/src/tests/Microsoft.PowerFx.Interpreter.Tests.Shared/UserDefinedTests.cs b/src/tests/Microsoft.PowerFx.Interpreter.Tests.Shared/UserDefinedTests.cs index 715e8cb96a..5db95d09f7 100644 --- a/src/tests/Microsoft.PowerFx.Interpreter.Tests.Shared/UserDefinedTests.cs +++ b/src/tests/Microsoft.PowerFx.Interpreter.Tests.Shared/UserDefinedTests.cs @@ -137,95 +137,6 @@ public void ImperativeUdfsEnabledOrDisabled(string script) errors.AddRange(parseResult.Errors ?? Enumerable.Empty()); Assert.False(errors.Any()); - } - - [Fact] - public void TestUdfsAndNfsAreMarkedAsAsync() - { - // Arrange - var script = "test(): Text = Button1InScreen2.Text;Nf=Button1InScreen2.Text;Test2(): Void={Set(x, Button1InScreen2.Text);};"; - var parseResult = TexlParser.ParseUserDefinitionScript(script, new ParserOptions() { AllowsSideEffects = true }); - var udfs = UserDefinedFunction.CreateFunctions(parseResult.UDFs.Where(udf => udf.IsParseValid), _primitiveTypes, out var errors); - var symbolTable = new MockSymbolTable(); - var dummyContol = new DummyExternalControl() { DisplayName = "Button1InScreen2" }; - symbolTable.AddControl("Button1InScreen2", dummyContol, TypeTree.Create(Enumerable.Empty>()).SetItem("Text", DType.String, true)); - var config = new BindingConfig(markAsAsyncOnLazilyLoadedControlRef: true); - - // Act & Assert - foreach (var udf in udfs) - { - udf.BindBody(symbolTable, new MockGlue(), config); - Assert.True(udf.IsAsync); - } - - foreach (var nf in parseResult.NamedFormulas) - { - var binding = TexlBinding.Run(new MockGlue(), nf.Formula.ParseTree, symbolTable, config, DType.EmptyRecord); - Assert.True(binding.IsAsync(binding.Top)); - } - } - - [Fact] - public void TestFormulaUsingUdfsOrNamedFormulaReferringControlAsAsync() - { - // Arrange - var script = "test(): Text = Button1InScreen2.Text;Nf=Button1InScreen2.Text;Test2(): Void={Set(x, Button1InScreen2.Text);};"; - var parseResult = TexlParser.ParseUserDefinitionScript(script, new ParserOptions() { AllowsSideEffects = true }); - var udfs = UserDefinedFunction.CreateFunctions(parseResult.UDFs.Where(udf => udf.IsParseValid), _primitiveTypes, out var errors); - var symbolTable = new MockSymbolTable(); - var dummyContol = new DummyExternalControl() { DisplayName = "Button1InScreen2" }; - symbolTable.AddControl("Button1InScreen2", dummyContol, TypeTree.Create(Enumerable.Empty>()).SetItem("Text", DType.String, true)); - var config = new BindingConfig(markAsAsyncOnLazilyLoadedControlRef: true); - var symbolTable2 = new MockSymbolTable(); - var symbolTable3 = new SymbolTable(); - foreach (var udf in udfs) - { - udf.BindBody(symbolTable, new MockGlue(), config); - Assert.True(udf.IsAsync); - symbolTable3.AddFunction(udf); - } - - foreach (var nf in parseResult.NamedFormulas) - { - var binding = TexlBinding.Run(new MockGlue(), nf.Formula.ParseTree, symbolTable, config, DType.EmptyRecord); - Assert.True(binding.IsAsync(binding.Top)); - symbolTable2.Add(nf.Ident.Name, new NameLookupInfo(BindKind.PowerFxResolvedObject, binding.GetType(binding.Top), DPath.Root, 0, isAsync: binding.IsAsync(binding.Top))); - } - - var combinedSymbolTable = ReadOnlySymbolTable.Compose(symbolTable2, symbolTable3); - - // Act - var checkResult1 = new Engine().Check("test() & \"ddd\"", null, combinedSymbolTable); - var checkResult2 = new Engine().Check("Nf & \"ddd\"", null, combinedSymbolTable); - var checkResult3 = new Engine().Check("Test2();", new ParserOptions { AllowsSideEffects = true }, combinedSymbolTable); - var checkResults = new List { checkResult1, checkResult2, checkResult3 }; - - // Assert - foreach (var checkResult in checkResults) - { - Assert.True(checkResult.IsSuccess); - Assert.True(checkResult.Binding.IsAsync(checkResult.Parse.Root)); - } - } - - [Fact] - public void TestUdfsAreNotMarkedAsAsynWhenReferringToNonLazilyLoadedControl() - { - // Arrange - var script = "test(): Text = App.Text;"; - var parseResult = TexlParser.ParseUserDefinitionScript(script, new ParserOptions() { AllowsSideEffects = true }); - var udfs = UserDefinedFunction.CreateFunctions(parseResult.UDFs.Where(udf => udf.IsParseValid), _primitiveTypes, out var errors); - var symbolTable = new MockSymbolTable(); - var dummyContol = new DummyExternalControl() { DisplayName = "App", IsAppInfoControl = true }; - symbolTable.AddControl("App", dummyContol, TypeTree.Create(Enumerable.Empty>()).SetItem("Text", DType.String, true)); - var config = new BindingConfig(markAsAsyncOnLazilyLoadedControlRef: true); - - // Act & Assert - foreach (var udf in udfs) - { - udf.BindBody(symbolTable, new MockGlue(), config); - Assert.False(udf.IsAsync); - } } } }