diff --git a/Cargo.lock b/Cargo.lock index 8c287a07cb..1a09eb3feb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2638,6 +2638,7 @@ dependencies = [ "ruff_source_file", "ruff_text_size", "rustc-hash 2.0.0", + "salsa", "schemars", "serde", ] diff --git a/crates/red_knot_python_semantic/Cargo.toml b/crates/red_knot_python_semantic/Cargo.toml index ab4d63ddb2..c08323b170 100644 --- a/crates/red_knot_python_semantic/Cargo.toml +++ b/crates/red_knot_python_semantic/Cargo.toml @@ -13,7 +13,7 @@ license = { workspace = true } [dependencies] ruff_db = { workspace = true } ruff_index = { workspace = true } -ruff_python_ast = { workspace = true } +ruff_python_ast = { workspace = true, features = ["salsa"] } ruff_python_stdlib = { workspace = true } ruff_source_file = { workspace = true } ruff_text_size = { workspace = true } diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index f817e39e00..1216a3cc43 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -856,7 +856,7 @@ impl<'db> TypeInferenceBuilder<'db> { }; let function_ty = Type::FunctionLiteral(FunctionType::new( self.db, - name.id.clone(), + &*name.id, function_kind, definition, decorator_tys, @@ -965,7 +965,7 @@ impl<'db> TypeInferenceBuilder<'db> { let class_ty = Type::ClassLiteral(ClassType::new( self.db, - name.id.clone(), + &*name.id, definition, body_scope, maybe_known_class, diff --git a/crates/ruff_python_ast/Cargo.toml b/crates/ruff_python_ast/Cargo.toml index 0d9cbc490f..bb02ae8bb2 100644 --- a/crates/ruff_python_ast/Cargo.toml +++ b/crates/ruff_python_ast/Cargo.toml @@ -26,13 +26,20 @@ is-macro = { workspace = true } itertools = { workspace = true } memchr = { workspace = true } rustc-hash = { workspace = true } +salsa = { workspace = true, optional = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } [features] schemars = ["dep:schemars"] cache = ["dep:ruff_cache", "dep:ruff_macros"] -serde = ["dep:serde", "ruff_text_size/serde", "dep:ruff_cache", "compact_str/serde"] +serde = [ + "dep:serde", + "ruff_text_size/serde", + "dep:ruff_cache", + "compact_str/serde", +] +salsa = ["dep:salsa"] [lints] workspace = true diff --git a/crates/ruff_python_ast/src/name.rs b/crates/ruff_python_ast/src/name.rs index 58da7e1459..80ade84f41 100644 --- a/crates/ruff_python_ast/src/name.rs +++ b/crates/ruff_python_ast/src/name.rs @@ -205,6 +205,21 @@ impl schemars::JsonSchema for Name { } } +#[cfg(feature = "salsa")] +impl salsa::plumbing::interned::Lookup for &str { + fn hash(&self, h: &mut H) { + std::hash::Hash::hash(self, h); + } + + fn eq(&self, data: &Name) -> bool { + self == data + } + + fn into_owned(self) -> Name { + Name::new(self) + } +} + /// A representation of a qualified name, like `typing.List`. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct QualifiedName<'a>(SegmentsVec<'a>);