Skip to content

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>
…typechecker

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

Coverage Report

Head Commit: c318efbd1a40ff596d8ca40d22780dc1892a4b1a

Base Commit: ea9b3afefaca34e0a2ac9574c1d8be809a9c87e9

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 50.00%

Status: FAILED ❌

Details
File Status Covered Coverage Missed Lines
cedar-policy-validator/src/diagnostics/validation_errors.rs 🔴 0/1 0.00% 479
cedar-policy-validator/src/typecheck.rs 🟢 1/1 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.49%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-policy 🔴 3055/4403 69.38% --
cedar-policy-cli 🔴 566/976 57.99% --
cedar-policy-core 🟢 11657/13899 83.87% --
cedar-policy-formatter 🟢 914/1043 87.63% --
cedar-policy-validator 🟢 8296/9701 85.52% --
cedar-wasm 🔴 0/29 0.00% --

@cdisselkoen
Copy link
Contributor Author

Ready for re-review. Corpus test failure is expected, see comments above; we will need to regenerate corpus tests because of this PR, which will be a separate PR to cedar-integration-tests. Also, DRT failure is because as of this writing we have merged #1535 but not cedar-policy/cedar-spec#587.

@cdisselkoen cdisselkoen requested a review from adpaco-aws March 25, 2025 20:16
@cdisselkoen cdisselkoen merged commit 1dcf194 into main Mar 25, 2025
17 of 20 checks passed
@cdisselkoen cdisselkoen deleted the cdisselkoen/simplify-typechecker branch March 25, 2025 20:21
jv-garcia pushed a commit to jv-garcia/cedar that referenced this pull request May 6, 2025
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
3 participants