Repository navigation
Implement CompiledAnnotation IR struct - #114
Open
dmartmillan wants to merge 5 commits into
Open
dmartmillan wants to merge 5 commits into
dmartmillan wants to merge 5 commits into
Conversation
| #[test] | ||
| fn upper_then_replace() { | ||
| let lambda = CompiledLambda::compile( | ||
| r#"|y| y.make_upper() ?? y.replace("CHR", "") ?? y"#, |
Collaborator
Author
There was a problem hiding this comment.
This is wrong. replace method is a mutating method, in this case mutates that temporary in place and evaluates to () then needs a ?? operator:
a() ?? b(); // b() is only evaluated if a() returns ()
also can be used for:
a ?? b // returns 'a' if it is not (), otherwise 'b'
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This pull request corresponds to the implementation of CompiledAnnotation IR struct and the implementation of CompiledLambda struct along with its tests. Relates to #65 issue.
Implemented the different data structures that form the Intermediate Representation (IR), which is an internal data structure that Rust will use to compile and represent the bridge between the high-level source (config that comes from YAML annotation file) and the low-level target machine code (the compiled annotation). The implementation that is in charge to compile the annotation file using IR will be developed on the Epic 2.
On this PR has been:
ir.rswhich encompassesCompiledAnnotation(which is the IR of the annotation file) andCompiledLambda(which is the IR of thefunctionvalue on the annotation file).In contrast to the Python-based implementation, the new version of OpenVariant uses the Rhai language for user-defined functions instead of Python lambda functions. Rhai is an embedded scripting language that can be interpreted directly by Rust. Therefore, users must follow Rhai’s syntax and semantics, as described in its documentation: https://rhai.rs/book/ref/values-and-types.html.
CompiledLambda::compileuses Rhai’scompile_expression, which accepts only a single parameter (eg.|x| x.replace("old", "new")). It does not supportletstatements, semicolon-separated statements, or{}blocks. Consequently, there is no way to express a sequence such as “do this, then do that, then returny” using ordinary statement syntax. The function must instead be expressed as a single valid Rhai expression.The Python implementation performs this work for every row of every file: it re-reads the YAML configuration, re-instantiates the builder classes, and calls
eval(self.func)(x)on the lambda string each time. In the new implementation, this expensive work will be performed exactly once, at load time.The resulting IR is plain data composed of enums, strings, pre-compiled regular expressions, and hash maps. It contains no file handles or Python objects. As a result, a single
CompiledAnnotationcan be wrapped inArcand safely shared across the threads, avoiding repeated parsing, object construction, and compilation.tests/test_annotation/test_ir.rsMakefileto perform specific test with a filter for example:make test-filter FILTER=test_ir, it will only performtest_ir.