Skip to content

Commit ab16b1d

Browse files
committed
Updated allowed-libfuncs jsons to provide the minimal support version.
1 parent be93463 commit ab16b1d

File tree

7 files changed

+819
-788
lines changed

7 files changed

+819
-788
lines changed

crates/cairo-lang-starknet-classes/src/allowed_libfuncs.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashSet;
1+
use std::collections::HashMap;
22
use std::fmt::{Display, Formatter};
33
use std::fs;
44

@@ -7,6 +7,8 @@ use serde::Deserialize;
77
use smol_str::SmolStr;
88
use thiserror::Error;
99

10+
use crate::compiler_version::VersionId;
11+
1012
#[cfg(test)]
1113
#[path = "allowed_libfuncs_test.rs"]
1214
mod test;
@@ -27,6 +29,15 @@ pub enum AllowedLibfuncsError {
2729
{BUILTIN_ALL_LIBFUNCS_LIST}' to allow all libfuncs."
2830
)]
2931
UnsupportedLibfunc { invalid_libfunc: String, allowed_libfuncs_list_name: String },
32+
#[error(
33+
"Libfunc {invalid_libfunc} requires version {required_version} while class version is {class_version}.\n
34+
Run with '--allowed-libfuncs-list-name {BUILTIN_ALL_LIBFUNCS_LIST}' to allow all libfuncs."
35+
)]
36+
UnsupportedLibfuncAtVersion {
37+
invalid_libfunc: String,
38+
required_version: VersionId,
39+
class_version: VersionId,
40+
},
3041
}
3142

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

74-
fn deserialize_libfuncs_set<'de, D: serde::Deserializer<'de>>(
85+
fn deserialize_libfuncs_map<'de, D: serde::Deserializer<'de>>(
7586
deserializer: D,
76-
) -> Result<HashSet<GenericLibfuncId>, D::Error> {
77-
Ok(HashSet::from_iter(
78-
Vec::<SmolStr>::deserialize(deserializer)?.into_iter().map(GenericLibfuncId::from_string),
87+
) -> Result<HashMap<GenericLibfuncId, Option<VersionId>>, D::Error> {
88+
Ok(HashMap::from_iter(
89+
HashMap::<SmolStr, Option<VersionId>>::deserialize(deserializer)?
90+
.into_iter()
91+
.map(|(id, v)| (GenericLibfuncId::from_string(id), v)),
7992
))
8093
}
8194

0 commit comments

Comments
 (0)