Skip to content

Refactor SpanPair to preserve zero-length location semantics#45

Merged
ehwan merged 4 commits into
new_locationfrom
copilot/change-location-to-byte-pair
Jun 15, 2026
Merged

Refactor SpanPair to preserve zero-length location semantics#45
ehwan merged 4 commits into
new_locationfrom
copilot/change-location-to-byte-pair

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown

Please run scripts/bootstrap_test.sh and push all of the changes it make before making the PR.

This will run brief tests, and make it easier to look at what part of generated code has been changed.

SpanPair previously used Option<(usize, usize)>, which collapsed zero-length and missing-context cases. This change makes zero-length spans explicit as (pos, pos) so identical length can still carry distinct source positions.

  • Span storage model

    • Changed SpanPair.pair from Option<(usize, usize)> to (usize, usize).
    • Updated constructors/converters to operate on concrete ranges.
  • Zero-length position semantics

    • For len == 0, location now resolves to the end position of the most recent token as (e, e).
    • This preserves positional meaning for empty spans instead of erasing it.
  • Fallback behavior

    • When there is no stack context, fallback remains (0, 0).
    • Byte-range → Span conversion remains centralized via byte_range_to_span.
#[derive(Clone, Debug, Copy)]
pub struct SpanPair {
    /// zero-length spans are represented with equal values `(pos, pos)`.
    pub pair: (usize, usize),
}

if len == 0 {
    if let Some(after_pos) = stack.next() {
        let (_, e) = after_pos.pair;
        return SpanPair { pair: (e, e) };
    }
    return SpanPair::default();
}

Copilot AI changed the title Centralize byte-range→Span fallback through one global function Refactor SpanPair to preserve zero-length location semantics Jun 15, 2026
Copilot finished work on behalf of ehwan June 15, 2026 11:32
Copilot AI requested a review from ehwan June 15, 2026 11:32
@ehwan ehwan changed the base branch from main to new_location June 15, 2026 11:54
@ehwan ehwan marked this pull request as ready for review June 15, 2026 12:12
@ehwan ehwan merged commit bb50ea9 into new_location Jun 15, 2026
@ehwan ehwan deleted the copilot/change-location-to-byte-pair branch June 15, 2026 12:12
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.

2 participants