Skip to content

Conversation

@xav-db
Copy link
Member

@xav-db xav-db commented Feb 5, 2026

Fixes #847

Greptile Overview

Greptile Summary

Fixes Rust codegen failure for WHERE clauses with multi-step traversals before property access (e.g., _::ToN::ID::EQ(id)).

The existing code generation only handled 2-step patterns (property access + boolean operation), causing compilation failures when traversal steps like ToN or FromN preceded property access. This PR extends the pattern matching to handle 3+ step traversals by:

  • Detecting patterns with traversal prefix steps before property access and boolean operations
  • Generating filter_ref closures that use G::from_iter to execute the traversal chain before property evaluation
  • Supporting both ReservedPropertyAccess (ID, Label) and PropertyFetch (custom properties)
  • Preserving backwards compatibility with existing 2-step patterns through explicit length checks

The fix includes comprehensive test coverage for ToN, FromN traversals with various property types and regression tests for simple cases.

Important Files Changed

Filename Overview
helix-db/src/helixc/generator/traversal_steps.rs Added code generation support for multi-step traversal patterns with property access (e.g., _::ToN::ID::EQ(id)), extending existing 2-step pattern handling to 3+ steps
hql-tests/tests/where_traversal_property_access/queries.hx Comprehensive test coverage for the fix including ToN, FromN traversals with both reserved properties (ID) and custom properties, plus regression tests

Sequence Diagram

sequenceDiagram
    participant HQL as HQL Query Parser
    participant TGen as Traversal Code Generator
    participant WhereRef as WhereRef Display
    participant RustCode as Generated Rust Code
    
    Note over HQL,RustCode: Example: WHERE(_::ToN::ID::EQ(id))
    
    HQL->>TGen: Parse traversal steps<br/>[_, ToN, ID, EQ(id)]
    TGen->>WhereRef: Display WhereRef with traversal
    
    alt 2-step pattern (existing)
        Note over WhereRef: Pattern: _::ID::EQ(id)
        WhereRef->>WhereRef: Check traversal.steps.len() == 2
        WhereRef->>WhereRef: Extract ReservedPropertyAccess + BoolOp
        WhereRef->>RustCode: Generate filter_ref with direct val access
    else 3+ step pattern (NEW FIX)
        Note over WhereRef: Pattern: _::ToN::ID::EQ(id)
        WhereRef->>WhereRef: Check traversal.steps.len() > 2
        WhereRef->>WhereRef: Extract last step (BoolOp)
        WhereRef->>WhereRef: Extract second-last step (PropertyAccess/ReservedProp)
        WhereRef->>WhereRef: Extract prefix steps ([_, ToN])
        alt ReservedPropertyAccess (ID/Label)
            WhereRef->>RustCode: Generate filter_ref with:<br/>1. G::from_iter for traversal<br/>2. node.id()/label() access<br/>3. Boolean comparison
        else PropertyFetch ({property})
            WhereRef->>RustCode: Generate filter_ref with:<br/>1. G::from_iter for traversal<br/>2. node.get_property() access<br/>3. Boolean expression
        end
    else Fallback
        WhereRef->>RustCode: Generate unoptimized filter_ref
    end
    
    RustCode->>RustCode: Compile generated Rust code
Loading

@xav-db xav-db changed the title fix(hql): property access causing codeine failure fix(hql): property access causing codegen failure Feb 5, 2026
@xav-db xav-db merged commit cae4abb into dev Feb 5, 2026
26 checks passed
@xav-db xav-db deleted the fix-issue-847-property-access-causing-codegen-failure branch February 5, 2026 16:31
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