mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:23:11 +00:00
[red-knot] Add tracing to Salsa queries (#11949)
This commit is contained in:
parent
2dfbf118d7
commit
b456051be8
6 changed files with 28 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
|||
use salsa::DebugWithDb;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -29,7 +30,6 @@ pub fn set_module_resolution_settings(db: &mut dyn Db, config: ModuleResolutionS
|
|||
}
|
||||
|
||||
/// Resolves a module name to a module.
|
||||
#[tracing::instrument(level = "debug", skip(db))]
|
||||
pub fn resolve_module(db: &dyn Db, module_name: ModuleName) -> Option<Module> {
|
||||
let interned_name = internal::ModuleNameIngredient::new(db, module_name);
|
||||
|
||||
|
@ -45,6 +45,8 @@ pub(crate) fn resolve_module_query(
|
|||
db: &dyn Db,
|
||||
module_name: internal::ModuleNameIngredient,
|
||||
) -> Option<Module> {
|
||||
let _ = tracing::trace_span!("resolve_module", module_name = ?module_name.debug(db)).enter();
|
||||
|
||||
let name = module_name.name(db);
|
||||
|
||||
let (search_path, module_file, kind) = resolve_name(db, name)?;
|
||||
|
@ -82,8 +84,9 @@ pub fn path_to_module(db: &dyn Db, path: &VfsPath) -> Option<Module> {
|
|||
///
|
||||
/// Returns `None` if the file is not a module locatable via `sys.path`.
|
||||
#[salsa::tracked]
|
||||
#[tracing::instrument(level = "debug", skip(db))]
|
||||
pub fn file_to_module(db: &dyn Db, file: VfsFile) -> Option<Module> {
|
||||
pub(crate) fn file_to_module(db: &dyn Db, file: VfsFile) -> Option<Module> {
|
||||
let _ = tracing::trace_span!("file_to_module", file = ?file.debug(db.upcast())).enter();
|
||||
|
||||
let path = file.path(db.upcast());
|
||||
|
||||
let search_paths = module_search_paths(db);
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::iter::FusedIterator;
|
|||
use std::sync::Arc;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use salsa::DebugWithDb;
|
||||
|
||||
use ruff_db::parsed::parsed_module;
|
||||
use ruff_db::vfs::VfsFile;
|
||||
|
@ -28,6 +29,8 @@ type SymbolMap = hashbrown::HashMap<ScopedSymbolId, (), ()>;
|
|||
/// Prefer using [`symbol_table`] when working with symbols from a single scope.
|
||||
#[salsa::tracked(return_ref, no_eq)]
|
||||
pub(crate) fn semantic_index(db: &dyn Db, file: VfsFile) -> SemanticIndex {
|
||||
let _ = tracing::trace_span!("semantic_index", file = ?file.debug(db.upcast())).enter();
|
||||
|
||||
let parsed = parsed_module(db.upcast(), file);
|
||||
|
||||
SemanticIndexBuilder::new(parsed).build()
|
||||
|
@ -40,6 +43,7 @@ pub(crate) fn semantic_index(db: &dyn Db, file: VfsFile) -> SemanticIndex {
|
|||
/// is unchanged.
|
||||
#[salsa::tracked]
|
||||
pub(crate) fn symbol_table(db: &dyn Db, scope: ScopeId) -> Arc<SymbolTable> {
|
||||
let _ = tracing::trace_span!("symbol_table", scope = ?scope.debug(db)).enter();
|
||||
let index = semantic_index(db, scope.file(db));
|
||||
|
||||
index.symbol_table(scope.file_scope_id(db))
|
||||
|
@ -48,6 +52,8 @@ pub(crate) fn symbol_table(db: &dyn Db, scope: ScopeId) -> Arc<SymbolTable> {
|
|||
/// Returns the root scope of `file`.
|
||||
#[salsa::tracked]
|
||||
pub(crate) fn root_scope(db: &dyn Db, file: VfsFile) -> ScopeId {
|
||||
let _ = tracing::trace_span!("root_scope", file = ?file.debug(db.upcast())).enter();
|
||||
|
||||
FileScopeId::root().to_scope_id(db, file)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::ops::Range;
|
|||
use bitflags::bitflags;
|
||||
use hashbrown::hash_map::RawEntryMut;
|
||||
use rustc_hash::FxHasher;
|
||||
use salsa::DebugWithDb;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use ruff_db::vfs::VfsFile;
|
||||
|
@ -132,6 +133,8 @@ impl ScopedSymbolId {
|
|||
/// Returns a mapping from [`FileScopeId`] to globally unique [`ScopeId`].
|
||||
#[salsa::tracked(return_ref)]
|
||||
pub(crate) fn scopes_map(db: &dyn Db, file: VfsFile) -> ScopesMap {
|
||||
let _ = tracing::trace_span!("scopes_map", file = ?file.debug(db.upcast())).enter();
|
||||
|
||||
let index = semantic_index(db, file);
|
||||
|
||||
let scopes: IndexVec<_, _> = index
|
||||
|
@ -162,6 +165,8 @@ impl ScopesMap {
|
|||
|
||||
#[salsa::tracked(return_ref)]
|
||||
pub(crate) fn public_symbols_map(db: &dyn Db, file: VfsFile) -> PublicSymbolsMap {
|
||||
let _ = tracing::trace_span!("public_symbols_map", file = ?file.debug(db.upcast())).enter();
|
||||
|
||||
let module_scope = root_scope(db, file);
|
||||
let symbols = symbol_table(db, module_scope);
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ pub(crate) fn expression_ty(db: &dyn Db, file: VfsFile, expression: &ast::Expr)
|
|||
/// This being a query ensures that the invalidation short-circuits if the type of this symbol didn't change.
|
||||
#[salsa::tracked]
|
||||
pub(crate) fn public_symbol_ty(db: &dyn Db, symbol: PublicSymbolId) -> Type {
|
||||
let _ = tracing::debug_span!("public_symbol_ty", symbol = ?symbol.debug(db)).enter();
|
||||
let _ = tracing::trace_span!("public_symbol_ty", symbol = ?symbol.debug(db)).enter();
|
||||
|
||||
let file = symbol.file(db);
|
||||
let scope = root_scope(db, file);
|
||||
|
@ -80,6 +80,8 @@ pub fn public_symbol_ty_by_name(db: &dyn Db, file: VfsFile, name: &str) -> Optio
|
|||
/// Infers all types for `scope`.
|
||||
#[salsa::tracked(return_ref)]
|
||||
pub(crate) fn infer_types(db: &dyn Db, scope: ScopeId) -> TypeInference {
|
||||
let _ = tracing::trace_span!("infer_types", scope = ?scope.debug(db)).enter();
|
||||
|
||||
let file = scope.file(db);
|
||||
// Using the index here is fine because the code below depends on the AST anyway.
|
||||
// The isolation of the query is by the return inferred types.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use salsa::DebugWithDb;
|
||||
use std::fmt::Formatter;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
@ -22,6 +23,8 @@ use crate::Db;
|
|||
/// for determining if a query result is unchanged.
|
||||
#[salsa::tracked(return_ref, no_eq)]
|
||||
pub fn parsed_module(db: &dyn Db, file: VfsFile) -> ParsedModule {
|
||||
let _ = tracing::trace_span!("parse_module", file = ?file.debug(db)).enter();
|
||||
|
||||
let source = source_text(db, file);
|
||||
let path = file.path(db);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use salsa::DebugWithDb;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -9,6 +10,8 @@ use crate::Db;
|
|||
/// Reads the content of file.
|
||||
#[salsa::tracked]
|
||||
pub fn source_text(db: &dyn Db, file: VfsFile) -> SourceText {
|
||||
let _ = tracing::trace_span!("source_text", file = ?file.debug(db)).enter();
|
||||
|
||||
let content = file.read(db);
|
||||
|
||||
SourceText {
|
||||
|
@ -19,6 +22,8 @@ pub fn source_text(db: &dyn Db, file: VfsFile) -> SourceText {
|
|||
/// Computes the [`LineIndex`] for `file`.
|
||||
#[salsa::tracked]
|
||||
pub fn line_index(db: &dyn Db, file: VfsFile) -> LineIndex {
|
||||
let _ = tracing::trace_span!("line_index", file = ?file.debug(db)).enter();
|
||||
|
||||
let source = source_text(db, file);
|
||||
|
||||
LineIndex::from_source_text(&source)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue