Skip to content

s2c: effect rows (E1) - #33

Merged
vic merged 2 commits into
mainfrom
e1-effect-rows
Nov 9, 2026
Merged

vic merged 2 commits into
mainfrom
e1-effect-rows

Conversation

@vic

@vic vic commented Nov 9, 2026

Copy link
Copy Markdown
Owner

E1 of the effects epic. A request names its protocol (Log.say(n)). No fn writes its effect row: the compiler infers it.

What changes

  • s2/eff.srs (new) computes each def's row with Datalog, in the same shape as s2/pure.srs. A request, a constructor (a request on Region), a written {} binder of a protocol, and the row of each callee add to the row. A handle removes its protocol from the row of the rest of its block.
  • The type checker gives each row protocol P an implicit capability eff.P. In C this is a param after the written capabilities (p_eff__P).
  • A request, a constructor and each inferred capability take the innermost handler in scope. Written {} binders keep the old rule: exactly one in scope.
  • A def named main gets no row. So an effect that would escape main is error[unhandled-effect] at the line that needs it.
  • Names declares P.op as a call name. Flow tracks a request as an op step on the innermost capability. Pure counts a row as an effect, so a spec def cannot call such a def.
  • The types test checks the self lib once, not three times (same output). This keeps it under its 1 s limit.

Tests

  • tests/s2/prog/eff_row.srs and tests/s2/prog/eff_inner.srs check inferred rows and the innermost handler.
  • tests/s2/neg/eff_unhandled.srs checks the escape errors in main at lines 19, 20 and 22.
  • tests/s2/neg/eff_pure.srs and tests/s2/neg/eff_flow.srs check purity and the protocol state of requests.
  • Local gate: 194 ok, 0 FAIL. Seven mutants, one per rule, are all killed.

Speed

tests/bench.sh on the frozen corpus: wall time ok. Instructions +1.0% (corpus-self) and +1.1% (corpus-tests), peak memory +1.1%. The script flags these as SLOWER. The cost is one Datalog solve over the whole program, about 38M instructions per run for the s2 sources. The baseline is not updated in this PR.

vic added 2 commits November 9, 2026 05:30
…'s row is inferred by Datalog (s2/eff.srs: requests, constructors as Region requests, explicit protocol binders, and callee rows minus handled scopes) and becomes implicit {eff.P} capabilities; requests, constructors and inferred caps take the innermost handler; a def named main gets no row, so an escaping effect is error[unhandled-effect]; Flow steps requests, Pure counts rows as effects; types test checks the self lib once
@vic
vic merged commit 7c6c91d into main Nov 9, 2026
3 checks passed
@vic
vic deleted the e1-effect-rows branch November 17, 2026 16:49
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