Skip to content

Conversation

notdanilo
Copy link
Contributor

@notdanilo notdanilo commented Sep 24, 2025

Status Type ⚠️ Core Change Issue
Ready Feature Yes/No Link

Problem

Explicit lifetimes are required to deal with extra accounts but we don't want to expose lifetimes to people who are not 100% experienced with Rust.

Solution

Add implicit lifetimes.

Transform fn execute(ctx: Context<Components>, ...) to fn execute<'a, 'b, 'c, 'info>(ctx: Context<'a, 'b, 'c, 'info, Components<'info>>, ...)

Greptile Overview

Updated On: 2025-09-24 17:32:59 UTC

Summary

This PR implements implicit lifetimes for BOLT system execute functions, automatically transforming fn execute(ctx: Context<Components>, ...) to fn execute<'a, 'b, 'c, 'info>(ctx: Context<'a, 'b, 'c, 'info, Components<'info>>, ...) at compile time.

  • Added inject_lifetimes_and_context function that automatically injects the required lifetimes ('a, 'b, 'c, 'info) to execute functions
  • Transforms Context<Components> type to fully qualified Context<'a, 'b, 'c, 'info, Components<'info>> type
  • Updated escrow-funding example to demonstrate the simplified syntax without explicit lifetimes
  • Version bump to 0.2.5 in workspace dependencies

The transformation is handled intelligently by checking for existing lifetimes before adding new ones and properly handling both empty and populated generic argument lists. This significantly improves developer experience by hiding Rust lifetime complexity from users who don't need to deal with extra accounts.

Confidence Score: 4/5

  • This PR is safe to merge with low risk, implementing a well-structured compile-time transformation
  • The implementation is solid with proper error handling and checks for existing lifetimes. The transformation logic is comprehensive and the example demonstrates it working correctly. Minor deduction for complexity of AST manipulation code that could benefit from additional testing.
  • Pay close attention to crates/bolt-lang/attribute/system/src/lib.rs for the AST transformation logic

Important Files Changed

File Analysis

Filename        Score        Overview
crates/bolt-lang/attribute/system/src/lib.rs 4/5 Added inject_lifetimes_and_context function that automatically transforms Context to Context<'a, 'b, 'c, 'info, Components<'info>>
examples/escrow-funding/src/lib.rs 5/5 Simplified execute function signature by removing explicit lifetimes, demonstrating the new implicit lifetime feature
examples/system-simple-movement/Cargo.toml 5/5 Version bump from 0.2.4 to 0.2.5 to match workspace version

Sequence Diagram

sequenceDiagram
    participant Developer
    participant SystemMacro
    participant Extractor
    participant SystemTransform
    participant AST

    Developer->>SystemMacro: Write fn execute(ctx: Context<Components>, ...)
    SystemMacro->>Extractor: Extract component bundle info
    Extractor->>AST: Visit module and find Components struct
    Extractor-->>SystemMacro: Return field count and struct name
    
    SystemMacro->>SystemTransform: Transform execute function
    SystemTransform->>AST: Call visit_item_fn_mut for execute
    SystemTransform->>SystemTransform: Call inject_lifetimes_and_context
    
    SystemTransform->>AST: Check existing lifetimes ('a, 'b, 'c, 'info)
    SystemTransform->>AST: Add missing lifetimes to function generics
    SystemTransform->>AST: Extract Components type from Context<Components>
    SystemTransform->>AST: Transform to Context<'a, 'b, 'c, 'info, Components<'info>>
    
    SystemTransform-->>SystemMacro: Return transformed function
    SystemMacro-->>Developer: Output fn execute<'a, 'b, 'c, 'info>(ctx: Context<'a, 'b, 'c, 'info, Components<'info>>, ...)
Loading

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, no comments

Edit Code Review Bot Settings | Greptile

@notdanilo notdanilo force-pushed the feature/implicit-execute-lifetimes branch from c99f314 to 02a33f4 Compare September 24, 2025 17:52
@notdanilo notdanilo merged commit d210487 into main Sep 24, 2025
5 checks passed
@greptile-apps greptile-apps bot mentioned this pull request Sep 24, 2025
@notdanilo notdanilo deleted the feature/implicit-execute-lifetimes branch October 8, 2025 13:56
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