Skip to content

Adopt ref in Core.Iterate.Next#7381

Open
zygoloid wants to merge 10 commits into
carbon-language:trunkfrom
zygoloid:proposal-adopt-ref-in-core-iterate-next
Open

Adopt ref in Core.Iterate.Next#7381
zygoloid wants to merge 10 commits into
carbon-language:trunkfrom
zygoloid:proposal-adopt-ref-in-core-iterate-next

Conversation

@zygoloid

@zygoloid zygoloid commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Change the cursor parameter in Core.Iterate.Next to be a ref parameter
instead of a pointer parameter.

Assisted-by: Gemini via Antigravity

@zygoloid zygoloid added proposal A proposal proposal draft Proposal in draft, not ready for review labels Jun 17, 2026
@zygoloid zygoloid force-pushed the proposal-adopt-ref-in-core-iterate-next branch from 31b3b88 to 58eaf5a Compare June 17, 2026 21:56
zygoloid added 2 commits June 17, 2026 22:19
Also incorporate the description of `for` from carbon-language#1885 into the design,
suitably updated.
@zygoloid zygoloid force-pushed the proposal-adopt-ref-in-core-iterate-next branch from 58eaf5a to 5a31928 Compare June 17, 2026 22:19
@zygoloid zygoloid marked this pull request as ready for review June 17, 2026 22:26
@zygoloid zygoloid requested review from a team as code owners June 17, 2026 22:26
@zygoloid zygoloid requested review from KateGregory and geoffromer and removed request for a team June 17, 2026 22:26
@github-actions github-actions Bot added proposal rfc Proposal with request-for-comment sent out documentation An issue or proposed change to our documentation toolchain and removed proposal draft Proposal in draft, not ready for review labels Jun 17, 2026
Comment thread docs/design/control_flow/loops.md Outdated
Comment thread docs/design/control_flow/loops.md Outdated
Comment thread docs/design/control_flow/loops.md Outdated
Comment thread docs/design/control_flow/loops.md Outdated
Co-authored-by: Geoff Romer <gromer@google.com>
Comment thread docs/design/control_flow/loops.md Outdated
Comment thread docs/design/control_flow/loops.md
Co-authored-by: Richard Smith <richard@metafoo.co.uk>

@zygoloid zygoloid left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have modernized the desugaring, bringing it not to the present but to a little bit into the future. Hopefully that's not too distracting and the intent is clear?

@zygoloid zygoloid requested a review from geoffromer June 18, 2026 20:24
Comment thread docs/design/control_flow/loops.md Outdated
Comment thread docs/design/control_flow/loops.md Outdated
{
let range:? auto = <range>;
var cursor: auto = range.(Iterate.NewCursor)();
while (let .Some(<pattern>) = range.(Iterate.Next)(cursor)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm ambivalent about using if let in the desugaring when it's not proposed yet, and we don't even know what syntax we want (although I think I agree with your choice here). Does this solve any problems aside from making the code cleaner?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was trying to make this code ready for when we change the interface to be exttype-generic. Switched to a match to achieve this without using imaginary features :)

@zygoloid

Copy link
Copy Markdown
Contributor Author

Argh, this collided with #7350, which was incorporating the old for rules into the design. I've tried to resolve the conflicts, but just noting that I might have clobbered something from there that we want to keep, so I think the loops.md changes need a full re-review. (I'm also checking now...)

@zygoloid zygoloid requested a review from geoffromer June 18, 2026 22:41
ExecuteForBlock(iter.Get());
iter = container.(Iterate.Next)(ref cursor);
{
let range:? auto = <range>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I thought :? hadn't been through a proposal?

Should there be a TODO to more holistically revisit this with generics over extended types?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation An issue or proposed change to our documentation proposal rfc Proposal with request-for-comment sent out proposal A proposal toolchain

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants