Skip to content

🐛 make sure to propagate unwind outside scoped#1186

Merged
cowboyd merged 1 commit into
v4from
dont-swallow-scope-unwind
Jun 10, 2026
Merged

🐛 make sure to propagate unwind outside scoped#1186
cowboyd merged 1 commit into
v4from
dont-swallow-scope-unwind

Conversation

@cowboyd

@cowboyd cowboyd commented Jun 10, 2026

Copy link
Copy Markdown
Member

Motivation

Fix #1185.

If a routine was halted while suspended inside scoped(), code after yield* scoped(...) would still run.

iter.return() yielded the destroy() effects in scoped's finally, but the resume came back as iter.next() which takes the frame out of return-mode. trap() re-arms via trap.exit(); scoped() had no equivalent.

Fix: inline the Trap, run destroy() in critical() so cleanup completes, then yield trap.exit() to re-arm unwind based on the inner trap's outcome.

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/effection@1186

commit: 5779c0b

@codspeed-hq

codspeed-hq Bot commented Jun 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing dont-swallow-scope-unwind (5779c0b) with v4 (846b97e)

Open in CodSpeed

Fixes #1185. If a routine was halted while suspended inside
scoped(), code after yield* scoped(...) would still run.

iter.return() yielded the destroy() effects in scoped's finally,
but the resume came back as iter.next() — which takes the frame
out of return-mode. trap() re-arms via trap.exit(); scoped() had
no equivalent. Pre-d3266784 the Delimiter handled this with a
sticky "cancelling" state; the unify refactor lost it.

Fix: inline the Trap, run destroy() in critical() so cleanup
completes, then yield trap.exit() to re-arm unwind based on the
inner trap's outcome.
@cowboyd cowboyd marked this pull request as ready for review June 10, 2026 21:12
@cowboyd cowboyd force-pushed the dont-swallow-scope-unwind branch from 86c2842 to 5779c0b Compare June 10, 2026 21:13
@taras taras self-requested a review June 10, 2026 21:20

@taras taras left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Toight

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.

scoped() + race() prevents halt propagation in callcc resolution path

2 participants