Skip to content

Commit b3cf375

Browse files
committed
remove Loc from protobufs in AST.proto
Signed-off-by: Craig Disselkoen <[email protected]>
1 parent c554807 commit b3cf375

File tree

7 files changed

+16
-105
lines changed

7 files changed

+16
-105
lines changed

cedar-policy-core/protobuf_schema/AST.proto

+2-14
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@ message Context {
4848

4949
message EntityUidEntry {
5050
EntityUid euid = 1;
51-
Loc loc = 2;
5251
}
5352

5453
message EntityUid {
5554
EntityType ty = 1;
5655
string eid = 2;
57-
Loc loc = 3;
5856
}
5957

6058
message EntityType {
@@ -65,13 +63,6 @@ message EntityType {
6563
message Name {
6664
string id = 1;
6765
repeated string path = 2;
68-
Loc loc = 3;
69-
}
70-
71-
message Loc {
72-
uint32 offset = 1;
73-
uint32 length = 2;
74-
string src = 3;
7566
}
7667

7768

@@ -93,7 +84,6 @@ message LiteralPolicy {
9384

9485
message Annotation {
9586
string val = 1;
96-
Loc loc = 2;
9787
}
9888

9989
enum Effect {
@@ -103,7 +93,6 @@ enum Effect {
10393

10494
message TemplateBody {
10595
string id = 1;
106-
Loc loc = 2;
10796
// alias AnyId = string
10897
// alias Annotations = map<AnyId, Annotation>
10998
map<string, Annotation> annotations = 3;
@@ -188,7 +177,6 @@ message ActionConstraint {
188177

189178
message Expr {
190179
ExprKind expr_kind = 1;
191-
Loc source_loc = 2;
192180

193181
message ExprKind {
194182
oneof data {
@@ -321,7 +309,7 @@ message Expr {
321309
// END POLICYSET MESSAGES
322310

323311

324-
// ENTER ENTITITES MESSAGES
312+
// ENTER ENTITIES MESSAGES
325313

326314
message Entity {
327315
EntityUid uid = 1;
@@ -330,4 +318,4 @@ message Entity {
330318
map<string, Expr> tags = 4;
331319
}
332320

333-
// END ENTITITES MESSAGES
321+
// END ENTITIES MESSAGES

cedar-policy-core/src/ast/entity.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -283,27 +283,24 @@ impl From<&proto::EntityUid> for EntityUID {
283283
// PANIC SAFETY: experimental feature
284284
#[allow(clippy::expect_used)]
285285
fn from(v: &proto::EntityUid) -> Self {
286-
let loc: Option<Loc> = v.loc.as_ref().map(Loc::from);
287286
Self {
288287
ty: EntityType::from(
289288
v.ty.as_ref()
290289
.expect("`as_ref()` for field that should exist"),
291290
),
292291
eid: Eid::new(v.eid.clone()),
293-
loc,
292+
loc: None,
294293
}
295294
}
296295
}
297296

298297
#[cfg(feature = "protobufs")]
299298
impl From<&EntityUID> for proto::EntityUid {
300299
fn from(v: &EntityUID) -> Self {
301-
let loc: Option<proto::Loc> = v.loc.as_ref().map(proto::Loc::from);
302300
let eid_ref: &str = v.eid.as_ref();
303301
Self {
304302
ty: Some(proto::EntityType::from(&v.ty)),
305303
eid: eid_ref.to_owned(),
306-
loc,
307304
}
308305
}
309306
}

cedar-policy-core/src/ast/expr.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ impl From<&proto::Expr> for Expr {
845845
// PANIC SAFETY: experimental feature
846846
#[allow(clippy::expect_used)]
847847
fn from(v: &proto::Expr) -> Self {
848-
let source_loc: Option<Loc> = v.source_loc.as_ref().map(Loc::from);
849848
let pdata = v
850849
.expr_kind
851850
.as_ref()
@@ -857,19 +856,19 @@ impl From<&proto::Expr> for Expr {
857856

858857
match ety {
859858
proto::expr::expr_kind::Data::Lit(lit) => {
860-
Expr::val(Literal::from(lit)).with_maybe_source_loc(source_loc)
859+
Expr::val(Literal::from(lit))
861860
}
862861

863862
proto::expr::expr_kind::Data::Var(var) => {
864863
let pvar =
865864
proto::expr::Var::try_from(var.to_owned()).expect("decode should succeed");
866-
Expr::var(Var::from(&pvar)).with_maybe_source_loc(source_loc)
865+
Expr::var(Var::from(&pvar))
867866
}
868867

869868
proto::expr::expr_kind::Data::Slot(slot) => {
870869
let pslot =
871870
proto::SlotId::try_from(slot.to_owned()).expect("decode should succeed");
872-
Expr::slot(SlotId::from(&pslot)).with_maybe_source_loc(source_loc)
871+
Expr::slot(SlotId::from(&pslot))
873872
}
874873

875874
proto::expr::expr_kind::Data::If(msg) => {
@@ -893,7 +892,6 @@ impl From<&proto::Expr> for Expr {
893892
Expr::from(then_expr),
894893
Expr::from(else_expr),
895894
)
896-
.with_maybe_source_loc(source_loc)
897895
}
898896

899897
proto::expr::expr_kind::Data::And(msg) => {
@@ -907,7 +905,7 @@ impl From<&proto::Expr> for Expr {
907905
.as_ref()
908906
.expect("`as_ref()` for field that should exist")
909907
.as_ref();
910-
Expr::and(Expr::from(left), Expr::from(right)).with_maybe_source_loc(source_loc)
908+
Expr::and(Expr::from(left), Expr::from(right))
911909
}
912910

913911
proto::expr::expr_kind::Data::Or(msg) => {
@@ -921,7 +919,7 @@ impl From<&proto::Expr> for Expr {
921919
.as_ref()
922920
.expect("`as_ref()` for field that should exist")
923921
.as_ref();
924-
Expr::or(Expr::from(left), Expr::from(right)).with_maybe_source_loc(source_loc)
922+
Expr::or(Expr::from(left), Expr::from(right))
925923
}
926924

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

939936
proto::expr::expr_kind::Data::BApp(msg) => {
@@ -952,7 +949,6 @@ impl From<&proto::Expr> for Expr {
952949
Expr::from(left.as_ref()),
953950
Expr::from(right.as_ref()),
954951
)
955-
.with_maybe_source_loc(source_loc)
956952
}
957953

958954
proto::expr::expr_kind::Data::ExtApp(msg) => Expr::call_extension_fn(
@@ -962,8 +958,7 @@ impl From<&proto::Expr> for Expr {
962958
.expect("`as_ref()` for field that should exist"),
963959
),
964960
msg.args.iter().map(Expr::from).collect(),
965-
)
966-
.with_maybe_source_loc(source_loc),
961+
),
967962

968963
proto::expr::expr_kind::Data::GetAttr(msg) => {
969964
let arg = msg
@@ -972,7 +967,6 @@ impl From<&proto::Expr> for Expr {
972967
.expect("`as_ref()` for field that should exist")
973968
.as_ref();
974969
Expr::get_attr(Expr::from(arg), msg.attr.clone().into())
975-
.with_maybe_source_loc(source_loc)
976970
}
977971

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

988981
proto::expr::expr_kind::Data::Like(msg) => {
@@ -995,7 +988,6 @@ impl From<&proto::Expr> for Expr {
995988
Expr::from(arg),
996989
msg.pattern.iter().map(PatternElem::from).collect(),
997990
)
998-
.with_maybe_source_loc(source_loc)
999991
}
1000992

1001993
proto::expr::expr_kind::Data::Is(msg) => {
@@ -1012,20 +1004,18 @@ impl From<&proto::Expr> for Expr {
10121004
.expect("`as_ref()` for field that should exist"),
10131005
),
10141006
)
1015-
.with_maybe_source_loc(source_loc)
10161007
}
10171008

10181009
proto::expr::expr_kind::Data::Set(msg) => {
1019-
Expr::set(msg.elements.iter().map(Expr::from)).with_maybe_source_loc(source_loc)
1010+
Expr::set(msg.elements.iter().map(Expr::from))
10201011
}
10211012

10221013
proto::expr::expr_kind::Data::Record(msg) => Expr::record(
10231014
msg.items
10241015
.iter()
10251016
.map(|(key, value)| (key.into(), Expr::from(value))),
10261017
)
1027-
.expect("Expr should be valid")
1028-
.with_maybe_source_loc(source_loc),
1018+
.expect("Expr should be valid"),
10291019
}
10301020
}
10311021
}
@@ -1035,7 +1025,6 @@ impl From<&Expr> for proto::Expr {
10351025
// PANIC SAFETY: experimental feature
10361026
#[allow(clippy::unimplemented)]
10371027
fn from(v: &Expr) -> Self {
1038-
let source_loc: Option<proto::Loc> = v.source_loc.as_ref().map(proto::Loc::from);
10391028
let expr_kind = match &v.expr_kind {
10401029
ExprKind::Lit(l) => proto::expr::expr_kind::Data::Lit(proto::expr::Literal::from(l)),
10411030
ExprKind::Var(v) => proto::expr::expr_kind::Data::Var(proto::expr::Var::from(v).into()),
@@ -1139,7 +1128,6 @@ impl From<&Expr> for proto::Expr {
11391128
expr_kind: Some(Box::new(proto::expr::ExprKind {
11401129
data: Some(expr_kind),
11411130
})),
1142-
source_loc,
11431131
}
11441132
}
11451133
}

cedar-policy-core/src/ast/name.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -554,28 +554,26 @@ impl Name {
554554
#[cfg(feature = "protobufs")]
555555
impl From<&proto::Name> for Name {
556556
fn from(v: &proto::Name) -> Self {
557-
let loc: Option<Loc> = v.loc.as_ref().map(Loc::from);
558557
let path: Arc<Vec<Id>> = Arc::new(v.path.iter().map(Id::new_unchecked).collect());
559558
Self(InternalName {
560559
id: Id::new_unchecked(&v.id),
561560
path,
562-
loc,
561+
loc: None,
563562
})
564563
}
565564
}
566565

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

575574
Self {
576575
id: String::from(v.0.id.as_ref()),
577576
path,
578-
loc: v.0.loc.as_ref().map(proto::Loc::from),
579577
}
580578
}
581579
}

cedar-policy-core/src/ast/policy.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,6 @@ impl From<&proto::TemplateBody> for TemplateBody {
12191219
// PANIC SAFETY: experimental feature
12201220
#[allow(clippy::expect_used)]
12211221
fn from(v: &proto::TemplateBody) -> Self {
1222-
let loc: Option<Loc> = v.loc.as_ref().map(Loc::from);
12231222
let annotations: Annotations = Annotations::from_iter(
12241223
v.annotations
12251224
.iter()
@@ -1231,7 +1230,7 @@ impl From<&proto::TemplateBody> for TemplateBody {
12311230

12321231
let body: TemplateBody = TemplateBody::new(
12331232
PolicyID::from_string(policy_id),
1234-
loc,
1233+
None,
12351234
annotations,
12361235
effect,
12371236
PrincipalConstraint::from(
@@ -1263,7 +1262,6 @@ impl From<&proto::TemplateBody> for TemplateBody {
12631262
impl From<&TemplateBody> for proto::TemplateBody {
12641263
fn from(v: &TemplateBody) -> Self {
12651264
let id_str: &str = v.id.as_ref();
1266-
let loc: Option<proto::Loc> = v.loc.as_ref().map(proto::Loc::from);
12671265
let annotations: HashMap<String, proto::Annotation> = v
12681266
.annotations
12691267
.as_ref()
@@ -1276,7 +1274,6 @@ impl From<&TemplateBody> for proto::TemplateBody {
12761274

12771275
Self {
12781276
id: String::from(id_str),
1279-
loc,
12801277
annotations,
12811278
effect: proto::Effect::from(&v.effect).into(),
12821279
principal_constraint: Some(proto::PrincipalConstraint::from(&v.principal_constraint)),
@@ -1389,7 +1386,7 @@ impl From<&proto::Annotation> for Annotation {
13891386
fn from(v: &proto::Annotation) -> Self {
13901387
Self {
13911388
val: v.val.clone().into(),
1392-
loc: v.loc.as_ref().map(Loc::from),
1389+
loc: None,
13931390
}
13941391
}
13951392
}
@@ -1399,7 +1396,6 @@ impl From<&Annotation> for proto::Annotation {
13991396
fn from(v: &Annotation) -> Self {
14001397
Self {
14011398
val: v.val.to_string(),
1402-
loc: v.loc.as_ref().map(proto::Loc::from),
14031399
}
14041400
}
14051401
}

cedar-policy-core/src/ast/request.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ impl EntityUIDEntry {
118118
#[cfg(feature = "protobufs")]
119119
impl From<&proto::EntityUidEntry> for EntityUIDEntry {
120120
fn from(v: &proto::EntityUidEntry) -> Self {
121-
let loc: Option<Loc> = v.loc.as_ref().map(Loc::from);
122121
// PANIC SAFETY: experimental feature
123122
#[allow(clippy::expect_used)]
124123
EntityUIDEntry::known(
125124
EntityUID::from(v.euid.as_ref().expect("euid.as_ref()")),
126-
loc,
125+
None,
127126
)
128127
}
129128
}
@@ -141,7 +140,6 @@ impl From<&EntityUIDEntry> for proto::EntityUidEntry {
141140
}
142141
EntityUIDEntry::Known { euid, loc } => Self {
143142
euid: Some(proto::EntityUid::from(euid.as_ref())),
144-
loc: loc.as_ref().map(proto::Loc::from),
145143
},
146144
}
147145
}

0 commit comments

Comments
 (0)