[red-knot] intern types using Salsa (#12061)

Intern types using Salsa interning instead of in the `TypeInference`
result.

This eliminates the need for `TypingContext`, and also paves the way for
finer-grained type inference queries.
This commit is contained in:
Carl Meyer 2024-07-05 12:16:37 -07:00 committed by GitHub
parent 7b50061b43
commit 0e44235981
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 190 additions and 534 deletions

View file

@ -6,7 +6,7 @@ use ruff_python_ast::{Expr, ExpressionRef, StmtClassDef};
use crate::semantic_index::ast_ids::HasScopedAstId;
use crate::semantic_index::symbol::PublicSymbolId;
use crate::semantic_index::{public_symbol, semantic_index};
use crate::types::{infer_types, public_symbol_ty, Type, TypingContext};
use crate::types::{infer_types, public_symbol_ty, Type};
use crate::Db;
pub struct SemanticModel<'db> {
@ -19,6 +19,12 @@ impl<'db> SemanticModel<'db> {
Self { db, file }
}
// TODO we don't actually want to expose the Db directly to lint rules, but we need to find a
// solution for exposing information from types
pub fn db(&self) -> &dyn Db {
self.db
}
pub fn resolve_module(&self, module_name: ModuleName) -> Option<Module> {
resolve_module(self.db.upcast(), module_name)
}
@ -27,13 +33,9 @@ impl<'db> SemanticModel<'db> {
public_symbol(self.db, module.file(), symbol_name)
}
pub fn public_symbol_ty(&self, symbol: PublicSymbolId<'db>) -> Type<'db> {
pub fn public_symbol_ty(&self, symbol: PublicSymbolId<'db>) -> Type {
public_symbol_ty(self.db, symbol)
}
pub fn typing_context(&self) -> TypingContext<'db, '_> {
TypingContext::global(self.db)
}
}
pub trait HasTy {