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

feat(eval): add Evaluate::evaluate_in_place #292

Merged
merged 5 commits into from
Sep 17, 2023
Merged

Conversation

martinohmann
Copy link
Owner

Closes #184.

Key difference to the existing Evaluate::evaluate method:

  • It mutably borrows the value and tries to evaluate all nested expressions in-place.
  • It returns all errors that it encounters, not just the first one.

This allows for partial expression evaluation, e.g. to support use cases where a HCL document contains variable references to other parts within the same document that themselves contain expressions that are not evaluated yet.

In this case one would:

  1. Partially evaluate the document via evaluate_in_place.
  2. Update the Context with newly discovered variables.
  3. Repeat 1. and 2. until there are no more errors left.

This enables partial expression evaluation where not all sub-expression
cannot be resolved yet due to missing variables or function definitions.
This are false positives in this case.

The `is_empty` method does not make any sense on `Errors` since it
always contains at least one error.

Replacing `fold` with `try_fold` in will short-circuit, which is not
what we want.
@martinohmann martinohmann merged commit ccc000f into main Sep 17, 2023
5 checks passed
@martinohmann martinohmann deleted the hcl-rs/in-place-eval branch September 17, 2023 11:42
@github-actions github-actions bot mentioned this pull request Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support partial expression evaluation
1 participant