feat(syntax): a closure binds a var parameter #161
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/156-closure-var-parameter"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #156
Task
Issue #156: a closure binds a
varparameter (CONCURRENCY gap 5 / ECS gap 4, slice F), picked up by the torbscript project loop on 2026-10-07.What
varin front of a closure parameter name,{ var point => ... }and{ var point, scale => ... }. The parenthesized form{ (var point, scale) => ... }named in the issue is a parse error with a message that points to the unparenthesized form.var(by-reference convention of(var value: T) => Void); the write goes to the caller's value. The existing escape rule (BACKEND 5.8) refuses storing, returning orspawn-capturing avarparameter. Avarmismatch is an error that names thevarside, without a second "is a const" error on top.compiler/srcandstd/do not use the new form.closure-var-parameter(native and VM; aforEach-style function takingbody: (var value: Point) => Void, called with a closure that captures a localFloat).Decisions for review
{ var point, scale => ... }is implemented.{ (var point, scale) => ... }from the issue is a clear parse error ("A closure writes its parameters without parentheses"): parentheses in a closure's parameter position read as a tuple pattern, which has novarin it, and a second spelling of the list would be new syntax. Say so if the issue's spelling should be accepted instead.varagainst a function type without it is an error, and so is the reverse for function values (a namedfn). A closure withoutvarstill adoptsvarfrom the expected function type (closures docs rule 3), so existing closures such aspoints.each { p => ... }keep working.Test
Ran in a
gcc:14container after rebootstrapping (seed -> torb -> torb, fixpoint holds):sh tools/gates.sh a: every gate green, includingdocs check,docs index --check,docs skill --check,docs site --check,test compiler/tests (native), std/example packages in both back ends,tests/languagein both back ends, andformat --check(after formatting two files).sh tools/check-commits.sh origin/main HEAD: green.gates.sh b) not run locally: no IR, back-end or runtime change; the conformance program is covered by CI.After merge
Nothing to release or deploy. A later use of the form inside
std/waits for a seed refresh (owner's call).varparameter (CONCURRENCY gap 5, part of slice F) #156CI red on
5510623:ci / tier A (linux-x64)(and the aggregategates). The tier A log ends with a runner abort (context canceledat 22:42:55, aftertests/command-line), not with a failing check, so this looks like a runner/infra cancel: please re-run it.Also, the PR is not mergeable:
mainmoved to1d6f50c(merge base is9e2ab91) and both sides touchdocs/design/CONCURRENCY.md. Rebase ontomain; the new head will need a green CI run before review.Changes requested on
5510623.mainmoved to1d6f50c(merge base is9e2ab91) and both sides touchdocs/design/CONCURRENCY.md. Rebase ontomainand resolve the conflict (rebase merge, linear history).ci / tier A (linux-x64)and the aggregategates. The tier A log ends with a runner abort (context canceledaftertests/command-line), not a failing check, so it likely clears on a re-run. The rebased head needs a fully green run before merge.Not reviewed in depth yet: the rebase changes the head, so the diff review (parser/checker/lowering/formatter/LSP tests, conformance program
closure-var-parameter, docs) happens on the new head. Decisions 1 and 2 in the PR body are accepted as the author's design rationale.551062315bd55c8d9c10Approved on
d55c8d9. Both earlier blockers are cleared: the PR is mergeable on currentmain(1d6f50c) and CI is fully green on this head (tier A,gates,pdisc, bootstrap; tier B is skipped by the repo rule because no ir/backend/runtime/tools change).closure-var-parameter. I checked the.expectedby hand against the program (and thetrb rundoc example, validated bydocs check, prints the same record format).varis parsed as part of the try, so{ var total = 0 ... }stays a closure body; both mismatch directions are covered; a mismatched closure keeps avarbinding so the body is not blamed twice.varparameter stays under the existing escape rule (stored, returned and spawn-captured cases tested).Non-blocking: tier B (including the new conformance program) does not run on this PR, so it first runs on the push to
main; I verified the expected output by hand.varparameter (CONCURRENCY gap 5, part of slice F) #156