mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-10 10:22:14 +00:00
[ty] Shrink size of AstNodeRef
(#20028)
## Summary Removes the `module_ptr` field from `AstNodeRef` in release mode, and change `NodeIndex` to a `NonZeroU32` to reduce the size of `Option<AstNodeRef<_>>` fields. I believe CI runs in debug mode, so this won't show up in the memory report, but this reduces memory by ~2% in release mode.
This commit is contained in:
parent
886c4e4773
commit
7abc41727b
648 changed files with 19641 additions and 20364 deletions
|
@ -1489,7 +1489,7 @@ pub fn pep_604_optional(expr: &Expr) -> Expr {
|
|||
op: Operator::BitOr,
|
||||
right: Box::new(Expr::NoneLiteral(ast::ExprNoneLiteral::default())),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
@ -1501,7 +1501,7 @@ pub fn pep_604_union(elts: &[Expr]) -> Expr {
|
|||
elts: vec![],
|
||||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
parenthesized: true,
|
||||
}),
|
||||
[Expr::Tuple(ast::ExprTuple { elts, .. })] => pep_604_union(elts),
|
||||
|
@ -1511,7 +1511,7 @@ pub fn pep_604_union(elts: &[Expr]) -> Expr {
|
|||
op: Operator::BitOr,
|
||||
right: Box::new(pep_604_union(std::slice::from_ref(elt))),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -1522,13 +1522,13 @@ pub fn typing_optional(elt: Expr, binding: Name) -> Expr {
|
|||
value: Box::new(Expr::Name(ast::ExprName {
|
||||
id: binding,
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
ctx: ExprContext::Load,
|
||||
})),
|
||||
slice: Box::new(elt),
|
||||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1541,19 +1541,19 @@ pub fn typing_union(elts: &[Expr], binding: Name) -> Expr {
|
|||
value: Box::new(Expr::Name(ast::ExprName {
|
||||
id: binding,
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
ctx: ExprContext::Load,
|
||||
})),
|
||||
slice: Box::new(Expr::Tuple(ast::ExprTuple {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
elts: elts.to_vec(),
|
||||
ctx: ExprContext::Load,
|
||||
parenthesized: false,
|
||||
})),
|
||||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1686,34 +1686,34 @@ mod tests {
|
|||
let name = Expr::Name(ExprName {
|
||||
id: "x".into(),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
ctx: ExprContext::Load,
|
||||
});
|
||||
let constant_one = Expr::NumberLiteral(ExprNumberLiteral {
|
||||
value: Number::Int(Int::from(1u8)),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
});
|
||||
let constant_two = Expr::NumberLiteral(ExprNumberLiteral {
|
||||
value: Number::Int(Int::from(2u8)),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
});
|
||||
let constant_three = Expr::NumberLiteral(ExprNumberLiteral {
|
||||
value: Number::Int(Int::from(3u8)),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
});
|
||||
let type_var_one = TypeParam::TypeVar(TypeParamTypeVar {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
bound: Some(Box::new(constant_one.clone())),
|
||||
default: None,
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
});
|
||||
let type_var_two = TypeParam::TypeVar(TypeParamTypeVar {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
bound: None,
|
||||
default: Some(Box::new(constant_two.clone())),
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
|
@ -1723,11 +1723,11 @@ mod tests {
|
|||
type_params: Some(Box::new(TypeParams {
|
||||
type_params: vec![type_var_one, type_var_two],
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
})),
|
||||
value: Box::new(constant_three.clone()),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
});
|
||||
assert!(!any_over_stmt(&type_alias, &|expr| {
|
||||
seen.borrow_mut().push(expr.clone());
|
||||
|
@ -1743,7 +1743,7 @@ mod tests {
|
|||
fn any_over_type_param_type_var() {
|
||||
let type_var_no_bound = TypeParam::TypeVar(TypeParamTypeVar {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
bound: None,
|
||||
default: None,
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
|
@ -1753,12 +1753,12 @@ mod tests {
|
|||
let constant = Expr::NumberLiteral(ExprNumberLiteral {
|
||||
value: Number::Int(Int::ONE),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
});
|
||||
|
||||
let type_var_with_bound = TypeParam::TypeVar(TypeParamTypeVar {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
bound: Some(Box::new(constant.clone())),
|
||||
default: None,
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
|
@ -1776,7 +1776,7 @@ mod tests {
|
|||
|
||||
let type_var_with_default = TypeParam::TypeVar(TypeParamTypeVar {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
default: Some(Box::new(constant.clone())),
|
||||
bound: None,
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
|
@ -1797,7 +1797,7 @@ mod tests {
|
|||
fn any_over_type_param_type_var_tuple() {
|
||||
let type_var_tuple = TypeParam::TypeVarTuple(TypeParamTypeVarTuple {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
default: None,
|
||||
});
|
||||
|
@ -1809,12 +1809,12 @@ mod tests {
|
|||
let constant = Expr::NumberLiteral(ExprNumberLiteral {
|
||||
value: Number::Int(Int::ONE),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
});
|
||||
|
||||
let type_var_tuple_with_default = TypeParam::TypeVarTuple(TypeParamTypeVarTuple {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
default: Some(Box::new(constant.clone())),
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
});
|
||||
|
@ -1834,7 +1834,7 @@ mod tests {
|
|||
fn any_over_type_param_param_spec() {
|
||||
let type_param_spec = TypeParam::ParamSpec(TypeParamParamSpec {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
default: None,
|
||||
});
|
||||
|
@ -1846,12 +1846,12 @@ mod tests {
|
|||
let constant = Expr::NumberLiteral(ExprNumberLiteral {
|
||||
value: Number::Int(Int::ONE),
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
});
|
||||
|
||||
let param_spec_with_default = TypeParam::TypeVarTuple(TypeParamTypeVarTuple {
|
||||
range: TextRange::default(),
|
||||
node_index: AtomicNodeIndex::dummy(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
default: Some(Box::new(constant.clone())),
|
||||
name: Identifier::new("x", TextRange::default()),
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue