diff --git a/Cargo.lock b/Cargo.lock index 6e4c502f6c..55859345a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "adler2" @@ -3180,7 +3180,7 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "salsa" version = "0.21.1" -source = "git+https://github.com/salsa-rs/salsa.git?rev=7edce6e248f35c8114b4b021cdb474a3fb2813b3#7edce6e248f35c8114b4b021cdb474a3fb2813b3" +source = "git+https://github.com/salsa-rs/salsa.git?rev=4818b15f3b7516555d39f5a41cb75970448bee4c#4818b15f3b7516555d39f5a41cb75970448bee4c" dependencies = [ "boxcar", "compact_str", @@ -3203,12 +3203,12 @@ dependencies = [ [[package]] name = "salsa-macro-rules" version = "0.21.1" -source = "git+https://github.com/salsa-rs/salsa.git?rev=7edce6e248f35c8114b4b021cdb474a3fb2813b3#7edce6e248f35c8114b4b021cdb474a3fb2813b3" +source = "git+https://github.com/salsa-rs/salsa.git?rev=4818b15f3b7516555d39f5a41cb75970448bee4c#4818b15f3b7516555d39f5a41cb75970448bee4c" [[package]] name = "salsa-macros" version = "0.21.1" -source = "git+https://github.com/salsa-rs/salsa.git?rev=7edce6e248f35c8114b4b021cdb474a3fb2813b3#7edce6e248f35c8114b4b021cdb474a3fb2813b3" +source = "git+https://github.com/salsa-rs/salsa.git?rev=4818b15f3b7516555d39f5a41cb75970448bee4c#4818b15f3b7516555d39f5a41cb75970448bee4c" dependencies = [ "heck", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 7461248654..f2a9343875 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -129,7 +129,7 @@ regex = { version = "1.10.2" } rustc-hash = { version = "2.0.0" } rustc-stable-hash = { version = "0.1.2" } # When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml` -salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "7edce6e248f35c8114b4b021cdb474a3fb2813b3" } +salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "4818b15f3b7516555d39f5a41cb75970448bee4c" } schemars = { version = "0.8.16" } seahash = { version = "4.1.0" } serde = { version = "1.0.197", features = ["derive"] } diff --git a/crates/ruff_db/src/files.rs b/crates/ruff_db/src/files.rs index 32bbc619f1..cae4b51853 100644 --- a/crates/ruff_db/src/files.rs +++ b/crates/ruff_db/src/files.rs @@ -275,7 +275,12 @@ impl fmt::Debug for Files { impl std::panic::RefUnwindSafe for Files {} /// A file that's either stored on the host system's file system or in the vendored file system. +/// +/// # Ordering +/// Ordering is based on the file's salsa-assigned id and not on its values. +/// The id may change between runs. #[salsa::input] +#[derive(PartialOrd, Ord)] pub struct File { /// The path of the file (immutable). #[returns(ref)] diff --git a/crates/ty_ide/src/lib.rs b/crates/ty_ide/src/lib.rs index 27eb0fbbc6..9d862abac4 100644 --- a/crates/ty_ide/src/lib.rs +++ b/crates/ty_ide/src/lib.rs @@ -13,11 +13,10 @@ pub use hover::hover; pub use inlay_hints::inlay_hints; pub use markup::MarkupKind; -use rustc_hash::FxHashSet; -use std::ops::{Deref, DerefMut}; - use ruff_db::files::{File, FileRange}; use ruff_text_size::{Ranged, TextRange}; +use rustc_hash::FxHashSet; +use std::ops::{Deref, DerefMut}; use ty_python_semantic::types::{Type, TypeDefinition}; /// Information associated with a text range. diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index efe9eaa9d0..95246a5121 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -335,7 +335,12 @@ pub use crate::types::definition::TypeDefinition; pub(crate) use todo_type; /// Represents an instance of `builtins.property`. +/// +/// # Ordering +/// Ordering is based on the property instance's salsa-assigned id and not on its values. +/// The id may change between runs, or when the property instance was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct PropertyInstanceType<'db> { getter: Option>, setter: Option>, @@ -438,6 +443,7 @@ impl Default for DataclassTransformerParams { } /// Representation of a type: a set of possible values at runtime. +/// #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, salsa::Update)] pub enum Type<'db> { /// The dynamic type: a statically unknown set of values @@ -5825,7 +5831,12 @@ pub enum TypeVarKind { /// typevar represents as an annotation: that is, an unknown set of objects, constrained by the /// upper-bound/constraints on this type var, defaulting to the default type of this type var when /// not otherwise bound to a type. +/// +/// # Ordering +/// Ordering is based on the type var instance's salsa-assigned id and not on its values. +/// The id may change between runs, or when the type var instance was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct TypeVarInstance<'db> { /// The name of this TypeVar (e.g. `T`) #[returns(ref)] @@ -6745,7 +6756,11 @@ impl<'db> OverloadedFunction<'db> { } } +/// # Ordering +/// Ordering is based on the function type's salsa-assigned id and not on its values. +/// The id may change between runs, or when the function type was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct FunctionType<'db> { /// Name of the function at definition. #[returns(ref)] @@ -7368,7 +7383,12 @@ impl KnownFunction { /// on an instance of a class. For example, the expression `Path("a.txt").touch` creates /// a bound method object that represents the `Path.touch` method which is bound to the /// instance `Path("a.txt")`. +/// +/// # Ordering +/// Ordering is based on the bounded method's salsa-assigned id and not on its values. +/// The id may change between runs, or when the bounded method was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct BoundMethodType<'db> { /// The function that is being bound. Corresponds to the `__func__` attribute on a /// bound method object @@ -7434,7 +7454,12 @@ impl<'db> BoundMethodType<'db> { /// It can be written in type expressions using `typing.Callable`. `lambda` expressions are /// inferred directly as `CallableType`s; all function-literal types are subtypes of a /// `CallableType`. +/// +/// # Ordering +/// Ordering is based on the callable type's salsa-assigned id and not on its values. +/// The id may change between runs, or when the callable type was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct CallableType<'db> { #[returns(deref)] signatures: Box<[Signature<'db>]>, @@ -7801,7 +7826,11 @@ pub enum WrapperDescriptorKind { PropertyDunderSet, } +/// # Ordering +/// Ordering is based on the module literal's salsa-assigned id and not on its values. +/// The id may change between runs, or when the module literal was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct ModuleLiteralType<'db> { /// The file in which this module was imported. /// @@ -7850,7 +7879,11 @@ impl<'db> ModuleLiteralType<'db> { } } +/// # Ordering +/// Ordering is based on the type alias's salsa-assigned id and not on its values. +/// The id may change between runs, or when the alias was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct PEP695TypeAliasType<'db> { #[returns(ref)] pub name: ast::name::Name, @@ -7876,7 +7909,11 @@ impl<'db> PEP695TypeAliasType<'db> { } } +/// # Ordering +/// Ordering is based on the type alias's salsa-assigned id and not on its values. +/// The id may change between runs, or when the alias was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct BareTypeAliasType<'db> { #[returns(ref)] pub name: ast::name::Name, @@ -8380,7 +8417,11 @@ impl<'db> IntersectionType<'db> { } } +/// # Ordering +/// Ordering is based on the string literal's salsa-assigned id and not on its value. +/// The id may change between runs, or when the string literal was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct StringLiteralType<'db> { #[returns(deref)] value: Box, @@ -8401,7 +8442,11 @@ impl<'db> StringLiteralType<'db> { } } +/// # Ordering +/// Ordering is based on the byte literal's salsa-assigned id and not on its value. +/// The id may change between runs, or when the byte literal was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct BytesLiteralType<'db> { #[returns(deref)] value: Box<[u8]>, @@ -8413,7 +8458,11 @@ impl<'db> BytesLiteralType<'db> { } } +/// # Ordering +/// Ordering is based on the tuple's salsa-assigned id and not on its elements. +/// The id may change between runs, or when the tuple was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct TupleType<'db> { #[returns(deref)] elements: Box<[Type<'db>]>, diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 544c0e4437..586823f039 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -157,7 +157,12 @@ impl CodeGeneratorKind { } /// A specialization of a generic class with a particular assignment of types to typevars. +/// +/// # Ordering +/// Ordering is based on the generic aliases's salsa-assigned id and not on its values. +/// The id may change between runs, or when the alias was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct GenericAlias<'db> { pub(crate) origin: ClassLiteral<'db>, pub(crate) specialization: Specialization<'db>, @@ -503,7 +508,12 @@ impl<'db> From> for Type<'db> { /// /// This does not in itself represent a type, but can be transformed into a [`ClassType`] that /// does. (For generic classes, this requires specializing its generic context.) +/// +/// # Ordering +/// Ordering is based on the class's id assigned by salsa and not on the class literal's values. +/// The id may change between runs, or when the class literal was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct ClassLiteral<'db> { /// Name of the class at definition #[returns(ref)] diff --git a/crates/ty_python_semantic/src/types/generics.rs b/crates/ty_python_semantic/src/types/generics.rs index aa7e8c3c3d..eae850bbce 100644 --- a/crates/ty_python_semantic/src/types/generics.rs +++ b/crates/ty_python_semantic/src/types/generics.rs @@ -18,7 +18,12 @@ use crate::{Db, FxOrderSet}; /// /// TODO: Handle nested generic contexts better, with actual parent links to the lexically /// containing context. +/// +/// # Ordering +/// Ordering is based on the context's salsa-assigned id and not on its values. +/// The id may change between runs, or when the context was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub struct GenericContext<'db> { #[returns(ref)] pub(crate) variables: FxOrderSet>, diff --git a/crates/ty_python_semantic/src/types/instance.rs b/crates/ty_python_semantic/src/types/instance.rs index d1ad4d47f9..e63a420cd1 100644 --- a/crates/ty_python_semantic/src/types/instance.rs +++ b/crates/ty_python_semantic/src/types/instance.rs @@ -160,7 +160,7 @@ impl<'db> From> for Type<'db> { /// A `ProtocolInstanceType` represents the set of all possible runtime objects /// that conform to the interface described by a certain protocol. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, salsa::Update)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, salsa::Update, PartialOrd, Ord)] pub struct ProtocolInstanceType<'db> { pub(super) inner: Protocol<'db>, diff --git a/crates/ty_python_semantic/src/types/protocol_class.rs b/crates/ty_python_semantic/src/types/protocol_class.rs index 43d7697b61..005ea95765 100644 --- a/crates/ty_python_semantic/src/types/protocol_class.rs +++ b/crates/ty_python_semantic/src/types/protocol_class.rs @@ -58,7 +58,11 @@ impl<'db> Deref for ProtocolClassLiteral<'db> { } } +/// # Ordering +/// Ordering is based on the protocol interface member's salsa-assigned id and not on its members. +/// The id may change between runs, or when the protocol instance members was garbage collected and recreated. #[salsa::interned(debug)] +#[derive(PartialOrd, Ord)] pub(super) struct ProtocolInterfaceMembers<'db> { #[returns(ref)] inner: BTreeMap>, diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 8f3f9ac97c..6eca245196 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -30,7 +30,7 @@ ty_python_semantic = { path = "../crates/ty_python_semantic" } ty_vendored = { path = "../crates/ty_vendored" } libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer", default-features = false } -salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "7edce6e248f35c8114b4b021cdb474a3fb2813b3" } +salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "4818b15f3b7516555d39f5a41cb75970448bee4c" } similar = { version = "2.5.0" } tracing = { version = "0.1.40" }