os: CurrentProcess identity, executable and working directory (OS slice 2, part 2) #251

Closed
opened 2026-10-09 06:16:20 +00:00 by orion · 5 comments
Collaborator

Goal

The first half of CurrentProcess (OS.md section 5.9): the facts about this process that are cheap to read, and the move of Process.executablePath() to CurrentProcess.executable(), which also makes macOS and FreeBSD answer. Split from #126 (OS slice 2) to keep each PR to one or two commits.

Source

Current state on main

  • std/os has Environment, System, Directories, Entropy, OsError and the per-system halves; there is no CurrentProcess.
  • Process.executablePath(): String? is a native of std/process (manifest row Process.executablePath in compiler/src/backend/c/natives.trb, C in runtime/process.c over runtime/platform.c; _NSGetExecutablePath is in runtime/os/macos.c). Callers: compiler/src/project/toolchain.trb, compiler/src/cli/run.trb, compiler/src/cli/host.trb, tools/registry/tests/*.test.trb, the VM (compiler/src/vm/interpret.trb).

Scope

CurrentProcess in std/os/src/process.trb, exported from std/os: identifier(), parentIdentifier(), executable(): Result<Path, OsError>, workingDirectory(): Result<Path, OsError> (through the same platform.c function File.absolutePath uses), uptime() (the runtime notes the monotonic clock before main). Process.executablePath() is removed once its callers are migrated. resources, processors and memoryLimit are the follow-up issue.

Acceptance criteria

  • CurrentProcess.identifier() equals the process id the system reports; parentIdentifier() is a positive id on Linux, macOS and Windows (test compares against a spawned child's report of its parent).
  • CurrentProcess.executable() is an absolute Path to an existing file on linux-x64, linux-arm64, macos-arm64 and windows-x64 (Linux /proc/self/exe, macOS _NSGetExecutablePath plus realpath, Windows GetModuleFileNameW, FreeBSD KERN_PROC_PATHNAME per OS.md; the FreeBSD C is compiled only on FreeBSD).
  • Inside the VM (torb run), executable() answers what Process.executablePath() answers there today (the entry file); a test runs under both the VM and --native.
  • workingDirectory() agrees with File.absolutePath(".").
  • uptime() is positive and not larger than the monotonic clock.
  • Process.executablePath is gone from std/process, the manifest, runtime/process.c and the docs; every caller uses CurrentProcess.executable(); torb still finds its std/ and runtime/ on a macOS build.
  • torb check --every-target std/os is clean (a gate of tools/gates.sh a); docs/standard-library/os.md and process.md are updated and skills/ regenerated.
  • CI coverage: linux-x64 runs the gates on the forge; windows-x64, linux-arm64 and macos-arm64 run the gates on the forge where a runner of that label is configured (TORB_RUNNERS) and otherwise on the portable workflow of the mirror. Every target is lowered by check --every-target on linux-x64.

Seed

Two commits, because the compiler itself calls the moved native. (1) Add CurrentProcess and its natives beside Process.executablePath (manifest rows for the new names; both forms work), then the seed is refreshed by the owner or the merge gate and the seed workflow publishes it. (2) Migrate the callers and remove Process.executablePath.

Size

One PR, two Conventional Commits (feat(os): ... then refactor(os): ...).

Dependencies

OS slice 1 (done). Blocks #252 for resources, processors, memoryLimit of CurrentProcess only in that both edit std/os/src/process.trb.

## Goal The first half of `CurrentProcess` (OS.md section 5.9): the facts about this process that are cheap to read, and the move of `Process.executablePath()` to `CurrentProcess.executable()`, which also makes macOS and FreeBSD answer. Split from #126 (OS slice 2) to keep each PR to one or two commits. ## Source - [OS.md section 5.9](https://git.torb.dev/torbscript/language/src/commit/9889e8f998db8d4289b23fe9ce9441607e986c2e/docs/design/OS.md#L1310) and section 6, "What moves" - [OS.md slice 2](https://git.torb.dev/torbscript/language/src/commit/9889e8f998db8d4289b23fe9ce9441607e986c2e/docs/design/OS.md#L1622) ## Current state on main - `std/os` has `Environment`, `System`, `Directories`, `Entropy`, `OsError` and the per-system halves; there is no `CurrentProcess`. - `Process.executablePath(): String?` is a native of `std/process` (manifest row `Process.executablePath` in `compiler/src/backend/c/natives.trb`, C in `runtime/process.c` over `runtime/platform.c`; `_NSGetExecutablePath` is in `runtime/os/macos.c`). Callers: `compiler/src/project/toolchain.trb`, `compiler/src/cli/run.trb`, `compiler/src/cli/host.trb`, `tools/registry/tests/*.test.trb`, the VM (`compiler/src/vm/interpret.trb`). ## Scope `CurrentProcess` in `std/os/src/process.trb`, exported from `std/os`: `identifier()`, `parentIdentifier()`, `executable(): Result<Path, OsError>`, `workingDirectory(): Result<Path, OsError>` (through the same `platform.c` function `File.absolutePath` uses), `uptime()` (the runtime notes the monotonic clock before `main`). `Process.executablePath()` is removed once its callers are migrated. `resources`, `processors` and `memoryLimit` are the follow-up issue. ## Acceptance criteria - [ ] `CurrentProcess.identifier()` equals the process id the system reports; `parentIdentifier()` is a positive id on Linux, macOS and Windows (test compares against a spawned child's report of its parent). - [ ] `CurrentProcess.executable()` is an absolute `Path` to an existing file on linux-x64, linux-arm64, macos-arm64 and windows-x64 (Linux `/proc/self/exe`, macOS `_NSGetExecutablePath` plus `realpath`, Windows `GetModuleFileNameW`, FreeBSD `KERN_PROC_PATHNAME` per OS.md; the FreeBSD C is compiled only on FreeBSD). - [ ] Inside the VM (`torb run`), `executable()` answers what `Process.executablePath()` answers there today (the entry file); a test runs under both the VM and `--native`. - [ ] `workingDirectory()` agrees with `File.absolutePath(".")`. - [ ] `uptime()` is positive and not larger than the monotonic clock. - [ ] `Process.executablePath` is gone from `std/process`, the manifest, `runtime/process.c` and the docs; every caller uses `CurrentProcess.executable()`; `torb` still finds its `std/` and `runtime/` on a macOS build. - [ ] `torb check --every-target std/os` is clean (a gate of `tools/gates.sh a`); `docs/standard-library/os.md` and `process.md` are updated and `skills/` regenerated. - [ ] CI coverage: linux-x64 runs the gates on the forge; windows-x64, linux-arm64 and macos-arm64 run the gates on the forge where a runner of that label is configured (`TORB_RUNNERS`) and otherwise on the portable workflow of the mirror. Every target is lowered by `check --every-target` on linux-x64. ## Seed Two commits, because the compiler itself calls the moved native. (1) Add `CurrentProcess` and its natives beside `Process.executablePath` (manifest rows for the new names; both forms work), then the seed is refreshed by the owner or the merge gate and the `seed` workflow publishes it. (2) Migrate the callers and remove `Process.executablePath`. ## Size One PR, two Conventional Commits (`feat(os): ...` then `refactor(os): ...`). ## Dependencies OS slice 1 (done). Blocks #252 for `resources`, `processors`, `memoryLimit` of `CurrentProcess` only in that both edit `std/os/src/process.trb`.
Author
Collaborator

[loop:torbscript] intake: in scope (author orion, label loop, split from #126), not a duplicate, no collision with a design record (OS.md 5.9). Body already carries goal, sources, criteria; #126 has landed. refine: ready as written, label set. Seed impact: see the body (the move of Process.executablePath follows the two-commit rule if a native goes).

[loop:torbscript] intake: in scope (author orion, label loop, split from #126), not a duplicate, no collision with a design record (OS.md 5.9). Body already carries goal, sources, criteria; #126 has landed. refine: ready as written, label set. Seed impact: see the body (the move of Process.executablePath follows the two-commit rule if a native goes).
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-20261009 until 2026-10-09T14:55Z

[loop:torbscript] claim implement by session:loop-torbscript-20261009 until 2026-10-09T14:55Z
Author
Collaborator

[loop:torbscript] implement: part 1 landed with PR #262 (approved and merged by argus, merge commit 9ea9bb27): CurrentProcess identifier, parentIdentifier, executable, workingDirectory, uptime. Part 2 (migrate the compiler's callers of Process.executablePath to CurrentProcess.executable() and remove the old native) follows the two-commit rule and needs a published seed that contains CurrentProcess. Claim released. next: waiting (seed with CurrentProcess, published by the owner) until 2026-10-10T04:00:00Z

[loop:torbscript] implement: part 1 landed with PR #262 (approved and merged by argus, merge commit 9ea9bb27): CurrentProcess identifier, parentIdentifier, executable, workingDirectory, uptime. Part 2 (migrate the compiler's callers of Process.executablePath to CurrentProcess.executable() and remove the old native) follows the two-commit rule and needs a published seed that contains CurrentProcess. Claim released. next: waiting (seed with CurrentProcess, published by the owner) until 2026-10-10T04:00:00Z
Author
Collaborator

[loop:torbscript] claim implement by session:loop-torbscript-20261010 until 2026-10-10T15:40Z (unblocked: the published seed torb-seed-5f22f071d02f of nightly-20261010 postdates the part 1 commit)

[loop:torbscript] claim implement by session:loop-torbscript-20261010 until 2026-10-10T15:40Z (unblocked: the published seed torb-seed-5f22f071d02f of nightly-20261010 postdates the part 1 commit)
Author
Collaborator

[loop:torbscript] implement: part 2 in PR #304 (one commit refactor(os): ..., head 11be6846): every caller of Process.executablePath (toolchain search, torb run key, script host key, debug adapter, registry tests, one conformance program) now calls CurrentProcess.executable(); Process.executablePath is removed from std/process, the manifest, runtime/process.c, torb.h and the VM substitute; torb_natives.h and machine_natives.c regenerated by hand (one thunk out, renumbered, count 258; the compiler tests compare them with torb natives --header); conformance process-executable-path folded into current-process; docs (process.md, os.md, torb-run.md, OS.md, VM.md, RELEASE.md fact 5, runtime/README.md) and the skill references updated. No local build (CI only); CI: commit messages and pdisc green, bootstrap and gates queued on the runners. Argus requested as reviewer. Est. token usage ~150k. Claim released. next: waiting (review by argus)

[loop:torbscript] implement: part 2 in PR https://git.torb.dev/torbscript/language/pulls/304 (one commit `refactor(os): ...`, head 11be6846): every caller of Process.executablePath (toolchain search, torb run key, script host key, debug adapter, registry tests, one conformance program) now calls CurrentProcess.executable(); Process.executablePath is removed from std/process, the manifest, runtime/process.c, torb.h and the VM substitute; torb_natives.h and machine_natives.c regenerated by hand (one thunk out, renumbered, count 258; the compiler tests compare them with `torb natives --header`); conformance process-executable-path folded into current-process; docs (process.md, os.md, torb-run.md, OS.md, VM.md, RELEASE.md fact 5, runtime/README.md) and the skill references updated. No local build (CI only); CI: commit messages and pdisc green, bootstrap and gates queued on the runners. Argus requested as reviewer. Est. token usage ~150k. Claim released. next: waiting (review by argus)
argus closed this issue 2026-10-10 11:04:44 +00:00
Sign in to join this conversation.
No labels
loop
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language#251
No description provided.