Skip to content

Commit

Permalink
Fix ci with really correct bugfix...
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Oct 3, 2023
1 parent d361605 commit 35dd937
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
6 changes: 3 additions & 3 deletions frozen-abi/src/abi_digester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ impl AbiDigester {
}
}

pub fn create_new_opaque(&self, top_scope: &str) -> Self {
pub fn create_new_opaque(&self, scope: &str) -> Self {
Self {
data_types: self.data_types.clone(),
depth: self.depth,
for_enum: false,
opaque_scope: Some(top_scope.to_owned()),
opaque_scope: Some(scope.to_owned()),
}
}

Expand Down Expand Up @@ -124,7 +124,7 @@ impl AbiDigester {
let type_name = normalize_type_name(type_name::<T>());
if type_name.ends_with("__SerializeWith")
|| (self.opaque_scope.is_some()
&& type_name.starts_with(self.opaque_scope.as_ref().unwrap()))
&& type_name.contains(self.opaque_scope.as_ref().unwrap()))
{
// we can't use the AbiEnumVisitor trait for these cases.
value.serialize(self.create_new())
Expand Down
27 changes: 20 additions & 7 deletions frozen-abi/src/abi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,9 @@ pub trait AbiEnumVisitor: Serialize {
}

pub trait IgnoreAsHelper {}
pub trait EvenAsOpaque {}
pub trait EvenAsOpaque {
const SCOPE: Option<&'static str> = None;
}

impl<T: Serialize + ?Sized> AbiEnumVisitor for T {
default fn visit_for_abi(&self, _digester: &mut AbiDigester) -> DigestResult {
Expand All @@ -493,8 +495,11 @@ impl<T: Serialize + ?Sized> AbiEnumVisitor for T {

impl<T: Serialize + ?Sized + AbiExample> AbiEnumVisitor for T {
default fn visit_for_abi(&self, digester: &mut AbiDigester) -> DigestResult {
info!("AbiEnumVisitor for (default): {}", type_name::<T>());
self.serialize(digester.create_new())
info!("AbiEnumVisitor for T: {}", type_name::<T>());
// not calling self.serialize(...) is intentional here as the most generic impl
// consider IgnoreAsHelper and EvenAsOpaque if you're stuck on this....
T::example()
.serialize(digester.create_new())
.map_err(DigestError::wrap_by_type::<T>)
}
}
Expand All @@ -504,7 +509,7 @@ impl<T: Serialize + ?Sized + AbiExample> AbiEnumVisitor for T {
// relevant test: TestVecEnum
impl<T: Serialize + ?Sized + AbiEnumVisitor> AbiEnumVisitor for &T {
default fn visit_for_abi(&self, digester: &mut AbiDigester) -> DigestResult {
info!("AbiEnumVisitor for (&default): {}", type_name::<T>());
info!("AbiEnumVisitor for &T: {}", type_name::<T>());
// Don't call self.visit_for_abi(...) to avoid the infinite recursion!
T::visit_for_abi(self, digester)
}
Expand All @@ -524,9 +529,17 @@ impl<T: Serialize + IgnoreAsHelper> AbiEnumVisitor for &T {
// inability of implementing AbiExample for private structs from other crates
impl<T: Serialize + IgnoreAsHelper + EvenAsOpaque> AbiEnumVisitor for &T {
default fn visit_for_abi(&self, digester: &mut AbiDigester) -> DigestResult {
info!("AbiEnumVisitor for (IgnoreAsOpaque): {}", type_name::<T>());
let top_scope = type_name::<T>().split("::").next().unwrap();
self.serialize(digester.create_new_opaque(top_scope))
let type_name = type_name::<T>();
let scope = if let Some(scope) = T::SCOPE {
scope
} else {
type_name.split("::").next().unwrap()
};
info!(
"AbiEnumVisitor for (EvenAsOpaque): {}: scope: {}",
type_name, scope
);
self.serialize(digester.create_new_opaque(scope))
.map_err(DigestError::wrap_by_type::<T>)
}
}
Expand Down
8 changes: 8 additions & 0 deletions sdk/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ impl ::solana_frozen_abi::abi_example::AbiExample for PacketFlags {
}
}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl ::solana_frozen_abi::abi_example::IgnoreAsHelper for PacketFlags {}

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl ::solana_frozen_abi::abi_example::EvenAsOpaque for PacketFlags {
const SCOPE: Option<&'static str> = Some("InternalBitFlags");
}

// serde_as is used as a work around because array isn't supported by serde
// (and serde_bytes).
//
Expand Down

0 comments on commit 35dd937

Please sign in to comment.