Skip to content

Commit

Permalink
rename Concrete to either Specified or Known (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdisselkoen authored Nov 17, 2023
1 parent 3c6711d commit 35b7f79
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 96 deletions.
14 changes: 7 additions & 7 deletions cedar-policy-core/src/ast/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use thiserror::Error;
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum EntityType {
/// Concrete nominal type
Concrete(Name),
Specified(Name),
/// Unspecified
Unspecified,
}
Expand All @@ -43,19 +43,19 @@ impl EntityType {
/// Is this an Action entity type
pub fn is_action(&self) -> bool {
match self {
Self::Concrete(name) => name.basename() == &Id::new_unchecked("Action"),
Self::Specified(name) => name.basename() == &Id::new_unchecked("Action"),
Self::Unspecified => false,
}
}
}

// Note: the characters '<' and '>' are not allowed in `Name`s, so the display for
// `Unspecified` never conflicts with `Concrete(name)`.
// `Unspecified` never conflicts with `Specified(name)`.
impl std::fmt::Display for EntityType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Unspecified => write!(f, "<Unspecified>"),
Self::Concrete(name) => write!(f, "{}", name),
Self::Specified(name) => write!(f, "{}", name),
}
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ impl EntityUID {
pub(crate) fn test_entity_type() -> EntityType {
let name = Name::parse_unqualified_name("test_entity_type")
.expect("test_entity_type should be a valid identifier");
EntityType::Concrete(name)
EntityType::Specified(name)
}
// by default, Coverlay does not track coverage for lines after a line
// containing #[cfg(test)].
Expand All @@ -110,7 +110,7 @@ impl EntityUID {
/// Create an `EntityUID` with the given (unqualified) typename, and the given string as its EID.
pub fn with_eid_and_type(typename: &str, eid: &str) -> Result<Self, ParseErrors> {
Ok(Self {
ty: EntityType::Concrete(Name::parse_unqualified_name(typename)?),
ty: EntityType::Specified(Name::parse_unqualified_name(typename)?),
eid: Eid(eid.into()),
})
}
Expand All @@ -124,7 +124,7 @@ impl EntityUID {
/// Create a nominally-typed `EntityUID` with the given typename and EID
pub fn from_components(name: Name, eid: Eid) -> Self {
Self {
ty: EntityType::Concrete(name),
ty: EntityType::Specified(name),
eid,
}
}
Expand Down
6 changes: 3 additions & 3 deletions cedar-policy-core/src/ast/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl std::fmt::Debug for Extension {
#[derive(Debug, Clone)]
pub enum ExtensionOutputValue {
/// A concrete value from an extension call
Concrete(Value),
Known(Value),
/// An unknown returned from an extension call
Unknown(Unknown),
}
Expand All @@ -82,7 +82,7 @@ where
T: Into<Value>,
{
fn from(v: T) -> Self {
ExtensionOutputValue::Concrete(v.into())
ExtensionOutputValue::Known(v.into())
}
}

Expand Down Expand Up @@ -310,7 +310,7 @@ impl ExtensionFunction {
/// Call the `ExtensionFunction` with the given args
pub fn call(&self, args: &[Value]) -> evaluator::Result<PartialValue> {
match (self.func)(args)? {
ExtensionOutputValue::Concrete(v) => Ok(PartialValue::Value(v)),
ExtensionOutputValue::Known(v) => Ok(PartialValue::Value(v)),
ExtensionOutputValue::Unknown(u) => Ok(PartialValue::Residual(Expr::unknown(u))),
}
}
Expand Down
4 changes: 2 additions & 2 deletions cedar-policy-core/src/ast/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ impl PrincipalOrResourceConstraint {
pub fn iter_entity_type_names(&self) -> impl Iterator<Item = &'_ Name> {
self.iter_euids()
.filter_map(|euid| match euid.entity_type() {
EntityType::Concrete(name) => Some(name),
EntityType::Specified(name) => Some(name),
EntityType::Unspecified => None,
})
.chain(match self {
Expand Down Expand Up @@ -1465,7 +1465,7 @@ impl ActionConstraint {
pub fn iter_entity_type_names(&self) -> impl Iterator<Item = &'_ Name> {
self.iter_euids()
.filter_map(|euid| match euid.entity_type() {
EntityType::Concrete(name) => Some(name),
EntityType::Specified(name) => Some(name),
EntityType::Unspecified => None,
})
}
Expand Down
10 changes: 5 additions & 5 deletions cedar-policy-core/src/ast/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct Request {
#[derive(Debug, Clone, Serialize)]
pub enum EntityUIDEntry {
/// A concrete (but perhaps unspecified) EntityUID
Concrete(Arc<EntityUID>),
Known(Arc<EntityUID>),
/// An EntityUID left as unknown for partial evaluation
Unknown,
}
Expand All @@ -61,20 +61,20 @@ impl EntityUIDEntry {
/// An unknown corresponding to the passed `var`
pub fn evaluate(&self, var: Var) -> PartialValue {
match self {
EntityUIDEntry::Concrete(euid) => Value::Lit(Literal::EntityUID(euid.clone())).into(),
EntityUIDEntry::Known(euid) => Value::Lit(Literal::EntityUID(euid.clone())).into(),
EntityUIDEntry::Unknown => Expr::unknown(Unknown::new_untyped(var.to_string())).into(),
}
}

/// Create an entry with a concrete EntityUID
pub fn concrete(euid: EntityUID) -> Self {
Self::Concrete(Arc::new(euid))
Self::Known(Arc::new(euid))
}

/// Get the UID of the entry, or `None` if it is unknown (partial evaluation)
pub fn uid(&self) -> Option<&EntityUID> {
match self {
Self::Concrete(euid) => Some(euid),
Self::Known(euid) => Some(euid),
Self::Unknown => None,
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Request {
impl std::fmt::Display for Request {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let display_euid = |maybe_euid: &EntityUIDEntry| match maybe_euid {
EntityUIDEntry::Concrete(euid) => format!("{euid}"),
EntityUIDEntry::Known(euid) => format!("{euid}"),
EntityUIDEntry::Unknown => "unknown".to_string(),
};
write!(
Expand Down
4 changes: 2 additions & 2 deletions cedar-policy-core/src/ast/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Type {
/// Shorthand for constructing an entity type.
pub fn entity_type(name: Name) -> Self {
Type::Entity {
ty: EntityType::Concrete(name),
ty: EntityType::Specified(name),
}
}
}
Expand All @@ -81,7 +81,7 @@ impl std::fmt::Display for Type {
Self::Record => write!(f, "record"),
Self::Entity { ty } => match ty {
EntityType::Unspecified => write!(f, "(entity of unspecified type)"),
EntityType::Concrete(name) => write!(f, "(entity of type `{}`)", name),
EntityType::Specified(name) => write!(f, "(entity of type `{}`)", name),
},
Self::Extension { name } => write!(f, "{}", name),
}
Expand Down
12 changes: 6 additions & 6 deletions cedar-policy-core/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,10 +1718,10 @@ mod schema_based_parsing_tests {
basename: &'a Id,
) -> Box<dyn Iterator<Item = EntityType> + 'a> {
match basename.as_ref() {
"Employee" => Box::new(std::iter::once(EntityType::Concrete(
"Employee" => Box::new(std::iter::once(EntityType::Specified(
Name::unqualified_name(basename.clone()),
))),
"Action" => Box::new(std::iter::once(EntityType::Concrete(
"Action" => Box::new(std::iter::once(EntityType::Specified(
Name::unqualified_name(basename.clone()),
))),
_ => Box::new(std::iter::empty()),
Expand All @@ -1736,15 +1736,15 @@ mod schema_based_parsing_tests {
struct MockEmployeeDescription;
impl EntityTypeDescription for MockEmployeeDescription {
fn entity_type(&self) -> EntityType {
EntityType::Concrete(Name::parse_unqualified_name("Employee").expect("valid"))
EntityType::Specified(Name::parse_unqualified_name("Employee").expect("valid"))
}

fn attr_type(&self, attr: &str) -> Option<SchemaType> {
let employee_ty = || SchemaType::Entity {
ty: self.entity_type(),
};
let hr_ty = || SchemaType::Entity {
ty: EntityType::Concrete(Name::parse_unqualified_name("HR").expect("valid")),
ty: EntityType::Specified(Name::parse_unqualified_name("HR").expect("valid")),
};
match attr {
"isFullTime" => Some(SchemaType::Bool),
Expand Down Expand Up @@ -2839,7 +2839,7 @@ mod schema_based_parsing_tests {
basename: &'a Id,
) -> Box<dyn Iterator<Item = EntityType> + 'a> {
match basename.as_ref() {
"Employee" => Box::new(std::iter::once(EntityType::Concrete(
"Employee" => Box::new(std::iter::once(EntityType::Specified(
Name::from_str("XYZCorp::Employee").expect("valid name"),
))),
_ => Box::new(std::iter::empty()),
Expand All @@ -2853,7 +2853,7 @@ mod schema_based_parsing_tests {
struct MockEmployeeDescription;
impl EntityTypeDescription for MockEmployeeDescription {
fn entity_type(&self) -> EntityType {
EntityType::Concrete("XYZCorp::Employee".parse().expect("valid"))
EntityType::Specified("XYZCorp::Employee".parse().expect("valid"))
}

fn attr_type(&self, attr: &str) -> Option<SchemaType> {
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-core/src/entities/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'a, S: Schema> EntitySchemaConformanceChecker<'a, S> {
} else {
let schema_etype = self.schema.entity_type(etype).ok_or_else(|| {
let suggested_types = match etype {
EntityType::Concrete(name) => self
EntityType::Specified(name) => self
.schema
.entity_types_with_basename(name.basename())
.collect(),
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-core/src/entities/json/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<'e, 's, S: Schema> EntityJsonParser<'e, 's, S> {
} else {
EntitySchemaInfo::NonAction(schema.entity_type(etype).ok_or_else(|| {
let suggested_types = match etype {
EntityType::Concrete(name) => {
EntityType::Specified(name) => {
schema.entity_types_with_basename(name.basename()).collect()
}
EntityType::Unspecified => vec![],
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-core/src/entities/json/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Schema for AllEntitiesNoAttrsSchema {
&'a self,
basename: &'a Id,
) -> Box<dyn Iterator<Item = EntityType> + 'a> {
Box::new(std::iter::once(EntityType::Concrete(
Box::new(std::iter::once(EntityType::Specified(
Name::unqualified_name(basename.clone()),
)))
}
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-core/src/entities/json/schema_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl std::fmt::Display for SchemaType {
}
Self::Entity { ty } => match ty {
EntityType::Unspecified => write!(f, "(entity of unspecified type)"),
EntityType::Concrete(name) => write!(f, "`{}`", name),
EntityType::Specified(name) => write!(f, "`{}`", name),
},
Self::Extension { name } => write!(f, "{}", name),
}
Expand Down
4 changes: 2 additions & 2 deletions cedar-policy-core/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl<'e> Evaluator<'e> {
let v = self.partial_interpret(expr, slots)?;
match v {
PartialValue::Value(v) => Ok(match v.get_as_entity()?.entity_type() {
EntityType::Concrete(expr_entity_type) => entity_type == expr_entity_type,
EntityType::Specified(expr_entity_type) => entity_type == expr_entity_type,
EntityType::Unspecified => false,
}
.into()),
Expand Down Expand Up @@ -691,7 +691,7 @@ impl<'e> Evaluator<'e> {
EntityType::Unspecified => {
EvaluationError::unspecified_entity_access(attr.clone())
}
EntityType::Concrete(_) => {
EntityType::Specified(_) => {
EvaluationError::entity_does_not_exist(uid.clone())
}
}),
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-core/src/parser/cst_to_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ fn action_constraint_contains_only_action_types(

/// Check if an EUID has the type `Action` under an arbitrary namespace
fn euid_has_action_type(euid: &EntityUID) -> bool {
if let EntityType::Concrete(name) = euid.entity_type() {
if let EntityType::Specified(name) = euid.entity_type() {
name.id.as_ref() == "Action"
} else {
false
Expand Down
Loading

0 comments on commit 35b7f79

Please sign in to comment.