Skip to content

Commit a0900b8

Browse files
committed
remove type_store 'query'
1 parent 1e4d8a0 commit a0900b8

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

crates/red_knot/src/types.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(dead_code)]
22
use crate::ast_ids::NodeKey;
3-
use crate::db::{QueryResult, SemanticDb};
3+
use crate::db::{QueryResult, SemanticDb, SemanticJar};
44
use crate::files::FileId;
55
use crate::symbols::{symbol_table, GlobalSymbolId, ScopeId, ScopeKind, SymbolId};
66
use crate::{FxDashMap, FxIndexSet, Name};
@@ -9,7 +9,7 @@ use rustc_hash::FxHashMap;
99

1010
pub(crate) mod infer;
1111

12-
pub(crate) use infer::{infer_definition_type, infer_symbol_type, type_store};
12+
pub(crate) use infer::{infer_definition_type, infer_symbol_type};
1313

1414
/// unique ID for a type
1515
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
@@ -263,8 +263,9 @@ pub struct FunctionTypeId {
263263
}
264264

265265
impl FunctionTypeId {
266-
pub(crate) fn function(self, db: &dyn SemanticDb) -> QueryResult<FunctionTypeRef> {
267-
Ok(type_store(db)?.get_function(self))
266+
fn function(self, db: &dyn SemanticDb) -> QueryResult<FunctionTypeRef> {
267+
let jar: &SemanticJar = db.jar()?;
268+
Ok(jar.type_store.get_function(self))
268269
}
269270

270271
pub(crate) fn name(self, db: &dyn SemanticDb) -> QueryResult<Name> {
@@ -283,7 +284,7 @@ impl FunctionTypeId {
283284
}
284285

285286
pub(crate) fn symbol(self, db: &dyn SemanticDb) -> QueryResult<SymbolId> {
286-
let FunctionType { symbol_id, .. } = *type_store(db)?.get_function(self);
287+
let FunctionType { symbol_id, .. } = *self.function(db)?;
287288
Ok(symbol_id)
288289
}
289290

@@ -292,7 +293,7 @@ impl FunctionTypeId {
292293
db: &dyn SemanticDb,
293294
) -> QueryResult<Option<ClassTypeId>> {
294295
let table = symbol_table(db, self.file_id)?;
295-
let FunctionType { symbol_id, .. } = *type_store(db)?.get_function(self);
296+
let FunctionType { symbol_id, .. } = *self.function(db)?;
296297
let scope_id = symbol_id.symbol(&table).scope_id();
297298
let scope = scope_id.scope(&table);
298299
if !matches!(scope.kind(), ScopeKind::Class) {
@@ -342,9 +343,13 @@ pub struct ClassTypeId {
342343
}
343344

344345
impl ClassTypeId {
346+
fn class(self, db: &dyn SemanticDb) -> QueryResult<ClassTypeRef> {
347+
let jar: &SemanticJar = db.jar()?;
348+
Ok(jar.type_store.get_class(self))
349+
}
350+
345351
pub(crate) fn name(self, db: &dyn SemanticDb) -> QueryResult<Name> {
346-
let class = type_store(db)?.get_class(self);
347-
Ok(class.name().into())
352+
Ok(self.class(db)?.name().into())
348353
}
349354

350355
pub(crate) fn get_super_class_member(
@@ -353,7 +358,7 @@ impl ClassTypeId {
353358
name: &Name,
354359
) -> QueryResult<Option<Type>> {
355360
// TODO we should linearize the MRO instead of doing this recursively
356-
let class = type_store(db)?.get_class(self);
361+
let class = self.class(db)?;
357362
for base in class.bases() {
358363
if let Type::Class(base) = base {
359364
if let Some(own_member) = base.get_own_class_member(db, name)? {
@@ -369,7 +374,7 @@ impl ClassTypeId {
369374

370375
fn get_own_class_member(self, db: &dyn SemanticDb, name: &Name) -> QueryResult<Option<Type>> {
371376
// TODO: this should distinguish instance-only members (e.g. `x: int`) and not return them
372-
let ClassType { scope_id, .. } = *type_store(db)?.get_class(self);
377+
let ClassType { scope_id, .. } = *self.class(db)?;
373378
let table = symbol_table(db, self.file_id)?;
374379
if let Some(symbol_id) = table.symbol_id_by_name(scope_id, name) {
375380
Ok(Some(infer_symbol_type(

crates/red_knot/src/types/infer.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ use crate::parse::parse;
1010
use crate::symbols::{
1111
resolve_global_symbol, symbol_table, Definition, GlobalSymbolId, ImportFromDefinition,
1212
};
13-
use crate::types::{Type, TypeStore};
13+
use crate::types::Type;
1414
use crate::FileId;
1515

16-
#[tracing::instrument(level = "trace", skip(db))]
17-
pub fn type_store(db: &dyn SemanticDb) -> QueryResult<&TypeStore> {
18-
let jar: &SemanticJar = db.jar()?;
19-
Ok(&jar.type_store)
20-
}
21-
2216
// FIXME: Figure out proper dead-lock free synchronisation now that this takes `&db` instead of `&mut db`.
2317
#[tracing::instrument(level = "trace", skip(db))]
2418
pub fn infer_symbol_type(db: &dyn SemanticDb, symbol: GlobalSymbolId) -> QueryResult<Type> {

0 commit comments

Comments
 (0)