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

clarity refactors around typechecking in #620

Merged
merged 2 commits into from
Feb 5, 2024

Conversation

cdisselkoen
Copy link
Contributor

Description of changes

This PR represents the parts of #603 which we still want to keep after #615 fixed the underlying issue. See discussion on #603. This PR should be no-functional-changes.

I threw in a small refactor in the caller typecheck_in() that wasn't in #603, but which I feel improves clarity slightly

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 Dafny model or DRT infrastructure.

Disclaimer

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines +2022 to +2023
Some(EntityType::Unspecified) => {
// It's perfectly valid for `principal` or `resource` to be `EntityType::Unspecified`
Copy link
Contributor

Choose a reason for hiding this comment

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

The rest of the changes in this PR look good to me, but I think this case is a behavior change. To match the Dafny spec I think you just want to use Type::primitive_boolean() here.

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 don't think this is a behavior change, because the case where we return Type::singleton_boolean(false) is actually unreachable -- we would have already returned at line 1762 and never even reached this function.

For the question about the Dafny spec, I believe the Dafny spec returns singleton-false for this case as well (unspecified in RHS where RHS is a single specified entity literal or set of specified entity literals) at lines 417-418 at your link, and never reaches the line 439 which you pointed to.

Perhaps both the Rust and Dafny need additional comments to clarify which cases actually reach particular lines. It took me a long time to puzzle these out as well. I feel that neither codebase is particularly well organized in how it typechecks in.

Copy link
Contributor

Choose a reason for hiding this comment

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

This part of the code is quite annoying due to the handling of unspecified entities 😞 Looking at it again, I think you're right that the earlier handling means that the else statement here will never be reached. I think the then part is also unreachable: it is impossible to have a set of entity literals that contains an unspecified entity. So maybe there was a reason to return TypecheckFail after all 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

It still seems incorrect to ignore the failure of TypecheckFail though.

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 changing the behavior many layers above to not ignore TypecheckFail would be a great idea but is well beyond the scope of this PR. Perhaps we could do that first though? If we're right that this is unreachable, then it shouldn't matter whether we return Fail or Success, at least until some refactor makes this code reachable again

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Kesha's assessment of the un-reachability of both branches. The then statement could only be reached if an entity literal had an unspecified entity type, but that can't happen. The else branch is more subtle, but Craig seems to be correct that the unspecified-in-specifed case rules out that branch.

Copy link
Contributor

@khieta khieta left a comment

Choose a reason for hiding this comment

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

Just realized I forgot to approve. The unreachability is weird, but I agree that this is a non-functional change that improves clarity.

@cdisselkoen cdisselkoen merged commit 14764c0 into main Feb 5, 2024
11 checks passed
@cdisselkoen cdisselkoen deleted the cdisselkoen/unspecified-precision-v3 branch February 5, 2024 14:26
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