From a0dc8b58efeaa858dc1b2aa396f1230495becaa3 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Sat, 11 Nov 2023 20:54:39 +0800 Subject: [PATCH] dev(compiler): add appropriate Debug and Copy impl --- compiler/src/browser.rs | 1 + compiler/src/font/system.rs | 3 ++- compiler/src/font/web/mod.rs | 1 + compiler/src/lib.rs | 3 +++ compiler/src/package/browser.rs | 3 ++- compiler/src/parser/semantic_tokens.rs | 4 +++- compiler/src/parser/typst_tokens.rs | 4 ++-- compiler/src/service/compile.rs | 1 + compiler/src/service/diag.rs | 1 + compiler/src/service/export.rs | 2 -- compiler/src/service/features.rs | 7 ++++--- compiler/src/service/mod.rs | 1 + compiler/src/service/watch.rs | 2 ++ compiler/src/system.rs | 1 + compiler/src/vfs/browser.rs | 1 + compiler/src/vfs/cached.rs | 2 ++ compiler/src/vfs/dummy.rs | 2 +- compiler/src/vfs/mod.rs | 14 ++++++++++++++ compiler/src/vfs/notify.rs | 1 + compiler/src/vfs/path_interner.rs | 1 + compiler/src/vfs/system.rs | 3 +++ compiler/src/vfs/trace.rs | 1 + compiler/src/world.rs | 1 + core/src/concepts/marker.rs | 1 + core/src/concepts/query.rs | 16 ++++++++++++++++ core/src/font/partial_book.rs | 2 +- core/src/font/resolver.rs | 1 + core/src/font/slot.rs | 10 ++++++++++ 28 files changed, 78 insertions(+), 12 deletions(-) diff --git a/compiler/src/browser.rs b/compiler/src/browser.rs index e73e243c..81b0381b 100644 --- a/compiler/src/browser.rs +++ b/compiler/src/browser.rs @@ -8,6 +8,7 @@ use crate::{package::browser::ProxyRegistry, vfs::browser::ProxyAccessModel}; /// It is under development. pub type TypstBrowserWorld = crate::world::CompilerWorld; +#[derive(Debug, Clone, Copy)] pub struct BrowserCompilerFeat; impl crate::world::CompilerFeat for BrowserCompilerFeat { diff --git a/compiler/src/font/system.rs b/compiler/src/font/system.rs index 47956879..207b9e2a 100644 --- a/compiler/src/font/system.rs +++ b/compiler/src/font/system.rs @@ -23,7 +23,7 @@ use typst_ts_core::{ use crate::vfs::system::LazyFile; -#[derive(Default)] +#[derive(Debug, Default)] struct FontProfileRebuilder { path_items: HashMap, pub profile: FontProfile, @@ -77,6 +77,7 @@ impl FontProfileRebuilder { } /// Searches for fonts. +#[derive(Debug)] pub struct SystemFontSearcher { db: Database, diff --git a/compiler/src/font/web/mod.rs b/compiler/src/font/web/mod.rs index d3ffc03f..d00b25af 100644 --- a/compiler/src/font/web/mod.rs +++ b/compiler/src/font/web/mod.rs @@ -347,6 +347,7 @@ impl WebFont { unsafe impl Send for WebFont {} +#[derive(Debug)] pub struct WebFontLoader { font: WebFont, index: u32, diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 4b25cd14..c117ffc6 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -23,6 +23,9 @@ //! - [`service::CompileDriver`]: A driver for the compiler. Examples: //! - Single thread (Sync): //! - Multiple thread (Async): +// #![warn(missing_docs)] +// #![warn(missing_debug_implementations)] +// #![warn(missing_copy_implementations)] pub(crate) mod macros; diff --git a/compiler/src/package/browser.rs b/compiler/src/package/browser.rs index ae087bd4..246c1cf2 100644 --- a/compiler/src/package/browser.rs +++ b/compiler/src/package/browser.rs @@ -7,7 +7,7 @@ use wasm_bindgen::{prelude::*, JsValue}; use super::{PackageError, PackageSpec, Registry}; #[wasm_bindgen] -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct ProxyContext { context: JsValue, } @@ -70,6 +70,7 @@ impl ProxyContext { } } +#[derive(Debug)] pub struct ProxyRegistry { pub context: ProxyContext, pub real_resolve_fn: js_sys::Function, diff --git a/compiler/src/parser/semantic_tokens.rs b/compiler/src/parser/semantic_tokens.rs index 38596b49..022a914b 100644 --- a/compiler/src/parser/semantic_tokens.rs +++ b/compiler/src/parser/semantic_tokens.rs @@ -6,7 +6,7 @@ use typst::syntax::{ast, LinkedNode, Source, SyntaxKind}; use super::modifier_set::ModifierSet; use super::typst_tokens::{Modifier, TokenType}; -#[derive(serde::Deserialize, serde::Serialize)] +#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] pub struct SemanticTokensLegend { #[serde(rename = "tokenTypes")] pub token_types: Vec, @@ -33,6 +33,7 @@ pub fn get_semantic_tokens_legend() -> SemanticTokensLegend { } } +#[derive(Debug, Clone, Copy)] pub enum OffsetEncoding { Utf8, Utf16, @@ -83,6 +84,7 @@ fn tokenize_tree(root: &LinkedNode<'_>, parent_modifiers: ModifierSet) -> Vec for &'static str { } } -#[derive(Clone, Copy, EnumIter)] +#[derive(Debug, Clone, Copy, EnumIter)] #[repr(u8)] pub enum Modifier { Strong, diff --git a/compiler/src/service/compile.rs b/compiler/src/service/compile.rs index 005417fd..d6ab145a 100644 --- a/compiler/src/service/compile.rs +++ b/compiler/src/service/compile.rs @@ -421,6 +421,7 @@ impl CompileActor { self.latest_doc.clone() } } +#[derive(Debug, Clone)] pub struct CompileClient { steal_send: mpsc::UnboundedSender>, memory_send: mpsc::UnboundedSender, diff --git a/compiler/src/service/diag.rs b/compiler/src/service/diag.rs index f4782e63..22f599fb 100644 --- a/compiler/src/service/diag.rs +++ b/compiler/src/service/diag.rs @@ -118,6 +118,7 @@ pub fn status(entry_file: TypstFileId, status: DiagStatus) -> io::Result<()> { Ok(()) } +#[derive(Debug, Clone, Copy)] pub struct ConsoleDiagReporter(PhantomParamData); impl Default for ConsoleDiagReporter diff --git a/compiler/src/service/export.rs b/compiler/src/service/export.rs index c05fd4c4..9e4ec1eb 100644 --- a/compiler/src/service/export.rs +++ b/compiler/src/service/export.rs @@ -115,13 +115,11 @@ impl CompileReport { pub type ReportExporter = DynExporter; pub type FeaturedReportExporter = DynExporter<(Arc, CompileReport)>; -#[allow(dead_code)] pub struct CompileReporter { pub compiler: C, pub reporter: DynGenericExporter, CompileReport)>, } -#[allow(dead_code)] impl CompileReporter where C::World: 'static, diff --git a/compiler/src/service/features.rs b/compiler/src/service/features.rs index b1b208a5..2f761625 100644 --- a/compiler/src/service/features.rs +++ b/compiler/src/service/features.rs @@ -11,7 +11,7 @@ pub struct FeatureSlot(u16); static ALLOCATOR: Lazy = Lazy::new(|| std::sync::atomic::AtomicU16::new(1)); -#[derive(Default)] +#[derive(Debug, Default)] pub struct LazyFeatureSlot(once_cell::sync::OnceCell); impl From<&LazyFeatureSlot> for FeatureSlot { @@ -22,7 +22,7 @@ impl From<&LazyFeatureSlot> for FeatureSlot { } } -#[derive(Default, Clone)] +#[derive(Debug, Default, Clone)] pub struct FeatureSet { features: Vec, } @@ -54,6 +54,7 @@ pub trait CompileFeature { fn retrieve(&self, features: &FeatureSet) -> T; } +#[derive(Debug, Clone, Copy)] pub struct DiagFmtFeature; const DIAG_FEATURE: FeatureSlot = FeatureSlot(0); pub static DIAG_FMT_FEATURE: DiagFmtFeature = DiagFmtFeature; @@ -78,7 +79,7 @@ impl CompileFeature for DiagFmtFeature { } } -#[derive(Default)] +#[derive(Debug, Default)] pub struct BuiltinFeature(LazyFeatureSlot, std::marker::PhantomData); impl BuiltinFeature { diff --git a/compiler/src/service/mod.rs b/compiler/src/service/mod.rs index 0dc1aa9f..1635219f 100644 --- a/compiler/src/service/mod.rs +++ b/compiler/src/service/mod.rs @@ -315,6 +315,7 @@ where } /// The status in which the watcher can be. +#[derive(Debug, Clone, Copy)] pub enum DiagStatus { Stage(&'static str), Success(std::time::Duration), diff --git a/compiler/src/service/watch.rs b/compiler/src/service/watch.rs index 494ad1c2..856726ac 100644 --- a/compiler/src/service/watch.rs +++ b/compiler/src/service/watch.rs @@ -55,6 +55,7 @@ impl Default for WatchState { } /// The data entry of a watched file. +#[derive(Debug)] struct WatchedEntry { /// The lifetime of the entry. /// @@ -85,6 +86,7 @@ struct UndeterminedNotifyEvent { // Drop order is significant. /// The actor that watches files. /// It is used to watch files and send events to the consumers +#[derive(Debug)] pub struct NotifyActor { /// The access model of the actor. /// We concrete the access model to `SystemAccessModel` for now. diff --git a/compiler/src/system.rs b/compiler/src/system.rs index 46292cd0..6baffd8a 100644 --- a/compiler/src/system.rs +++ b/compiler/src/system.rs @@ -9,6 +9,7 @@ use crate::{ }; /// type trait of [`TypstSystemWorld`]. +#[derive(Debug, Clone, Copy)] pub struct SystemCompilerFeat; impl crate::world::CompilerFeat for SystemCompilerFeat { diff --git a/compiler/src/vfs/browser.rs b/compiler/src/vfs/browser.rs index d089db08..87a09c54 100644 --- a/compiler/src/vfs/browser.rs +++ b/compiler/src/vfs/browser.rs @@ -9,6 +9,7 @@ use crate::time::SystemTime; use super::AccessModel; +#[derive(Debug)] pub struct ProxyAccessModel { pub context: JsValue, pub mtime_fn: js_sys::Function, diff --git a/compiler/src/vfs/cached.rs b/compiler/src/vfs/cached.rs index 44869df3..5910a9a2 100644 --- a/compiler/src/vfs/cached.rs +++ b/compiler/src/vfs/cached.rs @@ -12,6 +12,7 @@ use super::AccessModel; /// incrementally query a value from a self holding state type IncrQueryRef = QueryRef>; +#[derive(Debug)] pub struct FileCache { lifetime_cnt: usize, mtime: SystemTime, @@ -20,6 +21,7 @@ pub struct FileCache { source_state: IncrQueryRef, } +#[derive(Debug)] pub struct CachedAccessModel { inner: Inner, lifetime_cnt: usize, diff --git a/compiler/src/vfs/dummy.rs b/compiler/src/vfs/dummy.rs index 01ff67d4..d4f4f597 100644 --- a/compiler/src/vfs/dummy.rs +++ b/compiler/src/vfs/dummy.rs @@ -8,7 +8,7 @@ use crate::time::SystemTime; use super::AccessModel; -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone, Copy)] pub struct DummyAccessModel; impl AccessModel for DummyAccessModel { diff --git a/compiler/src/vfs/mod.rs b/compiler/src/vfs/mod.rs index 83dd5f06..46b8affb 100644 --- a/compiler/src/vfs/mod.rs +++ b/compiler/src/vfs/mod.rs @@ -20,6 +20,7 @@ mod path_interner; pub(crate) use path_interner::PathInterner; +use core::fmt; use std::{collections::HashMap, ffi::OsStr, hash::Hash, path::Path, sync::Arc}; use append_only_vec::AppendOnlyVec; @@ -65,6 +66,7 @@ pub trait AccessModel { type FileQuery = QueryRef; /// Holds canonical data for all paths pointing to the same entity. +#[derive(Debug)] pub struct PathSlot { idx: FileId, sampled_path: once_cell::sync::OnceCell, @@ -100,6 +102,18 @@ pub struct Vfs { pub do_reparse: bool, } +impl fmt::Debug for Vfs { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Vfs") + .field("lifetime_cnt", &self.lifetime_cnt) + .field("path2slot", &self.path2slot) + .field("src2file_id", &self.src2file_id) + .field("slots", &self.slots) + .field("do_reparse", &self.do_reparse) + .finish() + } +} + impl Vfs { pub fn new(access_model: M) -> Self { let access_model = NotifyAccessModel::new(access_model); diff --git a/compiler/src/vfs/notify.rs b/compiler/src/vfs/notify.rs index d7fe3738..2867cc8d 100644 --- a/compiler/src/vfs/notify.rs +++ b/compiler/src/vfs/notify.rs @@ -198,6 +198,7 @@ pub enum NotifyMessage { /// Notify shadowing access model, which the typical underlying access model is /// [`crate::vfs::system::SystemAccessModel`] +#[derive(Debug)] pub struct NotifyAccessModel { files: HashMap, pub inner: M, diff --git a/compiler/src/vfs/path_interner.rs b/compiler/src/vfs/path_interner.rs index 8daa2638..96e47b4d 100644 --- a/compiler/src/vfs/path_interner.rs +++ b/compiler/src/vfs/path_interner.rs @@ -10,6 +10,7 @@ use rustc_hash::FxHasher; use super::FileId; /// Structure to map between [`VfsPath`] and [`FileId`]. +#[derive(Debug)] pub(crate) struct PathInterner { map: IndexMap>, } diff --git a/compiler/src/vfs/system.rs b/compiler/src/vfs/system.rs index d7fd4ff1..46060485 100644 --- a/compiler/src/vfs/system.rs +++ b/compiler/src/vfs/system.rs @@ -10,6 +10,7 @@ use typst_ts_core::{Bytes, ReadAllOnce}; use super::AccessModel; +#[derive(Debug)] pub struct LazyFile { path: std::path::PathBuf, file: Option>, @@ -34,11 +35,13 @@ impl ReadAllOnce for LazyFile { } } +#[derive(Debug, Clone, Copy)] pub struct SystemFileMeta { mt: std::time::SystemTime, is_file: bool, } +#[derive(Debug, Clone, Copy)] pub struct SystemAccessModel; impl SystemAccessModel { diff --git a/compiler/src/vfs/trace.rs b/compiler/src/vfs/trace.rs index 01a2b1a5..ffb8f782 100644 --- a/compiler/src/vfs/trace.rs +++ b/compiler/src/vfs/trace.rs @@ -8,6 +8,7 @@ use crate::time::SystemTime; use super::{cached::CachedAccessModel, AccessModel}; +#[derive(Debug)] pub struct TraceAccessModel { inner: M, trace: [AtomicU64; 6], diff --git a/compiler/src/world.rs b/compiler/src/world.rs index ae6f1f38..880d4ab9 100644 --- a/compiler/src/world.rs +++ b/compiler/src/world.rs @@ -45,6 +45,7 @@ pub trait CompilerFeat { } /// A world that provides access to the operating system. +#[derive(Debug)] pub struct CompilerWorld { /// Path to the root directory of compilation. /// The world forbids direct access to files outside this directory. diff --git a/core/src/concepts/marker.rs b/core/src/concepts/marker.rs index 5f6010e8..57f4ff6c 100644 --- a/core/src/concepts/marker.rs +++ b/core/src/concepts/marker.rs @@ -10,6 +10,7 @@ use serde_with::{DeserializeAs, SerializeAs}; /// Generic marker for type that only occurs in parameter position. /// /// Safety: The signature is type checked by the compiler. +#[derive(Debug, Clone, Copy)] pub struct PhantomParamData(std::marker::PhantomData); unsafe impl Send for PhantomParamData {} diff --git a/core/src/concepts/query.rs b/core/src/concepts/query.rs index 0eafb2b4..74d363ae 100644 --- a/core/src/concepts/query.rs +++ b/core/src/concepts/query.rs @@ -127,3 +127,19 @@ impl Default for QueryRef { } } } + +impl fmt::Debug for QueryRef +where + T: fmt::Debug, + E: fmt::Debug, + QC: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let borrowed = self.cell.borrow(); + let (ref ctx, ref res) = *borrowed; + f.debug_struct("QueryRef") + .field("context", &ctx) + .field("result", &res) + .finish() + } +} diff --git a/core/src/font/partial_book.rs b/core/src/font/partial_book.rs index 3b9cbd0d..e7e2a4c0 100644 --- a/core/src/font/partial_book.rs +++ b/core/src/font/partial_book.rs @@ -21,7 +21,7 @@ impl From<&FontInfo> for FontInfoKey { } } -#[derive(Default)] +#[derive(Debug, Default)] pub struct PartialFontBook { pub revision: usize, pub partial_hit: bool, diff --git a/core/src/font/resolver.rs b/core/src/font/resolver.rs index 1aa40ff3..fcba665b 100644 --- a/core/src/font/resolver.rs +++ b/core/src/font/resolver.rs @@ -36,6 +36,7 @@ pub trait FontResolver { } } +#[derive(Debug)] /// The default FontResolver implementation. pub struct FontResolverImpl { book: Prehashed, diff --git a/core/src/font/slot.rs b/core/src/font/slot.rs index 0af406e0..6cc62ef6 100644 --- a/core/src/font/slot.rs +++ b/core/src/font/slot.rs @@ -1,3 +1,5 @@ +use core::fmt; + use typst::font::Font; use crate::{FontLoader, QueryRef}; @@ -35,3 +37,11 @@ impl FontSlot { { unsafe { res.unwrap_unchecked() } }.clone() } } + +impl fmt::Debug for FontSlot { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_tuple("FontSlot") + .field(&self.get_uninitialized()) + .finish() + } +}