mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 11:14:38 +08:00
* Preserve explicit AST column locations through code generation Assisted-by: OpenAI Codex:model version unavailable * Remove obsolete location bindings after span migration Assisted-by: OpenAI Codex:model version unavailable * Propagate inconsistent AST span provenance without panicking Assisted-by: OpenAI Codex:model version unavailable * Preserve mapped positions when exporting optimized Pass nodes Assisted-by: OpenAI Codex:model version unavailable * Consolidate AST location regressions and satisfy strict compiler lints Assisted-by: OpenAI Codex:model version unavailable * Consolidate equivalent AST literal location cases Replace the six-way literal-only optimizer matrix with one optimized-AST round-trip, preserving all assertions. Keep the distinct normalized-range identity, explicit Pass provenance, and synthetic format-spec regressions. Validation: all four appended location cases passed using the verified final-f6a RustPython binary with unchanged native sources. Ran normal pre-commit hooks; no Cargo build or full cyclic snippet suite. Assisted-by: OpenAI Codex:model version unavailable * Reuse Ruff source locations in AST conversion Replace redundant PySourceLocation, Row, and Column wrappers with the compiler-core re-export of Ruff SourceLocation. Use UTF-8 byte coordinates and retain the empty-source fallback. Share the normalized range conversion while preserving caller validation and signed semantic metadata. Validation so far: independent source and boundary review, rustfmt, and git diff --check. Runtime validation follows after the shared build target is released. Assisted-by: OpenAI Codex:model version unavailable * Preserve the first AST preprocessing location error Share first-error recording between generated-node allocation and synthetic-pass coordinate overflow. Exercise both real compiler-state failure paths in both orders using one MAX_ID location entry. Validation: focused compiler-state regression, strict codegen all-target Clippy, unchanged full-source seals, rustfmt, and normal pre-commit hooks. No interpreter runtime or broad suite rerun for this error-only change. Assisted-by: OpenAI Codex:model version unavailable
41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
//! Explicit locations supplied by Python AST objects.
|
|
//!
|
|
//! Parser input continues to resolve its text ranges through the source file.
|
|
//! AST input needs node identity because absent columns and a real column zero
|
|
//! can produce the same normalized text range.
|
|
|
|
use ruff_python_ast::HasNodeIndex;
|
|
use ruff_text_size::TextRange;
|
|
use rustpython_compiler_core::{AstLocations, SourceLocationRange};
|
|
|
|
/// NONE is a shared placeholder and can never identify semantic coordinates.
|
|
pub(crate) fn node_location(
|
|
locations: &AstLocations,
|
|
node: &impl HasNodeIndex,
|
|
) -> Option<SourceLocationRange> {
|
|
locations.get(node.node_index().load().as_u32()?)
|
|
}
|
|
|
|
/// Navigation range and semantic coordinates must be saved/restored together.
|
|
#[derive(Clone, Copy, Debug)]
|
|
pub(crate) struct CompilerSourceSpan {
|
|
pub range: TextRange,
|
|
pub location: Option<SourceLocationRange>,
|
|
}
|
|
|
|
impl CompilerSourceSpan {
|
|
pub(crate) fn is_artificial(self) -> bool {
|
|
self.location.map_or_else(
|
|
|| self.range == TextRange::default(),
|
|
|location| location.line < 0,
|
|
)
|
|
}
|
|
|
|
pub(crate) const fn parsed(range: TextRange) -> Self {
|
|
Self {
|
|
range,
|
|
location: None,
|
|
}
|
|
}
|
|
}
|