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

Decouple concrete evaluator from partial evaluator #1392

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

shaobo-he-aws
Copy link
Contributor

@shaobo-he-aws shaobo-he-aws commented Dec 23, 2024

Description of changes

Issue #, if available

#209

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A change "invisible" to users (e.g., documentation, changes to "internal" crates like cedar-policy-core, cedar-validator, etc.)

I confirm that this PR (choose one, and delete the other options):

  • Does not update the CHANGELOG because my change does not significantly impact released code.

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar language specification.

@shaobo-he-aws shaobo-he-aws linked an issue Dec 23, 2024 that may be closed by this pull request
2 tasks
@shaobo-he-aws shaobo-he-aws marked this pull request as draft December 23, 2024 18:57
Signed-off-by: Shaobo He <[email protected]>
Signed-off-by: Shaobo He <[email protected]>
@shaobo-he-aws shaobo-he-aws marked this pull request as ready for review December 23, 2024 22:01
Copy link
Contributor

@cdisselkoen cdisselkoen left a comment

Choose a reason for hiding this comment

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

This does introduce some duplication between the partial-evaluation and concrete-evaluation code, and I'm vaguely worried that the two could get out of sync if we update one and forget to update the other, but nonetheless I'll approve this, it seems like a reasonable code organization

This is an invasive change to the core Cedar evaluation code, which makes me nervous, but we have tests and DRT to catch any problems, and can rely on that

Comment on lines +91 to +92
/// The language spec and formal model give a precise definition of how this is
/// computed.
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment probably makes more sense on is_authorized_core(); we don't have a formal model for partial authorization at the moment

&self,
q: Request,
pset: &PolicySet,
evaluator: impl Fn(&Policy) -> std::result::Result<Either<bool, Expr>, EvaluationError>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
evaluator: impl Fn(&Policy) -> std::result::Result<Either<bool, Expr>, EvaluationError>,
evaluate: impl Fn(&Policy) -> std::result::Result<Either<bool, Expr>, EvaluationError>,

#[allow(clippy::unreachable)]
expr => unreachable!("internal invariant violation: BorrowedRestrictedExpr somehow contained this expr case: {expr:?}"),
}
}
}

impl<'e> Evaluator<'e> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest moving this impl block (or at least its evaluate() function) to concrete.rs where the Evaluator struct is defined

Comment on lines +265 to +272
let long_op = match op {
BinaryOrd::Less => |x, y| x < y,
BinaryOrd::LessEq => |x, y| x <= y,
};
let ext_op = match op {
BinaryOrd::Less => |x, y| x < y,
BinaryOrd::LessEq => |x, y| x <= y,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need both of these?

Copy link
Contributor

Choose a reason for hiding this comment

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

alternately should we just inline them? they are each only used one place


/// Interpret an `Expr` into a `Value` in this evaluation environment.
///
/// May return a residual expression, if the input expression is symbolic.
Copy link
Contributor

Choose a reason for hiding this comment

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

does this comment needs updating? This is the concrete evaluator, right?

@shaobo-he-aws
Copy link
Contributor Author

shaobo-he-aws commented Jan 3, 2025

This does introduce some duplication between the partial-evaluation and concrete-evaluation code, and I'm vaguely worried that the two could get out of sync if we update one and forget to update the other

But isn't it the goal of this PR? That being said, I admit the duplication could be reduced. The major obstacle that prevents us from reducing it is that the two evaluators still share the same request and entity store types.

@cdisselkoen
Copy link
Contributor

Yes, this PR is doing exactly as #209 requests. My nervousness is indeed about #209 itself. Before we had a PR, it was hard to make a compelling argument about duplication or maintainability. Now that we have a PR (thanks!) we can much more concretely (ha) evaluate whether the duplication is worth the benefits of #209.

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.

Separate partial evaluation from concrete evaluation
2 participants