Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debug implementation with clippy #5515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bin/starknet-sierra-compile/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Args {

/// Same as `ContractClass` - but ignores `abi` in deserialization.
/// Enables loading old contract classes.
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
pub struct ContractClassIgnoreAbi {
pub sierra_program: Vec<BigUintAsHex>,
pub sierra_program_debug_info: Option<cairo_lang_sierra::debug_info::DebugInfo>,
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/starknet-sierra-upgrade-validate/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn parse_version_id(major_minor_patch: &str) -> anyhow::Result<VersionId> {
}

/// The contract class from db.
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
pub struct ContractClassInfo {
/// The previous compiled class hash.
pub compiled_class_hash: BigUintAsHex,
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-casm/src/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct InstructionRepr {
}

/// An assembled representation of a cairo program.
#[derive(Debug)]
pub struct AssembledCairoProgram {
/// The bytecode of the program.
pub bytecode: Vec<BigInt>,
Expand Down
3 changes: 3 additions & 0 deletions crates/cairo-lang-casm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl State {
}

/// A statement added to the builder.
#[derive(Debug)]
enum Statement {
/// A final instruction, no need for further editing.
Final(Instruction),
Expand All @@ -106,6 +107,7 @@ enum Statement {
}

/// The builder result.
#[derive(Debug)]
pub struct CasmBuildResult<const BRANCH_COUNT: usize> {
/// The actual casm code.
pub instructions: Vec<Instruction>,
Expand All @@ -116,6 +118,7 @@ pub struct CasmBuildResult<const BRANCH_COUNT: usize> {
/// Builder to more easily write casm code without specifically thinking about ap changes and the
/// sizes of opcodes. Wrong usages of it would panic instead of returning a result, as this builder
/// assumes we are in a post validation of parameters stage.
#[derive(Debug)]
pub struct CasmBuilder {
/// The state at a point of jumping into a label, per label.
label_state: UnorderedHashMap<String, State>,
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-casm/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ macro_rules! is_inc_ap {
}

#[allow(dead_code)]
#[derive(Default)]
#[derive(Default, Debug)]
pub struct CasmContext {
pub current_code_offset: usize,
pub current_hints: Vec<Hint>,
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-compiler/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::project::{update_crate_root, update_crate_roots_from_project_config};
SierraGenDatabase,
SyntaxDatabase
)]
#[allow(missing_debug_implementations)]
pub struct RootDatabase {
storage: salsa::Storage<RootDatabase>,
}
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-compiler/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl<'a> DiagnosticCallback for Option<Box<dyn DiagnosticCallback + 'a>> {
}

/// Collects compilation diagnostics and presents them in preconfigured way.
#[allow(missing_debug_implementations)]
pub struct DiagnosticsReporter<'a> {
callback: Option<Box<dyn DiagnosticCallback + 'a>>,
crate_ids: Vec<CrateId>,
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod test;

/// Configuration for the compiler.
#[derive(Default)]
#[allow(missing_debug_implementations)]
pub struct CompilerConfig<'c> {
pub diagnostics_reporter: DiagnosticsReporter<'c>,

Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-debug/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ pub mod helper {
}
}

#[derive(Debug)]
pub struct HelperDebug<T, Db: ?Sized>(PhantomData<T>, PhantomData<Db>);

impl<T: DebugWithDb<Db>, Db: ?Sized> HelperDebug<T, Db> {
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-defs/src/patcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub struct ModifiedNode {
pub children: Option<Vec<RewriteNode>>,
}

#[allow(missing_debug_implementations)]
pub struct PatchBuilder<'a> {
pub db: &'a dyn SyntaxGroup,
code: String,
Expand Down
6 changes: 4 additions & 2 deletions crates/cairo-lang-defs/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl PartialEq for DynGeneratedFileAuxData {
impl Eq for DynGeneratedFileAuxData {}

/// Virtual code file generated by a plugin.
#[derive(Debug)]
pub struct PluginGeneratedFile {
/// Name for the virtual file. Will appear in diagnostics.
pub name: SmolStr,
Expand All @@ -51,7 +52,7 @@ pub struct PluginGeneratedFile {
}

/// Result of plugin code generation.
#[derive(Default)]
#[derive(Default, Debug)]
pub struct PluginResult {
/// Filename, content.
pub code: Option<PluginGeneratedFile>,
Expand All @@ -78,6 +79,7 @@ impl PluginDiagnostic {

/// A structure containing additional info about the current module item on which macro plugin
/// operates.
#[derive(Debug)]
pub struct MacroPluginMetadata<'a> {
/// Config set of a crate to which the current item belongs.
pub cfg_set: &'a CfgSet,
Expand Down Expand Up @@ -114,7 +116,7 @@ pub trait MacroPlugin: std::fmt::Debug + Sync + Send {
}

/// Result of plugin code generation.
#[derive(Default)]
#[derive(Default, Debug)]
pub struct InlinePluginResult {
pub code: Option<PluginGeneratedFile>,
/// Diagnostics.
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-filesystem/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::db::{init_files_group, AsFilesGroupMut, FilesDatabase, FilesGroup};

// Test salsa database.
#[salsa::database(FilesDatabase)]
#[allow(missing_debug_implementations)]
pub struct FilesDatabaseForTesting {
storage: salsa::Storage<FilesDatabaseForTesting>,
}
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-formatter/src/cairo_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl Display for ParsingError {

/// A struct used to indicate that the formatter input should be read from stdin.
/// Implements the [`FormattableInput`] trait.
#[derive(Debug)]
pub struct StdinFmt;

/// A trait for types that can be used as input for the cairo formatter.
Expand Down
2 changes: 2 additions & 0 deletions crates/cairo-lang-formatter/src/formatter_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ impl PendingLineState {
}

/// Represents the break line points before and after a syntax node.
#[derive(Debug)]
pub enum BreakLinePointsPositions {
Leading(BreakLinePointProperties),
Trailing(BreakLinePointProperties),
Expand Down Expand Up @@ -737,6 +738,7 @@ pub trait SyntaxNodeFormat {
fn should_skip_terminal(&self, db: &dyn SyntaxGroup) -> bool;
}

#[allow(missing_debug_implementations)]
pub struct FormatterImpl<'a> {
db: &'a dyn SyntaxGroup,
config: FormatterConfig,
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-language-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ mod vfs;
/// [lib]: crate#running-with-customizations
#[non_exhaustive]
#[derive(Default)]
#[allow(missing_debug_implementations)]
pub struct Tricks {
/// A function that returns a list of additional compiler plugin suites to be loaded in the
/// language server database.
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-lowering/src/borrow_check/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub trait Analyzer<'a> {
}

/// Main analysis type that allows traversing the flow backwards.
#[derive(Debug)]
pub struct BackAnalysis<'a, TAnalyzer: Analyzer<'a>> {
lowered: &'a FlatLowered,
pub analyzer: TAnalyzer,
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-lowering/src/borrow_check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub trait DemandReporter<Var, Aux = ()> {

/// Demanded variables from a certain point in the flow until the end of the function.
/// Needs to be updates in backwards order.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Demand<Var: std::hash::Hash + Eq + Copy, UsePosition, Aux: Clone + Default = ()> {
pub vars: OrderedHashMap<Var, UsePosition>,
pub aux: Aux,
Expand Down
3 changes: 2 additions & 1 deletion crates/cairo-lang-lowering/src/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod analysis;
pub mod demand;

pub type BorrowCheckerDemand = Demand<VariableId, LocationId, PanicState>;
#[allow(missing_debug_implementations)]
pub struct BorrowChecker<'a> {
db: &'a dyn LoweringGroup,
diagnostics: &'a mut LoweringDiagnostics,
Expand All @@ -37,7 +38,7 @@ pub struct BorrowChecker<'a> {

/// A state saved for each position in the back analysis.
/// Used to determine if this flow is guaranteed to end in a panic.
#[derive(Copy, Clone, Default)]
#[derive(Copy, Clone, Default, Debug)]
pub enum PanicState {
EndsWithPanic,
#[default]
Expand Down
5 changes: 3 additions & 2 deletions crates/cairo-lang-lowering/src/destructs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum AddDestructFlowType {
}

/// Context for the destructor call addition phase,
#[allow(missing_debug_implementations)]
pub struct DestructAdder<'a> {
db: &'a dyn LoweringGroup,
lowered: &'a FlatLowered,
Expand Down Expand Up @@ -160,7 +161,7 @@ impl<'a> DemandReporter<VariableId, PanicState> for DestructAdder<'a> {

/// A state saved for each position in the back analysis.
/// Used to determine if a Panic object is guaranteed to exist or be created, an where.
#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
pub enum PanicState {
/// The flow will end with a panic. The locations are all the possible places a Panic object
/// can be created from this flow.
Expand Down Expand Up @@ -189,7 +190,7 @@ impl AuxCombine for PanicState {
}

/// Location where a `Panic` is first available.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum PanicLocation {
/// The `Panic` value is at a variable created by a StructConstruct at `statement_location`.
PanicVar { statement_location: StatementLocation },
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-lowering/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{

/// Holds all the information needed for formatting lowered representations.
/// Acts like a "db" for DebugWithDb.
#[allow(missing_debug_implementations)]
pub struct LoweredFormatter<'db> {
pub db: &'db dyn LoweringGroup,
pub variables: &'db Arena<Variable>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::DependencyType;

/// A node to use in graph-algorithms.
#[derive(Clone)]
#[allow(missing_debug_implementations)]
pub struct ConcreteFunctionWithBodyNode<'a> {
pub function_id: ConcreteFunctionWithBodyId,
pub db: &'a dyn LoweringGroup,
Expand Down Expand Up @@ -44,6 +45,7 @@ impl<'a> ComputeScc for ConcreteFunctionWithBodyNode<'a> {
}

#[derive(Clone)]
#[allow(missing_debug_implementations)]
pub struct ConcreteFunctionWithBodyPostPanicNode<'a> {
pub function_id: ConcreteFunctionWithBodyId,
pub db: &'a dyn LoweringGroup,
Expand Down
3 changes: 3 additions & 0 deletions crates/cairo-lang-lowering/src/inline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ fn should_inline_lowered(
// TODO(ilya): Add Rewriter trait.

/// A rewriter that inlines functions annotated with #[inline(always)].
#[allow(missing_debug_implementations)]
pub struct FunctionInlinerRewriter<'db> {
/// The LoweringContext were we are building the new blocks.
variables: VariableAllocator<'db>,
Expand All @@ -130,6 +131,7 @@ pub struct FunctionInlinerRewriter<'db> {
calling_function_id: ConcreteFunctionWithBodyId,
}

#[derive(Debug)]
pub struct BlockRewriteQueue {
/// A Queue of blocks that require processing, and their id.
block_queue: VecDeque<(FlatBlock, bool)>,
Expand Down Expand Up @@ -161,6 +163,7 @@ impl BlockRewriteQueue {
}

/// Context for mapping ids from `lowered` to a new `FlatLowered` object.
#[allow(missing_debug_implementations)]
pub struct Mapper<'a, 'b> {
variables: &'a mut VariableAllocator<'b>,
lowered: &'a FlatLowered,
Expand Down
3 changes: 2 additions & 1 deletion crates/cairo-lang-lowering/src/lower/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
};

/// FlatBlock builder, describing its current state.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct BlockBuilder {
/// A store for semantic variables, owning their OwnedVariable instances.
pub semantics: SemanticLoweringMapping,
Expand Down Expand Up @@ -309,6 +309,7 @@ pub struct SemanticRemapping {

/// A sealed BlockBuilder, ready to be merged with sibling blocks to end the block.
#[allow(clippy::large_enum_variant)]
#[derive(Debug)]
pub enum SealedBlockBuilder {
/// Block should end by goto callsite. `expr` may be None for blocks that return the unit type.
GotoCallsite { builder: BlockBuilder, expr: Option<VarUsage> },
Expand Down
4 changes: 4 additions & 0 deletions crates/cairo-lang-lowering/src/lower/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::lower::external::{extern_facade_expr, extern_facade_return_tys};
use crate::objects::Variable;
use crate::{FlatLowered, MatchArm, MatchExternInfo, MatchInfo, VarUsage, VariableId};

#[allow(missing_debug_implementations)]
pub struct VariableAllocator<'db> {
pub db: &'db dyn LoweringGroup,
/// Arena of allocated lowered variables.
Expand Down Expand Up @@ -101,6 +102,7 @@ impl<'db> Index<VariableId> for VariableAllocator<'db> {
/// Lowering context for the encapsulating semantic function.
/// Each semantic function may generate multiple lowered functions. This context is common to all
/// the generated lowered functions of an encapsulating semantic function.
#[allow(missing_debug_implementations)]
pub struct EncapsulatingLoweringContext<'db> {
pub db: &'db dyn LoweringGroup,
/// Id for the current function being lowered.
Expand Down Expand Up @@ -136,6 +138,7 @@ impl<'db> EncapsulatingLoweringContext<'db> {
}
}

#[allow(missing_debug_implementations)]
pub struct LoweringContext<'a, 'db> {
pub encapsulating_ctx: Option<&'a mut EncapsulatingLoweringContext<'db>>,
/// Variable allocator.
Expand Down Expand Up @@ -211,6 +214,7 @@ impl<'a, 'db> LoweringContext<'a, 'db> {
}

/// Request for a lowered variable allocation.
#[derive(Debug)]
pub struct VarRequest {
pub ty: semantic::TypeId,
pub location: LocationId,
Expand Down
Loading
Loading