Skip to content

Commit 184a795

Browse files
committed
use coarse-grained tracked structs
1 parent cb3361e commit 184a795

File tree

12 files changed

+27
-44
lines changed

12 files changed

+27
-44
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ rayon = { version = "1.10.0" }
121121
regex = { version = "1.10.2" }
122122
rustc-hash = { version = "2.0.0" }
123123
# When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml`
124-
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "88a1d7774d78f048fbd77d40abca9ebd729fd1f0" }
124+
salsa = { git = "https://github.com/ibraheemdev/salsa.git", rev = "5afc02d69487976d700ad74e954f51606e8376ff" }
125125
schemars = { version = "0.8.16" }
126126
seahash = { version = "4.1.0" }
127127
serde = { version = "1.0.197", features = ["derive"] }

crates/red_knot_python_semantic/src/ast_node_ref.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use ruff_db::parsed::ParsedModule;
1212
/// Holding on to any [`AstNodeRef`] prevents the [`ParsedModule`] from being released.
1313
///
1414
/// ## Equality
15-
/// Two `AstNodeRef` are considered equal if their wrapped nodes are equal.
15+
/// Two `AstNodeRef` are considered equal if their pointer addresses are equal.
1616
#[derive(Clone)]
1717
pub struct AstNodeRef<T> {
1818
/// Owned reference to the node's [`ParsedModule`].
@@ -67,23 +67,17 @@ where
6767
}
6868
}
6969

70-
impl<T> PartialEq for AstNodeRef<T>
71-
where
72-
T: PartialEq,
73-
{
70+
impl<T> PartialEq for AstNodeRef<T> {
7471
fn eq(&self, other: &Self) -> bool {
75-
self.node().eq(other.node())
72+
self.node.eq(&other.node)
7673
}
7774
}
7875

79-
impl<T> Eq for AstNodeRef<T> where T: Eq {}
76+
impl<T> Eq for AstNodeRef<T> {}
8077

81-
impl<T> Hash for AstNodeRef<T>
82-
where
83-
T: Hash,
84-
{
78+
impl<T> Hash for AstNodeRef<T> {
8579
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
86-
self.node().hash(state);
80+
self.node.hash(state);
8781
}
8882
}
8983

crates/red_knot_python_semantic/src/module_resolver/resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::path::{ModulePath, SearchPath, SearchPathValidationError};
1818

1919
/// Resolves a module name to a module.
2020
pub fn resolve_module(db: &dyn Db, module_name: &ModuleName) -> Option<Module> {
21-
let interned_name = ModuleNameIngredient::new(db, module_name);
21+
let interned_name = ModuleNameIngredient::new(db, module_name.clone());
2222

2323
resolve_module_query(db, interned_name)
2424
}

crates/red_knot_python_semantic/src/semantic_index/constraint.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) enum ConstraintNode<'db> {
1818
}
1919

2020
/// Pattern kinds for which we support type narrowing and/or static visibility analysis.
21-
#[derive(Debug, Clone, PartialEq)]
21+
#[derive(Debug, Clone, PartialEq, Hash)]
2222
pub(crate) enum PatternConstraintKind<'db> {
2323
Singleton(Singleton, Option<Expression<'db>>),
2424
Value(Expression<'db>, Option<Expression<'db>>),
@@ -28,10 +28,8 @@ pub(crate) enum PatternConstraintKind<'db> {
2828

2929
#[salsa::tracked]
3030
pub(crate) struct PatternConstraint<'db> {
31-
#[id]
3231
pub(crate) file: File,
3332

34-
#[id]
3533
pub(crate) file_scope: FileScopeId,
3634

3735
#[no_eq]

crates/red_knot_python_semantic/src/semantic_index/definition.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ use crate::Db;
2525
#[salsa::tracked]
2626
pub struct Definition<'db> {
2727
/// The file in which the definition occurs.
28-
#[id]
2928
pub(crate) file: File,
3029

3130
/// The scope in which the definition occurs.
32-
#[id]
3331
pub(crate) file_scope: FileScopeId,
3432

3533
/// The symbol defined.
36-
#[id]
3734
pub(crate) symbol: ScopedSymbolId,
3835

3936
#[no_eq]
@@ -435,7 +432,7 @@ impl DefinitionCategory {
435432
}
436433
}
437434

438-
#[derive(Clone, Debug)]
435+
#[derive(Clone, Debug, Hash)]
439436
pub enum DefinitionKind<'db> {
440437
Import(AstNodeRef<ast::Alias>),
441438
ImportFrom(ImportFromDefinitionKind),
@@ -540,7 +537,7 @@ impl DefinitionKind<'_> {
540537
}
541538
}
542539

543-
#[derive(Copy, Clone, Debug, PartialEq)]
540+
#[derive(Copy, Clone, Debug, PartialEq, Hash)]
544541
pub(crate) enum TargetKind<'db> {
545542
Sequence(Unpack<'db>),
546543
Name,
@@ -555,7 +552,7 @@ impl<'db> From<Option<Unpack<'db>>> for TargetKind<'db> {
555552
}
556553
}
557554

558-
#[derive(Clone, Debug)]
555+
#[derive(Clone, Debug, Hash)]
559556
#[allow(dead_code)]
560557
pub struct MatchPatternDefinitionKind {
561558
pattern: AstNodeRef<ast::Pattern>,
@@ -573,7 +570,7 @@ impl MatchPatternDefinitionKind {
573570
}
574571
}
575572

576-
#[derive(Clone, Debug)]
573+
#[derive(Clone, Debug, Hash)]
577574
pub struct ComprehensionDefinitionKind {
578575
iterable: AstNodeRef<ast::Expr>,
579576
target: AstNodeRef<ast::ExprName>,
@@ -599,7 +596,7 @@ impl ComprehensionDefinitionKind {
599596
}
600597
}
601598

602-
#[derive(Clone, Debug)]
599+
#[derive(Clone, Debug, Hash)]
603600
pub struct ImportFromDefinitionKind {
604601
node: AstNodeRef<ast::StmtImportFrom>,
605602
alias_index: usize,
@@ -615,7 +612,7 @@ impl ImportFromDefinitionKind {
615612
}
616613
}
617614

618-
#[derive(Clone, Debug)]
615+
#[derive(Clone, Debug, Hash)]
619616
pub struct AssignmentDefinitionKind<'db> {
620617
target: TargetKind<'db>,
621618
value: AstNodeRef<ast::Expr>,
@@ -641,7 +638,7 @@ impl<'db> AssignmentDefinitionKind<'db> {
641638
}
642639
}
643640

644-
#[derive(Clone, Debug)]
641+
#[derive(Clone, Debug, Hash)]
645642
pub struct WithItemDefinitionKind {
646643
node: AstNodeRef<ast::WithItem>,
647644
target: AstNodeRef<ast::ExprName>,
@@ -662,7 +659,7 @@ impl WithItemDefinitionKind {
662659
}
663660
}
664661

665-
#[derive(Clone, Debug)]
662+
#[derive(Clone, Debug, Hash)]
666663
pub struct ForStmtDefinitionKind<'db> {
667664
target: TargetKind<'db>,
668665
iterable: AstNodeRef<ast::Expr>,
@@ -693,7 +690,7 @@ impl<'db> ForStmtDefinitionKind<'db> {
693690
}
694691
}
695692

696-
#[derive(Clone, Debug)]
693+
#[derive(Clone, Debug, Hash)]
697694
pub struct ExceptHandlerDefinitionKind {
698695
handler: AstNodeRef<ast::ExceptHandlerExceptHandler>,
699696
is_star: bool,

crates/red_knot_python_semantic/src/semantic_index/expression.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ use salsa;
2323
#[salsa::tracked]
2424
pub(crate) struct Expression<'db> {
2525
/// The file in which the expression occurs.
26-
#[id]
2726
pub(crate) file: File,
2827

2928
/// The scope in which the expression occurs.
30-
#[id]
3129
pub(crate) file_scope: FileScopeId,
3230

3331
/// The expression node.

crates/red_knot_python_semantic/src/semantic_index/symbol.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ pub struct ScopedSymbolId;
101101
/// A cross-module identifier of a scope that can be used as a salsa query parameter.
102102
#[salsa::tracked]
103103
pub struct ScopeId<'db> {
104-
#[id]
105104
pub file: File,
106105

107-
#[id]
108106
pub file_scope_id: FileScopeId,
109107

110108
#[no_eq]

crates/red_knot_python_semantic/src/types/infer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ impl<'db> TypeInferenceBuilder<'db> {
11341134

11351135
let function_ty = Type::FunctionLiteral(FunctionType::new(
11361136
self.db(),
1137-
&name.id,
1137+
name.id.clone(),
11381138
function_kind,
11391139
body_scope,
11401140
decorator_tys.into_boxed_slice(),
@@ -1362,7 +1362,7 @@ impl<'db> TypeInferenceBuilder<'db> {
13621362

13631363
let maybe_known_class = KnownClass::try_from_file_and_name(self.db(), self.file(), name);
13641364

1365-
let class = Class::new(self.db(), &name.id, body_scope, maybe_known_class);
1365+
let class = Class::new(self.db(), name.id.clone(), body_scope, maybe_known_class);
13661366
let class_ty = Type::class_literal(class);
13671367

13681368
self.add_declaration_with_binding(
@@ -1419,7 +1419,7 @@ impl<'db> TypeInferenceBuilder<'db> {
14191419
let type_alias_ty =
14201420
Type::KnownInstance(KnownInstanceType::TypeAliasType(TypeAliasType::new(
14211421
self.db(),
1422-
&type_alias.name.as_name_expr().unwrap().id,
1422+
type_alias.name.as_name_expr().unwrap().id.clone(),
14231423
rhs_scope,
14241424
)));
14251425

crates/red_knot_python_semantic/src/unpack.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ use crate::Db;
2828
/// * an argument of a cross-module query
2929
#[salsa::tracked]
3030
pub(crate) struct Unpack<'db> {
31-
#[id]
3231
pub(crate) file: File,
3332

34-
#[id]
3533
pub(crate) file_scope: FileScopeId,
3634

3735
/// The target expression that is being unpacked. For example, in `(a, b) = (1, 2)`, the target
@@ -62,7 +60,7 @@ impl<'db> Unpack<'db> {
6260
}
6361

6462
/// The expression that is being unpacked.
65-
#[derive(Clone, Copy, Debug)]
63+
#[derive(Clone, Copy, Debug, Hash)]
6664
pub(crate) enum UnpackValue<'db> {
6765
/// An iterable expression like the one in a `for` loop or a comprehension.
6866
Iterable(Expression<'db>),

0 commit comments

Comments
 (0)