Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: paritytech/scale-info
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.4.0
Choose a base ref
...
head repository: paritytech/scale-info
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.5.0
Choose a head ref
  • 2 commits
  • 12 files changed
  • 1 contributor

Commits on Mar 29, 2023

  1. ty: Make type fields public (#176)

    * portable: Expose types as mutable from the PortableRegistry
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    * ty: Make type fields public
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    * portable: Make `PortableType` public
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    * Deprecate getters
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    * Adjust codebase to use inner fields
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    * portable: Deprecate PortableType id() and ty()
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    * portable: Don't use deprecated getters
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    ---------
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    lexnv authored Mar 29, 2023
    Copy the full SHA
    78ff15a View commit details
  2. Release 2.5.0 (#177)

    * Bump versions to v2.5.0
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    * Update changelog
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    * Change changelog to reflect the irreversibal passing of time
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    
    ---------
    
    Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
    lexnv authored Mar 29, 2023
    Copy the full SHA
    caa38cb View commit details
Showing with 167 additions and 53 deletions.
  1. +6 −1 CHANGELOG.md
  2. +2 −2 Cargo.toml
  3. +1 −1 derive/Cargo.toml
  4. +1 −1 src/build.rs
  5. +5 −1 src/interner.rs
  6. +33 −24 src/portable.rs
  7. +3 −3 src/registry.rs
  8. +5 −1 src/ty/composite.rs
  9. +20 −4 src/ty/fields.rs
  10. +65 −13 src/ty/mod.rs
  11. +5 −1 src/ty/path.rs
  12. +21 −1 src/ty/variant.rs
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.0] - 2022-03-23
## [2.5.0] - 2023-03-29

### Added
- ty: Make type fields public [(#176)](https://github.com/paritytech/scale-info/pull/176)

## [2.4.0] - 2023-03-23

### Added
- portable: Retain the provided type IDs [(#174)](https://github.com/paritytech/scale-info/pull/174)
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scale-info"
version = "2.4.0"
version = "2.5.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"
rust-version = "1.60.0"
@@ -17,7 +17,7 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]
[dependencies]
bitvec = { version = "1", default-features = false, features = ["alloc"], optional = true }
cfg-if = "1.0"
scale-info-derive = { version = "2.4.0", path = "derive", default-features = false, optional = true }
scale-info-derive = { version = "2.5.0", path = "derive", default-features = false, optional = true }
serde = { version = "1", default-features = false, optional = true, features = ["derive", "alloc"] }
derive_more = { version = "0.99.1", default-features = false, features = ["from"] }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scale-info-derive"
version = "2.4.0"
version = "2.5.0"
authors = [
"Parity Technologies <admin@parity.io>",
"Centrality Developers <support@centrality.ai>",
2 changes: 1 addition & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
@@ -303,7 +303,7 @@ impl<F: Form, T> FieldsBuilder<F, T> {
impl<T> FieldsBuilder<MetaForm, T> {
fn push_field(mut self, field: Field) -> Self {
// filter out fields of PhantomData
if !field.ty().is_phantom() {
if !field.ty.is_phantom() {
self.fields.push(field);
}
self
6 changes: 5 additions & 1 deletion src/interner.rs
Original file line number Diff line number Diff line change
@@ -49,13 +49,17 @@ use serde::{
pub struct UntrackedSymbol<T> {
/// The index to the symbol in the interner table.
#[codec(compact)]
id: u32,
pub id: u32,
#[cfg_attr(feature = "serde", serde(skip))]
marker: PhantomData<fn() -> T>,
}

impl<T> UntrackedSymbol<T> {
/// Returns the index to the symbol in the interner table.
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn id(&self) -> u32 {
self.id
}
57 changes: 33 additions & 24 deletions src/portable.rs
Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ use scale::Encode;
#[cfg_attr(any(feature = "std", feature = "decode"), derive(scale::Decode))]
#[derive(Clone, Debug, PartialEq, Eq, Encode)]
pub struct PortableRegistry {
types: Vec<PortableType>,
/// The types contained by the [`PortableRegistry`].
pub types: Vec<PortableType>,
}

impl From<Registry> for PortableRegistry {
@@ -56,7 +57,7 @@ impl From<Registry> for PortableRegistry {
.types()
.map(|(k, v)| {
PortableType {
id: k.id(),
id: k.id,
ty: v.clone(),
}
})
@@ -68,10 +69,14 @@ impl From<Registry> for PortableRegistry {
impl PortableRegistry {
/// Returns the type definition for the given identifier, `None` if no type found for that ID.
pub fn resolve(&self, id: u32) -> Option<&Type<PortableForm>> {
self.types.get(id as usize).map(|ty| ty.ty())
self.types.get(id as usize).map(|ty| &ty.ty)
}

/// Returns all types with their associated identifiers.
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn types(&self) -> &[PortableType] {
&self.types
}
@@ -121,31 +126,27 @@ impl PortableRegistry {

// Make sure any type params are also retained:
for param in ty.ty.type_params.iter_mut() {
let Some(ty) = param.ty() else {
let Some(ty) = &param.ty else {
continue
};
let new_id = retain_type(ty.id(), types, new_types, retained_mappings);
let new_id = retain_type(ty.id, types, new_types, retained_mappings);
param.ty = Some(new_id).map(Into::into);
}

// make sure any types inside this type are also retained and update the IDs:
match &mut ty.ty.type_def {
TypeDef::Composite(composite) => {
for field in composite.fields.iter_mut() {
let new_id = retain_type(
field.ty.id(),
types,
new_types,
retained_mappings,
);
let new_id =
retain_type(field.ty.id, types, new_types, retained_mappings);
field.ty = new_id.into();
}
}
TypeDef::Variant(variant) => {
for var in variant.variants.iter_mut() {
for field in var.fields.iter_mut() {
let new_id = retain_type(
field.ty.id(),
field.ty.id,
types,
new_types,
retained_mappings,
@@ -156,7 +157,7 @@ impl PortableRegistry {
}
TypeDef::Sequence(sequence) => {
let new_id = retain_type(
sequence.type_param.id(),
sequence.type_param.id,
types,
new_types,
retained_mappings,
@@ -165,7 +166,7 @@ impl PortableRegistry {
}
TypeDef::Array(array) => {
let new_id = retain_type(
array.type_param.id(),
array.type_param.id,
types,
new_types,
retained_mappings,
@@ -175,14 +176,14 @@ impl PortableRegistry {
TypeDef::Tuple(tuple) => {
for ty in tuple.fields.iter_mut() {
let new_id =
retain_type(ty.id(), types, new_types, retained_mappings);
retain_type(ty.id, types, new_types, retained_mappings);
*ty = new_id.into();
}
}
TypeDef::Primitive(_) => (),
TypeDef::Compact(compact) => {
let new_id = retain_type(
compact.type_param().id(),
compact.type_param.id,
types,
new_types,
retained_mappings,
@@ -191,13 +192,13 @@ impl PortableRegistry {
}
TypeDef::BitSequence(bit_seq) => {
let bit_store_id = retain_type(
bit_seq.bit_store_type().id(),
bit_seq.bit_store_type.id,
types,
new_types,
retained_mappings,
);
let bit_order_id = retain_type(
bit_seq.bit_order_type().id(),
bit_seq.bit_order_type.id,
types,
new_types,
retained_mappings,
@@ -236,9 +237,9 @@ impl PortableRegistry {
#[derive(Clone, Debug, PartialEq, Eq, Encode)]
pub struct PortableType {
#[codec(compact)]
id: u32,
pub id: u32,
#[cfg_attr(feature = "serde", serde(rename = "type"))]
ty: Type<PortableForm>,
pub ty: Type<PortableForm>,
}

impl PortableType {
@@ -248,11 +249,19 @@ impl PortableType {
}

/// Returns the index of the [`PortableType`].
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn id(&self) -> u32 {
self.id
}

/// Returns the type of the [`PortableType`].
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn ty(&self) -> &Type<PortableForm> {
&self.ty
}
@@ -278,7 +287,7 @@ impl PortableRegistryBuilder {
///
/// If the type is already registered it will return the existing ID.
pub fn register_type(&mut self, ty: Type<PortableForm>) -> u32 {
self.types.intern_or_get(ty).1.into_untracked().id()
self.types.intern_or_get(ty).1.into_untracked().id
}

/// Returns the type id that would be assigned to a newly registered type.
@@ -632,10 +641,10 @@ mod tests {

let readonly: PortableRegistry = registry.into();

assert_eq!(4, readonly.types().len());
assert_eq!(4, readonly.types.len());

for (expected, ty) in readonly.types().iter().enumerate() {
assert_eq!(expected as u32, ty.id());
for (expected, ty) in readonly.types.iter().enumerate() {
assert_eq!(expected as u32, ty.id);
}
}

6 changes: 3 additions & 3 deletions src/registry.rs
Original file line number Diff line number Diff line change
@@ -215,9 +215,9 @@ mod tests {
let type_id = registry.register_type(&meta_type::<RecursiveRefs>());

let recursive = registry.types.get(&type_id).unwrap();
if let TypeDef::Composite(composite) = recursive.type_def() {
for field in composite.fields() {
assert_eq!(*field.ty(), type_id)
if let TypeDef::Composite(composite) = &recursive.type_def {
for field in &composite.fields {
assert_eq!(field.ty, type_id)
}
} else {
panic!("Should be a composite type definition")
6 changes: 5 additions & 1 deletion src/ty/composite.rs
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ pub struct TypeDefComposite<T: Form = MetaForm> {
feature = "serde",
serde(skip_serializing_if = "Vec::is_empty", default)
)]
pub(crate) fields: Vec<Field<T>>,
pub fields: Vec<Field<T>>,
}

impl IntoPortable for TypeDefComposite {
@@ -109,6 +109,10 @@ where
T: Form,
{
/// Returns the fields of the composite type.
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn fields(&self) -> &[Field<T>] {
&self.fields
}
24 changes: 20 additions & 4 deletions src/ty/fields.rs
Original file line number Diff line number Diff line change
@@ -78,22 +78,22 @@ pub struct Field<T: Form = MetaForm> {
feature = "serde",
serde(skip_serializing_if = "Option::is_none", default)
)]
pub(crate) name: Option<T::String>,
pub name: Option<T::String>,
/// The type of the field.
#[cfg_attr(feature = "serde", serde(rename = "type"))]
pub(crate) ty: T::Type,
pub ty: T::Type,
/// The name of the type of the field as it appears in the source code.
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "Option::is_none", default)
)]
pub(crate) type_name: Option<T::String>,
pub type_name: Option<T::String>,
/// Documentation
#[cfg_attr(
feature = "serde",
serde(skip_serializing_if = "Vec::is_empty", default)
)]
pub(crate) docs: Vec<T::String>,
pub docs: Vec<T::String>,
}

impl IntoPortable for Field {
@@ -141,11 +141,19 @@ where
T: Form,
{
/// Returns the name of the field. None for unnamed fields.
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn name(&self) -> Option<&T::String> {
self.name.as_ref()
}

/// Returns the type of the field.
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn ty(&self) -> &T::Type {
&self.ty
}
@@ -155,11 +163,19 @@ where
/// name are not specified, but in practice will be the name of any valid
/// type for a field. This is intended for informational and diagnostic
/// purposes only.
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn type_name(&self) -> Option<&T::String> {
self.type_name.as_ref()
}

/// Returns the documentation of the field.
#[deprecated(
since = "2.5.0",
note = "Prefer to access the fields directly; this getter will be removed in the next major version"
)]
pub fn docs(&self) -> &[T::String] {
&self.docs
}
Loading