Integrate PR #667: Add .id() method for borrowed ID support #675
+225
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR integrates the fix from #667 into the arena-implementation branch. It adds an .id() method to the ID struct to resolve compilation errors when using AddE with borrowed IDs in FOR loops.
Changes
Technical Details
The helixc code generator consistently generates .id() calls to access ID values. Before this change, calling .id() on &ID (borrowed ID) would fail. This fix leverages Rust's auto-deref so both ID.id() and &ID.id() work seamlessly.
Testing
✅ cargo check --workspace passes
✅ All 27 ID struct unit tests pass
✅ New test case compiles successfully
Co-Authored-By: ishaksebsib
Greptile Overview
Updated On: 2025-10-29 11:46:27 UTC
Greptile Summary
This PR fixes a compilation error where AddE queries with borrowed ID references in FOR loops failed because
&IDdidn't have an.id()method. The solution adds an.id()method to the ID struct that returnsu128, leveraging Rust's auto-deref so bothID.id()and&ID.id()work seamlessly.Key Changes:
pub fn id(&self) -> u128method to ID struct inhelix-db/src/utils/id.rs:28-30.inner()method but provides the interface expected by code generatorhelix-db/src/helixc/analyzer/utils.rs:100generates{name}.id()calls for identifier referencesTechnical Context:
The helixc code generator's
gen_id_access_or_paramfunction consistently generates.id()calls to access ID values from identifiers. When iterating over arrays in FOR loops (likeFOR {from_id, to_id} IN edges), the variables are borrowed references (&ID). Before this change, calling.id()on&IDwould fail to compile. By adding the.id()method, Rust's auto-deref mechanism automatically handles both owned and borrowed cases.Important Files Changed
File Analysis
.id()method to ID struct returning u128, enabling both owned and borrowed IDs to work with code generatorSequence Diagram
sequenceDiagram participant User as HQL Query participant Parser as HQL Parser participant Analyzer as Semantic Analyzer participant CodeGen as Code Generator participant ID as ID Struct User->>Parser: AddE query with FOR loop Note over User: FOR {from_id, to_id} IN edges<br/>AddE::From(from_id)::To(to_id) Parser->>Analyzer: Parse AddE with identifiers Analyzer->>Analyzer: Validate identifiers in scope Note over Analyzer: from_id: &ID (borrowed from iteration) Analyzer->>CodeGen: gen_id_access_or_param(from_id) Note over CodeGen: Generates: from_id.id() CodeGen->>ID: Call .id() on &ID Note over ID: Before: &ID had no .id() method<br/>Compiler error: "no method named id" ID-->>CodeGen: After: auto-deref to ID.id() Note over ID: Rust auto-deref: &ID -> ID<br/>Returns u128 from self.0 CodeGen-->>Analyzer: GeneratedValue with u128 Analyzer-->>User: Compiled query code