Skip to content

Parse [runtime] with.toml keys (fiber_stack_size, fiber_pool_size) #403

Closed

Description

@ehartford

Summary

Parse the planned [runtime] with.toml keys for fiber stack and pool sizing and plumb them into program runtime initialization. The runtime has hardcoded defaults and test-only stack-size hooks today; project configuration can parse package/build/c_import settings but ignores [runtime]. This turns §14.19's planned surface into enforceable configuration.

Spec

§14.19 says stack sizing is implementation-defined configuration and calls out planned [runtime] with.toml keys. Requirements 14.19.1.5 and 14.19.1.36 track fiber_stack_size and fiber_pool_size.

[runtime]
fiber_stack_size = 131072
fiber_pool_size = 64

Current state

ProjectConfig has fields for package metadata, c_import paths, link paths, no_std/alloc/runtime booleans, and overflow mode, but no runtime stack/pool fields (src/compiler/ProjectConfig.w:5). project_config_apply_entry handles std, alloc, runtime, [build].overflow, [c_import].include_paths, [link].search_paths, and C deps only (src/compiler/ProjectConfig.w:114). project_config_wants_key likewise ignores [runtime] (src/compiler/ProjectConfig.w:249).

The runtime hardcodes stack size in platform cores (rt/fiber_core_darwin.w:27, rt/fiber_core_windows.w:26) and has pool counters/stack reuse internals (rt/fiber_core_darwin.w:66, rt/fiber_core_darwin.w:701; Windows mirrors this at rt/fiber_core_windows.w:65, rt/fiber_core_windows.w:700). with_fiber_spawn accepts an explicit stack-size parameter (rt/fiber_core_darwin.w:522, rt/fiber_core_windows.w:521), but project defaults are not configured.

Implementation plan

  1. Add runtime_fiber_stack_size and runtime_fiber_pool_size fields to ProjectConfig, with 0 meaning runtime default.
  2. Teach project_config_wants_key and project_config_apply_entry to accept [runtime] fiber_stack_size and fiber_pool_size, parse positive integer values, and produce manifest errors for invalid/negative/zero values as appropriate.
  3. Thread the config through CompilationConfig or a dedicated runtime-config object so check/build/run/test paths all see the same values.
  4. Add runtime functions in rt/fiber_core_darwin.w and rt/fiber_core_windows.w to set defaults before first fiber spawn. Do not mutate stack size after fibers exist unless the runtime loudly rejects it.
  5. Apply default stack size in with_fiber_spawn when the per-task @[stack_size] argument is zero; keep per-task stack size taking precedence.
  6. Implement pool-size limiting in the free-stack pool. fiber_pool_size = 0 should mean implementation default or unlimited; document the chosen meaning and test it.
  7. Update §14.19 wording from "planned" to normative when implementation lands.

Test plan

Add project-config tests with temporary with.toml fixtures:

  • valid [runtime] fiber_stack_size changes with_fiber_default_stack_size();
  • invalid string/negative/zero values produce a manifest error;
  • per-task @[stack_size] still overrides the project default.

Add behavior coverage for pool size using with_fiber_pool_allocs() / with_fiber_pool_reuses() (rt/fiber_core_darwin.w:701, rt/fiber_core_darwin.w:704) where those test hooks are available.

Acceptance criteria

  • [runtime] fiber_stack_size and fiber_pool_size are parsed from with.toml.
  • Invalid values fail loudly with manifest diagnostics.
  • Runtime defaults are applied before first fiber spawn and do not affect already-created fibers.
  • Existing @[stack_size] behavior remains higher priority.
  • with build && with build :fixpoint && with build :test pass.

Dependencies

Overlaps #501 for stack-pool test coverage.

Activity

  1. ehartford commented on Jun 11, 2026

    @ehartford
    ContributorAuthor

    Implemented in 913466f. [runtime] fiber_stack_size and fiber_pool_size now parse from with.toml, validate positive integer values, appear in project-info output, flow through sema into native and emit-C main wrappers, configure the async fiber runtime before init, preserve @[stack_size] priority, and cap the reusable fiber stack pool. Added positive runtime behavior coverage and negative manifest diagnostics. Also fixed the release embedded-runtime dependency so updated runtime objects are baked into the compiler binary. Verification passed on 2026-06-11: WITH=$PWD/out/bin/with ./out/bin/with build, WITH=$PWD/out/bin/with ./out/release/bin/with build :fixpoint, WITH=$PWD/out/bin/with ./out/release/bin/with build :test, and WITH=$PWD/out/bin/with ./out/release/bin/with build :test-green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions