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 Loc from protobufs in AST.proto #1343

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 2 additions & 14 deletions cedar-policy-cli/protobuf_schema/AST.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ message Context {

message EntityUidEntry {
EntityUid euid = 1;
Loc loc = 2;
}

message EntityUid {
EntityType ty = 1;
string eid = 2;
Loc loc = 3;
}

message EntityType {
Expand All @@ -65,13 +63,6 @@ message EntityType {
message Name {
string id = 1;
repeated string path = 2;
Loc loc = 3;
}

message Loc {
uint32 offset = 1;
uint32 length = 2;
string src = 3;
}


Expand All @@ -93,7 +84,6 @@ message LiteralPolicy {

message Annotation {
string val = 1;
Loc loc = 2;
}

enum Effect {
Expand All @@ -103,7 +93,6 @@ enum Effect {

message TemplateBody {
string id = 1;
Loc loc = 2;
// alias AnyId = string
// alias Annotations = map<AnyId, Annotation>
map<string, Annotation> annotations = 3;
Expand Down Expand Up @@ -188,7 +177,6 @@ message ActionConstraint {

message Expr {
ExprKind expr_kind = 1;
Loc source_loc = 2;

message ExprKind {
oneof data {
Expand Down Expand Up @@ -321,7 +309,7 @@ message Expr {
// END POLICYSET MESSAGES


// ENTER ENTITITES MESSAGES
// ENTER ENTITIES MESSAGES

message Entity {
EntityUid uid = 1;
Expand All @@ -330,4 +318,4 @@ message Entity {
map<string, Expr> tags = 4;
}

// END ENTITITES MESSAGES
// END ENTITIES MESSAGES
16 changes: 2 additions & 14 deletions cedar-policy-core/protobuf_schema/AST.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ message Context {

message EntityUidEntry {
EntityUid euid = 1;
Loc loc = 2;
}

message EntityUid {
EntityType ty = 1;
string eid = 2;
Loc loc = 3;
}

message EntityType {
Expand All @@ -65,13 +63,6 @@ message EntityType {
message Name {
string id = 1;
repeated string path = 2;
Loc loc = 3;
}

message Loc {
uint32 offset = 1;
uint32 length = 2;
string src = 3;
}


Expand All @@ -93,7 +84,6 @@ message LiteralPolicy {

message Annotation {
string val = 1;
Loc loc = 2;
}

enum Effect {
Expand All @@ -103,7 +93,6 @@ enum Effect {

message TemplateBody {
string id = 1;
Loc loc = 2;
// alias AnyId = string
// alias Annotations = map<AnyId, Annotation>
map<string, Annotation> annotations = 3;
Expand Down Expand Up @@ -188,7 +177,6 @@ message ActionConstraint {

message Expr {
ExprKind expr_kind = 1;
Loc source_loc = 2;

message ExprKind {
oneof data {
Expand Down Expand Up @@ -321,7 +309,7 @@ message Expr {
// END POLICYSET MESSAGES


// ENTER ENTITITES MESSAGES
// ENTER ENTITIES MESSAGES

message Entity {
EntityUid uid = 1;
Expand All @@ -330,4 +318,4 @@ message Entity {
map<string, Expr> tags = 4;
}

// END ENTITITES MESSAGES
// END ENTITIES MESSAGES
5 changes: 1 addition & 4 deletions cedar-policy-core/src/ast/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,27 +283,24 @@ impl From<&proto::EntityUid> for EntityUID {
// PANIC SAFETY: experimental feature
#[allow(clippy::expect_used)]
fn from(v: &proto::EntityUid) -> Self {
let loc: Option<Loc> = v.loc.as_ref().map(Loc::from);
Self {
ty: EntityType::from(
v.ty.as_ref()
.expect("`as_ref()` for field that should exist"),
),
eid: Eid::new(v.eid.clone()),
loc,
loc: None,
}
}
}

#[cfg(feature = "protobufs")]
impl From<&EntityUID> for proto::EntityUid {
fn from(v: &EntityUID) -> Self {
let loc: Option<proto::Loc> = v.loc.as_ref().map(proto::Loc::from);
let eid_ref: &str = v.eid.as_ref();
Self {
ty: Some(proto::EntityType::from(&v.ty)),
eid: eid_ref.to_owned(),
loc,
}
}
}
Expand Down
30 changes: 8 additions & 22 deletions cedar-policy-core/src/ast/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,6 @@ impl From<&proto::Expr> for Expr {
// PANIC SAFETY: experimental feature
#[allow(clippy::expect_used)]
fn from(v: &proto::Expr) -> Self {
let source_loc: Option<Loc> = v.source_loc.as_ref().map(Loc::from);
let pdata = v
.expr_kind
.as_ref()
Expand All @@ -856,20 +855,18 @@ impl From<&proto::Expr> for Expr {
.expect("`as_ref()` for field that should exist");

match ety {
proto::expr::expr_kind::Data::Lit(lit) => {
Expr::val(Literal::from(lit)).with_maybe_source_loc(source_loc)
}
proto::expr::expr_kind::Data::Lit(lit) => Expr::val(Literal::from(lit)),

proto::expr::expr_kind::Data::Var(var) => {
let pvar =
proto::expr::Var::try_from(var.to_owned()).expect("decode should succeed");
Expr::var(Var::from(&pvar)).with_maybe_source_loc(source_loc)
Expr::var(Var::from(&pvar))
}

proto::expr::expr_kind::Data::Slot(slot) => {
let pslot =
proto::SlotId::try_from(slot.to_owned()).expect("decode should succeed");
Expr::slot(SlotId::from(&pslot)).with_maybe_source_loc(source_loc)
Expr::slot(SlotId::from(&pslot))
}

proto::expr::expr_kind::Data::If(msg) => {
Expand All @@ -893,7 +890,6 @@ impl From<&proto::Expr> for Expr {
Expr::from(then_expr),
Expr::from(else_expr),
)
.with_maybe_source_loc(source_loc)
}

proto::expr::expr_kind::Data::And(msg) => {
Expand All @@ -907,7 +903,7 @@ impl From<&proto::Expr> for Expr {
.as_ref()
.expect("`as_ref()` for field that should exist")
.as_ref();
Expr::and(Expr::from(left), Expr::from(right)).with_maybe_source_loc(source_loc)
Expr::and(Expr::from(left), Expr::from(right))
}

proto::expr::expr_kind::Data::Or(msg) => {
Expand All @@ -921,7 +917,7 @@ impl From<&proto::Expr> for Expr {
.as_ref()
.expect("`as_ref()` for field that should exist")
.as_ref();
Expr::or(Expr::from(left), Expr::from(right)).with_maybe_source_loc(source_loc)
Expr::or(Expr::from(left), Expr::from(right))
}

proto::expr::expr_kind::Data::UApp(msg) => {
Expand All @@ -933,7 +929,6 @@ impl From<&proto::Expr> for Expr {
let puop =
proto::expr::unary_app::Op::try_from(msg.op).expect("decode should succeed");
Expr::unary_app(UnaryOp::from(&puop), Expr::from(arg))
.with_maybe_source_loc(source_loc)
}

proto::expr::expr_kind::Data::BApp(msg) => {
Expand All @@ -952,7 +947,6 @@ impl From<&proto::Expr> for Expr {
Expr::from(left.as_ref()),
Expr::from(right.as_ref()),
)
.with_maybe_source_loc(source_loc)
}

proto::expr::expr_kind::Data::ExtApp(msg) => Expr::call_extension_fn(
Expand All @@ -962,8 +956,7 @@ impl From<&proto::Expr> for Expr {
.expect("`as_ref()` for field that should exist"),
),
msg.args.iter().map(Expr::from).collect(),
)
.with_maybe_source_loc(source_loc),
),

proto::expr::expr_kind::Data::GetAttr(msg) => {
let arg = msg
Expand All @@ -972,7 +965,6 @@ impl From<&proto::Expr> for Expr {
.expect("`as_ref()` for field that should exist")
.as_ref();
Expr::get_attr(Expr::from(arg), msg.attr.clone().into())
.with_maybe_source_loc(source_loc)
}

proto::expr::expr_kind::Data::HasAttr(msg) => {
Expand All @@ -982,7 +974,6 @@ impl From<&proto::Expr> for Expr {
.expect("`as_ref()` for field that should exist")
.as_ref();
Expr::has_attr(Expr::from(arg), msg.attr.clone().into())
.with_maybe_source_loc(source_loc)
}

proto::expr::expr_kind::Data::Like(msg) => {
Expand All @@ -995,7 +986,6 @@ impl From<&proto::Expr> for Expr {
Expr::from(arg),
msg.pattern.iter().map(PatternElem::from).collect(),
)
.with_maybe_source_loc(source_loc)
}

proto::expr::expr_kind::Data::Is(msg) => {
Expand All @@ -1012,20 +1002,18 @@ impl From<&proto::Expr> for Expr {
.expect("`as_ref()` for field that should exist"),
),
)
.with_maybe_source_loc(source_loc)
}

proto::expr::expr_kind::Data::Set(msg) => {
Expr::set(msg.elements.iter().map(Expr::from)).with_maybe_source_loc(source_loc)
Expr::set(msg.elements.iter().map(Expr::from))
}

proto::expr::expr_kind::Data::Record(msg) => Expr::record(
msg.items
.iter()
.map(|(key, value)| (key.into(), Expr::from(value))),
)
.expect("Expr should be valid")
.with_maybe_source_loc(source_loc),
.expect("Expr should be valid"),
}
}
}
Expand All @@ -1035,7 +1023,6 @@ impl From<&Expr> for proto::Expr {
// PANIC SAFETY: experimental feature
#[allow(clippy::unimplemented)]
fn from(v: &Expr) -> Self {
let source_loc: Option<proto::Loc> = v.source_loc.as_ref().map(proto::Loc::from);
let expr_kind = match &v.expr_kind {
ExprKind::Lit(l) => proto::expr::expr_kind::Data::Lit(proto::expr::Literal::from(l)),
ExprKind::Var(v) => proto::expr::expr_kind::Data::Var(proto::expr::Var::from(v).into()),
Expand Down Expand Up @@ -1139,7 +1126,6 @@ impl From<&Expr> for proto::Expr {
expr_kind: Some(Box::new(proto::expr::ExprKind {
data: Some(expr_kind),
})),
source_loc,
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions cedar-policy-core/src/ast/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,28 +554,26 @@ impl Name {
#[cfg(feature = "protobufs")]
impl From<&proto::Name> for Name {
fn from(v: &proto::Name) -> Self {
let loc: Option<Loc> = v.loc.as_ref().map(Loc::from);
let path: Arc<Vec<Id>> = Arc::new(v.path.iter().map(Id::new_unchecked).collect());
Self(InternalName {
id: Id::new_unchecked(&v.id),
path,
loc,
loc: None,
})
}
}

#[cfg(feature = "protobufs")]
impl From<&Name> for proto::Name {
fn from(v: &Name) -> Self {
let mut path: Vec<String> = Vec::with_capacity(v.0.path.as_ref().len());
let mut path: Vec<String> = Vec::with_capacity(v.0.path.len());
for value in v.0.path.as_ref() {
path.push(String::from(value.as_ref()));
}

Self {
id: String::from(v.0.id.as_ref()),
path,
loc: v.0.loc.as_ref().map(proto::Loc::from),
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions cedar-policy-core/src/ast/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,6 @@ impl From<&proto::TemplateBody> for TemplateBody {
// PANIC SAFETY: experimental feature
#[allow(clippy::expect_used)]
fn from(v: &proto::TemplateBody) -> Self {
let loc: Option<Loc> = v.loc.as_ref().map(Loc::from);
let annotations: Annotations = Annotations::from_iter(
v.annotations
.iter()
Expand All @@ -1231,7 +1230,7 @@ impl From<&proto::TemplateBody> for TemplateBody {

let body: TemplateBody = TemplateBody::new(
PolicyID::from_string(policy_id),
loc,
None,
annotations,
effect,
PrincipalConstraint::from(
Expand Down Expand Up @@ -1263,7 +1262,6 @@ impl From<&proto::TemplateBody> for TemplateBody {
impl From<&TemplateBody> for proto::TemplateBody {
fn from(v: &TemplateBody) -> Self {
let id_str: &str = v.id.as_ref();
let loc: Option<proto::Loc> = v.loc.as_ref().map(proto::Loc::from);
let annotations: HashMap<String, proto::Annotation> = v
.annotations
.as_ref()
Expand All @@ -1276,7 +1274,6 @@ impl From<&TemplateBody> for proto::TemplateBody {

Self {
id: String::from(id_str),
loc,
annotations,
effect: proto::Effect::from(&v.effect).into(),
principal_constraint: Some(proto::PrincipalConstraint::from(&v.principal_constraint)),
Expand Down Expand Up @@ -1389,7 +1386,7 @@ impl From<&proto::Annotation> for Annotation {
fn from(v: &proto::Annotation) -> Self {
Self {
val: v.val.clone().into(),
loc: v.loc.as_ref().map(Loc::from),
loc: None,
}
}
}
Expand All @@ -1399,7 +1396,6 @@ impl From<&Annotation> for proto::Annotation {
fn from(v: &Annotation) -> Self {
Self {
val: v.val.to_string(),
loc: v.loc.as_ref().map(proto::Loc::from),
}
}
}
Expand Down
Loading