Skip to content

Updated allowed-libfuncs jsons to provide the minimal support version. #7844

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

Open
wants to merge 1 commit into
base: orizi/version-supports
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
27 changes: 20 additions & 7 deletions crates/cairo-lang-starknet-classes/src/allowed_libfuncs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::fs;

Expand All @@ -7,6 +7,8 @@ use serde::Deserialize;
use smol_str::SmolStr;
use thiserror::Error;

use crate::compiler_version::VersionId;

#[cfg(test)]
#[path = "allowed_libfuncs_test.rs"]
mod test;
Expand All @@ -27,6 +29,15 @@ pub enum AllowedLibfuncsError {
{BUILTIN_ALL_LIBFUNCS_LIST}' to allow all libfuncs."
)]
UnsupportedLibfunc { invalid_libfunc: String, allowed_libfuncs_list_name: String },
#[error(
"Libfunc {invalid_libfunc} requires version {required_version} while class version is {class_version}.\n
Run with '--allowed-libfuncs-list-name {BUILTIN_ALL_LIBFUNCS_LIST}' to allow all libfuncs."
)]
UnsupportedLibfuncAtVersion {
invalid_libfunc: String,
required_version: VersionId,
class_version: VersionId,
},
}

/// A selector for the allowed libfunc list.
Expand Down Expand Up @@ -67,15 +78,17 @@ impl Display for ListSelector {
/// Represents a list of allowed sierra libfuncs.
#[derive(Debug, PartialEq, Eq, Deserialize)]
pub struct AllowedLibfuncs {
#[serde(deserialize_with = "deserialize_libfuncs_set::<_>")]
pub allowed_libfuncs: HashSet<GenericLibfuncId>,
#[serde(deserialize_with = "deserialize_libfuncs_map::<_>")]
pub allowed_libfuncs: HashMap<GenericLibfuncId, Option<VersionId>>,
}

fn deserialize_libfuncs_set<'de, D: serde::Deserializer<'de>>(
fn deserialize_libfuncs_map<'de, D: serde::Deserializer<'de>>(
deserializer: D,
) -> Result<HashSet<GenericLibfuncId>, D::Error> {
Ok(HashSet::from_iter(
Vec::<SmolStr>::deserialize(deserializer)?.into_iter().map(GenericLibfuncId::from_string),
) -> Result<HashMap<GenericLibfuncId, Option<VersionId>>, D::Error> {
Ok(HashMap::from_iter(
HashMap::<SmolStr, Option<VersionId>>::deserialize(deserializer)?
.into_iter()
.map(|(id, v)| (GenericLibfuncId::from_string(id), v)),
))
}

Expand Down
Loading
Loading