Skip to content

Conversation

@xav-db
Copy link
Member

@xav-db xav-db commented Nov 20, 2025

Description

Related Issues

Closes #

Checklist when merging to main

  • No compiler warnings (if applicable)
  • Code is formatted with rustfmt
  • No useless or dead code (if applicable)
  • Code is easy to understand
  • Doc comments are used for all functions, enums, structs, and fields (where appropriate)
  • All tests pass
  • Performance has not regressed (assuming change was not to fix a bug)
  • Version number has been updated in helix-cli/Cargo.toml and helixdb/Cargo.toml

Additional Notes

Greptile Overview

Greptile Summary

This PR fixes critical panic issues in HQL's EXISTS operation and field validation logic. The changes replace unsafe unwrap() calls with proper error handling using match statements.

Key Changes

  • Panic Prevention: Replaced .unwrap() calls with match statements in infer_expr_type.rs to gracefully handle missing schema fields/types instead of panicking
  • EXISTS Validation: Added validation to ensure identifiers used in EXISTS operations are either in scope or are query parameters (generates E301 error if not)
  • Code Generation Fix: Fixed EXISTS optimization in bool_ops.rs to only apply when source step is Identifier or Anonymous, preventing incorrect code generation
  • Test Coverage: Added comprehensive test case with cloud queries schema to verify EXISTS operation works correctly

Impact

The changes improve robustness by preventing runtime panics when users write queries with invalid field names or types that don't match the schema. Errors are now properly reported during compilation rather than causing panics.

Important Files Changed

File Analysis

Filename Score Overview
helix-db/src/helixc/analyzer/methods/infer_expr_type.rs 4/5 replaced unwrap() calls with proper match statements to prevent panics when fields/types don't exist in schema; added validation for EXISTS identifiers to ensure they exist in scope or are parameters
helix-db/src/helixc/generator/bool_ops.rs 5/5 added check to ensure EXISTS optimization only applies to Identifier/Anonymous source steps, preventing incorrect code generation
hql-tests/tests/cloud_queries_2/queries.hx 5/5 added test query for EXISTS operation with User node and github_id parameter

Sequence Diagram

sequenceDiagram
    participant User as HQL Query
    participant Analyzer as Type Inference Analyzer
    participant Validator as Field Validator
    participant Generator as Code Generator
    participant Schema as Schema Store
    
    User->>Analyzer: EXISTS(N<User>({github_id: github_id}))
    Analyzer->>Analyzer: infer_expr_type() for EXISTS
    Analyzer->>Validator: Check identifier in scope or param
    alt Identifier not in scope and not param
        Validator-->>Analyzer: Generate E301 error
    end
    Analyzer->>Schema: Get node_fields for User type
    alt Type doesn't exist
        Schema-->>Analyzer: None
        Note over Analyzer: Skip validation, error already generated
    else Type exists
        Schema-->>Analyzer: Some(fields)
        Analyzer->>Schema: Get field github_id
        alt Field doesn't exist
            Schema-->>Analyzer: None
            Note over Analyzer: Skip validation, error already generated
        else Field exists
            Schema-->>Analyzer: Some(field)
            Analyzer->>Validator: Validate value type matches field type
            alt Type mismatch
                Validator-->>Analyzer: Generate E205 error
            end
        end
    end
    Analyzer->>Generator: Generate traversal code
    Generator->>Generator: Check if optimization applies
    Note over Generator: Only optimize if source is<br/>Identifier or Anonymous
    Generator-->>User: Generated Rust code
Loading

@xav-db xav-db marked this pull request as ready for review November 20, 2025 23:16
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.

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@xav-db xav-db merged commit 096deac into dev Nov 21, 2025
19 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.

2 participants