Skip to content

Conversation

@cwaldren-ld
Copy link
Contributor

@cwaldren-ld cwaldren-ld commented Jul 11, 2023

This PR contains the main evaluation engine and associated tests.

Lacking rule matching logic, which is stubbed out.
Also lacking store interface.
* false.)
*/
explicit operator bool() const;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unclear to me if we need both IsError and operator bool().

The intention is to allow users (and us, in test code) to check if the evaluation has an error, without having to reach deep into the object.

Having if (detail) is pretty convenient and fits in with std::optional and tl::expected, I just don't know if we need the explicit IsError as well.

Copy link
Member

Choose a reason for hiding this comment

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

std::optional, and tl::expected both have kind of pointer like behavior, and they both additionally have an explicit way to check for a value has_value. We don't really have pointer like behavior, so I don't know that the boolean operator would be very apparent. It isn't bad to have, but an error and having a value are a bit different for an evaluation reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's true it's not pointer-like, but we do have operator* to get at the value. So you could do:

 if (result) {
      double x = (*result).AsDouble()
 }

But this does feel clunky. Hmm.

Copy link
Contributor Author

@cwaldren-ld cwaldren-ld Jul 17, 2023

Choose a reason for hiding this comment

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

Perhaps the VariationDetail methods should really accept detail as an out-param, or just not have VariationDetail at all and use overloads instead.

Copy link
Member

@kinyoklion kinyoklion Jul 17, 2023

Choose a reason for hiding this comment

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

Producing an evaluation result seems totally reasonable, the VariationDetail methods are typed, so there should be no AsDouble. Unless you really just want to make yourself more work.

If you just are using it for a side effect, then you could deref it. I would likely just call .Value() myself. It isn't conditional, it is just a value.

An out variable, in my view, just makes it even more inconvenient when you may not care about it at all.

Copy link
Member

Choose a reason for hiding this comment

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

Generally speaking I don't think you usually even care if there was an error.

@cwaldren-ld cwaldren-ld force-pushed the cw/sc-206689/evaluator branch from ab3a130 to 3c4bbf9 Compare July 17, 2023 19:28
@cwaldren-ld cwaldren-ld marked this pull request as ready for review July 17, 2023 19:28
@cwaldren-ld cwaldren-ld requested review from a team and kinyoklion July 17, 2023 19:28
if (!segment.salt) {
return tl::make_unexpected(Error::MissingSalt(segment.key));
}
if (Match(rule, context, store, stack, segment.key, *segment.salt)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct? Reflexively it feels incorrect, but maybe I am not following the logic correctly (I would expect the value to be used, versus presence of value?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is wrong. I missed that this was returning a tl::expected. Updated and added a unit test to make sure this piece is getting exercised.

Copy link
Member

@kinyoklion kinyoklion left a comment

Choose a reason for hiding this comment

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

Inline question about segment matching.

@cwaldren-ld cwaldren-ld merged commit a78dff4 into evaluator Jul 18, 2023
@cwaldren-ld cwaldren-ld deleted the cw/sc-206689/evaluator branch July 18, 2023 01:12
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.

3 participants