From 51d9ae28b317a471dc5c9574fc10463327f427b3 Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Fri, 4 Oct 2024 11:19:53 +1000 Subject: [PATCH 1/4] impl Serialize & Deserialize for ast node types --- sway-ast/src/intrinsics.rs | 3 +- sway-ast/src/literal.rs | 14 +++--- sway-ast/src/priv_prelude.rs | 2 +- sway-core/Cargo.toml | 2 +- sway-core/src/decl_engine/id.rs | 40 ++++++++++++---- .../src/decl_engine/interface_decl_id.rs | 4 +- sway-core/src/decl_engine/parsed_id.rs | 45 +++++++++++++----- sway-core/src/decl_engine/ref.rs | 12 ++--- sway-core/src/language/asm.rs | 6 +-- sway-core/src/language/call_path.rs | 24 +++++----- sway-core/src/language/lazy_op.rs | 4 +- sway-core/src/language/literal.rs | 11 +++-- .../src/language/parsed/declaration/trait.rs | 13 +++--- .../src/language/parsed/expression/mod.rs | 6 +-- .../src/language/parsed/use_statement.rs | 3 +- sway-core/src/language/purity.rs | 4 +- sway-core/src/language/ty/ast_node.rs | 22 ++++----- sway-core/src/language/ty/code_block.rs | 11 ++--- sway-core/src/language/ty/declaration/abi.rs | 6 +-- .../language/ty/declaration/configurable.rs | 17 ++++--- .../src/language/ty/declaration/constant.rs | 17 ++++--- .../language/ty/declaration/declaration.rs | 46 ++++++++++--------- sway-core/src/language/ty/declaration/enum.rs | 24 +++++----- .../src/language/ty/declaration/function.rs | 27 +++++------ .../src/language/ty/declaration/impl_trait.rs | 11 ++--- .../src/language/ty/declaration/storage.rs | 20 ++++---- .../src/language/ty/declaration/struct.rs | 22 ++++----- .../src/language/ty/declaration/trait.rs | 25 +++++----- .../src/language/ty/declaration/trait_type.rs | 15 +++--- .../src/language/ty/declaration/type_alias.rs | 12 ++--- .../src/language/ty/declaration/variable.rs | 9 ++-- sway-core/src/language/ty/expression/asm.rs | 6 +-- .../src/language/ty/expression/contract.rs | 3 +- .../src/language/ty/expression/expression.rs | 23 +++++----- .../ty/expression/expression_variant.rs | 22 ++++----- .../ty/expression/intrinsic_function.rs | 12 ++--- .../language/ty/expression/reassignment.rs | 22 ++++----- .../src/language/ty/expression/scrutinee.rs | 10 ++-- .../src/language/ty/expression/storage.rs | 11 ++--- .../ty/expression/struct_exp_field.rs | 13 +++--- .../ty/side_effect/include_statement.rs | 4 +- .../language/ty/side_effect/side_effect.rs | 5 +- .../language/ty/side_effect/use_statement.rs | 3 +- .../src/language/ty/variable_mutability.rs | 3 +- sway-core/src/language/visibility.rs | 4 +- sway-core/src/transform/attribute.rs | 12 ++--- .../src/type_system/ast_elements/binding.rs | 14 +++--- .../ast_elements/trait_constraint.rs | 26 +++++------ .../type_system/ast_elements/type_argument.rs | 3 +- .../ast_elements/type_parameter.rs | 15 +++--- sway-core/src/type_system/id.rs | 3 +- sway-core/src/type_system/info.rs | 15 +++--- sway-error/src/handler.rs | 3 +- sway-types/src/ident.rs | 28 ++++++----- sway-types/src/span.rs | 39 ++++++++-------- sway-types/src/u256.rs | 6 +-- 56 files changed, 409 insertions(+), 373 deletions(-) diff --git a/sway-ast/src/intrinsics.rs b/sway-ast/src/intrinsics.rs index 182d47fa3d9..c1151493395 100644 --- a/sway-ast/src/intrinsics.rs +++ b/sway-ast/src/intrinsics.rs @@ -1,6 +1,7 @@ +use serde::{Serialize, Deserialize}; use std::fmt; -#[derive(Eq, PartialEq, Debug, Clone, Hash)] +#[derive(Eq, PartialEq, Debug, Clone, Hash, Serialize, Deserialize)] pub enum Intrinsic { IsReferenceType, SizeOfType, diff --git a/sway-ast/src/literal.rs b/sway-ast/src/literal.rs index 1cede566e18..0b175235506 100644 --- a/sway-ast/src/literal.rs +++ b/sway-ast/src/literal.rs @@ -1,25 +1,25 @@ use crate::priv_prelude::*; -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] pub struct LitString { pub span: Span, pub parsed: String, } -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] pub struct LitChar { pub span: Span, pub parsed: char, } -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] pub struct LitInt { pub span: Span, pub parsed: BigUint, pub ty_opt: Option<(LitIntType, Span)>, } -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] pub enum LitIntType { U8, U16, @@ -32,13 +32,13 @@ pub enum LitIntType { I64, } -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] pub struct LitBool { pub span: Span, pub kind: LitBoolType, } -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] pub enum LitBoolType { True, False, @@ -53,7 +53,7 @@ impl From for bool { } } -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] pub enum Literal { String(LitString), Char(LitChar), diff --git a/sway-ast/src/priv_prelude.rs b/sway-ast/src/priv_prelude.rs index b799d69f37d..0e8540b71f9 100644 --- a/sway-ast/src/priv_prelude.rs +++ b/sway-ast/src/priv_prelude.rs @@ -35,7 +35,7 @@ pub use { }, extension_trait::extension_trait, num_bigint::BigUint, - serde::Serialize, + serde::{Serialize, Deserialize}, sway_types::{ ast::{Delimiter, PunctKind}, Ident, Span, Spanned, diff --git a/sway-core/Cargo.toml b/sway-core/Cargo.toml index 3a351390cbb..444ef744969 100644 --- a/sway-core/Cargo.toml +++ b/sway-core/Cargo.toml @@ -23,7 +23,7 @@ graph-cycles.workspace = true hashbrown.workspace = true hex = { workspace = true, optional = true } im.workspace = true -indexmap.workspace = true +indexmap = { workspace = true, features = ["serde"] } itertools.workspace = true lazy_static.workspace = true object = { workspace = true, features = ["write"] } diff --git a/sway-core/src/decl_engine/id.rs b/sway-core/src/decl_engine/id.rs index 8878b9aaa79..b2f3c4b12a6 100644 --- a/sway-core/src/decl_engine/id.rs +++ b/sway-core/src/decl_engine/id.rs @@ -1,20 +1,21 @@ -use std::collections::hash_map::DefaultHasher; -use std::hash::Hasher; -use std::marker::PhantomData; -use std::{fmt, hash::Hash}; - -use sway_types::{Named, Spanned}; - -use crate::language::ty::{TyDeclParsedType, TyTraitType}; use crate::{ decl_engine::*, engine_threading::*, language::ty::{ TyEnumDecl, TyFunctionDecl, TyImplSelfOrTrait, TyStructDecl, TyTraitDecl, TyTraitFn, - TyTypeAliasDecl, + TyTypeAliasDecl, TyDeclParsedType, TyTraitType, }, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::{ + collections::hash_map::DefaultHasher, + fmt, + hash::{Hash, Hasher}, + marker::PhantomData, +}; +use sway_types::{Named, Spanned}; + pub type DeclIdIndexType = usize; @@ -27,7 +28,7 @@ impl fmt::Debug for DeclId { } } -#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize, Deserialize)] pub struct DeclUniqueId(pub(crate) u64); impl DeclId { @@ -258,3 +259,22 @@ where } } } + +impl Serialize for DeclId { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.0.serialize(serializer) + } +} + +impl<'de, T> Deserialize<'de> for DeclId { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let id = DeclIdIndexType::deserialize(deserializer)?; + Ok(DeclId::new(id)) + } +} diff --git a/sway-core/src/decl_engine/interface_decl_id.rs b/sway-core/src/decl_engine/interface_decl_id.rs index 2306622a94a..94d6e0b25ff 100644 --- a/sway-core/src/decl_engine/interface_decl_id.rs +++ b/sway-core/src/decl_engine/interface_decl_id.rs @@ -6,8 +6,8 @@ use crate::{ ty, }, }; - use super::{parsed_engine::ParsedDeclEngineGet, parsed_id::ParsedDeclId}; +use serde::{Serialize, Deserialize}; #[derive(Debug, Eq, PartialEq, Hash, Clone)] pub enum ParsedInterfaceDeclId { @@ -43,7 +43,7 @@ impl From> for ParsedInterfaceDeclId { } } -#[derive(Debug, Eq, PartialEq, Hash, Clone)] +#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize)] pub enum InterfaceDeclId { Abi(DeclId), Trait(DeclId), diff --git a/sway-core/src/decl_engine/parsed_id.rs b/sway-core/src/decl_engine/parsed_id.rs index 3a97459aa75..7af8ea26c33 100644 --- a/sway-core/src/decl_engine/parsed_id.rs +++ b/sway-core/src/decl_engine/parsed_id.rs @@ -1,16 +1,18 @@ -use std::hash::{DefaultHasher, Hasher}; -use std::marker::PhantomData; -use std::{fmt, hash::Hash}; - -use sway_types::{Named, Spanned}; - -use crate::engine_threading::{ - EqWithEngines, HashWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext, +use crate::{ + Engines, + engine_threading::{EqWithEngines, HashWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext}, }; -use crate::Engines; - -use super::parsed_engine::{ParsedDeclEngine, ParsedDeclEngineGet, ParsedDeclEngineIndex}; -use super::DeclUniqueId; +use super::{ + DeclUniqueId, + parsed_engine::{ParsedDeclEngine, ParsedDeclEngineGet, ParsedDeclEngineIndex}, +}; +use serde::{Serialize, Deserialize}; +use std::{ + hash::{DefaultHasher, Hasher}, + marker::PhantomData, + {fmt, hash::Hash}, +}; +use sway_types::{Named, Spanned}; pub type ParsedDeclIdIndexType = usize; @@ -91,6 +93,25 @@ impl Ord for ParsedDeclId { } } +impl Serialize for ParsedDeclId { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.0.serialize(serializer) + } +} + +impl<'de, T> Deserialize<'de> for ParsedDeclId { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + let id = usize::deserialize(deserializer)?; + Ok(ParsedDeclId::new(id)) + } +} + impl ParsedDeclId { pub(crate) fn new(id: usize) -> Self { ParsedDeclId(id, PhantomData) diff --git a/sway-core/src/decl_engine/ref.rs b/sway-core/src/decl_engine/ref.rs index 663fd563a60..455a8842f31 100644 --- a/sway-core/src/decl_engine/ref.rs +++ b/sway-core/src/decl_engine/ref.rs @@ -20,11 +20,6 @@ //! `fn my_function() { .. }`, and to use [DeclRef] for cases like function //! application `my_function()`. -use std::hash::{Hash, Hasher}; - -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ decl_engine::*, engine_threading::*, @@ -35,6 +30,11 @@ use crate::{ semantic_analysis::TypeCheckContext, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::hash::{Hash, Hasher}; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::{Ident, Named, Span, Spanned}; + pub type DeclRefFunction = DeclRef>; pub type DeclRefTrait = DeclRef>; @@ -53,7 +53,7 @@ pub type DeclRefMixedInterface = DeclRef; /// Represents the use of / syntactic reference to a declaration. A /// smart-wrapper around a [DeclId], containing additional information about a /// declaration. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct DeclRef { /// The name of the declaration. // NOTE: In the case of storage, the name is "storage". diff --git a/sway-core/src/language/asm.rs b/sway-core/src/language/asm.rs index c8fcbb429a5..3ea81b6c0fd 100644 --- a/sway-core/src/language/asm.rs +++ b/sway-core/src/language/asm.rs @@ -1,8 +1,8 @@ +use serde::{Serialize, Deserialize}; use std::hash::{Hash, Hasher}; - use sway_types::{BaseIdent, Ident, Span}; -#[derive(Debug, Clone, Eq)] +#[derive(Debug, Clone, Eq, Serialize, Deserialize)] pub struct AsmOp { pub(crate) op_name: Ident, pub(crate) op_args: Vec, @@ -43,7 +43,7 @@ impl PartialEq for AsmOp { } } -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct AsmRegister { pub(crate) name: String, } diff --git a/sway-core/src/language/call_path.rs b/sway-core/src/language/call_path.rs index 8036d3ecab8..fb4d70e633a 100644 --- a/sway-core/src/language/call_path.rs +++ b/sway-core/src/language/call_path.rs @@ -1,27 +1,25 @@ -use std::{ - cmp::Ordering, - fmt, - hash::{Hash, Hasher}, - sync::Arc, -}; - use crate::{ engine_threading::{ DebugWithEngines, DisplayWithEngines, EqWithEngines, HashWithEngines, OrdWithEngines, OrdWithEnginesContext, PartialEqWithEngines, PartialEqWithEnginesContext, }, + parsed::QualifiedPathType, Engines, Ident, Namespace, }; - +use serde::{Serialize, Deserialize}; +use std::{ + cmp::Ordering, + fmt, + hash::{Hash, Hasher}, + sync::Arc, +}; use sway_error::{ error::CompileError, handler::{ErrorEmitted, Handler}, }; use sway_types::{span::Span, Spanned}; -use super::parsed::QualifiedPathType; - -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct CallPathTree { pub qualified_call_path: QualifiedCallPath, pub children: Vec, @@ -75,7 +73,7 @@ impl OrdWithEngines for CallPathTree { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct QualifiedCallPath { pub call_path: CallPath, @@ -179,7 +177,7 @@ impl DebugWithEngines for QualifiedCallPath { /// In the expression `a::b::c()`, `a` and `b` are the prefixes and `c` is the suffix. /// `c` can be any type `T`, but in practice `c` is either an `Ident` or a `TypeInfo`. -#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize, Deserialize)] pub struct CallPath { pub prefixes: Vec, pub suffix: T, diff --git a/sway-core/src/language/lazy_op.rs b/sway-core/src/language/lazy_op.rs index 73e3daae256..e175dd6d96a 100644 --- a/sway-core/src/language/lazy_op.rs +++ b/sway-core/src/language/lazy_op.rs @@ -1,4 +1,6 @@ -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +use serde::{Serialize, Deserialize}; + +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum LazyOp { And, Or, diff --git a/sway-core/src/language/literal.rs b/sway-core/src/language/literal.rs index afedaad12d0..47c9784ca1f 100644 --- a/sway-core/src/language/literal.rs +++ b/sway-core/src/language/literal.rs @@ -1,15 +1,16 @@ use crate::{type_system::*, Engines}; - -use sway_error::error::CompileError; -use sway_types::{integer_bits::IntegerBits, span, u256::U256}; - +use serde::{Serialize, Deserialize}; use std::{ fmt, hash::{Hash, Hasher}, num::{IntErrorKind, ParseIntError}, }; +use sway_error::error::CompileError; +use sway_types::{integer_bits::IntegerBits, span, u256::U256}; + + -#[derive(Debug, Clone, Eq)] +#[derive(Debug, Clone, Eq, Serialize, Deserialize)] pub enum Literal { U8(u8), U16(u16), diff --git a/sway-core/src/language/parsed/declaration/trait.rs b/sway-core/src/language/parsed/declaration/trait.rs index 12e76e554c6..163df3c1ef2 100644 --- a/sway-core/src/language/parsed/declaration/trait.rs +++ b/sway-core/src/language/parsed/declaration/trait.rs @@ -1,7 +1,3 @@ -use std::hash::{Hash, Hasher}; - -use super::{ConstantDeclaration, FunctionDeclaration, FunctionParameter}; - use crate::{ decl_engine::{parsed_id::ParsedDeclId, DeclRefTrait}, engine_threading::*, @@ -9,16 +5,19 @@ use crate::{ transform, type_system::*, }; +use super::{ConstantDeclaration, FunctionDeclaration, FunctionParameter}; +use serde::{Serialize, Deserialize}; +use std::hash::{Hash, Hasher}; use sway_error::handler::ErrorEmitted; use sway_types::{ident::Ident, span::Span, Named, Spanned}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub enum TraitItem { TraitFn(ParsedDeclId), Constant(ParsedDeclId), Type(ParsedDeclId), // to handle parser recovery: Error represents an incomplete trait item - Error(Box<[Span]>, ErrorEmitted), + Error(Box<[Span]>, #[serde(skip)] ErrorEmitted), } impl EqWithEngines for TraitItem {} @@ -75,7 +74,7 @@ impl Spanned for TraitDeclaration { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Supertrait { pub name: CallPath, pub decl_ref: Option, diff --git a/sway-core/src/language/parsed/expression/mod.rs b/sway-core/src/language/parsed/expression/mod.rs index 90d41fbf19b..73ae0d4f7f6 100644 --- a/sway-core/src/language/parsed/expression/mod.rs +++ b/sway-core/src/language/parsed/expression/mod.rs @@ -1,5 +1,3 @@ -use std::{cmp::Ordering, fmt, hash::Hasher}; - use crate::{ decl_engine::parsed_id::ParsedDeclId, engine_threading::{ @@ -10,6 +8,8 @@ use crate::{ type_system::TypeBinding, Engines, TypeArgument, TypeId, }; +use serde::{Serialize, Deserialize}; +use std::{cmp::Ordering, fmt, hash::Hasher}; use sway_error::handler::ErrorEmitted; use sway_types::{ident::Ident, Span, Spanned}; @@ -198,7 +198,7 @@ impl Spanned for AmbiguousSuffix { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct QualifiedPathType { pub ty: TypeArgument, pub as_trait: TypeId, diff --git a/sway-core/src/language/parsed/use_statement.rs b/sway-core/src/language/parsed/use_statement.rs index ceda688d75f..5443da84d1e 100644 --- a/sway-core/src/language/parsed/use_statement.rs +++ b/sway-core/src/language/parsed/use_statement.rs @@ -1,7 +1,8 @@ use crate::{language::Visibility, parsed::Span}; +use serde::{Serialize, Deserialize}; use sway_types::ident::Ident; -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum ImportType { Star, SelfImport(Span), diff --git a/sway-core/src/language/purity.rs b/sway-core/src/language/purity.rs index 4b498b2fcdd..d223faaa18e 100644 --- a/sway-core/src/language/purity.rs +++ b/sway-core/src/language/purity.rs @@ -1,7 +1,9 @@ +use serde::{Serialize, Deserialize}; + /// The purity of a function is related to its access of contract storage. If a function accesses /// or could potentially access contract storage, it is [Purity::Impure]. If a function does not utilize any /// any accesses (reads _or_ writes) of storage, then it is [Purity::Pure]. -#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, Default)] +#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub enum Purity { #[default] Pure, diff --git a/sway-core/src/language/ty/ast_node.rs b/sway-core/src/language/ty/ast_node.rs index 59d9e942004..684fcfbf7ce 100644 --- a/sway-core/src/language/ty/ast_node.rs +++ b/sway-core/src/language/ty/ast_node.rs @@ -1,11 +1,3 @@ -use std::{ - fmt::{self, Debug}, - hash::{Hash, Hasher}, -}; - -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::{Ident, Span}; - use crate::{ decl_engine::*, engine_threading::*, @@ -18,12 +10,20 @@ use crate::{ type_system::*, types::*, }; +use serde::{Serialize, Deserialize}; +use std::{ + fmt::{self, Debug}, + hash::{Hash, Hasher}, +}; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::{Ident, Span}; + pub trait GetDeclIdent { fn get_decl_ident(&self, engines: &Engines) -> Option; } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyAstNode { pub content: TyAstNodeContent, pub span: Span, @@ -353,13 +353,13 @@ impl TyAstNode { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyAstNodeContent { Declaration(TyDecl), Expression(TyExpression), // a no-op node used for something that just issues a side effect, like an import statement. SideEffect(TySideEffect), - Error(Box<[Span]>, ErrorEmitted), + Error(Box<[Span]>, #[serde(skip)] ErrorEmitted), } impl EqWithEngines for TyAstNodeContent {} diff --git a/sway-core/src/language/ty/code_block.rs b/sway-core/src/language/ty/code_block.rs index 6ae9b0d0dea..2e881639f4f 100644 --- a/sway-core/src/language/ty/code_block.rs +++ b/sway-core/src/language/ty/code_block.rs @@ -1,14 +1,13 @@ -use std::hash::Hasher; - -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::Span; - use crate::{ decl_engine::*, engine_threading::*, language::ty::*, semantic_analysis::TypeCheckContext, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::hash::Hasher; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::Span; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyCodeBlock { pub contents: Vec, pub(crate) whole_block_span: Span, diff --git a/sway-core/src/language/ty/declaration/abi.rs b/sway-core/src/language/ty/declaration/abi.rs index 5ad5ea2c3dc..9623c62a036 100644 --- a/sway-core/src/language/ty/declaration/abi.rs +++ b/sway-core/src/language/ty/declaration/abi.rs @@ -4,15 +4,15 @@ use crate::{ transform, type_system::*, }; +use super::{TyDeclParsedType, TyTraitInterfaceItem, TyTraitItem}; +use serde::{Serialize, Deserialize}; use std::hash::{Hash, Hasher}; - use sway_types::{Ident, Named, Span, Spanned}; -use super::{TyDeclParsedType, TyTraitInterfaceItem, TyTraitItem}; /// A [TyAbiDecl] contains the type-checked version of the parse tree's /// `AbiDeclaration`. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyAbiDecl { /// The name of the abi trait (also known as a "contract trait") pub name: Ident, diff --git a/sway-core/src/language/ty/declaration/configurable.rs b/sway-core/src/language/ty/declaration/configurable.rs index da7349fc91b..a4a82c01500 100644 --- a/sway-core/src/language/ty/declaration/configurable.rs +++ b/sway-core/src/language/ty/declaration/configurable.rs @@ -1,11 +1,3 @@ -use std::{ - fmt, - hash::{Hash, Hasher}, -}; - -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ decl_engine::{DeclId, DeclMapping, DeclRef, ReplaceDecls}, engine_threading::*, @@ -15,8 +7,15 @@ use crate::{ transform, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::{ + fmt, + hash::{Hash, Hasher}, +}; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::{Ident, Named, Span, Spanned}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyConfigurableDecl { pub call_path: CallPath, pub value: Option, diff --git a/sway-core/src/language/ty/declaration/constant.rs b/sway-core/src/language/ty/declaration/constant.rs index c8acda6b5cf..875045a1f0a 100644 --- a/sway-core/src/language/ty/declaration/constant.rs +++ b/sway-core/src/language/ty/declaration/constant.rs @@ -1,11 +1,3 @@ -use std::{ - fmt, - hash::{Hash, Hasher}, -}; - -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ decl_engine::{DeclMapping, ReplaceDecls}, engine_threading::*, @@ -15,8 +7,15 @@ use crate::{ transform, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::{ + fmt, + hash::{Hash, Hasher}, +}; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::{Ident, Named, Span, Spanned}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyConstantDecl { pub call_path: CallPath, pub value: Option, diff --git a/sway-core/src/language/ty/declaration/declaration.rs b/sway-core/src/language/ty/declaration/declaration.rs index 9bd68ec0046..c0905d8f779 100644 --- a/sway-core/src/language/ty/declaration/declaration.rs +++ b/sway-core/src/language/ty/declaration/declaration.rs @@ -1,3 +1,11 @@ +use crate::{ + decl_engine::*, + engine_threading::*, + language::{parsed::Declaration, ty::*, Visibility}, + type_system::*, + types::*, +}; +use serde::{Serialize, Deserialize}; use std::{ fmt, hash::{Hash, Hasher}, @@ -9,15 +17,9 @@ use sway_error::{ }; use sway_types::{Ident, Named, Span, Spanned}; -use crate::{ - decl_engine::*, - engine_threading::*, - language::{parsed::Declaration, ty::*, Visibility}, - type_system::*, - types::*, -}; -#[derive(Clone, Debug)] + +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyDecl { VariableDecl(Box), ConstantDecl(ConstantDecl), @@ -33,7 +35,7 @@ pub enum TyDecl { // If type parameters are defined for a function, they are put in the namespace just for // the body of that function. GenericTypeForFunctionScope(GenericTypeForFunctionScope), - ErrorRecovery(Span, ErrorEmitted), + ErrorRecovery(Span, #[serde(skip)] ErrorEmitted), StorageDecl(StorageDecl), TypeAliasDecl(TypeAliasDecl), } @@ -46,70 +48,70 @@ pub trait TyDeclParsedType { type ParsedType; } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct ConstantDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct ConfigurableDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TraitTypeDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct FunctionDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TraitDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct StructDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct EnumDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct EnumVariantDecl { pub enum_ref: DeclRefEnum, pub variant_name: Ident, pub variant_decl_span: Span, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct ImplSelfOrTrait { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct AbiDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct GenericTypeForFunctionScope { pub name: Ident, pub type_id: TypeId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct StorageDecl { pub decl_id: DeclId, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TypeAliasDecl { pub decl_id: DeclId, } diff --git a/sway-core/src/language/ty/declaration/enum.rs b/sway-core/src/language/ty/declaration/enum.rs index 2ce5e3eae46..f2931710175 100644 --- a/sway-core/src/language/ty/declaration/enum.rs +++ b/sway-core/src/language/ty/declaration/enum.rs @@ -1,26 +1,24 @@ +use crate::{ + engine_threading::*, + has_changes, + language::{parsed::EnumDeclaration, CallPath, Visibility, ty::TyDeclParsedType}, + transform, + type_system::*, +}; +use monomorphization::MonomorphizeHelper; +use serde::{Serialize, Deserialize}; use std::{ cmp::Ordering, hash::{Hash, Hasher}, }; - -use monomorphization::MonomorphizeHelper; use sway_error::{ error::CompileError, handler::{ErrorEmitted, Handler}, }; use sway_types::{Ident, Named, Span, Spanned}; -use crate::{ - engine_threading::*, - has_changes, - language::{parsed::EnumDeclaration, CallPath, Visibility}, - transform, - type_system::*, -}; - -use super::TyDeclParsedType; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyEnumDecl { pub call_path: CallPath, pub type_parameters: Vec, @@ -133,7 +131,7 @@ impl Spanned for TyEnumVariant { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TyEnumVariant { pub name: Ident, pub type_argument: TypeArgument, diff --git a/sway-core/src/language/ty/declaration/function.rs b/sway-core/src/language/ty/declaration/function.rs index 8bb26f1f598..41f63bf7938 100644 --- a/sway-core/src/language/ty/declaration/function.rs +++ b/sway-core/src/language/ty/declaration/function.rs @@ -1,12 +1,3 @@ -use std::{ - fmt, - hash::{Hash, Hasher}, -}; - -use monomorphization::MonomorphizeHelper; -use sha2::{Digest, Sha256}; -use sway_error::handler::{ErrorEmitted, Handler}; - use crate::{ has_changes, language::{ @@ -14,9 +5,6 @@ use crate::{ CallPath, }, transform::AttributeKind, -}; - -use crate::{ decl_engine::*, engine_threading::*, language::{parsed, ty::*, Inline, Purity, Visibility}, @@ -25,13 +13,20 @@ use crate::{ type_system::*, types::*, }; - +use monomorphization::MonomorphizeHelper; +use serde::{Serialize, Deserialize}; +use sha2::{Digest, Sha256}; +use std::{ + fmt, + hash::{Hash, Hasher}, +}; +use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::{ constants::{INLINE_ALWAYS_NAME, INLINE_NEVER_NAME}, Ident, Named, Span, Spanned, }; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyFunctionDeclKind { Default, Entry, @@ -39,7 +34,7 @@ pub enum TyFunctionDeclKind { Test, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyFunctionDecl { pub name: Ident, pub body: TyCodeBlock, @@ -489,7 +484,7 @@ impl TyFunctionDecl { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TyFunctionParameter { pub name: Ident, pub is_reference: bool, diff --git a/sway-core/src/language/ty/declaration/impl_trait.rs b/sway-core/src/language/ty/declaration/impl_trait.rs index 0c2d25aa5fd..8deef675be5 100644 --- a/sway-core/src/language/ty/declaration/impl_trait.rs +++ b/sway-core/src/language/ty/declaration/impl_trait.rs @@ -1,7 +1,3 @@ -use std::hash::{Hash, Hasher}; - -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ decl_engine::DeclRefMixedInterface, engine_threading::*, @@ -9,13 +5,16 @@ use crate::{ language::{parsed::ImplSelfOrTrait, CallPath}, type_system::*, }; - use super::{TyDeclParsedType, TyTraitItem}; +use serde::{Serialize, Deserialize}; +use std::hash::{Hash, Hasher}; +use sway_types::{Ident, Named, Span, Spanned}; + pub type TyImplItem = TyTraitItem; // impl Trait for Type -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyImplSelfOrTrait { pub impl_type_parameters: Vec, pub trait_name: CallPath, diff --git a/sway-core/src/language/ty/declaration/storage.rs b/sway-core/src/language/ty/declaration/storage.rs index 767d5728ee7..c772d9451a0 100644 --- a/sway-core/src/language/ty/declaration/storage.rs +++ b/sway-core/src/language/ty/declaration/storage.rs @@ -1,11 +1,3 @@ -use std::hash::{Hash, Hasher}; - -use sway_error::{ - error::{CompileError, StructFieldUsageContext}, - handler::{ErrorEmitted, Handler}, -}; -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ engine_threading::*, language::{parsed::StorageDeclaration, ty::*, Visibility}, @@ -13,8 +5,16 @@ use crate::{ type_system::*, Namespace, }; +use serde::{Serialize, Deserialize}; +use std::hash::{Hash, Hasher}; +use sway_error::{ + error::{CompileError, StructFieldUsageContext}, + handler::{ErrorEmitted, Handler}, +}; +use sway_types::{Ident, Named, Span, Spanned}; + -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStorageDecl { pub fields: Vec, pub span: Span, @@ -262,7 +262,7 @@ impl Spanned for TyStorageField { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStorageField { pub name: Ident, pub namespace_names: Vec, diff --git a/sway-core/src/language/ty/declaration/struct.rs b/sway-core/src/language/ty/declaration/struct.rs index c4dc7e3e219..cd3d726cf7f 100644 --- a/sway-core/src/language/ty/declaration/struct.rs +++ b/sway-core/src/language/ty/declaration/struct.rs @@ -1,24 +1,22 @@ -use std::{ - cmp::Ordering, - hash::{Hash, Hasher}, -}; - -use monomorphization::MonomorphizeHelper; -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ engine_threading::*, error::module_can_be_changed, has_changes, - language::{parsed::StructDeclaration, CallPath, Visibility}, + language::{parsed::StructDeclaration, CallPath, Visibility, ty::TyDeclParsedType}, transform, type_system::*, Namespace, }; +use monomorphization::MonomorphizeHelper; +use serde::{Serialize, Deserialize}; +use std::{ + cmp::Ordering, + hash::{Hash, Hasher}, +}; +use sway_types::{Ident, Named, Span, Spanned}; -use super::TyDeclParsedType; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStructDecl { pub call_path: CallPath, pub fields: Vec, @@ -182,7 +180,7 @@ impl From for (bool, bool) { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TyStructField { pub visibility: Visibility, pub name: Ident, diff --git a/sway-core/src/language/ty/declaration/trait.rs b/sway-core/src/language/ty/declaration/trait.rs index f0c7ee24ff3..ca3f4d65311 100644 --- a/sway-core/src/language/ty/declaration/trait.rs +++ b/sway-core/src/language/ty/declaration/trait.rs @@ -1,12 +1,3 @@ -use std::{ - fmt, - hash::{Hash, Hasher}, -}; - -use monomorphization::MonomorphizeHelper; -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ decl_engine::{ DeclEngineReplace, DeclRefConstant, DeclRefFunction, DeclRefTraitFn, DeclRefTraitType, @@ -17,6 +8,7 @@ use crate::{ language::{ parsed::{self, TraitDeclaration}, CallPath, Visibility, + ty::{TyDecl, TyDeclParsedType}, }, semantic_analysis::{ TypeCheckAnalysis, TypeCheckAnalysisContext, TypeCheckFinalization, @@ -25,10 +17,17 @@ use crate::{ transform, type_system::*, }; +use monomorphization::MonomorphizeHelper; +use serde::{Serialize, Deserialize}; +use std::{ + fmt, + hash::{Hash, Hasher}, +}; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::{Ident, Named, Span, Spanned}; -use super::{TyDecl, TyDeclParsedType}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyTraitDecl { pub name: Ident, pub type_parameters: Vec, @@ -46,7 +45,7 @@ impl TyDeclParsedType for TyTraitDecl { type ParsedType = TraitDeclaration; } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyTraitInterfaceItem { TraitFn(DeclRefTraitFn), Constant(DeclRefConstant), @@ -82,7 +81,7 @@ impl DebugWithEngines for TyTraitInterfaceItem { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyTraitItem { Fn(DeclRefFunction), Constant(DeclRefConstant), diff --git a/sway-core/src/language/ty/declaration/trait_type.rs b/sway-core/src/language/ty/declaration/trait_type.rs index 24925afa457..4416731dba2 100644 --- a/sway-core/src/language/ty/declaration/trait_type.rs +++ b/sway-core/src/language/ty/declaration/trait_type.rs @@ -1,18 +1,17 @@ +use crate::{ + language::ty::TyDeclParsedType, + engine_threading::*, has_changes, language::parsed::TraitTypeDeclaration, transform, + type_system::*, +}; +use serde::{Serialize, Deserialize}; use std::{ fmt, hash::{Hash, Hasher}, }; - use sway_types::{Ident, Named, Span, Spanned}; -use crate::{ - engine_threading::*, has_changes, language::parsed::TraitTypeDeclaration, transform, - type_system::*, -}; - -use super::TyDeclParsedType; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyTraitType { pub name: Ident, pub attributes: transform::AttributesMap, diff --git a/sway-core/src/language/ty/declaration/type_alias.rs b/sway-core/src/language/ty/declaration/type_alias.rs index e2e5844de3f..5c3eb072d55 100644 --- a/sway-core/src/language/ty/declaration/type_alias.rs +++ b/sway-core/src/language/ty/declaration/type_alias.rs @@ -1,17 +1,15 @@ -use std::hash::{Hash, Hasher}; - -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ engine_threading::*, - language::{parsed::TypeAliasDeclaration, CallPath, Visibility}, + language::{parsed::TypeAliasDeclaration, CallPath, Visibility, ty::TyDeclParsedType}, transform, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::hash::{Hash, Hasher}; +use sway_types::{Ident, Named, Span, Spanned}; -use super::TyDeclParsedType; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyTypeAliasDecl { pub name: Ident, pub call_path: CallPath, diff --git a/sway-core/src/language/ty/declaration/variable.rs b/sway-core/src/language/ty/declaration/variable.rs index d7eb80ad7c6..4059f10714a 100644 --- a/sway-core/src/language/ty/declaration/variable.rs +++ b/sway-core/src/language/ty/declaration/variable.rs @@ -1,14 +1,13 @@ -use std::hash::{Hash, Hasher}; - -use sway_types::{Ident, Named, Spanned}; - use crate::{ engine_threading::*, language::{parsed::VariableDeclaration, ty::*}, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::hash::{Hash, Hasher}; +use sway_types::{Ident, Named, Spanned}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyVariableDecl { pub name: Ident, pub body: TyExpression, diff --git a/sway-core/src/language/ty/expression/asm.rs b/sway-core/src/language/ty/expression/asm.rs index 04944125258..71068b128b7 100644 --- a/sway-core/src/language/ty/expression/asm.rs +++ b/sway-core/src/language/ty/expression/asm.rs @@ -1,10 +1,10 @@ +use crate::{engine_threading::*, language::ty::*, type_system::*}; +use serde::{Serialize, Deserialize}; use std::hash::{Hash, Hasher}; - use sway_types::Ident; -use crate::{engine_threading::*, language::ty::*, type_system::*}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyAsmRegisterDeclaration { pub initializer: Option, pub(crate) name: Ident, diff --git a/sway-core/src/language/ty/expression/contract.rs b/sway-core/src/language/ty/expression/contract.rs index 2bdec40421e..4c63ff03869 100644 --- a/sway-core/src/language/ty/expression/contract.rs +++ b/sway-core/src/language/ty/expression/contract.rs @@ -1,6 +1,7 @@ use crate::language::ty::*; +use serde::{Serialize, Deserialize}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct ContractCallParams { // This is none in encoding V1 pub(crate) func_selector: Option<[u8; 4]>, diff --git a/sway-core/src/language/ty/expression/expression.rs b/sway-core/src/language/ty/expression/expression.rs index 15f57369007..850ab65d057 100644 --- a/sway-core/src/language/ty/expression/expression.rs +++ b/sway-core/src/language/ty/expression/expression.rs @@ -1,13 +1,3 @@ -use std::{fmt, hash::Hasher}; - -use sway_error::{ - error::CompileError, - handler::{ErrorEmitted, Handler}, - type_error::TypeError, - warning::{CompileWarning, Warning}, -}; -use sway_types::{Span, Spanned}; - use crate::{ decl_engine::*, engine_threading::*, @@ -21,8 +11,19 @@ use crate::{ type_system::*, types::*, }; +use serde::{Serialize, Deserialize}; +use std::{fmt, hash::Hasher}; +use sway_error::{ + error::CompileError, + handler::{ErrorEmitted, Handler}, + type_error::TypeError, + warning::{CompileWarning, Warning}, +}; +use sway_types::{Span, Spanned}; + + -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyExpression { pub expression: TyExpressionVariant, pub return_type: TypeId, diff --git a/sway-core/src/language/ty/expression/expression_variant.rs b/sway-core/src/language/ty/expression/expression_variant.rs index 9908bb09f5b..14082595759 100644 --- a/sway-core/src/language/ty/expression/expression_variant.rs +++ b/sway-core/src/language/ty/expression/expression_variant.rs @@ -1,13 +1,3 @@ -use std::{ - collections::VecDeque, - fmt::{self, Write}, - hash::{Hash, Hasher}, -}; - -use indexmap::IndexMap; -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::{Ident, Named, Span, Spanned}; - use crate::{ decl_engine::*, engine_threading::*, @@ -20,8 +10,18 @@ use crate::{ }, type_system::*, }; +use indexmap::IndexMap; +use serde::{Serialize, Deserialize}; +use std::{ + collections::VecDeque, + fmt::{self, Write}, + hash::{Hash, Hasher}, +}; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::{Ident, Named, Span, Spanned}; + -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyExpressionVariant { Literal(Literal), FunctionApplication { diff --git a/sway-core/src/language/ty/expression/intrinsic_function.rs b/sway-core/src/language/ty/expression/intrinsic_function.rs index 4fb4e72c3bc..488c45fa788 100644 --- a/sway-core/src/language/ty/expression/intrinsic_function.rs +++ b/sway-core/src/language/ty/expression/intrinsic_function.rs @@ -1,18 +1,18 @@ -use std::{ - fmt, - hash::{Hash, Hasher}, -}; - use crate::{ abi_generation::abi_str::AbiStrContext, engine_threading::*, has_changes, language::ty::*, type_system::*, types::*, }; use itertools::Itertools; +use serde::{Serialize, Deserialize}; +use std::{ + fmt, + hash::{Hash, Hasher}, +}; use sway_ast::Intrinsic; use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::Span; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TyIntrinsicFunctionKind { pub kind: Intrinsic, pub arguments: Vec, diff --git a/sway-core/src/language/ty/expression/reassignment.rs b/sway-core/src/language/ty/expression/reassignment.rs index 54a8e740c5c..a6e08a4b69d 100644 --- a/sway-core/src/language/ty/expression/reassignment.rs +++ b/sway-core/src/language/ty/expression/reassignment.rs @@ -1,11 +1,3 @@ -use std::{ - borrow::Cow, - hash::{Hash, Hasher}, -}; - -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::{Ident, Span, Spanned}; - use crate::{ decl_engine::*, engine_threading::*, @@ -17,14 +9,22 @@ use crate::{ }, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::{ + borrow::Cow, + hash::{Hash, Hasher}, +}; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::{Ident, Span, Spanned}; + -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyReassignment { pub lhs: TyReassignmentTarget, pub rhs: TyExpression, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyReassignmentTarget { /// An [TyExpression] representing a single variable or a path /// to a part of an aggregate. @@ -258,7 +258,7 @@ impl UpdateConstantExpression for TyReassignment { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum ProjectionKind { StructField { name: Ident, diff --git a/sway-core/src/language/ty/expression/scrutinee.rs b/sway-core/src/language/ty/expression/scrutinee.rs index 68c51af26eb..3f0c4d31d98 100644 --- a/sway-core/src/language/ty/expression/scrutinee.rs +++ b/sway-core/src/language/ty/expression/scrutinee.rs @@ -1,19 +1,19 @@ -use sway_types::{Ident, Span}; - use crate::{ decl_engine::{DeclRefEnum, DeclRefStruct}, language::{ty::*, *}, type_system::*, }; +use serde::{Serialize, Deserialize}; +use sway_types::{Ident, Span}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TyScrutinee { pub variant: TyScrutineeVariant, pub type_id: TypeId, pub span: Span, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub enum TyScrutineeVariant { Or(Vec), CatchAll, @@ -36,7 +36,7 @@ pub enum TyScrutineeVariant { Tuple(Vec), } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TyStructScrutineeField { pub field: Ident, pub scrutinee: Option, diff --git a/sway-core/src/language/ty/expression/storage.rs b/sway-core/src/language/ty/expression/storage.rs index 127d64fd20b..01eaf7ad0c2 100644 --- a/sway-core/src/language/ty/expression/storage.rs +++ b/sway-core/src/language/ty/expression/storage.rs @@ -1,13 +1,12 @@ +use crate::{engine_threading::*, type_system::TypeId}; +use super::TyExpression; +use serde::{Serialize, Deserialize}; use std::hash::{Hash, Hasher}; - use sway_types::{Ident, Span, Spanned}; -use crate::{engine_threading::*, type_system::TypeId}; - -use super::TyExpression; /// Describes the full storage access including all the subfields -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStorageAccess { pub fields: Vec, pub storage_field_names: Vec, @@ -64,7 +63,7 @@ impl TyStorageAccess { } /// Describes a single subfield access in the sequence when accessing a subfield within storage. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStorageAccessDescriptor { pub name: Ident, pub type_id: TypeId, diff --git a/sway-core/src/language/ty/expression/struct_exp_field.rs b/sway-core/src/language/ty/expression/struct_exp_field.rs index 5f879640fb3..246158e5425 100644 --- a/sway-core/src/language/ty/expression/struct_exp_field.rs +++ b/sway-core/src/language/ty/expression/struct_exp_field.rs @@ -1,8 +1,3 @@ -use std::hash::{Hash, Hasher}; - -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::Ident; - use crate::{ decl_engine::*, engine_threading::*, @@ -10,8 +5,14 @@ use crate::{ semantic_analysis::{TypeCheckContext, TypeCheckFinalization, TypeCheckFinalizationContext}, type_system::*, }; +use serde::{Serialize, Deserialize}; +use std::hash::{Hash, Hasher}; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::Ident; + + -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStructExpressionField { pub name: Ident, pub value: TyExpression, diff --git a/sway-core/src/language/ty/side_effect/include_statement.rs b/sway-core/src/language/ty/side_effect/include_statement.rs index 5d35f02b722..fc34f611d86 100644 --- a/sway-core/src/language/ty/side_effect/include_statement.rs +++ b/sway-core/src/language/ty/side_effect/include_statement.rs @@ -1,8 +1,8 @@ use crate::language::Visibility; - +use serde::{Serialize, Deserialize}; use sway_types::{ident::Ident, Span, Spanned}; -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct TyIncludeStatement { pub span: Span, pub visibility: Visibility, diff --git a/sway-core/src/language/ty/side_effect/side_effect.rs b/sway-core/src/language/ty/side_effect/side_effect.rs index 41f2a5b945b..aaf7a39b90b 100644 --- a/sway-core/src/language/ty/side_effect/side_effect.rs +++ b/sway-core/src/language/ty/side_effect/side_effect.rs @@ -1,11 +1,12 @@ use super::{TyIncludeStatement, TyUseStatement}; +use serde::{Serialize, Deserialize}; -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct TySideEffect { pub side_effect: TySideEffectVariant, } -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum TySideEffectVariant { IncludeStatement(TyIncludeStatement), UseStatement(TyUseStatement), diff --git a/sway-core/src/language/ty/side_effect/use_statement.rs b/sway-core/src/language/ty/side_effect/use_statement.rs index 5d9c0cf1ca1..590faf9e38b 100644 --- a/sway-core/src/language/ty/side_effect/use_statement.rs +++ b/sway-core/src/language/ty/side_effect/use_statement.rs @@ -1,7 +1,8 @@ use crate::language::parsed; +use serde::{Serialize, Deserialize}; use sway_types::{ident::Ident, Span, Spanned}; -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct TyUseStatement { pub call_path: Vec, pub span: Span, diff --git a/sway-core/src/language/ty/variable_mutability.rs b/sway-core/src/language/ty/variable_mutability.rs index ba2532028b6..b81bcaf055c 100644 --- a/sway-core/src/language/ty/variable_mutability.rs +++ b/sway-core/src/language/ty/variable_mutability.rs @@ -1,6 +1,7 @@ use crate::language::Visibility; +use serde::{Serialize, Deserialize}; -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub enum VariableMutability { // mutable Mutable, diff --git a/sway-core/src/language/visibility.rs b/sway-core/src/language/visibility.rs index a3838e06aff..64f490342e7 100644 --- a/sway-core/src/language/visibility.rs +++ b/sway-core/src/language/visibility.rs @@ -1,4 +1,6 @@ -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Visibility { Private, Public, diff --git a/sway-core/src/transform/attribute.rs b/sway-core/src/transform/attribute.rs index d29978205c8..bd2041ee6a4 100644 --- a/sway-core/src/transform/attribute.rs +++ b/sway-core/src/transform/attribute.rs @@ -21,6 +21,8 @@ //! #[foo(bar, bar)] use indexmap::IndexMap; +use serde::{Serialize, Deserialize}; +use std::{hash::Hash, sync::Arc}; use sway_ast::Literal; use sway_types::{ constants::{ @@ -29,9 +31,7 @@ use sway_types::{ Ident, Span, Spanned, }; -use std::{hash::Hash, sync::Arc}; - -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct AttributeArg { pub name: Ident, pub value: Option, @@ -47,7 +47,7 @@ impl Spanned for AttributeArg { /// An attribute has a name (i.e "doc", "storage"), /// a vector of possible arguments and /// a span from its declaration. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct Attribute { pub name: Ident, pub args: Vec, @@ -55,7 +55,7 @@ pub struct Attribute { } /// Valid kinds of attributes supported by the compiler -#[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] pub enum AttributeKind { Doc, DocComment, @@ -104,7 +104,7 @@ impl AttributeKind { } /// Stores the attributes associated with the type. -#[derive(Default, Clone, Debug, Eq, PartialEq)] +#[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct AttributesMap(Arc>>); impl AttributesMap { diff --git a/sway-core/src/type_system/ast_elements/binding.rs b/sway-core/src/type_system/ast_elements/binding.rs index 9a4c7c1dd43..9803aef7632 100644 --- a/sway-core/src/type_system/ast_elements/binding.rs +++ b/sway-core/src/type_system/ast_elements/binding.rs @@ -1,7 +1,3 @@ -use sway_ast::Intrinsic; -use sway_error::handler::{ErrorEmitted, Handler}; -use sway_types::{Span, Spanned}; - use crate::{ decl_engine::{ parsed_id::ParsedDeclId, DeclEngineGetParsedDeclId, DeclEngineInsert, DeclId, DeclRef, @@ -18,6 +14,12 @@ use crate::{ type_system::priv_prelude::*, EnforceTypeArguments, Ident, }; +use serde::{Serialize, Deserialize}; +use sway_ast::Intrinsic; +use sway_error::handler::{ErrorEmitted, Handler}; +use sway_types::{Span, Spanned}; + + /// A `TypeBinding` is the result of using turbofish to bind types to /// generic parameters. @@ -78,7 +80,7 @@ use crate::{ /// - `data4` has a type ascription and has type arguments in the `TypeBinding`, /// so, with the type from the value passed to `value`, all three are unified /// together -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TypeBinding { pub inner: T, pub type_arguments: TypeArgs, @@ -103,7 +105,7 @@ pub struct TypeBinding { /// ``` /// So we can have type parameters in the `Prefix` or `Regular` variant but not /// in both. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub enum TypeArgs { /// `Regular` variant indicates the type arguments are located after the suffix. Regular(Vec), diff --git a/sway-core/src/type_system/ast_elements/trait_constraint.rs b/sway-core/src/type_system/ast_elements/trait_constraint.rs index e91411595bb..7c5e75a927d 100644 --- a/sway-core/src/type_system/ast_elements/trait_constraint.rs +++ b/sway-core/src/type_system/ast_elements/trait_constraint.rs @@ -1,15 +1,3 @@ -use std::{ - cmp::Ordering, - fmt, - hash::{Hash, Hasher}, -}; - -use sway_error::{ - error::CompileError, - handler::{ErrorEmitted, Handler}, -}; -use sway_types::Spanned; - use crate::{ engine_threading::*, language::{parsed::Supertrait, ty, CallPath}, @@ -21,8 +9,20 @@ use crate::{ types::{CollectTypesMetadata, CollectTypesMetadataContext, TypeMetadata}, EnforceTypeArguments, }; +use serde::{Serialize, Deserialize}; +use std::{ + cmp::Ordering, + fmt, + hash::{Hash, Hasher}, +}; +use sway_error::{ + error::CompileError, + handler::{ErrorEmitted, Handler}, +}; +use sway_types::Spanned; + -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TraitConstraint { pub trait_name: CallPath, pub type_arguments: Vec, diff --git a/sway-core/src/type_system/ast_elements/type_argument.rs b/sway-core/src/type_system/ast_elements/type_argument.rs index 1476fe6627b..dbfafa80756 100644 --- a/sway-core/src/type_system/ast_elements/type_argument.rs +++ b/sway-core/src/type_system/ast_elements/type_argument.rs @@ -1,8 +1,9 @@ use crate::{engine_threading::*, language::CallPathTree, type_system::priv_prelude::*}; +use serde::{Serialize, Deserialize}; use std::{cmp::Ordering, fmt, hash::Hasher}; use sway_types::{Span, Spanned}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TypeArgument { pub type_id: TypeId, pub initial_type_id: TypeId, diff --git a/sway-core/src/type_system/ast_elements/type_parameter.rs b/sway-core/src/type_system/ast_elements/type_parameter.rs index fb008336f4d..24cfaf005b6 100644 --- a/sway-core/src/type_system/ast_elements/type_parameter.rs +++ b/sway-core/src/type_system/ast_elements/type_parameter.rs @@ -7,21 +7,20 @@ use crate::{ semantic_analysis::{GenericShadowingMode, TypeCheckContext}, type_system::priv_prelude::*, }; - -use sway_error::{ - error::CompileError, - handler::{ErrorEmitted, Handler}, -}; -use sway_types::{ident::Ident, span::Span, Spanned}; - +use serde::{Serialize, Deserialize}; use std::{ cmp::Ordering, collections::BTreeMap, fmt, hash::{Hash, Hasher}, }; +use sway_error::{ + error::CompileError, + handler::{ErrorEmitted, Handler}, +}; +use sway_types::{ident::Ident, span::Span, Spanned}; -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub struct TypeParameter { pub type_id: TypeId, pub(crate) initial_type_id: TypeId, diff --git a/sway-core/src/type_system/id.rs b/sway-core/src/type_system/id.rs index 7a7480fe838..8f1a8d26f91 100644 --- a/sway-core/src/type_system/id.rs +++ b/sway-core/src/type_system/id.rs @@ -1,5 +1,6 @@ #![allow(clippy::mutable_key_type)] use indexmap::IndexMap; +use serde::{Deserialize, Serialize}; use sway_error::{ error::CompileError, handler::{ErrorEmitted, Handler}, @@ -34,7 +35,7 @@ pub enum TreatNumericAs { } /// A identifier to uniquely refer to our type terms -#[derive(PartialEq, Eq, Hash, Clone, Copy, Ord, PartialOrd, Debug)] +#[derive(PartialEq, Eq, Hash, Clone, Copy, Ord, PartialOrd, Debug, Deserialize, Serialize)] pub struct TypeId(usize); impl DisplayWithEngines for TypeId { diff --git a/sway-core/src/type_system/info.rs b/sway-core/src/type_system/info.rs index 29767d81fc0..df5b4714c97 100644 --- a/sway-core/src/type_system/info.rs +++ b/sway-core/src/type_system/info.rs @@ -12,20 +12,21 @@ use crate::{ type_system::priv_prelude::*, Ident, }; -use sway_error::{ - error::{CompileError, InvalidImplementingForType}, - handler::{ErrorEmitted, Handler}, -}; -use sway_types::{integer_bits::IntegerBits, span::Span, SourceId}; - +use serde::{Serialize, Deserialize}; use std::{ cmp::Ordering, fmt, hash::{Hash, Hasher}, sync::Arc, }; +use sway_error::{ + error::{CompileError, InvalidImplementingForType}, + handler::{ErrorEmitted, Handler}, +}; +use sway_types::{integer_bits::IntegerBits, span::Span, SourceId}; + -#[derive(Debug, Clone, Hash, Eq, PartialEq, PartialOrd, Ord)] +#[derive(Debug, Clone, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub enum AbiName { Deferred, Known(CallPath), diff --git a/sway-error/src/handler.rs b/sway-error/src/handler.rs index 24d2222da1b..ddb4d3b24f5 100644 --- a/sway-error/src/handler.rs +++ b/sway-error/src/handler.rs @@ -1,5 +1,4 @@ use crate::{error::CompileError, warning::CompileWarning}; - use core::cell::RefCell; /// A handler with which you can emit diagnostics. @@ -127,7 +126,7 @@ impl Handler { } /// Proof that an error was emitted through a `Handler`. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash)] pub struct ErrorEmitted { _priv: (), } diff --git a/sway-types/src/ident.rs b/sway-types/src/ident.rs index f4aa577bc5d..9d5f7c40753 100644 --- a/sway-types/src/ident.rs +++ b/sway-types/src/ident.rs @@ -1,7 +1,5 @@ -use serde::Serialize; - use crate::{span::Span, Spanned}; - +use serde::{Serialize, Deserialize}; use std::{ cmp::{Ord, Ordering}, fmt, @@ -13,7 +11,7 @@ pub trait Named { fn name(&self) -> &BaseIdent; } -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub struct BaseIdent { name_override_opt: Option>, span: Span, @@ -93,17 +91,17 @@ impl BaseIdent { /// often be different. pub type Ident = BaseIdent; -impl Serialize for Ident { - // Serialize an `Ident` struct with two fields: `to_string` and `span`. - fn serialize(&self, serializer: S) -> Result { - use serde::ser::SerializeStruct; - - let mut state = serializer.serialize_struct("Ident", 2)?; - state.serialize_field("to_string", &self.to_string())?; - state.serialize_field("span", &self.span)?; - state.end() - } -} +// impl Serialize for Ident { +// // Serialize an `Ident` struct with two fields: `to_string` and `span`. +// fn serialize(&self, serializer: S) -> Result { +// use serde::ser::SerializeStruct; + +// let mut state = serializer.serialize_struct("Ident", 2)?; +// state.serialize_field("to_string", &self.to_string())?; +// state.serialize_field("span", &self.span)?; +// state.end() +// } +// } impl Hash for Ident { fn hash(&self, state: &mut H) { diff --git a/sway-types/src/span.rs b/sway-types/src/span.rs index c757fb523da..ff0d099c4da 100644 --- a/sway-types/src/span.rs +++ b/sway-types/src/span.rs @@ -1,12 +1,11 @@ -use std::fmt::Display; - -use serde::{Deserialize, Serialize}; - use crate::SourceId; - -use { - lazy_static::lazy_static, - std::{cmp, fmt, hash::Hash, sync::Arc}, +use lazy_static::lazy_static; +use serde::{Deserialize, Serialize}; +use std::{ + cmp, + fmt::{self, Display}, + hash::Hash, + sync::Arc, }; lazy_static! { @@ -43,7 +42,7 @@ impl<'a> Position<'a> { } /// Represents a span of the source code in a specific file. -#[derive(Clone, Ord, PartialOrd)] +#[derive(Clone, Ord, PartialOrd, Serialize, Deserialize)] pub struct Span { // The original source code. src: Arc, @@ -71,17 +70,17 @@ impl PartialEq for Span { impl Eq for Span {} -impl Serialize for Span { - // Serialize a tuple two fields: `start` and `end`. - fn serialize(&self, serializer: S) -> Result { - use serde::ser::SerializeTuple; - - let mut state = serializer.serialize_tuple(2)?; - state.serialize_element(&self.start)?; - state.serialize_element(&self.end)?; - state.end() - } -} +// impl Serialize for Span { +// // Serialize a tuple two fields: `start` and `end`. +// fn serialize(&self, serializer: S) -> Result { +// use serde::ser::SerializeTuple; + +// let mut state = serializer.serialize_tuple(2)?; +// state.serialize_element(&self.start)?; +// state.serialize_element(&self.end)?; +// state.end() +// } +// } impl From for std::ops::Range { fn from(value: Span) -> Self { diff --git a/sway-types/src/u256.rs b/sway-types/src/u256.rs index e116308f169..310f10bd5b9 100644 --- a/sway-types/src/u256.rs +++ b/sway-types/src/u256.rs @@ -1,10 +1,10 @@ -use std::ops::{Not, Shl, Shr}; - use num_bigint::{BigUint, ParseBigIntError, TryFromBigIntError}; use num_traits::Zero; +use serde::{Serialize, Deserialize}; +use std::ops::{Not, Shl, Shr}; use thiserror::Error; -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize)] pub struct U256(BigUint); impl U256 { From 60ffa117b2bf27b513dc4b58689841c400fc69a8 Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Fri, 4 Oct 2024 11:27:14 +1000 Subject: [PATCH 2/4] Remove commented-out code for serialization in Ident and Span structs. --- sway-types/src/ident.rs | 12 ------------ sway-types/src/span.rs | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/sway-types/src/ident.rs b/sway-types/src/ident.rs index 9d5f7c40753..886967cae8a 100644 --- a/sway-types/src/ident.rs +++ b/sway-types/src/ident.rs @@ -91,18 +91,6 @@ impl BaseIdent { /// often be different. pub type Ident = BaseIdent; -// impl Serialize for Ident { -// // Serialize an `Ident` struct with two fields: `to_string` and `span`. -// fn serialize(&self, serializer: S) -> Result { -// use serde::ser::SerializeStruct; - -// let mut state = serializer.serialize_struct("Ident", 2)?; -// state.serialize_field("to_string", &self.to_string())?; -// state.serialize_field("span", &self.span)?; -// state.end() -// } -// } - impl Hash for Ident { fn hash(&self, state: &mut H) { self.as_str().hash(state); diff --git a/sway-types/src/span.rs b/sway-types/src/span.rs index ff0d099c4da..99536c080ee 100644 --- a/sway-types/src/span.rs +++ b/sway-types/src/span.rs @@ -70,18 +70,6 @@ impl PartialEq for Span { impl Eq for Span {} -// impl Serialize for Span { -// // Serialize a tuple two fields: `start` and `end`. -// fn serialize(&self, serializer: S) -> Result { -// use serde::ser::SerializeTuple; - -// let mut state = serializer.serialize_tuple(2)?; -// state.serialize_element(&self.start)?; -// state.serialize_element(&self.end)?; -// state.end() -// } -// } - impl From for std::ops::Range { fn from(value: Span) -> Self { Self { From f30b692c767205452343f3b28728b66de631e939 Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Fri, 4 Oct 2024 11:36:36 +1000 Subject: [PATCH 3/4] fmt --- sway-ast/src/intrinsics.rs | 2 +- sway-ast/src/priv_prelude.rs | 2 +- sway-core/src/decl_engine/id.rs | 7 +++---- sway-core/src/decl_engine/interface_decl_id.rs | 4 ++-- sway-core/src/decl_engine/ref.rs | 3 +-- sway-core/src/language/asm.rs | 2 +- sway-core/src/language/call_path.rs | 2 +- sway-core/src/language/lazy_op.rs | 2 +- sway-core/src/language/literal.rs | 4 +--- sway-core/src/language/parsed/declaration/trait.rs | 4 ++-- sway-core/src/language/parsed/expression/mod.rs | 2 +- sway-core/src/language/parsed/use_statement.rs | 2 +- sway-core/src/language/purity.rs | 2 +- sway-core/src/language/ty/ast_node.rs | 3 +-- sway-core/src/language/ty/code_block.rs | 2 +- sway-core/src/language/ty/declaration/abi.rs | 5 ++--- sway-core/src/language/ty/declaration/configurable.rs | 2 +- sway-core/src/language/ty/declaration/constant.rs | 2 +- sway-core/src/language/ty/declaration/declaration.rs | 4 +--- sway-core/src/language/ty/declaration/enum.rs | 1 - sway-core/src/language/ty/declaration/function.rs | 4 ++++ sway-core/src/language/ty/declaration/impl_trait.rs | 5 ++--- sway-core/src/language/ty/declaration/storage.rs | 3 +-- sway-core/src/language/ty/declaration/struct.rs | 1 - sway-core/src/language/ty/declaration/trait.rs | 3 +-- sway-core/src/language/ty/declaration/trait_type.rs | 8 +++----- sway-core/src/language/ty/declaration/type_alias.rs | 5 ++--- sway-core/src/language/ty/declaration/variable.rs | 2 +- sway-core/src/language/ty/expression/asm.rs | 3 +-- sway-core/src/language/ty/expression/contract.rs | 2 +- sway-core/src/language/ty/expression/expression.rs | 4 +--- .../src/language/ty/expression/expression_variant.rs | 3 +-- .../src/language/ty/expression/intrinsic_function.rs | 2 +- sway-core/src/language/ty/expression/reassignment.rs | 3 +-- sway-core/src/language/ty/expression/scrutinee.rs | 2 +- sway-core/src/language/ty/expression/storage.rs | 5 ++--- sway-core/src/language/ty/expression/struct_exp_field.rs | 4 +--- .../src/language/ty/side_effect/include_statement.rs | 2 +- sway-core/src/language/ty/side_effect/side_effect.rs | 2 +- sway-core/src/language/ty/side_effect/use_statement.rs | 2 +- sway-core/src/language/ty/variable_mutability.rs | 2 +- sway-core/src/language/visibility.rs | 2 +- sway-core/src/transform/attribute.rs | 2 +- sway-core/src/type_system/ast_elements/binding.rs | 4 +--- .../src/type_system/ast_elements/trait_constraint.rs | 3 +-- sway-core/src/type_system/ast_elements/type_argument.rs | 2 +- sway-core/src/type_system/ast_elements/type_parameter.rs | 2 +- sway-core/src/type_system/info.rs | 3 +-- sway-types/src/ident.rs | 2 +- sway-types/src/u256.rs | 2 +- 50 files changed, 61 insertions(+), 85 deletions(-) diff --git a/sway-ast/src/intrinsics.rs b/sway-ast/src/intrinsics.rs index c1151493395..56091c57307 100644 --- a/sway-ast/src/intrinsics.rs +++ b/sway-ast/src/intrinsics.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Eq, PartialEq, Debug, Clone, Hash, Serialize, Deserialize)] diff --git a/sway-ast/src/priv_prelude.rs b/sway-ast/src/priv_prelude.rs index 0e8540b71f9..9da93d80994 100644 --- a/sway-ast/src/priv_prelude.rs +++ b/sway-ast/src/priv_prelude.rs @@ -35,7 +35,7 @@ pub use { }, extension_trait::extension_trait, num_bigint::BigUint, - serde::{Serialize, Deserialize}, + serde::{Deserialize, Serialize}, sway_types::{ ast::{Delimiter, PunctKind}, Ident, Span, Spanned, diff --git a/sway-core/src/decl_engine/id.rs b/sway-core/src/decl_engine/id.rs index b2f3c4b12a6..597b716f1c1 100644 --- a/sway-core/src/decl_engine/id.rs +++ b/sway-core/src/decl_engine/id.rs @@ -2,12 +2,12 @@ use crate::{ decl_engine::*, engine_threading::*, language::ty::{ - TyEnumDecl, TyFunctionDecl, TyImplSelfOrTrait, TyStructDecl, TyTraitDecl, TyTraitFn, - TyTypeAliasDecl, TyDeclParsedType, TyTraitType, + TyDeclParsedType, TyEnumDecl, TyFunctionDecl, TyImplSelfOrTrait, TyStructDecl, TyTraitDecl, + TyTraitFn, TyTraitType, TyTypeAliasDecl, }, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ collections::hash_map::DefaultHasher, fmt, @@ -16,7 +16,6 @@ use std::{ }; use sway_types::{Named, Spanned}; - pub type DeclIdIndexType = usize; /// An ID used to refer to an item in the [DeclEngine](super::decl_engine::DeclEngine) diff --git a/sway-core/src/decl_engine/interface_decl_id.rs b/sway-core/src/decl_engine/interface_decl_id.rs index 94d6e0b25ff..cba36cfd429 100644 --- a/sway-core/src/decl_engine/interface_decl_id.rs +++ b/sway-core/src/decl_engine/interface_decl_id.rs @@ -1,3 +1,4 @@ +use super::{parsed_engine::ParsedDeclEngineGet, parsed_id::ParsedDeclId}; use crate::{ decl_engine::*, engine_threading::{EqWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext}, @@ -6,8 +7,7 @@ use crate::{ ty, }, }; -use super::{parsed_engine::ParsedDeclEngineGet, parsed_id::ParsedDeclId}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Debug, Eq, PartialEq, Hash, Clone)] pub enum ParsedInterfaceDeclId { diff --git a/sway-core/src/decl_engine/ref.rs b/sway-core/src/decl_engine/ref.rs index 455a8842f31..4fb8f1bb87f 100644 --- a/sway-core/src/decl_engine/ref.rs +++ b/sway-core/src/decl_engine/ref.rs @@ -30,12 +30,11 @@ use crate::{ semantic_analysis::TypeCheckContext, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::{Ident, Named, Span, Spanned}; - pub type DeclRefFunction = DeclRef>; pub type DeclRefTrait = DeclRef>; pub type DeclRefTraitFn = DeclRef>; diff --git a/sway-core/src/language/asm.rs b/sway-core/src/language/asm.rs index 3ea81b6c0fd..409e343eef6 100644 --- a/sway-core/src/language/asm.rs +++ b/sway-core/src/language/asm.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_types::{BaseIdent, Ident, Span}; diff --git a/sway-core/src/language/call_path.rs b/sway-core/src/language/call_path.rs index fb4d70e633a..4ef90706af1 100644 --- a/sway-core/src/language/call_path.rs +++ b/sway-core/src/language/call_path.rs @@ -6,7 +6,7 @@ use crate::{ parsed::QualifiedPathType, Engines, Ident, Namespace, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, fmt, diff --git a/sway-core/src/language/lazy_op.rs b/sway-core/src/language/lazy_op.rs index e175dd6d96a..abcb6149d26 100644 --- a/sway-core/src/language/lazy_op.rs +++ b/sway-core/src/language/lazy_op.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum LazyOp { diff --git a/sway-core/src/language/literal.rs b/sway-core/src/language/literal.rs index 47c9784ca1f..df0bc8735fb 100644 --- a/sway-core/src/language/literal.rs +++ b/sway-core/src/language/literal.rs @@ -1,5 +1,5 @@ use crate::{type_system::*, Engines}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ fmt, hash::{Hash, Hasher}, @@ -8,8 +8,6 @@ use std::{ use sway_error::error::CompileError; use sway_types::{integer_bits::IntegerBits, span, u256::U256}; - - #[derive(Debug, Clone, Eq, Serialize, Deserialize)] pub enum Literal { U8(u8), diff --git a/sway-core/src/language/parsed/declaration/trait.rs b/sway-core/src/language/parsed/declaration/trait.rs index 163df3c1ef2..89bff7b4e94 100644 --- a/sway-core/src/language/parsed/declaration/trait.rs +++ b/sway-core/src/language/parsed/declaration/trait.rs @@ -1,3 +1,4 @@ +use super::{ConstantDeclaration, FunctionDeclaration, FunctionParameter}; use crate::{ decl_engine::{parsed_id::ParsedDeclId, DeclRefTrait}, engine_threading::*, @@ -5,8 +6,7 @@ use crate::{ transform, type_system::*, }; -use super::{ConstantDeclaration, FunctionDeclaration, FunctionParameter}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_error::handler::ErrorEmitted; use sway_types::{ident::Ident, span::Span, Named, Spanned}; diff --git a/sway-core/src/language/parsed/expression/mod.rs b/sway-core/src/language/parsed/expression/mod.rs index 73ae0d4f7f6..24ebc5eb271 100644 --- a/sway-core/src/language/parsed/expression/mod.rs +++ b/sway-core/src/language/parsed/expression/mod.rs @@ -8,7 +8,7 @@ use crate::{ type_system::TypeBinding, Engines, TypeArgument, TypeId, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{cmp::Ordering, fmt, hash::Hasher}; use sway_error::handler::ErrorEmitted; use sway_types::{ident::Ident, Span, Spanned}; diff --git a/sway-core/src/language/parsed/use_statement.rs b/sway-core/src/language/parsed/use_statement.rs index 5443da84d1e..106fa21e04a 100644 --- a/sway-core/src/language/parsed/use_statement.rs +++ b/sway-core/src/language/parsed/use_statement.rs @@ -1,5 +1,5 @@ use crate::{language::Visibility, parsed::Span}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use sway_types::ident::Ident; #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/sway-core/src/language/purity.rs b/sway-core/src/language/purity.rs index d223faaa18e..46961a8d0df 100644 --- a/sway-core/src/language/purity.rs +++ b/sway-core/src/language/purity.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; /// The purity of a function is related to its access of contract storage. If a function accesses /// or could potentially access contract storage, it is [Purity::Impure]. If a function does not utilize any diff --git a/sway-core/src/language/ty/ast_node.rs b/sway-core/src/language/ty/ast_node.rs index 684fcfbf7ce..34dcdf95572 100644 --- a/sway-core/src/language/ty/ast_node.rs +++ b/sway-core/src/language/ty/ast_node.rs @@ -10,7 +10,7 @@ use crate::{ type_system::*, types::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ fmt::{self, Debug}, hash::{Hash, Hasher}, @@ -18,7 +18,6 @@ use std::{ use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::{Ident, Span}; - pub trait GetDeclIdent { fn get_decl_ident(&self, engines: &Engines) -> Option; } diff --git a/sway-core/src/language/ty/code_block.rs b/sway-core/src/language/ty/code_block.rs index 2e881639f4f..77a841ff4bc 100644 --- a/sway-core/src/language/ty/code_block.rs +++ b/sway-core/src/language/ty/code_block.rs @@ -2,7 +2,7 @@ use crate::{ decl_engine::*, engine_threading::*, language::ty::*, semantic_analysis::TypeCheckContext, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::Hasher; use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::Span; diff --git a/sway-core/src/language/ty/declaration/abi.rs b/sway-core/src/language/ty/declaration/abi.rs index 9623c62a036..e4d5aa54223 100644 --- a/sway-core/src/language/ty/declaration/abi.rs +++ b/sway-core/src/language/ty/declaration/abi.rs @@ -1,15 +1,14 @@ +use super::{TyDeclParsedType, TyTraitInterfaceItem, TyTraitItem}; use crate::{ engine_threading::*, language::parsed::{self, AbiDeclaration}, transform, type_system::*, }; -use super::{TyDeclParsedType, TyTraitInterfaceItem, TyTraitItem}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_types::{Ident, Named, Span, Spanned}; - /// A [TyAbiDecl] contains the type-checked version of the parse tree's /// `AbiDeclaration`. #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/sway-core/src/language/ty/declaration/configurable.rs b/sway-core/src/language/ty/declaration/configurable.rs index a4a82c01500..3de69ed1425 100644 --- a/sway-core/src/language/ty/declaration/configurable.rs +++ b/sway-core/src/language/ty/declaration/configurable.rs @@ -7,7 +7,7 @@ use crate::{ transform, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ fmt, hash::{Hash, Hasher}, diff --git a/sway-core/src/language/ty/declaration/constant.rs b/sway-core/src/language/ty/declaration/constant.rs index 875045a1f0a..35b675e6ace 100644 --- a/sway-core/src/language/ty/declaration/constant.rs +++ b/sway-core/src/language/ty/declaration/constant.rs @@ -7,7 +7,7 @@ use crate::{ transform, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ fmt, hash::{Hash, Hasher}, diff --git a/sway-core/src/language/ty/declaration/declaration.rs b/sway-core/src/language/ty/declaration/declaration.rs index c0905d8f779..9ccf367b7fa 100644 --- a/sway-core/src/language/ty/declaration/declaration.rs +++ b/sway-core/src/language/ty/declaration/declaration.rs @@ -5,7 +5,7 @@ use crate::{ type_system::*, types::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ fmt, hash::{Hash, Hasher}, @@ -17,8 +17,6 @@ use sway_error::{ }; use sway_types::{Ident, Named, Span, Spanned}; - - #[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyDecl { VariableDecl(Box), diff --git a/sway-core/src/language/ty/declaration/enum.rs b/sway-core/src/language/ty/declaration/enum.rs index f2931710175..d308d447ee7 100644 --- a/sway-core/src/language/ty/declaration/enum.rs +++ b/sway-core/src/language/ty/declaration/enum.rs @@ -17,7 +17,6 @@ use sway_error::{ }; use sway_types::{Ident, Named, Span, Spanned}; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyEnumDecl { pub call_path: CallPath, diff --git a/sway-core/src/language/ty/declaration/function.rs b/sway-core/src/language/ty/declaration/function.rs index 41f63bf7938..9a72037bcb6 100644 --- a/sway-core/src/language/ty/declaration/function.rs +++ b/sway-core/src/language/ty/declaration/function.rs @@ -1,5 +1,8 @@ use crate::{ + decl_engine::*, + engine_threading::*, has_changes, + language::{parsed, ty::*, Inline, Purity, Visibility}, language::{ parsed::{FunctionDeclaration, FunctionDeclarationKind}, CallPath, @@ -10,6 +13,7 @@ use crate::{ language::{parsed, ty::*, Inline, Purity, Visibility}, semantic_analysis::TypeCheckContext, transform, + transform::AttributeKind, type_system::*, types::*, }; diff --git a/sway-core/src/language/ty/declaration/impl_trait.rs b/sway-core/src/language/ty/declaration/impl_trait.rs index 8deef675be5..6125eeb9569 100644 --- a/sway-core/src/language/ty/declaration/impl_trait.rs +++ b/sway-core/src/language/ty/declaration/impl_trait.rs @@ -1,3 +1,4 @@ +use super::{TyDeclParsedType, TyTraitItem}; use crate::{ decl_engine::DeclRefMixedInterface, engine_threading::*, @@ -5,12 +6,10 @@ use crate::{ language::{parsed::ImplSelfOrTrait, CallPath}, type_system::*, }; -use super::{TyDeclParsedType, TyTraitItem}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_types::{Ident, Named, Span, Spanned}; - pub type TyImplItem = TyTraitItem; // impl Trait for Type diff --git a/sway-core/src/language/ty/declaration/storage.rs b/sway-core/src/language/ty/declaration/storage.rs index c772d9451a0..86ba2976fca 100644 --- a/sway-core/src/language/ty/declaration/storage.rs +++ b/sway-core/src/language/ty/declaration/storage.rs @@ -5,7 +5,7 @@ use crate::{ type_system::*, Namespace, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_error::{ error::{CompileError, StructFieldUsageContext}, @@ -13,7 +13,6 @@ use sway_error::{ }; use sway_types::{Ident, Named, Span, Spanned}; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStorageDecl { pub fields: Vec, diff --git a/sway-core/src/language/ty/declaration/struct.rs b/sway-core/src/language/ty/declaration/struct.rs index cd3d726cf7f..cf0e94415db 100644 --- a/sway-core/src/language/ty/declaration/struct.rs +++ b/sway-core/src/language/ty/declaration/struct.rs @@ -15,7 +15,6 @@ use std::{ }; use sway_types::{Ident, Named, Span, Spanned}; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStructDecl { pub call_path: CallPath, diff --git a/sway-core/src/language/ty/declaration/trait.rs b/sway-core/src/language/ty/declaration/trait.rs index ca3f4d65311..e3adc2e6d65 100644 --- a/sway-core/src/language/ty/declaration/trait.rs +++ b/sway-core/src/language/ty/declaration/trait.rs @@ -7,8 +7,8 @@ use crate::{ has_changes, language::{ parsed::{self, TraitDeclaration}, - CallPath, Visibility, ty::{TyDecl, TyDeclParsedType}, + CallPath, Visibility, }, semantic_analysis::{ TypeCheckAnalysis, TypeCheckAnalysisContext, TypeCheckFinalization, @@ -26,7 +26,6 @@ use std::{ use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::{Ident, Named, Span, Spanned}; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyTraitDecl { pub name: Ident, diff --git a/sway-core/src/language/ty/declaration/trait_type.rs b/sway-core/src/language/ty/declaration/trait_type.rs index 4416731dba2..9c9cee3e5eb 100644 --- a/sway-core/src/language/ty/declaration/trait_type.rs +++ b/sway-core/src/language/ty/declaration/trait_type.rs @@ -1,16 +1,14 @@ use crate::{ - language::ty::TyDeclParsedType, - engine_threading::*, has_changes, language::parsed::TraitTypeDeclaration, transform, - type_system::*, + engine_threading::*, has_changes, language::parsed::TraitTypeDeclaration, + language::ty::TyDeclParsedType, transform, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ fmt, hash::{Hash, Hasher}, }; use sway_types::{Ident, Named, Span, Spanned}; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyTraitType { pub name: Ident, diff --git a/sway-core/src/language/ty/declaration/type_alias.rs b/sway-core/src/language/ty/declaration/type_alias.rs index 5c3eb072d55..8029addd328 100644 --- a/sway-core/src/language/ty/declaration/type_alias.rs +++ b/sway-core/src/language/ty/declaration/type_alias.rs @@ -1,14 +1,13 @@ use crate::{ engine_threading::*, - language::{parsed::TypeAliasDeclaration, CallPath, Visibility, ty::TyDeclParsedType}, + language::{parsed::TypeAliasDeclaration, ty::TyDeclParsedType, CallPath, Visibility}, transform, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_types::{Ident, Named, Span, Spanned}; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyTypeAliasDecl { pub name: Ident, diff --git a/sway-core/src/language/ty/declaration/variable.rs b/sway-core/src/language/ty/declaration/variable.rs index 4059f10714a..5337651b8e5 100644 --- a/sway-core/src/language/ty/declaration/variable.rs +++ b/sway-core/src/language/ty/declaration/variable.rs @@ -3,7 +3,7 @@ use crate::{ language::{parsed::VariableDeclaration, ty::*}, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_types::{Ident, Named, Spanned}; diff --git a/sway-core/src/language/ty/expression/asm.rs b/sway-core/src/language/ty/expression/asm.rs index 71068b128b7..6e4ad95af3c 100644 --- a/sway-core/src/language/ty/expression/asm.rs +++ b/sway-core/src/language/ty/expression/asm.rs @@ -1,9 +1,8 @@ use crate::{engine_threading::*, language::ty::*, type_system::*}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_types::Ident; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyAsmRegisterDeclaration { pub initializer: Option, diff --git a/sway-core/src/language/ty/expression/contract.rs b/sway-core/src/language/ty/expression/contract.rs index 4c63ff03869..926aba9923c 100644 --- a/sway-core/src/language/ty/expression/contract.rs +++ b/sway-core/src/language/ty/expression/contract.rs @@ -1,5 +1,5 @@ use crate::language::ty::*; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct ContractCallParams { diff --git a/sway-core/src/language/ty/expression/expression.rs b/sway-core/src/language/ty/expression/expression.rs index 850ab65d057..83d66aa6f62 100644 --- a/sway-core/src/language/ty/expression/expression.rs +++ b/sway-core/src/language/ty/expression/expression.rs @@ -11,7 +11,7 @@ use crate::{ type_system::*, types::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{fmt, hash::Hasher}; use sway_error::{ error::CompileError, @@ -21,8 +21,6 @@ use sway_error::{ }; use sway_types::{Span, Spanned}; - - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyExpression { pub expression: TyExpressionVariant, diff --git a/sway-core/src/language/ty/expression/expression_variant.rs b/sway-core/src/language/ty/expression/expression_variant.rs index 14082595759..ea221466273 100644 --- a/sway-core/src/language/ty/expression/expression_variant.rs +++ b/sway-core/src/language/ty/expression/expression_variant.rs @@ -11,7 +11,7 @@ use crate::{ type_system::*, }; use indexmap::IndexMap; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ collections::VecDeque, fmt::{self, Write}, @@ -20,7 +20,6 @@ use std::{ use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::{Ident, Named, Span, Spanned}; - #[derive(Clone, Debug, Serialize, Deserialize)] pub enum TyExpressionVariant { Literal(Literal), diff --git a/sway-core/src/language/ty/expression/intrinsic_function.rs b/sway-core/src/language/ty/expression/intrinsic_function.rs index 488c45fa788..d7646ecf64c 100644 --- a/sway-core/src/language/ty/expression/intrinsic_function.rs +++ b/sway-core/src/language/ty/expression/intrinsic_function.rs @@ -3,7 +3,7 @@ use crate::{ type_system::*, types::*, }; use itertools::Itertools; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ fmt, hash::{Hash, Hasher}, diff --git a/sway-core/src/language/ty/expression/reassignment.rs b/sway-core/src/language/ty/expression/reassignment.rs index a6e08a4b69d..698af692dda 100644 --- a/sway-core/src/language/ty/expression/reassignment.rs +++ b/sway-core/src/language/ty/expression/reassignment.rs @@ -9,7 +9,7 @@ use crate::{ }, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ borrow::Cow, hash::{Hash, Hasher}, @@ -17,7 +17,6 @@ use std::{ use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::{Ident, Span, Spanned}; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyReassignment { pub lhs: TyReassignmentTarget, diff --git a/sway-core/src/language/ty/expression/scrutinee.rs b/sway-core/src/language/ty/expression/scrutinee.rs index 3f0c4d31d98..78fde994732 100644 --- a/sway-core/src/language/ty/expression/scrutinee.rs +++ b/sway-core/src/language/ty/expression/scrutinee.rs @@ -3,7 +3,7 @@ use crate::{ language::{ty::*, *}, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use sway_types::{Ident, Span}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/sway-core/src/language/ty/expression/storage.rs b/sway-core/src/language/ty/expression/storage.rs index 01eaf7ad0c2..adaa6f28730 100644 --- a/sway-core/src/language/ty/expression/storage.rs +++ b/sway-core/src/language/ty/expression/storage.rs @@ -1,10 +1,9 @@ -use crate::{engine_threading::*, type_system::TypeId}; use super::TyExpression; -use serde::{Serialize, Deserialize}; +use crate::{engine_threading::*, type_system::TypeId}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_types::{Ident, Span, Spanned}; - /// Describes the full storage access including all the subfields #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStorageAccess { diff --git a/sway-core/src/language/ty/expression/struct_exp_field.rs b/sway-core/src/language/ty/expression/struct_exp_field.rs index 246158e5425..7262f38a901 100644 --- a/sway-core/src/language/ty/expression/struct_exp_field.rs +++ b/sway-core/src/language/ty/expression/struct_exp_field.rs @@ -5,13 +5,11 @@ use crate::{ semantic_analysis::{TypeCheckContext, TypeCheckFinalization, TypeCheckFinalizationContext}, type_system::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::Ident; - - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TyStructExpressionField { pub name: Ident, diff --git a/sway-core/src/language/ty/side_effect/include_statement.rs b/sway-core/src/language/ty/side_effect/include_statement.rs index fc34f611d86..666e5b63a58 100644 --- a/sway-core/src/language/ty/side_effect/include_statement.rs +++ b/sway-core/src/language/ty/side_effect/include_statement.rs @@ -1,5 +1,5 @@ use crate::language::Visibility; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use sway_types::{ident::Ident, Span, Spanned}; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/sway-core/src/language/ty/side_effect/side_effect.rs b/sway-core/src/language/ty/side_effect/side_effect.rs index aaf7a39b90b..9e8e672c5fa 100644 --- a/sway-core/src/language/ty/side_effect/side_effect.rs +++ b/sway-core/src/language/ty/side_effect/side_effect.rs @@ -1,5 +1,5 @@ use super::{TyIncludeStatement, TyUseStatement}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct TySideEffect { diff --git a/sway-core/src/language/ty/side_effect/use_statement.rs b/sway-core/src/language/ty/side_effect/use_statement.rs index 590faf9e38b..476a58907ef 100644 --- a/sway-core/src/language/ty/side_effect/use_statement.rs +++ b/sway-core/src/language/ty/side_effect/use_statement.rs @@ -1,5 +1,5 @@ use crate::language::parsed; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use sway_types::{ident::Ident, Span, Spanned}; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/sway-core/src/language/ty/variable_mutability.rs b/sway-core/src/language/ty/variable_mutability.rs index b81bcaf055c..b1831af1279 100644 --- a/sway-core/src/language/ty/variable_mutability.rs +++ b/sway-core/src/language/ty/variable_mutability.rs @@ -1,5 +1,5 @@ use crate::language::Visibility; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default, Serialize, Deserialize)] pub enum VariableMutability { diff --git a/sway-core/src/language/visibility.rs b/sway-core/src/language/visibility.rs index 64f490342e7..e6b19912e7e 100644 --- a/sway-core/src/language/visibility.rs +++ b/sway-core/src/language/visibility.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Visibility { diff --git a/sway-core/src/transform/attribute.rs b/sway-core/src/transform/attribute.rs index bd2041ee6a4..d44538befa2 100644 --- a/sway-core/src/transform/attribute.rs +++ b/sway-core/src/transform/attribute.rs @@ -21,7 +21,7 @@ //! #[foo(bar, bar)] use indexmap::IndexMap; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{hash::Hash, sync::Arc}; use sway_ast::Literal; use sway_types::{ diff --git a/sway-core/src/type_system/ast_elements/binding.rs b/sway-core/src/type_system/ast_elements/binding.rs index 9803aef7632..0b5884be66f 100644 --- a/sway-core/src/type_system/ast_elements/binding.rs +++ b/sway-core/src/type_system/ast_elements/binding.rs @@ -14,13 +14,11 @@ use crate::{ type_system::priv_prelude::*, EnforceTypeArguments, Ident, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use sway_ast::Intrinsic; use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::{Span, Spanned}; - - /// A `TypeBinding` is the result of using turbofish to bind types to /// generic parameters. /// diff --git a/sway-core/src/type_system/ast_elements/trait_constraint.rs b/sway-core/src/type_system/ast_elements/trait_constraint.rs index 7c5e75a927d..53146ad5f36 100644 --- a/sway-core/src/type_system/ast_elements/trait_constraint.rs +++ b/sway-core/src/type_system/ast_elements/trait_constraint.rs @@ -9,7 +9,7 @@ use crate::{ types::{CollectTypesMetadata, CollectTypesMetadataContext, TypeMetadata}, EnforceTypeArguments, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, fmt, @@ -21,7 +21,6 @@ use sway_error::{ }; use sway_types::Spanned; - #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TraitConstraint { pub trait_name: CallPath, diff --git a/sway-core/src/type_system/ast_elements/type_argument.rs b/sway-core/src/type_system/ast_elements/type_argument.rs index dbfafa80756..070598baec5 100644 --- a/sway-core/src/type_system/ast_elements/type_argument.rs +++ b/sway-core/src/type_system/ast_elements/type_argument.rs @@ -1,5 +1,5 @@ use crate::{engine_threading::*, language::CallPathTree, type_system::priv_prelude::*}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{cmp::Ordering, fmt, hash::Hasher}; use sway_types::{Span, Spanned}; diff --git a/sway-core/src/type_system/ast_elements/type_parameter.rs b/sway-core/src/type_system/ast_elements/type_parameter.rs index 24cfaf005b6..777bb6582ae 100644 --- a/sway-core/src/type_system/ast_elements/type_parameter.rs +++ b/sway-core/src/type_system/ast_elements/type_parameter.rs @@ -7,7 +7,7 @@ use crate::{ semantic_analysis::{GenericShadowingMode, TypeCheckContext}, type_system::priv_prelude::*, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, collections::BTreeMap, diff --git a/sway-core/src/type_system/info.rs b/sway-core/src/type_system/info.rs index df5b4714c97..4ad537f3122 100644 --- a/sway-core/src/type_system/info.rs +++ b/sway-core/src/type_system/info.rs @@ -12,7 +12,7 @@ use crate::{ type_system::priv_prelude::*, Ident, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, fmt, @@ -25,7 +25,6 @@ use sway_error::{ }; use sway_types::{integer_bits::IntegerBits, span::Span, SourceId}; - #[derive(Debug, Clone, Hash, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] pub enum AbiName { Deferred, diff --git a/sway-types/src/ident.rs b/sway-types/src/ident.rs index 886967cae8a..ff1c168e9e6 100644 --- a/sway-types/src/ident.rs +++ b/sway-types/src/ident.rs @@ -1,5 +1,5 @@ use crate::{span::Span, Spanned}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ cmp::{Ord, Ordering}, fmt, diff --git a/sway-types/src/u256.rs b/sway-types/src/u256.rs index 310f10bd5b9..2f42b43b0f3 100644 --- a/sway-types/src/u256.rs +++ b/sway-types/src/u256.rs @@ -1,6 +1,6 @@ use num_bigint::{BigUint, ParseBigIntError, TryFromBigIntError}; use num_traits::Zero; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::ops::{Not, Shl, Shr}; use thiserror::Error; From ead5541b742ca5c1228b45e7e9661d11ebdfd058 Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Tue, 29 Oct 2024 12:47:57 +1100 Subject: [PATCH 4/4] rebase master --- sway-core/src/decl_engine/parsed_id.rs | 14 ++++++++------ sway-core/src/language/ty/declaration/enum.rs | 4 ++-- sway-core/src/language/ty/declaration/function.rs | 9 ++------- sway-core/src/language/ty/declaration/struct.rs | 4 ++-- sway-core/src/language/ty/declaration/trait.rs | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/sway-core/src/decl_engine/parsed_id.rs b/sway-core/src/decl_engine/parsed_id.rs index 7af8ea26c33..1a513a6d5be 100644 --- a/sway-core/src/decl_engine/parsed_id.rs +++ b/sway-core/src/decl_engine/parsed_id.rs @@ -1,12 +1,14 @@ -use crate::{ - Engines, - engine_threading::{EqWithEngines, HashWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext}, -}; use super::{ - DeclUniqueId, parsed_engine::{ParsedDeclEngine, ParsedDeclEngineGet, ParsedDeclEngineIndex}, + DeclUniqueId, +}; +use crate::{ + engine_threading::{ + EqWithEngines, HashWithEngines, PartialEqWithEngines, PartialEqWithEnginesContext, + }, + Engines, }; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ hash::{DefaultHasher, Hasher}, marker::PhantomData, diff --git a/sway-core/src/language/ty/declaration/enum.rs b/sway-core/src/language/ty/declaration/enum.rs index d308d447ee7..126fb4549a5 100644 --- a/sway-core/src/language/ty/declaration/enum.rs +++ b/sway-core/src/language/ty/declaration/enum.rs @@ -1,12 +1,12 @@ use crate::{ engine_threading::*, has_changes, - language::{parsed::EnumDeclaration, CallPath, Visibility, ty::TyDeclParsedType}, + language::{parsed::EnumDeclaration, ty::TyDeclParsedType, CallPath, Visibility}, transform, type_system::*, }; use monomorphization::MonomorphizeHelper; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, hash::{Hash, Hasher}, diff --git a/sway-core/src/language/ty/declaration/function.rs b/sway-core/src/language/ty/declaration/function.rs index 9a72037bcb6..6849ccaa7db 100644 --- a/sway-core/src/language/ty/declaration/function.rs +++ b/sway-core/src/language/ty/declaration/function.rs @@ -7,18 +7,13 @@ use crate::{ parsed::{FunctionDeclaration, FunctionDeclarationKind}, CallPath, }, - transform::AttributeKind, - decl_engine::*, - engine_threading::*, - language::{parsed, ty::*, Inline, Purity, Visibility}, semantic_analysis::TypeCheckContext, - transform, - transform::AttributeKind, + transform::{self, AttributeKind}, type_system::*, types::*, }; use monomorphization::MonomorphizeHelper; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::{ fmt, diff --git a/sway-core/src/language/ty/declaration/struct.rs b/sway-core/src/language/ty/declaration/struct.rs index cf0e94415db..e64281b1ea9 100644 --- a/sway-core/src/language/ty/declaration/struct.rs +++ b/sway-core/src/language/ty/declaration/struct.rs @@ -2,13 +2,13 @@ use crate::{ engine_threading::*, error::module_can_be_changed, has_changes, - language::{parsed::StructDeclaration, CallPath, Visibility, ty::TyDeclParsedType}, + language::{parsed::StructDeclaration, ty::TyDeclParsedType, CallPath, Visibility}, transform, type_system::*, Namespace, }; use monomorphization::MonomorphizeHelper; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, hash::{Hash, Hasher}, diff --git a/sway-core/src/language/ty/declaration/trait.rs b/sway-core/src/language/ty/declaration/trait.rs index e3adc2e6d65..14970814fe3 100644 --- a/sway-core/src/language/ty/declaration/trait.rs +++ b/sway-core/src/language/ty/declaration/trait.rs @@ -18,7 +18,7 @@ use crate::{ type_system::*, }; use monomorphization::MonomorphizeHelper; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::{ fmt, hash::{Hash, Hasher},