Skip to content

feature(semantic): Allow immediate consumption of ref self of tempraries.#9565

Merged
orizi merged 2 commits intomainfrom
orizi/01-29-feature_semantic_allow_immediate_consumption_of_ref_self_of_tempraries
Feb 1, 2026
Merged

feature(semantic): Allow immediate consumption of ref self of tempraries.#9565
orizi merged 2 commits intomainfrom
orizi/01-29-feature_semantic_allow_immediate_consumption_of_ref_self_of_tempraries

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 29, 2026

Summary

Added support for calling ref self methods on temporary expressions, allowing code like make_counter().increment() where increment takes ref self. This enables method chaining on temporary values that modify self.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

Previously, methods that take ref self could only be called on variables, not on temporary expressions. This limitation prevented method chaining for methods that modify self, requiring users to create intermediate variables. This change allows for more fluent API design where methods can modify state and return self for chaining.


What was the behavior or documentation before?

Code like make_counter().increment() would fail to compile if increment took ref self, with an error message indicating that ref arguments must be variables. This forced developers to use intermediate variables even for simple method chains.


What is the behavior or documentation after?

Methods that take ref self can now be called on temporary expressions, enabling patterns like:

make_counter().increment().increment()

This works by introducing a new TempReference variant for function call arguments that handles passing temporary expressions by reference.


Additional context

The implementation:

  1. Adds a new TempReference variant to ExprFunctionCallArg
  2. Restructures NamedArg to track when temporary references are allowed
  3. Updates the lowering pass to handle the new argument type
  4. Adds test cases to verify the functionality

This change only applies to ref self parameters in method calls, not to regular ref parameters in function calls, which still require variables.

@reviewable-StarkWare
Copy link

This change is Reviewable

@orizi orizi requested a review from TomerStarkware January 29, 2026 13:16
Copy link
Collaborator Author

orizi commented Jan 29, 2026

@orizi orizi marked this pull request as ready for review January 29, 2026 13:18
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44bc6d5525

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@orizi orizi force-pushed the orizi/01-29-feature_semantic_allow_immediate_consumption_of_ref_self_of_tempraries branch from 44bc6d5 to 06c3c66 Compare January 29, 2026 14:34
Copy link
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@orizi made 1 comment.
Reviewable status: 0 of 9 files reviewed, 1 unresolved discussion (waiting on @TomerStarkware).

Copy link
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@TomerStarkware reviewed 9 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi).

Copy link
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

@orizi resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @orizi).

@orizi orizi enabled auto-merge February 1, 2026 12:07
@orizi orizi added this pull request to the merge queue Feb 1, 2026
Merged via the queue into main with commit 96f609d Feb 1, 2026
55 checks passed
@orizi orizi deleted the orizi/01-29-feature_semantic_allow_immediate_consumption_of_ref_self_of_tempraries branch February 2, 2026 11:55
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.

3 participants