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

Fix forward references in ExpressionBuilder #437

Merged

Conversation

ewoutkramer
Copy link
Member

@ewoutkramer ewoutkramer commented Jul 31, 2024

Fixes #397. Fixes #410.

This PR enables the translation of FunctionRef/ExpressionRef to rely on the ref's resultTypeSpecifier instead of having to look the definition up in the DefinitionDictionary. Not using the DefinitionDictionary avoids running into the situation where the ref is a forwards reference whereby the DefinitionDictionary does not yet contain the translated function we want to call.

This PR uses the recent functionality added to LibrarySet to lookup a symbol, and expands this to be able to lookup functions by signature. Given the function name in the FUnctionRef/ExpressionRef, and, in the case of an overload, the signature, we can now lookup any function defined in any library in the LibrarySet, so we can copy over the resultTypeSpecifier.

Filling out this resultTypeSpecifier is now done in a pre-processing step, happening when we are constructing the LibrarySet. The pre-processing step will find all Refs, and then do this:

  • Try to find the function by name. If it is not an overload, use the resultTypeSpecifier
  • If there is an overload, use the Ref's signature, if available.
  • If there is no signature, use the types from the Ref's parameters and match on those.

Otherwise, we cannot find the overload, and we will raise an error. This ensures that after the pre-processor has run, all Refs have a resultTypeSpecifier, and we can depend on that fact.

This PR re-uses the OverloadedFunctionDefinition, and there are some updates to the CanCombine function to make sure the pre-processor fix and the CanCombine use the same criteria.

I also added a bunch of useful extension methods for working with the Elm function elements and signatures.

Cql/Elm/ElmTreeWalker.cs Outdated Show resolved Hide resolved
Cql/Elm/ElmTreeWalker.cs Outdated Show resolved Hide resolved
Cql/Elm/Errors.cs Outdated Show resolved Hide resolved
Cql/Elm/Errors.cs Outdated Show resolved Hide resolved
Cql/Elm/ElmTreeWalker.cs Outdated Show resolved Hide resolved
Cql/Cql.Compiler/ExpressionBuilderContext.StaticHelpers.cs Outdated Show resolved Hide resolved
Cql/Elm/IDefinitionElement.cs Outdated Show resolved Hide resolved
Cql/Elm/IDefinitionElement.cs Show resolved Hide resolved
baseTwo
baseTwo previously approved these changes Aug 1, 2024
@EvanMachusak
Copy link
Collaborator

I've identified a small issue where we are creating empty ExpressionRef nodes for Retireve.context for statements that are in context Unfiltered and this is causing exceptions during the preprocessing phase. I will fix it.

EvanMachusak
EvanMachusak previously approved these changes Aug 2, 2024
Copy link
Collaborator

@EvanMachusak EvanMachusak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests pass. All HEDIS passes.

@ewoutkramer ewoutkramer dismissed EvanMachusak’s stale review August 2, 2024 13:48

The merge-base changed after approval.

@EvanMachusak EvanMachusak self-requested a review August 5, 2024 11:02
@ewoutkramer ewoutkramer dismissed EvanMachusak’s stale review August 5, 2024 11:02

The merge-base changed after approval.

EvanMachusak
EvanMachusak previously approved these changes Aug 5, 2024
@EvanMachusak EvanMachusak merged commit 0b5ed12 into develop-2.0 Aug 5, 2024
2 checks passed
@EvanMachusak EvanMachusak deleted the 397-fix-forward-references-in-expressionbuilder-2 branch August 5, 2024 11:15
@baseTwo
Copy link
Collaborator

baseTwo commented Aug 6, 2024

@EvanMachusak, none of the demo projects are able to rebuild as a result of the additional commits. Could you please have a look? Issue #450

@alexzautke alexzautke restored the 397-fix-forward-references-in-expressionbuilder-2 branch August 7, 2024 06:58
@baseTwo
Copy link
Collaborator

baseTwo commented Aug 7, 2024

I'm going to revert the entire previous PR #437. This means the related issues (#397, #410, #442 and #443 ) will be undone and moved back to TODO.

@baseTwo
Copy link
Collaborator

baseTwo commented Aug 19, 2024

@ewoutkramer I tried to duplicate the work into a new PR, but still getting stuck
#468

@ewoutkramer ewoutkramer deleted the 397-fix-forward-references-in-expressionbuilder-2 branch August 28, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants