mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
[red-knot] Migrate CLI to Salsa (#11972)
This commit is contained in:
parent
262053f85c
commit
4d385b60c8
36 changed files with 345 additions and 7840 deletions
|
@ -59,7 +59,7 @@ pub(crate) fn root_scope(db: &dyn Db, file: VfsFile) -> ScopeId<'_> {
|
|||
|
||||
/// Returns the symbol with the given name in `file`'s public scope or `None` if
|
||||
/// no symbol with the given name exists.
|
||||
pub fn public_symbol<'db>(
|
||||
pub(crate) fn public_symbol<'db>(
|
||||
db: &'db dyn Db,
|
||||
file: VfsFile,
|
||||
name: &str,
|
||||
|
@ -72,7 +72,7 @@ pub fn public_symbol<'db>(
|
|||
|
||||
/// The symbol tables for an entire file.
|
||||
#[derive(Debug)]
|
||||
pub struct SemanticIndex<'db> {
|
||||
pub(crate) struct SemanticIndex<'db> {
|
||||
/// List of all symbol tables in this file, indexed by scope.
|
||||
symbol_tables: IndexVec<FileScopeId, Arc<SymbolTable<'db>>>,
|
||||
|
||||
|
|
|
@ -47,8 +47,9 @@ pub(crate) fn public_symbol_ty<'db>(db: &'db dyn Db, symbol: PublicSymbolId<'db>
|
|||
inference.symbol_ty(symbol.scoped_symbol_id(db))
|
||||
}
|
||||
|
||||
/// Shorthand for `public_symbol_ty` that takes a symbol name instead of a [`PublicSymbolId`].
|
||||
pub fn public_symbol_ty_by_name<'db>(
|
||||
/// Shorthand for [`public_symbol_ty()`] that takes a symbol name instead of a [`PublicSymbolId`].
|
||||
#[allow(unused)]
|
||||
pub(crate) fn public_symbol_ty_by_name<'db>(
|
||||
db: &'db dyn Db,
|
||||
file: VfsFile,
|
||||
name: &str,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc_hash::FxHashMap;
|
||||
use std::borrow::Cow;
|
||||
use std::sync::Arc;
|
||||
|
||||
use red_knot_module_resolver::resolve_module;
|
||||
|
@ -487,35 +488,38 @@ impl<'db> TypeInferenceBuilder<'db> {
|
|||
|
||||
match ctx {
|
||||
ExprContext::Load => {
|
||||
if let Some(symbol_id) = self
|
||||
.index
|
||||
.symbol_table(self.file_scope_id)
|
||||
.symbol_id_by_name(id)
|
||||
{
|
||||
self.local_definition_ty(symbol_id)
|
||||
} else {
|
||||
let ancestors = self.index.ancestor_scopes(self.file_scope_id).skip(1);
|
||||
let ancestors = self.index.ancestor_scopes(self.file_scope_id);
|
||||
|
||||
for (ancestor_id, _) in ancestors {
|
||||
// TODO: Skip over class scopes unless the they are a immediately-nested type param scope.
|
||||
// TODO: Support built-ins
|
||||
for (ancestor_id, _) in ancestors {
|
||||
// TODO: Skip over class scopes unless the they are a immediately-nested type param scope.
|
||||
// TODO: Support built-ins
|
||||
|
||||
let (symbol_table, ancestor_scope) = if ancestor_id == self.file_scope_id {
|
||||
(Cow::Borrowed(&self.symbol_table), None)
|
||||
} else {
|
||||
let ancestor_scope = ancestor_id.to_scope_id(self.db, self.file_id);
|
||||
let symbol_table = symbol_table(self.db, ancestor_scope);
|
||||
(
|
||||
Cow::Owned(symbol_table(self.db, ancestor_scope)),
|
||||
Some(ancestor_scope),
|
||||
)
|
||||
};
|
||||
|
||||
if let Some(symbol_id) = symbol_table.symbol_id_by_name(id) {
|
||||
let symbol = symbol_table.symbol(symbol_id);
|
||||
if let Some(symbol_id) = symbol_table.symbol_id_by_name(id) {
|
||||
let symbol = symbol_table.symbol(symbol_id);
|
||||
|
||||
if !symbol.is_defined() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let types = infer_types(self.db, ancestor_scope);
|
||||
return types.symbol_ty(symbol_id);
|
||||
if !symbol.is_defined() {
|
||||
continue;
|
||||
}
|
||||
|
||||
return if let Some(ancestor_scope) = ancestor_scope {
|
||||
let types = infer_types(self.db, ancestor_scope);
|
||||
types.symbol_ty(symbol_id)
|
||||
} else {
|
||||
self.local_definition_ty(symbol_id)
|
||||
};
|
||||
}
|
||||
Type::Unknown
|
||||
}
|
||||
Type::Unknown
|
||||
}
|
||||
ExprContext::Del => Type::None,
|
||||
ExprContext::Invalid => Type::Unknown,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue