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

remove HierarchyNotRespected validation error #1355

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

Conversation

cdisselkoen
Copy link
Contributor

Description of changes

As suggested in #638, removes the HierarchyNotRespected validation error (well, except from the public error enum, where we leave it to avoid a breaking change, but adjust documentation to indicate it is never returned). This simplifies the typechecker code considerably.

I'm a little unclear from the discussion on #638 whether the Lean model needs any corresponding changes or not.

Issue #, if available

Fixes #638

Checklist for requesting a review

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

  • A bug fix or other functionality change requiring a patch to cedar-policy.

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

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).

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

  • Not sure about changes to the Lean model, see above

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.

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

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

I'm happy to see this changes, though I'm not 100% sure it will pass DRT. It might be returning Bool when the lean impl gives a more precise False type. Fixing any discrepancy there should also be a backwards compatible change, but we should take a close look at what both are doing with in.

If it does pass, then we might be able to use AgreeOnAll here if this is the only error the Rust reports but Lean doesn't.

https://github.com/cedar-policy/cedar-spec/blob/main/cedar-drt/src/lean_impl.rs#L516

if !self.mode.is_strict() {
TypecheckAnswer::success(type_of_in)
} else if matches!(type_of_in.data(), Some(Type::False)) {
if self.mode.is_strict() && matches!(type_of_in.data(), Some(Type::False)) {
TypecheckAnswer::success(
ExprBuilder::with_data(Some(Type::False)).val(false),
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think rewriting to the literal false should be required anymore. We could just return the original annotated expression if it simplifies things further

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do that in a separate PR since this one is a little delicate as-is and the change you suggest is technically orthogonal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that change was done in #1462?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated this PR, now simplified further as you say. (we just return success(type_of_in) in all cases)

@cdisselkoen
Copy link
Contributor Author

It might be returning Bool when the lean impl gives a more precise False type.

I looked at this Rust code some, and I think/hope that the logic I removed was already performed in type_of_var_in_entity_literals() and friends. The logic I removed only ever results in HierarchyNotRespected or success(type_of_in); it never returns False when type_of_in wasn't already False. So removing this logic shouldn't stop us from returning False in any situation where we were already returning False before this PR.

@john-h-kastner-aws
Copy link
Contributor

It might be returning Bool when the lean impl gives a more precise False type.

I looked at this Rust code some, and I think/hope that the logic I removed was already performed in type_of_var_in_entity_literals() and friends. The logic I removed only ever results in HierarchyNotRespected or success(type_of_in); it never returns False when type_of_in wasn't already False. So removing this logic shouldn't stop us from returning False in any situation where we were already returning False before this PR.

IIUC, the DRT currently passes if Rust returns an errors when lean doesn't. So, if rust has stopped returning errors here, there could be a precision difference in the non-error response.

…typechecker

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

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

This looks good to me. The concerns I mention will be fully addressed just by running the diff tests with this change merged, so we just need another review to look this over.

@cdisselkoen
Copy link
Contributor Author

Corpus tests are failing in CI, probably because there are edge cases where this PR changes the validation behavior from fail -> pass (as noted in the changelog entry). Adjusting the corpus test expectation will have to be a different PR against cedar-integration-tests

…typechecker

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
@cdisselkoen
Copy link
Contributor Author

note on the status of this: have been waiting for cedar-policy/cedar-integration-tests#14 to be merged first, to avoid conflicts in updating the corpus tests

…typechecker

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
…typechecker

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
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.

Remove HierarchyNotRespected validation error
2 participants