Configurable named types for UDF/UDT and configurable Number type#3014
Configurable named types for UDF/UDT and configurable Number type#3014gregli-msft wants to merge 10 commits intomainfrom
Conversation
src/libraries/Microsoft.PowerFx.Core/Public/Config/SymbolTable.cs
Outdated
Show resolved
Hide resolved
|
|
||
| if (!nameResolver.LookupType(returnTypeToken.Name, out var returnTypeFormulaType)) | ||
| // only the return type from a UDF can be a void type, it is not valid in other type contexts | ||
| if (returnTypeToken.Name == FormulaType.Void.Name) |
There was a problem hiding this comment.
Things could go haywire if someone added Void as a type in the builtinnamedtypes or as a UDT, but there are checks to prevent both from happening now. Is there another way you think it could be done?
There was a problem hiding this comment.
Can we put this inside the nameResolver If? (I know very edge case/ silly case) but what if we allowed SymbolTable to have "Void" named type that is not actually a VoidType.
| return argIndex == 1; | ||
| } | ||
|
|
||
| // This list is effectively intersected with the BuiltInNamedTypes in the Engine, with outliers generating errors before this list is checked. |
There was a problem hiding this comment.
I'm not sure I understand the question exactly. We need DType.Number (Float) in this list so that if a host supports Float, then it would be OK as a supported JSON type. DType.Decimal is a good example where it exists in this list, but wouldn't work in Canvas today.
src/libraries/Microsoft.PowerFx.Core/Public/Types/FormulaType.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.PowerFx.Core/Types/DefinedTypeResolver.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.PowerFx.Core/Types/DefinedTypeResolver.cs
Outdated
Show resolved
Hide resolved
|
✅ No public API change. |
|
✅ No public API change. |
…ower-fx into gregli/udt-decimal-2
|
✅ No public API change. |
| @@ -469,17 +469,23 @@ internal void AddTypes(IEnumerable<KeyValuePair<DName, FormulaType>> types) | |||
| /// Helper to create a symbol table with primitive types. | |||
Currently, there is a named types table in the Engine, that contains Number, Text, Boolean, etc. The problem is that there isn't one list of named types that are appropriate for consumers of the Engine: for example, Canvas doesn't support Decimal, while Dataverse formula columns support DateTimeNoTZ but nobody else does.
This is the key change in the Engine class (Engine.cs):

{ get; }.This change pulls the named types out and makes that something that needs to be setup in order to use UDF/UDTs. RecalcEngine does this automatically, with the correct types, for all consumers of the C# interpreter. Dataverse doesn't need to worry about it as UDF/UDTs aren't usable there. Canvas will require an update.
In addition, the Number type name needs to be added to the symbol table of the Engine as an alias for Float or Decimal as appropriate. Number should be setup with the default numeric type, allowing UDT/UDFs to be type agnostic for situations where it doesn't matter. Using Float or Decimal explicitly is always specific. Setting this up is in addition to passing the NumberIsFloat flag into the Parser. As Canvas doesn't have Decimal yet, and has only ever had Float, and it is the only product with UDT/UDFs today, this is not a breaking change.
Error messages associate with numeric types have been simplified. Instead of perhaps saying that a type could be one of
Number, Decimal, Float,these three will be folded into a singleNumber,. Which has several advantages:Finally, the list of reserved type names has been updated, attempting a small amount of future proofing.