[ty] Add environment variable to dump Salsa memory usage stats (#18928)

## Summary

Setting `TY_MEMORY_REPORT=full` will generate and print a memory usage
report to the CLI after a `ty check` run:

```
=======SALSA STRUCTS=======
`Definition`                                       metadata=7.24MB   fields=17.38MB  count=181062
`Expression`                                       metadata=4.45MB   fields=5.94MB   count=92804
`member_lookup_with_policy_::interned_arguments`   metadata=1.97MB   fields=2.25MB   count=35176
...
=======SALSA QUERIES=======
`File -> ty_python_semantic::semantic_index::SemanticIndex`
    metadata=11.46MB  fields=88.86MB  count=1638
`Definition -> ty_python_semantic::types::infer::TypeInference`
    metadata=24.52MB  fields=86.68MB  count=146018
`File -> ruff_db::parsed::ParsedModule`
    metadata=0.12MB   fields=69.06MB  count=1642
...
=======SALSA SUMMARY=======
TOTAL MEMORY USAGE: 577.61MB
    struct metadata = 29.00MB
    struct fields = 35.68MB
    memo metadata = 103.87MB
    memo fields = 409.06MB
```

Eventually, we should integrate these numbers into CI in some form. The
one limitation currently is that heap allocations in salsa structs (e.g.
interned values) are not tracked, but memoized values should have full
coverage. We may also want a peak memory usage counter (that accounts
for non-salsa memory), but that is relatively simple to profile manually
(e.g. `time -v ty check`) and would require a compile-time option to
avoid runtime overhead.
This commit is contained in:
Ibraheem Ahmed 2025-06-26 17:27:51 -04:00 committed by GitHub
parent a1579d82d0
commit 6f7b1c9bb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
79 changed files with 905 additions and 207 deletions

View file

@ -6,6 +6,7 @@ use crate::visitor::source_order::SourceOrderVisitor;
/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum Mod {
Module(crate::ModModule),
Expression(crate::ModExpression),
@ -120,6 +121,7 @@ impl Mod {
/// See also [stmt](https://docs.python.org/3/library/ast.html#ast.stmt)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum Stmt {
FunctionDef(crate::StmtFunctionDef),
ClassDef(crate::StmtClassDef),
@ -1292,6 +1294,7 @@ impl Stmt {
/// See also [expr](https://docs.python.org/3/library/ast.html#ast.expr)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum Expr {
BoolOp(crate::ExprBoolOp),
Named(crate::ExprNamed),
@ -2832,6 +2835,7 @@ impl Expr {
/// See also [excepthandler](https://docs.python.org/3/library/ast.html#ast.excepthandler)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum ExceptHandler {
ExceptHandler(crate::ExceptHandlerExceptHandler),
}
@ -2895,6 +2899,7 @@ impl ExceptHandler {
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum InterpolatedStringElement {
Interpolation(crate::InterpolatedElement),
Literal(crate::InterpolatedStringLiteralElement),
@ -3009,6 +3014,7 @@ impl InterpolatedStringElement {
/// See also [pattern](https://docs.python.org/3/library/ast.html#ast.pattern)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum Pattern {
MatchValue(crate::PatternMatchValue),
MatchSingleton(crate::PatternMatchSingleton),
@ -3399,6 +3405,7 @@ impl Pattern {
/// See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum TypeParam {
TypeVar(crate::TypeParamTypeVar),
TypeVarTuple(crate::TypeParamTypeVarTuple),
@ -4838,6 +4845,7 @@ impl TypeParam {
/// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod)
#[derive(Clone, Copy, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum ModRef<'a> {
Module(&'a crate::ModModule),
Expression(&'a crate::ModExpression),
@ -4884,6 +4892,7 @@ impl crate::HasNodeIndex for ModRef<'_> {
/// See also [stmt](https://docs.python.org/3/library/ast.html#ast.stmt)
#[derive(Clone, Copy, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum StmtRef<'a> {
#[is(name = "function_def_stmt")]
FunctionDef(&'a crate::StmtFunctionDef),
@ -5185,6 +5194,7 @@ impl crate::HasNodeIndex for StmtRef<'_> {
/// See also [expr](https://docs.python.org/3/library/ast.html#ast.expr)
#[derive(Clone, Copy, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum ExprRef<'a> {
#[is(name = "bool_op_expr")]
BoolOp(&'a crate::ExprBoolOp),
@ -5574,6 +5584,7 @@ impl crate::HasNodeIndex for ExprRef<'_> {
/// See also [excepthandler](https://docs.python.org/3/library/ast.html#ast.excepthandler)
#[derive(Clone, Copy, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum ExceptHandlerRef<'a> {
ExceptHandler(&'a crate::ExceptHandlerExceptHandler),
}
@ -5609,6 +5620,7 @@ impl crate::HasNodeIndex for ExceptHandlerRef<'_> {
}
#[derive(Clone, Copy, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum InterpolatedStringElementRef<'a> {
Interpolation(&'a crate::InterpolatedElement),
Literal(&'a crate::InterpolatedStringLiteralElement),
@ -5657,6 +5669,7 @@ impl crate::HasNodeIndex for InterpolatedStringElementRef<'_> {
/// See also [pattern](https://docs.python.org/3/library/ast.html#ast.pattern)
#[derive(Clone, Copy, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum PatternRef<'a> {
MatchValue(&'a crate::PatternMatchValue),
MatchSingleton(&'a crate::PatternMatchSingleton),
@ -5763,6 +5776,7 @@ impl crate::HasNodeIndex for PatternRef<'_> {
/// See also [type_param](https://docs.python.org/3/library/ast.html#ast.type_param)
#[derive(Clone, Copy, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum TypeParamRef<'a> {
TypeVar(&'a crate::TypeParamTypeVar),
TypeVarTuple(&'a crate::TypeParamTypeVarTuple),
@ -5819,6 +5833,7 @@ impl crate::HasNodeIndex for TypeParamRef<'_> {
/// A flattened enumeration of all AST nodes.
#[derive(Copy, Clone, Debug, is_macro::Is, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum AnyNodeRef<'a> {
ModModule(&'a crate::ModModule),
ModExpression(&'a crate::ModExpression),
@ -7418,6 +7433,7 @@ impl AnyNodeRef<'_> {
/// `AnyNodeRef` has top-level `AnyNodeRef::ModModule` and `AnyNodeRef::ModExpression`
/// variants.
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum AnyRootNodeRef<'a> {
Mod(&'a Mod),
Stmt(&'a Stmt),
@ -8935,6 +8951,7 @@ impl AnyNodeRef<'_> {
/// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ModModule {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -8943,6 +8960,7 @@ pub struct ModModule {
/// See also [Module](https://docs.python.org/3/library/ast.html#ast.Module)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ModExpression {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -8954,6 +8972,7 @@ pub struct ModExpression {
///
/// This type differs from the original Python AST, as it collapses the synchronous and asynchronous variants into a single type.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtFunctionDef {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -8968,6 +8987,7 @@ pub struct StmtFunctionDef {
/// See also [ClassDef](https://docs.python.org/3/library/ast.html#ast.ClassDef)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtClassDef {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -8980,6 +9000,7 @@ pub struct StmtClassDef {
/// See also [Return](https://docs.python.org/3/library/ast.html#ast.Return)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtReturn {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -8988,6 +9009,7 @@ pub struct StmtReturn {
/// See also [Delete](https://docs.python.org/3/library/ast.html#ast.Delete)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtDelete {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -8996,6 +9018,7 @@ pub struct StmtDelete {
/// See also [TypeAlias](https://docs.python.org/3/library/ast.html#ast.TypeAlias)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtTypeAlias {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9006,6 +9029,7 @@ pub struct StmtTypeAlias {
/// See also [Assign](https://docs.python.org/3/library/ast.html#ast.Assign)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtAssign {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9015,6 +9039,7 @@ pub struct StmtAssign {
/// See also [AugAssign](https://docs.python.org/3/library/ast.html#ast.AugAssign)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtAugAssign {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9025,6 +9050,7 @@ pub struct StmtAugAssign {
/// See also [AnnAssign](https://docs.python.org/3/library/ast.html#ast.AnnAssign)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtAnnAssign {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9039,6 +9065,7 @@ pub struct StmtAnnAssign {
///
/// This type differs from the original Python AST, as it collapses the synchronous and asynchronous variants into a single type.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtFor {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9052,6 +9079,7 @@ pub struct StmtFor {
/// See also [While](https://docs.python.org/3/library/ast.html#ast.While)
/// and [AsyncWhile](https://docs.python.org/3/library/ast.html#ast.AsyncWhile).
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtWhile {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9062,6 +9090,7 @@ pub struct StmtWhile {
/// See also [If](https://docs.python.org/3/library/ast.html#ast.If)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtIf {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9075,6 +9104,7 @@ pub struct StmtIf {
///
/// This type differs from the original Python AST, as it collapses the synchronous and asynchronous variants into a single type.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtWith {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9085,6 +9115,7 @@ pub struct StmtWith {
/// See also [Match](https://docs.python.org/3/library/ast.html#ast.Match)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtMatch {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9094,6 +9125,7 @@ pub struct StmtMatch {
/// See also [Raise](https://docs.python.org/3/library/ast.html#ast.Raise)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtRaise {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9104,6 +9136,7 @@ pub struct StmtRaise {
/// See also [Try](https://docs.python.org/3/library/ast.html#ast.Try)
/// and [TryStar](https://docs.python.org/3/library/ast.html#ast.TryStar)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtTry {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9116,6 +9149,7 @@ pub struct StmtTry {
/// See also [Assert](https://docs.python.org/3/library/ast.html#ast.Assert)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtAssert {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9125,6 +9159,7 @@ pub struct StmtAssert {
/// See also [Import](https://docs.python.org/3/library/ast.html#ast.Import)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtImport {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9133,6 +9168,7 @@ pub struct StmtImport {
/// See also [ImportFrom](https://docs.python.org/3/library/ast.html#ast.ImportFrom)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtImportFrom {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9143,6 +9179,7 @@ pub struct StmtImportFrom {
/// See also [Global](https://docs.python.org/3/library/ast.html#ast.Global)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtGlobal {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9151,6 +9188,7 @@ pub struct StmtGlobal {
/// See also [Nonlocal](https://docs.python.org/3/library/ast.html#ast.Nonlocal)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtNonlocal {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9159,6 +9197,7 @@ pub struct StmtNonlocal {
/// See also [Expr](https://docs.python.org/3/library/ast.html#ast.Expr)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtExpr {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9167,6 +9206,7 @@ pub struct StmtExpr {
/// See also [Pass](https://docs.python.org/3/library/ast.html#ast.Pass)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtPass {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9174,6 +9214,7 @@ pub struct StmtPass {
/// See also [Break](https://docs.python.org/3/library/ast.html#ast.Break)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtBreak {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9181,6 +9222,7 @@ pub struct StmtBreak {
/// See also [Continue](https://docs.python.org/3/library/ast.html#ast.Continue)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtContinue {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9241,6 +9283,7 @@ pub struct StmtContinue {
/// [Escape kind]: crate::IpyEscapeKind
///
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StmtIpyEscapeCommand {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9250,6 +9293,7 @@ pub struct StmtIpyEscapeCommand {
/// See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprBoolOp {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9259,6 +9303,7 @@ pub struct ExprBoolOp {
/// See also [NamedExpr](https://docs.python.org/3/library/ast.html#ast.NamedExpr)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprNamed {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9268,6 +9313,7 @@ pub struct ExprNamed {
/// See also [BinOp](https://docs.python.org/3/library/ast.html#ast.BinOp)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprBinOp {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9278,6 +9324,7 @@ pub struct ExprBinOp {
/// See also [UnaryOp](https://docs.python.org/3/library/ast.html#ast.UnaryOp)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprUnaryOp {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9287,6 +9334,7 @@ pub struct ExprUnaryOp {
/// See also [Lambda](https://docs.python.org/3/library/ast.html#ast.Lambda)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprLambda {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9296,6 +9344,7 @@ pub struct ExprLambda {
/// See also [IfExp](https://docs.python.org/3/library/ast.html#ast.IfExp)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprIf {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9306,6 +9355,7 @@ pub struct ExprIf {
/// See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprDict {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9314,6 +9364,7 @@ pub struct ExprDict {
/// See also [Set](https://docs.python.org/3/library/ast.html#ast.Set)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprSet {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9322,6 +9373,7 @@ pub struct ExprSet {
/// See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprListComp {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9331,6 +9383,7 @@ pub struct ExprListComp {
/// See also [SetComp](https://docs.python.org/3/library/ast.html#ast.SetComp)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprSetComp {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9340,6 +9393,7 @@ pub struct ExprSetComp {
/// See also [DictComp](https://docs.python.org/3/library/ast.html#ast.DictComp)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprDictComp {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9350,6 +9404,7 @@ pub struct ExprDictComp {
/// See also [GeneratorExp](https://docs.python.org/3/library/ast.html#ast.GeneratorExp)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprGenerator {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9360,6 +9415,7 @@ pub struct ExprGenerator {
/// See also [Await](https://docs.python.org/3/library/ast.html#ast.Await)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprAwait {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9368,6 +9424,7 @@ pub struct ExprAwait {
/// See also [Yield](https://docs.python.org/3/library/ast.html#ast.Yield)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprYield {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9376,6 +9433,7 @@ pub struct ExprYield {
/// See also [YieldFrom](https://docs.python.org/3/library/ast.html#ast.YieldFrom)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprYieldFrom {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9384,6 +9442,7 @@ pub struct ExprYieldFrom {
/// See also [Compare](https://docs.python.org/3/library/ast.html#ast.Compare)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprCompare {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9394,6 +9453,7 @@ pub struct ExprCompare {
/// See also [Call](https://docs.python.org/3/library/ast.html#ast.Call)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprCall {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9410,6 +9470,7 @@ pub struct ExprCall {
///
/// See also [JoinedStr](https://docs.python.org/3/library/ast.html#ast.JoinedStr)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprFString {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9425,6 +9486,7 @@ pub struct ExprFString {
///
/// See also [TemplateStr](https://docs.python.org/3/library/ast.html#ast.TemplateStr)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprTString {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9434,6 +9496,7 @@ pub struct ExprTString {
/// An AST node that represents either a single-part string literal
/// or an implicitly concatenated string literal.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprStringLiteral {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9443,6 +9506,7 @@ pub struct ExprStringLiteral {
/// An AST node that represents either a single-part bytestring literal
/// or an implicitly concatenated bytestring literal.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprBytesLiteral {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9450,6 +9514,7 @@ pub struct ExprBytesLiteral {
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprNumberLiteral {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9457,6 +9522,7 @@ pub struct ExprNumberLiteral {
}
#[derive(Clone, Debug, PartialEq, Default)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprBooleanLiteral {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9464,12 +9530,14 @@ pub struct ExprBooleanLiteral {
}
#[derive(Clone, Debug, PartialEq, Default)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprNoneLiteral {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
}
#[derive(Clone, Debug, PartialEq, Default)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprEllipsisLiteral {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9477,6 +9545,7 @@ pub struct ExprEllipsisLiteral {
/// See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprAttribute {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9487,6 +9556,7 @@ pub struct ExprAttribute {
/// See also [Subscript](https://docs.python.org/3/library/ast.html#ast.Subscript)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprSubscript {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9497,6 +9567,7 @@ pub struct ExprSubscript {
/// See also [Starred](https://docs.python.org/3/library/ast.html#ast.Starred)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprStarred {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9506,6 +9577,7 @@ pub struct ExprStarred {
/// See also [Name](https://docs.python.org/3/library/ast.html#ast.Name)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprName {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9515,6 +9587,7 @@ pub struct ExprName {
/// See also [List](https://docs.python.org/3/library/ast.html#ast.List)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprList {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9524,6 +9597,7 @@ pub struct ExprList {
/// See also [Tuple](https://docs.python.org/3/library/ast.html#ast.Tuple)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprTuple {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9534,6 +9608,7 @@ pub struct ExprTuple {
/// See also [Slice](https://docs.python.org/3/library/ast.html#ast.Slice)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprSlice {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,
@ -9554,6 +9629,7 @@ pub struct ExprSlice {
/// For more information related to terminology and syntax of escape commands,
/// see [`StmtIpyEscapeCommand`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExprIpyEscapeCommand {
pub node_index: crate::AtomicNodeIndex,
pub range: ruff_text_size::TextRange,

View file

@ -3,6 +3,7 @@ use std::str::FromStr;
/// A Python integer literal. Represents both small (fits in an `i64`) and large integers.
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Int(Number);
impl FromStr for Int {
@ -216,6 +217,7 @@ impl From<u64> for Int {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
enum Number {
/// A "small" number that can be represented as an `u64`.
Small(u64),

View file

@ -10,6 +10,7 @@ use crate::generated::ExprName;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "cache", derive(ruff_macros::CacheKey))]
#[cfg_attr(feature = "salsa", derive(salsa::Update))]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Name(compact_str::CompactString);
impl Name {

View file

@ -19,7 +19,7 @@ where
///
/// This type is interiorly mutable to allow assigning node indices
/// on-demand after parsing.
#[derive(Default)]
#[derive(Default, get_size2::GetSize)]
pub struct AtomicNodeIndex(AtomicU32);
impl AtomicNodeIndex {
@ -41,6 +41,7 @@ impl AtomicNodeIndex {
/// A unique index for a node within an AST.
#[derive(PartialEq, Eq, Debug, PartialOrd, Ord, Clone, Copy, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct NodeIndex(u32);
impl NodeIndex {

View file

@ -47,6 +47,7 @@ impl StmtClassDef {
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ElifElseClause {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -133,6 +134,7 @@ impl ExprRef<'_> {
///
/// [1]: https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct DictItem {
pub key: Option<Expr>,
pub value: Expr,
@ -316,6 +318,7 @@ impl<'a> IntoIterator for &'a ExprSet {
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct InterpolatedStringFormatSpec {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -324,6 +327,7 @@ pub struct InterpolatedStringFormatSpec {
/// See also [FormattedValue](https://docs.python.org/3/library/ast.html#ast.FormattedValue)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct InterpolatedElement {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -335,6 +339,7 @@ pub struct InterpolatedElement {
/// An `FStringLiteralElement` with an empty `value` is an invalid f-string element.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct InterpolatedStringLiteralElement {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -357,6 +362,7 @@ impl Deref for InterpolatedStringLiteralElement {
/// Transforms a value prior to formatting it.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
#[repr(i8)]
#[expect(clippy::cast_possible_wrap)]
pub enum ConversionFlag {
@ -383,6 +389,7 @@ impl ConversionFlag {
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct DebugText {
/// The text between the `{` and the expression node.
pub leading: String,
@ -403,6 +410,7 @@ impl ExprFString {
/// The value representing an [`ExprFString`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct FStringValue {
inner: FStringValueInner,
}
@ -539,6 +547,7 @@ impl<'a> IntoIterator for &'a mut FStringValue {
/// An internal representation of [`FStringValue`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
enum FStringValueInner {
/// A single f-string i.e., `f"foo"`.
///
@ -552,6 +561,7 @@ enum FStringValueInner {
/// An f-string part which is either a string literal or an f-string.
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum FStringPart {
Literal(StringLiteral),
FString(FString),
@ -595,6 +605,7 @@ impl ExprTString {
/// The value representing an [`ExprTString`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TStringValue {
inner: TStringValueInner,
}
@ -717,6 +728,7 @@ impl<'a> IntoIterator for &'a mut TStringValue {
/// An internal representation of [`TStringValue`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
enum TStringValueInner {
/// A single t-string i.e., `t"foo"`.
///
@ -731,6 +743,7 @@ enum TStringValueInner {
/// An t-string part which is either a string literal, an f-string,
/// or a t-string.
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum TStringPart {
Literal(StringLiteral),
FString(FString),
@ -862,6 +875,8 @@ bitflags! {
}
}
impl get_size2::GetSize for InterpolatedStringFlagsInner {}
/// Flags that can be queried to obtain information
/// regarding the prefixes and quotes used for an f-string.
///
@ -879,6 +894,7 @@ bitflags! {
/// will properly handle nested f-strings. For usage that doesn't fit into one of these categories,
/// the public constructor [`FStringFlags::empty`] can be used.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct FStringFlags(InterpolatedStringFlagsInner);
impl FStringFlags {
@ -975,6 +991,7 @@ impl FStringFlags {
/// will properly handle nested t-strings. For usage that doesn't fit into one of these categories,
/// the public constructor [`TStringFlags::empty`] can be used.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TStringFlags(InterpolatedStringFlagsInner);
impl TStringFlags {
@ -1129,6 +1146,7 @@ impl fmt::Debug for TStringFlags {
/// An AST node that represents a single f-string which is part of an [`ExprFString`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct FString {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -1149,6 +1167,7 @@ impl From<FString> for Expr {
/// A newtype wrapper around a list of [`InterpolatedStringElement`].
#[derive(Clone, Default, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct InterpolatedStringElements(Vec<InterpolatedStringElement>);
impl InterpolatedStringElements {
@ -1209,6 +1228,7 @@ impl fmt::Debug for InterpolatedStringElements {
/// An AST node that represents a single t-string which is part of an [`ExprTString`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TString {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -1240,6 +1260,7 @@ impl ExprStringLiteral {
/// The value representing a [`ExprStringLiteral`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StringLiteralValue {
inner: StringLiteralValueInner,
}
@ -1397,6 +1418,7 @@ impl fmt::Display for StringLiteralValue {
/// An internal representation of [`StringLiteralValue`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
enum StringLiteralValueInner {
/// A single string literal i.e., `"foo"`.
Single(StringLiteral),
@ -1440,6 +1462,8 @@ bitflags! {
}
}
impl get_size2::GetSize for StringLiteralFlagsInner {}
/// Flags that can be queried to obtain information
/// regarding the prefixes and quotes used for a string literal.
///
@ -1453,6 +1477,7 @@ bitflags! {
/// handle surrounding f-strings. For usage that doesn't fit into one of these categories, the
/// public constructor [`StringLiteralFlags::empty`] can be used.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StringLiteralFlags(StringLiteralFlagsInner);
impl StringLiteralFlags {
@ -1581,6 +1606,7 @@ impl fmt::Debug for StringLiteralFlags {
/// An AST node that represents a single string literal which is part of an
/// [`ExprStringLiteral`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct StringLiteral {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -1637,6 +1663,7 @@ impl From<StringLiteral> for Expr {
/// An internal representation of [`StringLiteral`] that represents an
/// implicitly concatenated string.
#[derive(Clone)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
struct ConcatenatedStringLiteral {
/// The individual [`StringLiteral`] parts that make up the concatenated string.
strings: Vec<StringLiteral>,
@ -1689,6 +1716,7 @@ impl ExprBytesLiteral {
/// The value representing a [`ExprBytesLiteral`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct BytesLiteralValue {
inner: BytesLiteralValueInner,
}
@ -1817,6 +1845,7 @@ impl<'a> From<&'a BytesLiteralValue> for Cow<'a, [u8]> {
/// An internal representation of [`BytesLiteralValue`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
enum BytesLiteralValueInner {
/// A single-part bytestring literal i.e., `b"foo"`.
Single(BytesLiteral),
@ -1851,6 +1880,8 @@ bitflags! {
}
}
impl get_size2::GetSize for BytesLiteralFlagsInner {}
/// Flags that can be queried to obtain information
/// regarding the prefixes and quotes used for a bytes literal.
///
@ -1863,6 +1894,7 @@ bitflags! {
/// will properly handle surrounding f-strings. For usage that doesn't fit into one of these
/// categories, the public constructor [`BytesLiteralFlags::empty`] can be used.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct BytesLiteralFlags(BytesLiteralFlagsInner);
impl BytesLiteralFlags {
@ -1972,6 +2004,7 @@ impl fmt::Debug for BytesLiteralFlags {
/// An AST node that represents a single bytes literal which is part of an
/// [`ExprBytesLiteral`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct BytesLiteral {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2328,6 +2361,7 @@ impl From<TStringFlags> for AnyStringFlags {
}
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum Number {
Int(int::Int),
Float(f64),
@ -2395,6 +2429,7 @@ impl<'a> IntoIterator for &'a ExprTuple {
/// See also [expr_context](https://docs.python.org/3/library/ast.html#ast.expr_context)
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum ExprContext {
Load,
Store,
@ -2404,6 +2439,7 @@ pub enum ExprContext {
/// See also [boolop](https://docs.python.org/3/library/ast.html#ast.BoolOp)
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum BoolOp {
And,
Or,
@ -2426,6 +2462,7 @@ impl fmt::Display for BoolOp {
/// See also [operator](https://docs.python.org/3/library/ast.html#ast.operator)
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum Operator {
Add,
Sub,
@ -2527,6 +2564,7 @@ impl fmt::Display for Operator {
/// See also [unaryop](https://docs.python.org/3/library/ast.html#ast.unaryop)
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum UnaryOp {
Invert,
Not,
@ -2553,6 +2591,7 @@ impl fmt::Display for UnaryOp {
/// See also [cmpop](https://docs.python.org/3/library/ast.html#ast.cmpop)
#[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum CmpOp {
Eq,
NotEq,
@ -2607,6 +2646,7 @@ impl fmt::Display for CmpOp {
/// See also [comprehension](https://docs.python.org/3/library/ast.html#ast.comprehension)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Comprehension {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2618,6 +2658,7 @@ pub struct Comprehension {
/// See also [ExceptHandler](https://docs.python.org/3/library/ast.html#ast.ExceptHandler)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ExceptHandlerExceptHandler {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2628,6 +2669,7 @@ pub struct ExceptHandlerExceptHandler {
/// See also [arg](https://docs.python.org/3/library/ast.html#ast.arg)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Parameter {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2647,6 +2689,7 @@ impl Parameter {
/// See also [keyword](https://docs.python.org/3/library/ast.html#ast.keyword)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Keyword {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2656,6 +2699,7 @@ pub struct Keyword {
/// See also [alias](https://docs.python.org/3/library/ast.html#ast.alias)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Alias {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2665,6 +2709,7 @@ pub struct Alias {
/// See also [withitem](https://docs.python.org/3/library/ast.html#ast.withitem)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct WithItem {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2674,6 +2719,7 @@ pub struct WithItem {
/// See also [match_case](https://docs.python.org/3/library/ast.html#ast.match_case)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct MatchCase {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2751,6 +2797,7 @@ pub struct IrrefutablePattern {
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum IrrefutablePatternKind {
Name(Name),
Wildcard,
@ -2758,6 +2805,7 @@ pub enum IrrefutablePatternKind {
/// See also [MatchValue](https://docs.python.org/3/library/ast.html#ast.MatchValue)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternMatchValue {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2766,6 +2814,7 @@ pub struct PatternMatchValue {
/// See also [MatchSingleton](https://docs.python.org/3/library/ast.html#ast.MatchSingleton)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternMatchSingleton {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2774,6 +2823,7 @@ pub struct PatternMatchSingleton {
/// See also [MatchSequence](https://docs.python.org/3/library/ast.html#ast.MatchSequence)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternMatchSequence {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2782,6 +2832,7 @@ pub struct PatternMatchSequence {
/// See also [MatchMapping](https://docs.python.org/3/library/ast.html#ast.MatchMapping)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternMatchMapping {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2792,6 +2843,7 @@ pub struct PatternMatchMapping {
/// See also [MatchClass](https://docs.python.org/3/library/ast.html#ast.MatchClass)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternMatchClass {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2804,6 +2856,7 @@ pub struct PatternMatchClass {
///
/// Like [`Arguments`], but for [`PatternMatchClass`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternArguments {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2816,6 +2869,7 @@ pub struct PatternArguments {
///
/// Like [`Keyword`], but for [`PatternMatchClass`].
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternKeyword {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2825,6 +2879,7 @@ pub struct PatternKeyword {
/// See also [MatchStar](https://docs.python.org/3/library/ast.html#ast.MatchStar)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternMatchStar {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2833,6 +2888,7 @@ pub struct PatternMatchStar {
/// See also [MatchAs](https://docs.python.org/3/library/ast.html#ast.MatchAs)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternMatchAs {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2842,6 +2898,7 @@ pub struct PatternMatchAs {
/// See also [MatchOr](https://docs.python.org/3/library/ast.html#ast.MatchOr)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PatternMatchOr {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2868,6 +2925,7 @@ impl TypeParam {
/// See also [TypeVar](https://docs.python.org/3/library/ast.html#ast.TypeVar)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TypeParamTypeVar {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2878,6 +2936,7 @@ pub struct TypeParamTypeVar {
/// See also [ParamSpec](https://docs.python.org/3/library/ast.html#ast.ParamSpec)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TypeParamParamSpec {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2887,6 +2946,7 @@ pub struct TypeParamParamSpec {
/// See also [TypeVarTuple](https://docs.python.org/3/library/ast.html#ast.TypeVarTuple)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TypeParamTypeVarTuple {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2896,6 +2956,7 @@ pub struct TypeParamTypeVarTuple {
/// See also [decorator](https://docs.python.org/3/library/ast.html#ast.decorator)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Decorator {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -2970,6 +3031,7 @@ impl Ranged for AnyParameterRef<'_> {
/// NOTE: This type differs from the original Python AST. See: [arguments](https://docs.python.org/3/library/ast.html#ast.arguments).
#[derive(Clone, Debug, PartialEq, Default)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Parameters {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -3189,6 +3251,7 @@ impl<'a> IntoIterator for &'a Box<Parameters> {
/// NOTE: This type is different from original Python AST.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct ParameterWithDefault {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -3233,6 +3296,7 @@ impl ParameterWithDefault {
/// typically used for `metaclass`, with any additional arguments being passed to the `metaclass`.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Arguments {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -3383,6 +3447,7 @@ impl Arguments {
/// the `T`, `U`, and `V` type parameters in the order they appear in the source code.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct TypeParams {
pub range: TextRange,
pub node_index: AtomicNodeIndex,
@ -3406,6 +3471,7 @@ pub type Suite = Vec<Stmt>;
///
/// [IPython Syntax]: https://github.com/ipython/ipython/blob/635815e8f1ded5b764d66cacc80bbe25e9e2587f/IPython/core/inputtransformer2.py#L335-L343
#[derive(PartialEq, Eq, Debug, Clone, Hash, Copy)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum IpyEscapeKind {
/// Send line to underlying system shell (`!`).
Shell,
@ -3497,6 +3563,7 @@ impl IpyEscapeKind {
/// ...
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct Identifier {
pub id: Name,
pub range: TextRange,
@ -3572,6 +3639,7 @@ impl From<Identifier> for Name {
}
#[derive(Clone, Copy, Debug, Hash, PartialEq)]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub enum Singleton {
None,
True,

View file

@ -5,6 +5,7 @@ use std::{fmt, str::FromStr};
/// N.B. This does not necessarily represent a Python version that we actually support.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "cache", derive(ruff_macros::CacheKey))]
#[cfg_attr(feature = "get-size", derive(get_size2::GetSize))]
pub struct PythonVersion {
pub major: u8,
pub minor: u8,