mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-23 04:45:21 +00:00
docs: rearrange and documenting cache structures (#978)
This commit is contained in:
parent
678b2d2111
commit
dde3f5dff1
1 changed files with 32 additions and 25 deletions
|
|
@ -66,7 +66,7 @@ pub struct Analysis {
|
||||||
pub tokens_caches: Arc<Mutex<SemanticTokenCache>>,
|
pub tokens_caches: Arc<Mutex<SemanticTokenCache>>,
|
||||||
/// The global caches for analysis.
|
/// The global caches for analysis.
|
||||||
pub caches: AnalysisGlobalCaches,
|
pub caches: AnalysisGlobalCaches,
|
||||||
/// The revisioned cache for analysis.
|
/// The revision-managed cache for analysis.
|
||||||
pub analysis_rev_cache: Arc<Mutex<AnalysisRevCache>>,
|
pub analysis_rev_cache: Arc<Mutex<AnalysisRevCache>>,
|
||||||
/// The statistics about the analyzers.
|
/// The statistics about the analyzers.
|
||||||
pub stats: Arc<AnalysisStats>,
|
pub stats: Arc<AnalysisStats>,
|
||||||
|
|
@ -90,7 +90,7 @@ impl Analysis {
|
||||||
rev_lock: lg,
|
rev_lock: lg,
|
||||||
local: LocalContext {
|
local: LocalContext {
|
||||||
tokens,
|
tokens,
|
||||||
caches: AnalysisCaches::default(),
|
caches: AnalysisLocalCaches::default(),
|
||||||
shared: Arc::new(SharedContext {
|
shared: Arc::new(SharedContext {
|
||||||
slot,
|
slot,
|
||||||
lifetime,
|
lifetime,
|
||||||
|
|
@ -189,20 +189,9 @@ pub trait PeriscopeProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shared workers to limit resource usage
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct AnalysisGlobalWorkers {
|
|
||||||
/// A possible long running import dynamic analysis task
|
|
||||||
import: RateLimiter,
|
|
||||||
/// A possible long running expression dynamic analysis task
|
|
||||||
expression: RateLimiter,
|
|
||||||
/// A possible long running tooltip dynamic analysis task
|
|
||||||
tooltip: RateLimiter,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The local context guard that performs gc once dropped.
|
/// The local context guard that performs gc once dropped.
|
||||||
pub struct LocalContextGuard {
|
pub struct LocalContextGuard {
|
||||||
/// Constructed local context
|
/// The guarded local context
|
||||||
pub local: LocalContext,
|
pub local: LocalContext,
|
||||||
/// The revision lock
|
/// The revision lock
|
||||||
pub rev_lock: AnalysisRevLock,
|
pub rev_lock: AnalysisRevLock,
|
||||||
|
|
@ -260,12 +249,13 @@ impl LocalContextGuard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The local context for analyzers.
|
/// The local context for analyzers. In addition to the shared context, it also
|
||||||
|
/// holds mutable local caches.
|
||||||
pub struct LocalContext {
|
pub struct LocalContext {
|
||||||
/// The created semantic token context.
|
/// The created semantic token context.
|
||||||
pub(crate) tokens: Option<SemanticTokenContext>,
|
pub(crate) tokens: Option<SemanticTokenContext>,
|
||||||
/// Local caches for analysis.
|
/// Local caches for analysis.
|
||||||
pub caches: AnalysisCaches,
|
pub caches: AnalysisLocalCaches,
|
||||||
/// The shared context
|
/// The shared context
|
||||||
pub shared: Arc<SharedContext>,
|
pub shared: Arc<SharedContext>,
|
||||||
}
|
}
|
||||||
|
|
@ -1002,6 +992,9 @@ impl SharedContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Needed by recursive computation
|
||||||
|
type DeferredCompute<T> = Arc<OnceCell<T>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct IncrCacheMap<K, V> {
|
struct IncrCacheMap<K, V> {
|
||||||
revision: usize,
|
revision: usize,
|
||||||
|
|
@ -1102,8 +1095,16 @@ impl<T: Default + Clone> CacheMap<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Needed by recursive computation
|
/// Shared workers to limit resource usage
|
||||||
type DeferredCompute<T> = Arc<OnceCell<T>>;
|
#[derive(Default)]
|
||||||
|
pub struct AnalysisGlobalWorkers {
|
||||||
|
/// A possible long running import dynamic analysis task
|
||||||
|
import: RateLimiter,
|
||||||
|
/// A possible long running expression dynamic analysis task
|
||||||
|
expression: RateLimiter,
|
||||||
|
/// A possible long running tooltip dynamic analysis task
|
||||||
|
tooltip: RateLimiter,
|
||||||
|
}
|
||||||
|
|
||||||
/// A global (compiler server spanned) cache for all level of analysis results
|
/// A global (compiler server spanned) cache for all level of analysis results
|
||||||
/// of a module.
|
/// of a module.
|
||||||
|
|
@ -1117,25 +1118,31 @@ pub struct AnalysisGlobalCaches {
|
||||||
terms: CacheMap<(Value, Ty)>,
|
terms: CacheMap<(Value, Ty)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A cache for all level of analysis results of a module.
|
/// A local (lsp request spanned) cache for all level of analysis results of a
|
||||||
|
/// module.
|
||||||
|
///
|
||||||
|
/// You should not hold it across requests, because input like source code may
|
||||||
|
/// change.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AnalysisCaches {
|
pub struct AnalysisLocalCaches {
|
||||||
modules: HashMap<TypstFileId, ModuleAnalysisCache>,
|
modules: HashMap<TypstFileId, ModuleAnalysisLocalCache>,
|
||||||
completion_files: OnceCell<Vec<TypstFileId>>,
|
completion_files: OnceCell<Vec<TypstFileId>>,
|
||||||
root_files: OnceCell<Vec<TypstFileId>>,
|
root_files: OnceCell<Vec<TypstFileId>>,
|
||||||
module_deps: OnceCell<HashMap<TypstFileId, ModuleDependency>>,
|
module_deps: OnceCell<HashMap<TypstFileId, ModuleDependency>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A cache for module-level analysis results of a module.
|
/// A local cache for module-level analysis results of a module.
|
||||||
///
|
///
|
||||||
/// You should not holds across requests, because source code may change.
|
/// You should not hold it across requests, because input like source code may
|
||||||
|
/// change.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ModuleAnalysisCache {
|
pub struct ModuleAnalysisLocalCache {
|
||||||
expr_stage: OnceCell<Arc<ExprInfo>>,
|
expr_stage: OnceCell<Arc<ExprInfo>>,
|
||||||
type_check: OnceCell<Arc<TypeScheme>>,
|
type_check: OnceCell<Arc<TypeScheme>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The grid cache for all level of analysis results of a module.
|
/// A revision-managed (per input change) cache for all level of analysis
|
||||||
|
/// results of a module.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AnalysisRevCache {
|
pub struct AnalysisRevCache {
|
||||||
default_slot: AnalysisRevSlot,
|
default_slot: AnalysisRevSlot,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue