Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove async flagging for control lazy loading #2711

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
8 changes: 0 additions & 8 deletions src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3077,14 +3077,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,95 +137,6 @@ public void ImperativeUdfsEnabledOrDisabled(string script)
errors.AddRange(parseResult.Errors ?? Enumerable.Empty<TexlError>());

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<KeyValuePair<string, DType>>()).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<KeyValuePair<string, DType>>()).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<CheckResult> { 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<KeyValuePair<string, DType>>()).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);
}
}
}
}