Skip to content

Fix primop callsite parameter, const primop args - #16213

Merged
xokdvium merged 5 commits into
NixOS:masterfrom
roberth:feat-primop-callsite
Jul 31, 2026
Merged

Fix primop callsite parameter, const primop args#16213
xokdvium merged 5 commits into
NixOS:masterfrom
roberth:feat-primop-callsite

Conversation

@roberth

@roberth roberth commented Jul 25, 2026

Copy link
Copy Markdown
Member

Motivation

Fix a tech debt adjacent to a followup to my STF work.

The tech debt:

  • pos was always noPos in primop impls
  • we don't actually want to print those, but occasionally use it for other purposes anyway

The change is more of a three parter

  1. 1st commit eval.cc / eval.hh changes, see commit message
  2. 1st commit bulk changes
  3. 2nd commit showcasing a valid usage

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@roberth
roberth requested a review from edolstra as a code owner July 25, 2026 19:36
@github-actions github-actions Bot added with-tests Issues related to testing. PRs with tests have some priority c api Nix as a C library with a stable interface labels Jul 25, 2026
@roberth roberth added the error-messages Confusing messages and better diagnostics label Jul 25, 2026
@roberth
roberth force-pushed the feat-primop-callsite branch from bccc046 to 7e2fe1a Compare July 25, 2026 19:42
Comment thread src/libexpr/primops/fetchClosure.cc Outdated
@roberth
roberth force-pushed the feat-primop-callsite branch from 7e2fe1a to d9a851a Compare July 29, 2026 19:16
roberth added 5 commits July 30, 2026 01:22
The primop `pos` was always `noPos`. Give it a purpose again.

Since the call pos is already printed by the evaluator, it should
not be forwarded everywhere. That would only add noise.

Why was it `noPos`?

The `PosIdx pos` parameter of `PrimOpFun` was always `noPos` in practice.
`Value::determinePos` for `tPrimOp`/`tPrimOpApp` falls through to
`default: return pos` with `noPos` as the fallback, so `callFunction`'s
`vCur.determinePos(noPos)` unconditionally returned `noPos`.

Why `CallSite`?

Clean break with the mistaken `pos` parameter that didn't fit the usual
pattern.
Adds some friction and a place to explain the whole dynamic; see comment.

The interesting bits are `eval.cc`, `eval.hh`. The rest is just putting
`noPos` and `CallSite` everywhere.

Assisted-By: Claude Opus 4.8
A demonstration of how the primop callsite can be used productively; see
previous commit.

Assisted-By: Claude Opus 4.7, 4.8
builtins.break keeps an (empty) position, because runDebugRepl falls
back to the call site when the position is null, which would duplicate it.

Equivalent in most cases.

Assisted-By: Claude Opus 4.8
These helpers were only ever called with noPos. Useless and not worth
filling in because the position is already logged by the caller's caller.
See the two preceding commits for context.

Assisted-By: Claude Opus 4.8
The value pointers passed to a primop are never reassigned, so express that
in the type. This completes the FIXME left on `PrimOpFun` when `callFunction`
was tightened to `std::span<Value * const>`, and lets the `const_cast<Value **>`
at the primop call site be dropped.

Assisted-By: Claude Opus 4.8
@roberth
roberth force-pushed the feat-primop-callsite branch from d71a64f to 76112d5 Compare July 29, 2026 23:36
@roberth roberth changed the title Fix primop callsite parameter Fix primop callsite parameter, const primop args Jul 30, 2026
@roberth
roberth requested a review from xokdvium July 30, 2026 14:19
@xokdvium
xokdvium added this pull request to the merge queue Jul 31, 2026
Merged via the queue into NixOS:master with commit 4d229f1 Jul 31, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c api Nix as a C library with a stable interface error-messages Confusing messages and better diagnostics with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants