From b6f94b2fa1e27a1080ec32711c7355cceb74ef25 Mon Sep 17 00:00:00 2001 From: pedrocarlo Date: Thu, 9 Oct 2025 17:19:47 -0300 Subject: [PATCH] remove dead code in sim --- simulator/generation/plan.rs | 28 ----------- simulator/generation/property.rs | 81 ++------------------------------ simulator/main.rs | 3 +- simulator/model/mod.rs | 10 ---- simulator/runner/bugbase.rs | 4 ++ simulator/runner/env.rs | 22 --------- simulator/runner/execution.rs | 1 + simulator/runner/memory/io.rs | 6 +-- simulator/runner/mod.rs | 2 +- 9 files changed, 14 insertions(+), 143 deletions(-) diff --git a/simulator/generation/plan.rs b/simulator/generation/plan.rs index c8925cd59..337978569 100644 --- a/simulator/generation/plan.rs +++ b/simulator/generation/plan.rs @@ -63,11 +63,6 @@ impl InteractionPlan { Self { plan, mvcc, len } } - #[inline] - pub fn plan(&self) -> &[Interactions] { - &self.plan - } - /// Length of interactions that are not transaction statements #[inline] pub fn len(&self) -> usize { @@ -629,14 +624,6 @@ impl InteractionsType { } impl Interactions { - pub(crate) fn name(&self) -> Option<&str> { - match &self.interactions { - InteractionsType::Property(property) => Some(property.name()), - InteractionsType::Query(_) => None, - InteractionsType::Fault(_) => None, - } - } - pub(crate) fn interactions(&self) -> Vec { match &self.interactions { InteractionsType::Property(property) => property.interactions(self.connection_index), @@ -726,17 +713,6 @@ pub(crate) struct InteractionStats { pub(crate) rollback_count: u32, } -impl InteractionStats { - pub fn total_writes(&self) -> u32 { - self.insert_count - + self.delete_count - + self.update_count - + self.create_count - + self.create_index_count - + self.drop_count - } -} - impl Display for InteractionStats { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( @@ -758,10 +734,6 @@ impl Display for InteractionStats { type AssertionFunc = dyn Fn(&Vec, &mut SimulatorEnv) -> Result>; -enum AssertionAST { - Pick(), -} - #[derive(Clone)] pub struct Assertion { pub func: Rc, diff --git a/simulator/generation/property.rs b/simulator/generation/property.rs index 47b352406..b67026dae 100644 --- a/simulator/generation/property.rs +++ b/simulator/generation/property.rs @@ -8,7 +8,7 @@ use rand::distr::{Distribution, weighted::WeightedIndex}; use serde::{Deserialize, Serialize}; use sql_generation::{ - generation::{Arbitrary, ArbitraryFrom, GenerationContext, Opts, pick, pick_index}, + generation::{Arbitrary, ArbitraryFrom, GenerationContext, pick, pick_index}, model::{ query::{ Create, Delete, Drop, Insert, Select, @@ -17,7 +17,7 @@ use sql_generation::{ transaction::{Begin, Commit, Rollback}, update::Update, }, - table::{SimValue, Table}, + table::SimValue, }, }; use strum::IntoEnumIterator; @@ -27,40 +27,15 @@ use turso_parser::ast::{self, Distinctness}; use crate::{ common::print_diff, generation::{ - Shadow as _, WeightedDistribution, - plan::InteractionType, - query::{QueryDistribution, possible_queries}, + Shadow as _, WeightedDistribution, plan::InteractionType, query::QueryDistribution, }, model::{Query, QueryCapabilities, QueryDiscriminants}, profiles::query::QueryProfile, - runner::env::{ShadowTablesMut, SimulatorEnv}, + runner::env::SimulatorEnv, }; use super::plan::{Assertion, Interaction, InteractionStats, ResultSet}; -#[derive(Debug, Clone, Copy)] -struct PropertyGenContext<'a> { - tables: &'a Vec, - opts: &'a sql_generation::generation::Opts, -} - -impl<'a> PropertyGenContext<'a> { - #[inline] - fn new(tables: &'a Vec, opts: &'a Opts) -> Self { - Self { tables, opts } - } -} - -impl<'a> GenerationContext for PropertyGenContext<'a> { - fn tables(&self) -> &Vec { - self.tables - } - - fn opts(&self) -> &sql_generation::generation::Opts { - self.opts - } -} - /// Properties are representations of executable specifications /// about the database behavior. #[derive(Debug, Clone, Serialize, Deserialize, strum::EnumDiscriminants)] @@ -1925,11 +1900,6 @@ impl PropertyDiscriminants { } } -pub fn possiple_properties(tables: &[Table]) -> Vec { - let queries = possible_queries(tables); - PropertyDiscriminants::can_generate(queries) -} - pub(super) struct PropertyDistribution<'a> { properties: Vec, weights: WeightedIndex, @@ -1995,49 +1965,6 @@ impl<'a> ArbitraryFrom<&PropertyDistribution<'a>> for Property { } } -fn generate_queries( - rng: &mut R, - ctx: &impl GenerationContext, - amount: usize, - init_queries: &[&Query], - func: F, -) -> Vec -where - F: Fn(&mut R, PropertyGenContext) -> Option, -{ - // Create random queries respecting the constraints - let mut queries = Vec::new(); - - let range = 0..amount; - if !range.is_empty() { - let mut tmp_tables = ctx.tables().clone(); - - for query in init_queries { - tmp_shadow(&mut tmp_tables, query); - } - - for _ in range { - let tmp_ctx = PropertyGenContext::new(&tmp_tables, ctx.opts()); - - let Some(query) = func(rng, tmp_ctx) else { - continue; - }; - - tmp_shadow(&mut tmp_tables, &query); - - queries.push(query); - } - } - queries -} - -fn tmp_shadow(tmp_tables: &mut Vec
, query: &Query) { - let mut tx_tables = None; - let mut tmp_shadow_tables = ShadowTablesMut::new(tmp_tables, &mut tx_tables); - - let _ = query.shadow(&mut tmp_shadow_tables); -} - fn print_row(row: &[SimValue]) -> String { row.iter() .map(|v| match &v.0 { diff --git a/simulator/main.rs b/simulator/main.rs index 15376a13b..6a5d097b8 100644 --- a/simulator/main.rs +++ b/simulator/main.rs @@ -1,4 +1,4 @@ -#![allow(clippy::arc_with_non_send_sync, dead_code)] +#![allow(clippy::arc_with_non_send_sync)] use anyhow::anyhow; use clap::Parser; use generation::plan::{InteractionPlan, InteractionPlanState}; @@ -421,6 +421,7 @@ enum SandboxedResult { error: String, last_execution: Execution, }, + #[expect(dead_code)] FoundBug { error: String, history: ExecutionHistory, diff --git a/simulator/model/mod.rs b/simulator/model/mod.rs index 9e3d29db2..3f8a4ec9d 100644 --- a/simulator/model/mod.rs +++ b/simulator/model/mod.rs @@ -204,16 +204,6 @@ impl QueryDiscriminants { QueryDiscriminants::Drop, QueryDiscriminants::CreateIndex, ]; - - #[inline] - pub fn is_transaction(&self) -> bool { - matches!(self, Self::Begin | Self::Commit | Self::Rollback) - } - - #[inline] - pub fn is_ddl(&self) -> bool { - matches!(self, Self::Create | Self::CreateIndex | Self::Drop) - } } impl Shadow for Create { diff --git a/simulator/runner/bugbase.rs b/simulator/runner/bugbase.rs index 179c292f1..dd0d6f432 100644 --- a/simulator/runner/bugbase.rs +++ b/simulator/runner/bugbase.rs @@ -49,6 +49,7 @@ pub(crate) struct BugRun { } impl Bug { + #[expect(dead_code)] /// Check if the bug is loaded. pub(crate) fn is_loaded(&self) -> bool { match self { @@ -130,6 +131,7 @@ impl BugBase { Err(anyhow!("failed to create bug base")) } + #[expect(dead_code)] /// Load the bug base from one of the potential paths. pub(crate) fn interactive_load() -> anyhow::Result { let potential_paths = vec![ @@ -338,6 +340,7 @@ impl BugBase { } } + #[expect(dead_code)] pub(crate) fn mark_successful_run( &mut self, seed: u64, @@ -434,6 +437,7 @@ impl BugBase { } impl BugBase { + #[expect(dead_code)] /// Get the path to the bug base directory. pub(crate) fn path(&self) -> &PathBuf { &self.path diff --git a/simulator/runner/env.rs b/simulator/runner/env.rs index 300b08c84..79497c38b 100644 --- a/simulator/runner/env.rs +++ b/simulator/runner/env.rs @@ -83,18 +83,6 @@ impl<'a, 'b> ShadowTablesMut<'a> where 'a: 'b, { - /// Creation of [ShadowTablesMut] outside of [SimulatorEnv] should be done sparingly and carefully. - /// Should only need to call this function if we need to do shadowing in a temporary model table - pub fn new( - commited_tables: &'a mut Vec
, - transaction_tables: &'a mut Option, - ) -> Self { - ShadowTablesMut { - commited_tables, - transaction_tables, - } - } - fn tables(&'a self) -> &'a Vec
{ self.transaction_tables .as_ref() @@ -312,7 +300,6 @@ impl SimulatorEnv { seed, ticks: rng .random_range(cli_opts.minimum_tests as usize..=cli_opts.maximum_tests as usize), - max_tables: rng.random_range(0..128), disable_select_optimizer: cli_opts.disable_select_optimizer, disable_insert_values_select: cli_opts.disable_insert_values_select, disable_double_create_failure: cli_opts.disable_double_create_failure, @@ -528,14 +515,6 @@ impl SimulatorEnv { } } -pub trait ConnectionTrait -where - Self: std::marker::Sized + Clone, -{ - fn is_connected(&self) -> bool; - fn disconnect(&mut self); -} - pub(crate) enum SimConnection { LimboConnection(Arc), SQLiteConnection(rusqlite::Connection), @@ -584,7 +563,6 @@ impl Display for SimConnection { pub(crate) struct SimulatorOpts { pub(crate) seed: u64, pub(crate) ticks: usize, - pub(crate) max_tables: usize, pub(crate) disable_select_optimizer: bool, pub(crate) disable_insert_values_select: bool, diff --git a/simulator/runner/execution.rs b/simulator/runner/execution.rs index e3cfef375..7bc9b40e4 100644 --- a/simulator/runner/execution.rs +++ b/simulator/runner/execution.rs @@ -46,6 +46,7 @@ impl ExecutionHistory { } pub struct ExecutionResult { + #[expect(dead_code)] pub history: ExecutionHistory, pub error: Option, } diff --git a/simulator/runner/memory/io.rs b/simulator/runner/memory/io.rs index 007398a10..557ada9a2 100644 --- a/simulator/runner/memory/io.rs +++ b/simulator/runner/memory/io.rs @@ -1,4 +1,4 @@ -use std::cell::{Cell, RefCell}; +use std::cell::RefCell; use std::sync::Arc; use indexmap::IndexMap; @@ -121,7 +121,7 @@ pub struct MemorySimIO { timeouts: CallbackQueue, pub files: RefCell>>, pub rng: RefCell, - pub nr_run_once_faults: Cell, + #[expect(dead_code)] pub page_size: usize, seed: u64, latency_probability: u8, @@ -141,13 +141,11 @@ impl MemorySimIO { ) -> Self { let files = RefCell::new(IndexMap::new()); let rng = RefCell::new(ChaCha8Rng::seed_from_u64(seed)); - let nr_run_once_faults = Cell::new(0); Self { callbacks: Arc::new(Mutex::new(Vec::new())), timeouts: Arc::new(Mutex::new(Vec::new())), files, rng, - nr_run_once_faults, page_size, seed, latency_probability, diff --git a/simulator/runner/mod.rs b/simulator/runner/mod.rs index 7afbaa720..0f60c95fb 100644 --- a/simulator/runner/mod.rs +++ b/simulator/runner/mod.rs @@ -5,7 +5,7 @@ pub mod differential; pub mod doublecheck; pub mod env; pub mod execution; -#[allow(dead_code)] +#[expect(dead_code)] pub mod file; pub mod io; pub mod memory;