Skip to content

Add RustPython runtime AST fields#2

Merged
youknowone merged 1 commit into
mainfrom
runtime-field
Jun 25, 2026
Merged

Add RustPython runtime AST fields#2
youknowone merged 1 commit into
mainfrom
runtime-field

Conversation

@youknowone

@youknowone youknowone commented Jun 25, 2026

Copy link
Copy Markdown
Member

Summary

Test Plan

Summary by CodeRabbit

  • New Features

    • Added support for constant expressions across parsing, traversal, and comparison logic.
    • Expanded syntax handling for f-strings, t-strings, match patterns, and several statement forms with richer runtime-aware AST coverage.
  • Bug Fixes

    • Improved handling of boolean, None, and ellipsis-style constants in expression analysis and precedence detection.
    • Fixed source-order and transform traversal so constant expressions are processed consistently.
    • Updated relocation and parsing paths to preserve the new AST structure during edits and recovery.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The AST schema adds ConstantValue, ExprConstant, and runtime_* storage across statements, expressions, patterns, and modules. Parsers initialize the new fields, and visitors, helpers, precedence, relocation, and comparable-node code add handling for Expr::Constant.

Changes

Constant AST runtime support

Layer / File(s) Summary
AST field contracts
crates/ruff_python_ast/ast.toml, crates/ruff_python_ast/src/nodes.rs, crates/ruff_python_ast/generate.py, crates/ruff_python_ast/src/generated.rs
ConstantValue and the new runtime_* fields are declared across AST schema and generated node structs, and the generator prefix list is extended for ConstantValue.
Constant expression wrappers
crates/ruff_python_ast/src/generated.rs
ExprConstant is wired through the generated expression wrappers, refs, node kinds, accessors, and root-node conversion APIs.
Expression parser runtime data
crates/ruff_python_parser/src/parser/expression.rs, crates/ruff_python_parser/src/parser/helpers.rs, crates/ruff_python_parser/src/parser/recovery.rs
Expression parser paths initialize runtime_* fields for args, containers, strings, comparisons, and comprehensions, and constant literals are recognized in parser helpers and recovery.
Statements, module, and pattern runtime data
crates/ruff_python_parser/src/parser/mod.rs, crates/ruff_python_parser/src/parser/statement.rs, crates/ruff_python_parser/src/parser/pattern.rs
Module, statement, and pattern parsing paths initialize the corresponding runtime_* fields on bodies, decorators, targets, match patterns, parameters, and type parameters.
Constant-aware semantics
crates/ruff_python_ast/src/comparable.rs, crates/ruff_python_ast/src/helpers.rs, crates/ruff_python_ast/src/operator_precedence.rs, crates/ruff_python_ast/src/relocate.rs
Comparable and helper logic treat Expr::Constant and ConstantValue as literal-like values for comparison, hashing, truthiness, singleton detection, operator precedence, and relocation.
Traversal and visitor updates
crates/ruff_python_ast/src/node.rs, crates/ruff_python_ast/src/visitor.rs, crates/ruff_python_ast/src/visitor/source_order.rs, crates/ruff_python_ast/src/visitor/transformer.rs, crates/ruff_python_ast/src/generated.rs
Traversal code visits Expr::Constant and broadens struct patterns to ignore the added runtime_* fields in source-order, walker, and transformer paths.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I hopped through Expr::Constant with a twitching nose,
And tucked runtime_* carrots where the AST grows.
I nibbled truthiness, then bounded through the trees,
While visitors and parsers rustled in the breeze.
🐇✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch runtime-field

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone youknowone merged commit 3c1ab2d into main Jun 25, 2026
1 check was pending
@youknowone youknowone deleted the runtime-field branch June 25, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant