Skip to content

std.task: with_concurrency starts the work itself and bounds it (#981, D164) - #2751

Merged
ehartford merged 1 commit into
fix-2744from
fix-981
Oct 27, 2026
Merged

ehartford merged 1 commit into
fix-2744from
fix-981

Conversation

@ehartford

@ehartford ehartford commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

std.task: with_concurrency starts the work itself and bounds it (#981, D164)

with_concurrency(tasks, n) documented "at most n tasks at a time" and
its body was let _ = n; tasks (lib/std/task.w:227-230); the call did
not even compile ("return type mismatch" inside task.w). No
task-taking signature can mean what the doc said: a Task is already
running (§24.1). Measured on the task-taking draft, ids |> map(f)
started all 6 tasks under limits 2 and 1, and the lazy adapter spelling
does not type-check into impl IntoIter[Task[T]].

with_concurrency[I, T](inputs: impl IntoIter[I], n: isize, f: fn(I) -> Task[T]) -> List[T]
runs f over the inputs, calling f(input) — which spawns (#2748) —
only when a slot frees, and returns results in input order. n < 1 is
the same loud refusal await_first gives empty input. Docs follow:
lib/std/async/with_concurrency.md, lib/std/async/README.md, and the
migration guide's ids |> map(fetch_user) |> with_concurrency(10) |> await_all
becomes ids |> with_concurrency(10, fetch_user).

Test behav_981_with_concurrency_bounds_running_tasks (fails pre-fix:
"expects 2 argument(s), found 3"): squares of [6..1] in input order,
peak 2 running under limit 2, peak 1 under limit 1, empty input empty;
debug allocator leak count=0. Delegated under D98 as D164 (80%).

Ceremony found, not fixed here: an unannotated list literal through an
ordinary generic call binds its isize default before a later fn
argument's demand (map takes the demand; with_concurrency does
not), so the fixture annotates List[i32].

… D164)

`with_concurrency(tasks, n)` documented "at most n tasks at a time" and
its body was `let _ = n; tasks` (lib/std/task.w:227-230); the call did
not even compile ("return type mismatch" inside task.w). No
task-taking signature can mean what the doc said: a Task is already
running (§24.1). Measured on the task-taking draft, `ids |> map(f)`
started all 6 tasks under limits 2 and 1, and the lazy adapter spelling
does not type-check into `impl IntoIter[Task[T]]`.

`with_concurrency[I, T](inputs: impl IntoIter[I], n: isize, f: fn(I) -> Task[T]) -> List[T]`
runs `f` over the inputs, calling `f(input)` — which spawns (#2748) —
only when a slot frees, and returns results in input order. `n < 1` is
the same loud refusal `await_first` gives empty input. Docs follow:
lib/std/async/with_concurrency.md, lib/std/async/README.md, and the
migration guide's `ids |> map(fetch_user) |> with_concurrency(10) |> await_all`
becomes `ids |> with_concurrency(10, fetch_user)`.

Test behav_981_with_concurrency_bounds_running_tasks (fails pre-fix:
"expects 2 argument(s), found 3"): squares of [6..1] in input order,
peak 2 running under limit 2, peak 1 under limit 1, empty input empty;
debug allocator leak count=0. Delegated under D98 as D164 (80%).

Ceremony found, not fixed here: an unannotated list literal through an
ordinary generic call binds its isize default before a later fn
argument's demand (`map` takes the demand; `with_concurrency` does
not), so the fixture annotates `List[i32]`.
@ehartford
ehartford added this pull request to stack #2754 October 27, 2026 01:51
@ehartford ehartford changed the title fix 981 std.task: with_concurrency starts the work itself and bounds it (#981, D164) Oct 27, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on the stack top 3e1594f7d (stack #2754: #2750 #2751 #2752 #2753): tools/battery.w rc=0, wall 440s — gate, UAT and battery-checks all green (behavior-tests 1957 files ok; uat 12 pass, 1 skip; every survey "all targets green"). Each layer also passed src/main build :gate on its own commit before the stack battery (fix-2744, fix-981, fix-959b, fix-2530-diag, all rc=0 under the pinned seed). Merging the stack.

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