Skip to content

Conversation

@xav-db
Copy link
Member

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

Greptile Overview

Greptile Summary

Fixed type checking for Count type in boolean expressions and added code generation support for WHERE clauses with multi-step traversals before property access (fixes #847).

Key Changes:

  • Type Analyzer: Added Type::Count case mapping to FieldType::I64 in traversal_validation.rs:888
  • Code Generator: Implemented pattern matching for traversals with 3+ steps ending in PropertyFetch/ReservedPropertyAccess + BoolOp in traversal_steps.rs:837-937
  • Test Coverage: Added comprehensive test suite covering ToN/FromN with ID access and property fetches

Implementation Details:
The new codegen handles patterns like _::ToN::ID::EQ(id) by:

  1. Extracting prefix traversal steps (e.g., _::ToN)
  2. Generating G::from_iter to execute the traversal chain
  3. Applying property access and boolean comparison on the resulting node

The code properly handles both reserved properties (ID, Label) and user-defined properties with appropriate getter methods.

Important Files Changed

Filename Overview
helix-db/src/helixc/analyzer/methods/traversal_validation.rs Added Type::Count case to map to FieldType::I64 in boolean expression type checking
helix-db/src/helixc/generator/traversal_steps.rs Added code generation for WHERE clauses with traversal steps before property access (fixes issue #847)
hql-tests/tests/where_traversal_property_access/queries.hx New test queries covering traversal property access patterns including ToN, FromN with ID and property fetches

Sequence Diagram

sequenceDiagram
    participant User as Query Code
    participant Parser as HQL Parser
    participant Analyzer as Type Analyzer
    participant Generator as Code Generator
    participant Runtime as Generated Rust Code

    User->>Parser: Parse WHERE clause with traversal
    Note over Parser: WHERE(_::ToN::ID::EQ(id))
    Parser->>Analyzer: Validate traversal steps
    
    alt Type::Count in boolean expression
        Analyzer->>Analyzer: Check expression type
        Note over Analyzer: (Type::Count, _) => FieldType::I64
        Analyzer->>Generator: Type validated as I64
    else Type::Boolean in boolean expression
        Analyzer->>Analyzer: Map to FieldType::Boolean
        Analyzer->>Generator: Type validated as Boolean
    else Type::Scalar in boolean expression
        Analyzer->>Analyzer: Use existing FieldType
        Analyzer->>Generator: Type validated
    end

    Generator->>Generator: Check pattern: steps > 2?
    alt Pattern: [...] + PropertyAccess + BoolOp
        Generator->>Generator: Extract prefix steps
        Generator->>Generator: Build traversal chain
        
        alt Case: ReservedPropertyAccess (ID/Label)
            Generator->>Runtime: Generate filter_ref with G::from_iter
            Note over Runtime: Access node.id() or node.label()
        else Case: PropertyFetch
            Generator->>Runtime: Generate filter_ref with get_property
            Note over Runtime: Access node.get_property(name)
        end
    else Simple 2-step pattern
        Generator->>Runtime: Use optimized short path
    end

    Runtime->>User: Return filtered results
Loading

@xav-db xav-db changed the base branch from main to dev February 5, 2026 16:33
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 5, 2026

Additional Comments (1)

helix-db/src/helixc/generator/traversal_steps.rs
Contains and IsIn on reserved properties might not work as expected - Contains expects a string method but ID values don't have string semantics, and is_in expects an array but the generated code directly appends the method call

@xav-db xav-db merged commit 3487a80 into dev Feb 6, 2026
29 checks passed
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