Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ty_python_semantic/src/diagnostic/levenshtein.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn substitution_cost(char_a: char, char_b: char) -> CharacterMatch {
}

/// The result of comparing two characters.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum CharacterMatch {
Exact,
CaseInsensitive,
Expand Down
1 change: 0 additions & 1 deletion crates/ty_python_semantic/src/semantic_index/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{

/// A cross-module identifier of a scope that can be used as a salsa query parameter.
#[salsa::tracked(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct ScopeId<'db> {
pub file: File,

Expand Down
81 changes: 7 additions & 74 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,7 @@ use crate::types::relation::{HasRelationToVisitor, IsDisjointVisitor, TypeRelati
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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct PropertyInstanceType<'db> {
getter: Option<Type<'db>>,
setter: Option<Type<'db>>,
Expand Down Expand Up @@ -532,7 +527,7 @@ bitflags! {
/// For the precise meaning of the fields, see [1].
///
/// [1]: https://docs.python.org/3/library/dataclasses.html
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DataclassFlags: u16 {
const INIT = 1 << 0;
const REPR = 1 << 1;
Expand Down Expand Up @@ -603,7 +598,6 @@ impl From<DataclassTransformerFlags> for DataclassFlags {
/// instance that we use as the return type of a `dataclasses.dataclass` and
/// dataclass-transformer decorator calls.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct DataclassParams<'db> {
flags: DataclassFlags,

Expand Down Expand Up @@ -7215,7 +7209,6 @@ impl<'db> TypeMapping<'_, 'db> {
/// sufficient. However, we currently think that tracked structs are unsound w.r.t. salsa cycles,
/// so out of an abundance of caution, we are interning the struct.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct InternedConstraintSet<'db> {
constraints: ConstraintSet<'db>,
}
Expand All @@ -7234,15 +7227,7 @@ impl get_size2::GetSize for InternedConstraintSet<'_> {}
/// are generally created by operations at runtime in some way, such as a type alias
/// statement, a typevar definition, or an instance of `Generic[T]` in a class's
/// bases list.
///
/// # Ordering
///
/// Ordering between variants is stable and should be the same between runs.
/// Ordering within variants is based on the wrapped data's salsa-assigned id and not on its values.
/// The id may change between runs, or when e.g. a `TypeVarInstance` was garbage-collected and recreated.
#[derive(
Copy, Clone, Debug, Eq, Hash, PartialEq, salsa::Update, Ord, PartialOrd, get_size2::GetSize,
)]
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, salsa::Update, get_size2::GetSize)]
pub enum KnownInstanceType<'db> {
/// The type of `Protocol[T]`, `Protocol[U, S]`, etc -- usually only found in a class's bases list.
///
Expand Down Expand Up @@ -7475,7 +7460,7 @@ impl<'db> KnownInstanceType<'db> {
/// (e.g. `Divergent` is assignable to `@Todo`, but `@Todo | Divergent` must not be reducted to `@Todo`).
/// Otherwise, type inference cannot converge properly.
/// For detailed properties of this type, see the unit test at the end of the file.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, salsa::Update)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Update)]
pub struct DivergentType {
/// The query ID that caused the cycle.
id: salsa::Id,
Expand Down Expand Up @@ -7899,7 +7884,6 @@ impl<'db> InvalidTypeExpression<'db> {

/// Data regarding a `warnings.deprecated` or `typing_extensions.deprecated` decorator.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct DeprecatedInstance<'db> {
/// The message for the deprecation
pub message: Option<StringLiteralType<'db>>,
Expand All @@ -7911,7 +7895,6 @@ impl get_size2::GetSize for DeprecatedInstance<'_> {}
/// Contains information about instances of `dataclasses.Field`, typically created using
/// `dataclasses.field()`.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct FieldInstance<'db> {
/// The type of the default value for this field. This is derived from the `default` or
/// `default_factory` arguments to `dataclasses.field()`.
Expand Down Expand Up @@ -8053,12 +8036,7 @@ impl<'db> TypeVarIdentity<'db> {
/// the typevar is defined and immediately bound to a single generic context. Just like in the
/// legacy case, we will create a `TypeVarInstance` and [`BoundTypeVarInstance`], and the type of
/// `T` at `[1]` and `[2]` will be that `TypeVarInstance` and `BoundTypeVarInstance`, respectively.
///
/// # 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct TypeVarInstance<'db> {
/// The identity of this typevar
pub(crate) identity: TypeVarIdentity<'db>,
Expand Down Expand Up @@ -8599,13 +8577,7 @@ pub struct BoundTypeVarIdentity<'db> {

/// A type variable that has been bound to a generic context, and which can be specialized to a
/// concrete type.
///
/// # Ordering
///
/// Ordering is based on the wrapped data's salsa-assigned id and not on its values.
/// The id may change between runs, or when e.g. a `BoundTypeVarInstance` was garbage-collected and recreated.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct BoundTypeVarInstance<'db> {
pub typevar: TypeVarInstance<'db>,
binding_context: BindingContext<'db>,
Expand Down Expand Up @@ -9159,12 +9131,7 @@ impl InferredAs {
/// Contains information about a `types.UnionType` instance built from a PEP 604
/// union or a legacy `typing.Union[…]` annotation in a value expression context,
/// e.g. `IntOrStr = int | str` or `IntOrStr = Union[int, str]`.
///
/// # 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct UnionTypeInstance<'db> {
/// The types of the elements of this union, as they were inferred in a value
/// expression context. For `int | str`, this would contain `<class 'int'>` and
Expand Down Expand Up @@ -9281,12 +9248,7 @@ impl<'db> UnionTypeInstance<'db> {
}

/// A salsa-interned `Type`
///
/// # 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct InternedType<'db> {
inner: Type<'db>,
}
Expand Down Expand Up @@ -10257,12 +10219,7 @@ impl From<bool> for Truthiness {
/// 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct BoundMethodType<'db> {
/// The function that is being bound. Corresponds to the `__func__` attribute on a
/// bound method object
Expand Down Expand Up @@ -10381,7 +10338,7 @@ impl<'db> BoundMethodType<'db> {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, get_size2::GetSize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, get_size2::GetSize)]
pub enum CallableTypeKind {
/// Represents regular callable objects.
Regular,
Expand Down Expand Up @@ -10409,12 +10366,7 @@ pub enum CallableTypeKind {
/// 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct CallableType<'db> {
#[returns(ref)]
pub(crate) signatures: CallableSignature<'db>,
Expand Down Expand Up @@ -10676,9 +10628,7 @@ impl<'db> CallableTypes<'db> {
///
/// Unlike bound methods of user-defined classes, these are not generally instances
/// of `types.BoundMethodType` at runtime.
#[derive(
Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, salsa::Update, get_size2::GetSize,
)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
pub enum KnownBoundMethodType<'db> {
/// Method wrapper for `some_function.__get__`
FunctionTypeDunderGet(FunctionType<'db>),
Expand Down Expand Up @@ -11111,9 +11061,7 @@ impl<'db> KnownBoundMethodType<'db> {
}

/// Represents a specific instance of `types.WrapperDescriptorType`
#[derive(
Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, salsa::Update, get_size2::GetSize,
)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, salsa::Update, get_size2::GetSize)]
pub enum WrapperDescriptorKind {
/// `FunctionType.__get__`
FunctionTypeDunderGet,
Expand Down Expand Up @@ -11202,11 +11150,7 @@ impl WrapperDescriptorKind {
}
}

/// # 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct ModuleLiteralType<'db> {
/// The imported module.
pub module: Module<'db>,
Expand Down Expand Up @@ -11365,11 +11309,7 @@ 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct PEP695TypeAliasType<'db> {
#[returns(ref)]
pub name: ast::name::Name,
Expand Down Expand Up @@ -11484,12 +11424,7 @@ impl<'db> PEP695TypeAliasType<'db> {
///
/// The value type is computed lazily via [`ManualPEP695TypeAliasType::value_type()`]
/// to avoid cycle non-convergence for mutually recursive definitions.
///
/// # 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct ManualPEP695TypeAliasType<'db> {
#[returns(ref)]
pub name: ast::name::Name,
Expand Down Expand Up @@ -11539,9 +11474,7 @@ impl<'db> ManualPEP695TypeAliasType<'db> {
}
}

#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, salsa::Update, get_size2::GetSize,
)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Update, get_size2::GetSize)]
pub enum TypeAliasType<'db> {
/// A type alias defined using the PEP 695 `type` statement.
PEP695(PEP695TypeAliasType<'db>),
Expand Down
42 changes: 2 additions & 40 deletions crates/ty_python_semantic/src/types/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,7 @@ impl<'db> CodeGeneratorKind<'db> {
}

/// 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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct GenericAlias<'db> {
pub(crate) origin: StaticClassLiteral<'db>,
pub(crate) specialization: Specialization<'db>,
Expand Down Expand Up @@ -400,17 +395,7 @@ impl<'db> VarianceInferable<'db> for GenericAlias<'db> {

/// A class literal, either defined via a `class` statement or a `type` function call.
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
salsa::Supertype,
salsa::Update,
get_size2::GetSize,
Clone, Copy, Debug, Eq, Hash, PartialEq, salsa::Supertype, salsa::Update, get_size2::GetSize,
)]
pub enum ClassLiteral<'db> {
/// A class defined via a `class` statement.
Expand Down Expand Up @@ -792,17 +777,7 @@ impl<'db> From<DynamicNamedTupleLiteral<'db>> for ClassLiteral<'db> {
/// Represents a class type, which might be a non-generic class, or a specialization of a generic
/// class.
#[derive(
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
salsa::Supertype,
salsa::Update,
get_size2::GetSize,
Clone, Copy, Debug, Eq, Hash, PartialEq, salsa::Supertype, salsa::Update, get_size2::GetSize,
)]
pub enum ClassType<'db> {
// `NonGeneric` is intended to mean that the `ClassLiteral` has no type parameters. There are
Expand Down Expand Up @@ -2089,12 +2064,7 @@ impl<'db> Field<'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, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct StaticClassLiteral<'db> {
/// Name of the class at definition
#[returns(ref)]
Expand Down Expand Up @@ -5039,7 +5009,6 @@ impl<'db> VarianceInferable<'db> for ClassLiteral<'db> {
/// - For dangling `type()` calls, a relative node offset anchored to the enclosing scope
/// provides stable identity that only changes when the scope itself changes.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct DynamicClassLiteral<'db> {
/// The name of the class (from the first argument to `type()`).
#[returns(ref)]
Expand Down Expand Up @@ -5612,7 +5581,6 @@ pub struct NamedTupleField<'db> {
///
/// The type of `Point` would be `type[Point]` where `Point` is a `DynamicNamedTupleLiteral`.
#[salsa::interned(debug, heap_size = ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct DynamicNamedTupleLiteral<'db> {
/// The name of the namedtuple (from the first argument).
#[returns(ref)]
Expand Down Expand Up @@ -6003,13 +5971,7 @@ pub enum DynamicNamedTupleAnchor<'db> {

/// A specification describing the fields of a dynamic `namedtuple`
/// or `NamedTuple` class.
///
/// # Ordering
///
/// Ordering is based on the spec's salsa-assigned id and not on its values.
/// The id may change between runs, or when the spec was garbage collected and recreated.
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct NamedTupleSpec<'db> {
#[returns(deref)]
pub(crate) fields: Box<[NamedTupleField<'db>]>,
Expand Down
Loading