Skip to content
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a41c793
existing tests pass
cdisselkoen Jun 20, 2024
e433f66
add some tests, not all passing yet
cdisselkoen Jul 8, 2024
7c60ca7
more
cdisselkoen Jul 10, 2024
74b8baf
fixed one problem
cdisselkoen Jul 10, 2024
48f85a6
all tests are passing again, and added a lot more tests
cdisselkoen Jul 10, 2024
1ddc92b
changelog
cdisselkoen Jul 11, 2024
8692e49
clarify a comment
cdisselkoen Jul 11, 2024
c4f2518
fix panic safety comments to be accepted by script
cdisselkoen Jul 11, 2024
264ee7f
clippy fixes
cdisselkoen Jul 11, 2024
b551fd6
make some more functions infallible
cdisselkoen Jul 11, 2024
3a70133
cargo fmt
cdisselkoen Jul 11, 2024
85b929f
syntax in comment
cdisselkoen Jul 11, 2024
6258ba6
fix some comments
cdisselkoen Jul 11, 2024
26f09af
review suggestion
cdisselkoen Jul 11, 2024
86cf5fb
review suggestion
cdisselkoen Jul 11, 2024
b7dfe57
move tests to separate file
cdisselkoen Jul 11, 2024
e1e7a31
Update cedar-policy-validator/src/types.rs
cdisselkoen Jul 11, 2024
689151b
resolution in entity parents, better help messages, add D tests
cdisselkoen Jul 12, 2024
770847d
add E tests
cdisselkoen Jul 12, 2024
17f5c0d
remove a collect
cdisselkoen Jul 12, 2024
2afeb45
update some comments to reference #1064
cdisselkoen Jul 12, 2024
ee6d9a6
tweak a help message
cdisselkoen Jul 12, 2024
4221b68
review comment
cdisselkoen Jul 12, 2024
2cf97c3
rename error
cdisselkoen Jul 12, 2024
a5f37a2
revise comment to point to 1063
cdisselkoen Jul 16, 2024
a8cfa0a
resolving action parents too
cdisselkoen Jul 17, 2024
788f1df
reorg tests
cdisselkoen Jul 17, 2024
c6f8abe
update some TODO comments
cdisselkoen Jul 17, 2024
9df4d1a
update comment
cdisselkoen Jul 17, 2024
ce2ec0a
add copyright header
cdisselkoen Jul 17, 2024
cdd5ae2
adjust another comment
cdisselkoen Jul 17, 2024
79da3f2
not working yet
cdisselkoen Jul 22, 2024
e5bc2f2
use `InternalName` inside validator
cdisselkoen Jul 22, 2024
6c435b0
TODOs point to 1085 and 1086
cdisselkoen Jul 23, 2024
8118df3
Merge remote-tracking branch 'origin/main' into cdisselkoen/fix-579
cdisselkoen Jul 23, 2024
3c3eeb6
update comments to point to 1084 instead of 174
cdisselkoen Jul 23, 2024
3938f2f
update comment
cdisselkoen Jul 23, 2024
cb1c596
improve invariant comments
cdisselkoen Jul 23, 2024
195f56d
fix after making a field private
cdisselkoen Jul 23, 2024
04bedb8
fully add EntityOrCommon to json syntax
cdisselkoen Jul 25, 2024
510631f
link to 1094
cdisselkoen Jul 25, 2024
d5c430f
Merge remote-tracking branch 'origin/main' into cdisselkoen/fix-579
cdisselkoen Jul 29, 2024
c2527f5
more helpers for DRT
cdisselkoen Jul 29, 2024
289fe64
Merge remote-tracking branch 'origin/main' into cdisselkoen/fix-579
cdisselkoen Jul 31, 2024
b87040a
Merge remote-tracking branch 'origin/main' into cdisselkoen/fix-579
cdisselkoen Aug 1, 2024
5260c93
fix deserialization of EntityOrCommon in schema JSON format
cdisselkoen Aug 1, 2024
9da67e4
fix annotation
cdisselkoen Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cedar-policy-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ lalrpop-util = { version = "0.20.0", features = ["lexer"] }
lazy_static = "1.4"
either = "1.8"
itertools = "0.13"
ref-cast = "1.0"
rustc_lexer = "0.1"
thiserror = "1.0"
smol_str = { version = "0.2", features = ["serde"] }
Expand Down
17 changes: 12 additions & 5 deletions cedar-policy-core/src/ast/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::transitive_closure::TCNode;
use crate::FromNormalizedStr;
use itertools::Itertools;
use miette::Diagnostic;
use ref_cast::RefCast;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, TryFromInto};
use smol_str::SmolStr;
Expand All @@ -35,9 +36,10 @@ use thiserror::Error;
pub static ACTION_ENTITY_TYPE: &str = "Action";

/// Entity type names are just [`Name`]s, but we have some operations on them specific to entity types.
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Hash, PartialOrd, Ord)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Hash, PartialOrd, Ord, RefCast)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(transparent)]
#[repr(transparent)]
pub struct EntityType(Name);

impl EntityType {
Expand All @@ -59,15 +61,14 @@ impl EntityType {
self.0.as_ref().loc()
}

/// Calls [`Name::qualify_with`] on the underlying [`Name`]
/// Calls [`Name::qualify_with_name`] on the underlying [`Name`]
pub fn qualify_with(&self, namespace: Option<&Name>) -> Self {
Self(self.0.qualify_with(namespace))
Self(self.0.qualify_with_name(namespace))
}

/// Wraps [`Name::from_normalized_str`]
pub fn from_normalized_str(src: &str) -> Result<Self, ParseErrors> {
UncheckedName::from_normalized_str(src)
.and_then(|n| n.try_into().map(Self).map_err(ParseErrors::singleton))
Name::from_normalized_str(src).map(Into::into)
}
}

Expand All @@ -77,6 +78,12 @@ impl From<Name> for EntityType {
}
}

impl From<EntityType> for Name {
fn from(ty: EntityType) -> Name {
ty.0
}
}

impl AsRef<Name> for EntityType {
fn as_ref(&self) -> &Name {
&self.0
Expand Down
11 changes: 11 additions & 0 deletions cedar-policy-core/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,16 @@ impl From<Var> for Id {
}
}

// PANIC SAFETY Tested by `test::all_vars_are_ids`. Never panics.
#[allow(clippy::fallible_impl_from)]
impl From<Var> for UnreservedId {
fn from(var: Var) -> Self {
// PANIC SAFETY: `Var` is a simple enum and all vars are formatted as valid `UnreservedId`. Tested by `test::all_vars_are_ids`
#[allow(clippy::unwrap_used)]
Id::from(var).try_into().unwrap()
}
}

impl std::fmt::Display for Var {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand All @@ -1487,6 +1497,7 @@ mod test {
fn all_vars_are_ids() {
for var in all_vars() {
let _id: Id = var.into();
let _id: UnreservedId = var.into();
}
}

Expand Down
10 changes: 8 additions & 2 deletions cedar-policy-core/src/ast/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use smol_str::SmolStr;

use crate::{parser::err::ParseErrors, FromNormalizedStr};

use super::{ReservedNameError, UncheckedName};
use super::{InternalName, ReservedNameError};

const RESERVED_ID: &str = "__cedar";

Expand Down Expand Up @@ -106,13 +106,19 @@ impl TryFrom<Id> for UnreservedId {
type Error = ReservedNameError;
fn try_from(value: Id) -> Result<Self, Self::Error> {
if value.is_reserved() {
Err(ReservedNameError(UncheckedName::unqualified_name(value)))
Err(ReservedNameError(InternalName::unqualified_name(value)))
} else {
Ok(Self(value))
}
}
}

impl AsRef<Id> for UnreservedId {
fn as_ref(&self) -> &Id {
&self.0
}
}

impl AsRef<str> for UnreservedId {
fn as_ref(&self) -> &str {
self.0.as_ref()
Expand Down
Loading