Skip to content

Conversation

@TimWhiting
Copy link
Collaborator

Fixes #854, and addresses a few todos.
@daanx

Copilot AI review requested due to automatic review settings January 25, 2026 03:01
@TimWhiting TimWhiting force-pushed the improve-continuation-refcount branch from aa5b101 to afc2c13 Compare January 25, 2026 03:03
@TimWhiting TimWhiting force-pushed the improve-continuation-refcount branch from afc2c13 to 1cb40e8 Compare January 25, 2026 03:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refines continuation handling and reference counting for control handlers, specifically optimizing behavior when continuations are unique, and adds a regression test around refcounts. It addresses the leaked or stuck reference counts seen with complex effects (e.g., async) by improving how composed continuations and finalization prompts are managed.

Changes:

  • Optimize kcompose in lib/std/core/inline/hnd.c to detect unique continuation blocks and avoid unnecessary dup/drop operations, with tailored handling when yielding.
  • Rework the protect/protect2 logic in lib/std/core/hnd.kk to track finalization state via a new protect-state type and a new unsafe-st2 helper, improving correctness for resumptions and finalization under effects.
  • Add test/cgen/simple-refcount.kk (and .kk.out) to validate simple refcount behavior around a custom ctl effect and resumption pattern.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
lib/std/core/inline/hnd.c Adds uniqueness-aware path in kcompose to optimize composed continuation invocation and yielding.
lib/std/core/hnd.kk Introduces protect-state and unsafe-st2, and rewrites protect / protect2 / protect-prompt to correctly manage finalization and resumptions with effects.
test/cgen/simple-refcount.kk / .kk.out New cgen test verifying refcount evolution for a boxed value across effectful resumptions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Reference count never goes to 0 with complex effect (async)?

1 participant