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

feat(types): impl PartialEq and Hash for Ident instead of ModulePath #108

Merged
merged 4 commits into from
Jun 14, 2024
Merged
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
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ark-ff = "0.3.0"
ark-bls12-381 = "0.3.0" # bls12-381 curve for r1cs backend
ark-bn254 = "0.3.0" # bn128 curve for r1cs backend
ark-serialize = "0.3.0" # serialization of arkworks types
educe = { version = "0.6", default-features = false, features = ["Hash", "PartialEq"] }
ena = "0.14.0" # union-find implementation for the wiring
num-bigint = "0.4.3" # big int library
camino = "1.1.1" # to replace Path and PathBuf
Expand All @@ -20,16 +21,16 @@ dirs = "4.0.0"
itertools = "0.10.3" # useful iter traits
kimchi = { git = "https://github.com/o1-labs/proof-systems", rev = "a5d8883ddf649c22f38aaac122d368ecb9fa2230" } # ZKP - Dec 5th, 2023 revision
#kimchi = { git = "https://github.com/o1-labs/proof-systems", rev = "b9589626f834f9dbf9d587e73fd8176171231e90" } # ZKP
miette = { version = "5.0.0", features = ["fancy"] } # nice errors
num-traits = "0.2.15" # useful traits on big ints
once_cell = "1.15.0" # for lazy statics
regex = "1.6.0" # for regexes
rmp-serde = "1.1.1" # for serialization
serde_with = "2.0.1" # for serializing arkworks types
serde_json = "1.0.85" # to (de)serialize JSON
serde = "1.0.144" # to (de)serialize objects
thiserror = "1.0.31" # helpful error traits
toml = "0.8.8" # to parse manifest files
constraint_writers = { git = "https://github.com/iden3/circom.git", tag = "v2.1.8"} # to generate r1cs file
num-bigint-dig = "0.6.0" # to adapt for circom lib
rstest = "0.19.0" # for testing different backend cases
miette = { version = "5.0.0", features = ["fancy"] } # nice errors
num-traits = "0.2.15" # useful traits on big ints
once_cell = "1.15.0" # for lazy statics
regex = "1.6.0" # for regexes
rmp-serde = "1.1.1" # for serialization
serde_with = "2.0.1" # for serializing arkworks types
serde_json = "1.0.85" # to (de)serialize JSON
serde = "1.0.144" # to (de)serialize objects
thiserror = "1.0.31" # helpful error traits
toml = "0.8.8" # to parse manifest files
constraint_writers = { git = "https://github.com/iden3/circom.git", tag = "v2.1.8" } # to generate r1cs file
num-bigint-dig = "0.6.0" # to adapt for circom lib
rstest = "0.19.0" # for testing different backend cases
27 changes: 11 additions & 16 deletions src/parser/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::{fmt::Display, str::FromStr};
use educe::Educe;
use std::{
fmt::Display,
hash::{Hash, Hasher},
str::FromStr,
};

use ark_ff::Field;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -152,8 +157,7 @@ pub struct Ty {
}

/// The module preceding structs, functions, or variables.
// TODO: Hash should probably be implemented manually, right now two alias might have different span and so this will give different hashes
#[derive(Default, Debug, Clone, Serialize, Deserialize, Hash, Eq)]
#[derive(Default, Debug, Clone, Serialize, Deserialize, Hash, PartialEq, Eq)]
pub enum ModulePath {
#[default]
/// This is a local type, not imported from another module.
Expand All @@ -167,18 +171,6 @@ pub enum ModulePath {
Absolute(UserRepo),
}

// TODO: do we want to implement this on Ident instead?
impl PartialEq for ModulePath {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(ModulePath::Alias(a), ModulePath::Alias(b)) => a.value == b.value,
(ModulePath::Local, ModulePath::Local) => true,
(ModulePath::Absolute(a), ModulePath::Absolute(b)) => a == b,
_ => false,
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum TyKind {
/// The main primitive type. 'Nuf said.
Expand Down Expand Up @@ -401,9 +393,12 @@ impl FnSig {
}

/// Any kind of text that can represent a type, a variable, a function name, etc.
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Eq, Serialize, Deserialize, Educe)]
#[educe(Hash, PartialEq)]
pub struct Ident {
pub value: String,
#[educe(Hash(ignore))]
#[educe(PartialEq(ignore))]
pub span: Span,
}

Expand Down
Loading