Skip to content

Commit 675fde5

Browse files
committed
Remove PodClass from front-end Origin type
1 parent 7ca92d0 commit 675fde5

File tree

2 files changed

+23
-61
lines changed

2 files changed

+23
-61
lines changed

src/frontend/custom.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,7 @@ impl StatementTmplArg {
447447
(
448448
Self::Key(tmpl_o, tmpl_k),
449449
StatementArg::Key(AnchoredKey {
450-
origin:
451-
Origin {
452-
pod_id: PodId(o),
453-
pod_class: _,
454-
},
450+
origin: Origin { pod_id: PodId(o) },
455451
key: k,
456452
}),
457453
) => {

src/frontend/mod.rs

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ pub enum PodClass {
3838
// An Origin, which represents a reference to an ancestor POD.
3939
#[derive(Clone, Debug, PartialEq, Eq, h::Hash, Default, Serialize, Deserialize, JsonSchema)]
4040
pub struct Origin {
41-
pub pod_class: PodClass,
4241
pub pod_id: PodId,
4342
}
4443

4544
impl Origin {
46-
pub fn new(pod_class: PodClass, pod_id: PodId) -> Self {
47-
Self { pod_class, pod_id }
45+
pub fn new(pod_id: PodId) -> Self {
46+
Self { pod_id }
4847
}
4948
}
5049

@@ -265,7 +264,7 @@ impl SignedPod {
265264
self.pod.id()
266265
}
267266
pub fn origin(&self) -> Origin {
268-
Origin::new(PodClass::Signed, self.id())
267+
Origin::new(self.id())
269268
}
270269
pub fn verify(&self) -> Result<()> {
271270
self.pod.verify()
@@ -308,7 +307,6 @@ pub struct MainPodBuilder {
308307
// Internal state
309308
const_cnt: usize,
310309
key_table: HashMap<Hash, String>,
311-
pod_class_table: HashMap<PodId, PodClass>,
312310
}
313311

314312
impl fmt::Display for MainPodBuilder {
@@ -343,7 +341,6 @@ impl MainPodBuilder {
343341
public_statements: Vec::new(),
344342
const_cnt: 0,
345343
key_table: HashMap::new(),
346-
pod_class_table: HashMap::from_iter([(SELF, PodClass::Main)]),
347344
}
348345
}
349346
pub fn add_signed_pod(&mut self, pod: &SignedPod) {
@@ -352,25 +349,19 @@ impl MainPodBuilder {
352349
pod.kvs.iter().for_each(|(key, _)| {
353350
self.key_table.insert(hash_str(key), key.clone());
354351
});
355-
// Add POD class to POD class table.
356-
self.pod_class_table.insert(pod.id(), PodClass::Signed);
357352
}
358353
pub fn add_main_pod(&mut self, pod: MainPod) {
359-
// Add POD class to POD class table.
360-
self.pod_class_table.insert(pod.id(), PodClass::Main);
361354
// Add key-hash and POD ID-class correspondences to tables.
362355
pod.public_statements
363356
.iter()
364357
.flat_map(|s| &s.args)
365358
.flat_map(|arg| match arg {
366-
StatementArg::Key(AnchoredKey {
367-
origin: Origin { pod_class, pod_id },
368-
key,
369-
}) => Some((*pod_id, pod_class.clone(), hash_str(key), key.clone())),
359+
StatementArg::Key(AnchoredKey { origin: _, key }) => {
360+
Some((hash_str(key), key.clone()))
361+
}
370362
_ => None,
371363
})
372-
.for_each(|(pod_id, pod_class, hash, key)| {
373-
self.pod_class_table.insert(pod_id, pod_class);
364+
.for_each(|(hash, key)| {
374365
self.key_table.insert(hash, key);
375366
});
376367
self.input_main_pods.push(pod);
@@ -405,7 +396,7 @@ impl MainPodBuilder {
405396
}
406397
OperationArg::Entry(k, v) => {
407398
st_args.push(StatementArg::Key(AnchoredKey::new(
408-
Origin::new(PodClass::Main, SELF),
399+
Origin::new(SELF),
409400
k.clone(),
410401
)));
411402
st_args.push(StatementArg::Literal(v.clone()))
@@ -678,19 +669,10 @@ impl MainPodBuilder {
678669
.chunks(2)
679670
.map(|chunk| {
680671
Ok(StatementArg::Key(AnchoredKey::new(
681-
Origin::new(
682-
self.pod_class_table
683-
.get(&PodId(match chunk[0] {
684-
Value::Raw(v) => v.try_into()?,
685-
_ => return Err(anyhow!("Invalid POD class value.")),
686-
}))
687-
.cloned()
688-
.ok_or(anyhow!("Missing POD class value."))?,
689-
PodId(match chunk[0] {
690-
Value::Raw(v) => v.try_into()?,
691-
_ => return Err(anyhow!("Invalid POD class value.")),
692-
}),
693-
),
672+
Origin::new(PodId(match chunk[0] {
673+
Value::Raw(v) => v.try_into()?,
674+
_ => return Err(anyhow!("Invalid POD class value.")),
675+
})),
694676
self.key_table
695677
.get(&match &chunk[1] {
696678
Value::String(s) => hash_str(s.as_str()),
@@ -782,7 +764,7 @@ impl MainPodBuilder {
782764
predicate: Predicate::Native(NativePredicate::ValueOf),
783765
args: vec![
784766
StatementArg::Key(AnchoredKey::new(
785-
Origin::new(PodClass::Main, pod_id),
767+
Origin::new(pod_id),
786768
KEY_TYPE.to_string(),
787769
)),
788770
StatementArg::Literal(value.into()),
@@ -802,14 +784,10 @@ impl MainPodBuilder {
802784
.into_iter()
803785
.map(|arg| match arg {
804786
StatementArg::Key(AnchoredKey {
805-
origin:
806-
Origin {
807-
pod_class: class,
808-
pod_id: id,
809-
},
787+
origin: Origin { pod_id: id },
810788
key,
811789
}) if id == SELF => {
812-
StatementArg::Key(AnchoredKey::new(Origin::new(class, pod_id), key))
790+
StatementArg::Key(AnchoredKey::new(Origin::new(pod_id), key))
813791
}
814792
_ => arg,
815793
})
@@ -853,7 +831,7 @@ impl MainPod {
853831
self.pod.id()
854832
}
855833
pub fn origin(&self) -> Origin {
856-
Origin::new(PodClass::Main, self.id())
834+
Origin::new(self.id())
857835
}
858836
}
859837

@@ -1254,10 +1232,7 @@ pub mod tests {
12541232
Statement::new(
12551233
Predicate::Native(NativePredicate::ValueOf),
12561234
vec![
1257-
StatementArg::Key(AnchoredKey::new(
1258-
Origin::new(PodClass::Main, SELF),
1259-
"a".into(),
1260-
)),
1235+
StatementArg::Key(AnchoredKey::new(Origin::new(SELF), "a".into())),
12611236
StatementArg::Literal(Value::Int(3)),
12621237
],
12631238
),
@@ -1267,10 +1242,7 @@ pub mod tests {
12671242
Statement::new(
12681243
Predicate::Native(NativePredicate::ValueOf),
12691244
vec![
1270-
StatementArg::Key(AnchoredKey::new(
1271-
Origin::new(PodClass::Main, SELF),
1272-
"a".into(),
1273-
)),
1245+
StatementArg::Key(AnchoredKey::new(Origin::new(SELF), "a".into())),
12741246
StatementArg::Literal(Value::Int(28)),
12751247
],
12761248
),
@@ -1285,25 +1257,19 @@ pub mod tests {
12851257
// right now the mock prover catches this when it calls compile()
12861258
let params = Params::default();
12871259
let mut builder = MainPodBuilder::new(&params);
1288-
let self_a = AnchoredKey::new(Origin::new(PodClass::Main, SELF), "a".into());
1289-
let self_b = AnchoredKey::new(Origin::new(PodClass::Main, SELF), "b".into());
1260+
let self_a = AnchoredKey::new(Origin::new(SELF), "a".into());
1261+
let self_b = AnchoredKey::new(Origin::new(SELF), "b".into());
12901262
let value_of_a = Statement::new(
12911263
Predicate::Native(NativePredicate::ValueOf),
12921264
vec![
1293-
StatementArg::Key(AnchoredKey::new(
1294-
Origin::new(PodClass::Main, SELF),
1295-
"a".into(),
1296-
)),
1265+
StatementArg::Key(self_a.clone()),
12971266
StatementArg::Literal(Value::Int(3)),
12981267
],
12991268
);
13001269
let value_of_b = Statement::new(
13011270
Predicate::Native(NativePredicate::ValueOf),
13021271
vec![
1303-
StatementArg::Key(AnchoredKey::new(
1304-
Origin::new(PodClass::Main, SELF),
1305-
"b".into(),
1306-
)),
1272+
StatementArg::Key(self_b.clone()),
13071273
StatementArg::Literal(Value::Int(27)),
13081274
],
13091275
);

0 commit comments

Comments
 (0)