Skip to content

evalArgAt, perform, do and init run their code as frames, so it can wait - #528

Merged
stevedekorte merged 1 commit into
masterfrom
eval-in-frame
Nov 20, 2026
Merged

stevedekorte merged 1 commit into
masterfrom
eval-in-frame

Conversation

@stevedekorte

Copy link
Copy Markdown
Member

Problem

A CFunction that evaluates Io code itself did so in a nested C eval loop, where a coroutine switch can't happen. In the browser that raises "can't wait or switch coroutines here". The plan listed this as "sortBy and similar", but a survey of about 50 constructs showed everyday ones were affected: map, perform, do, call evalArgAt, an object's init, repeat, select.

Change

IoState_evalInFrame_ turns the calling frame into a DO_EVAL frame for the code, the mechanism doMessage already used, with an optional fixed result (clone returns the new object after init; do returns self). It only applies when the primitive was activated straight from the eval loop; otherwise the old path runs.

Now using it: call evalArgAt, perform, performWithArgList, do, and the init that clone runs. List map, Map select and foreachSlot become waitable with them. doMessage, doString and doFile share the helper.

Still not waitable (listed in Plan.md as the next batch): repeat, List select/selectInPlace, Sequence foreach, the sortBy family, interpolate, lexicalDo.

Speed

Compared with a build of master on the same machine (ms, lower is better):

before after
clone with init, 500k 1269 622
perform, 500k 1632 1004
performWithArgList, 500k 1714 1085
list map, 5 x 200k 1851 1830
clone without init, do, evalArgAt within about 10% either way; single runs, so likely noise

Testing

  • New browser-module test covering nine constructs that wait.
  • return, break, continue and errors through these primitives give the same results as master (compared side by side).
  • make check 279 pass, make check-component pass, make check-browser-node 32 pass, Playwright suite 83 / 83 (run locally).

🤖 Generated with Claude Code

A CFunction that evaluates Io code itself did so in a nested C eval
loop, where a coroutine switch can't happen; in the browser that raises
"can't wait or switch coroutines here". IoState_evalInFrame_ turns the
calling frame into a DO_EVAL frame instead, optionally with a fixed
result (clone returns the new object after init, do returns self).

Used by: call evalArgAt, perform, performWithArgList, do, and the init
that clone runs. List map, Map select and foreachSlot become waitable
with them. doMessage, doString and doFile now share the helper.

No nested eval loop starts for these any more, so clone of an object
with an init is about 2x faster and perform about 1.6x.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@stevedekorte
stevedekorte merged commit 9a04ca6 into master Nov 20, 2026
1 check passed
@stevedekorte
stevedekorte deleted the eval-in-frame branch November 20, 2026 05:58
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