Skip to content

experimental/debug-coercions-as-xml - #111

Closed
MarcWeber wants to merge 1 commit into
NixOS:masterfrom
MarcWeber:submit/debug-coercions-as-xml
Closed

MarcWeber wants to merge 1 commit into
NixOS:masterfrom
MarcWeber:submit/debug-coercions-as-xml

Conversation

@MarcWeber

Copy link
Copy Markdown
Contributor

We're all pretty helpless seeing messages like:

value is an attribute set while a list was expected

This patch add the flag --xml-debug-coercion-failure
making nix output the xml representation of the attribute set.

Please not that this may fail if the thing to be coerced
cannot be turned into xml, eg because its evaluation does not end, eg due to
infinite recursion.

TODO: document this flag

Signed-off-by: Marc Weber [email protected]

We're all pretty helpless seeing messages like:

  value is an attribute set while a list was expected

This patch add the flag --xml-debug-coercion-failure
making nix output the xml representation of the attribute set.

Please not that this may fail if the thing to be coerced
cannot be turned into xml, eg because its evaluation does not end, eg due to
infinite recursion.

TODO: document this flag

Signed-off-by: Marc Weber <[email protected]>
@MarcWeber

Copy link
Copy Markdown
Contributor Author

Please have a look and tell me whether you're interested in this patch. Then I'm writing the documentation for it.

@MarcWeber MarcWeber closed this Dec 10, 2014
@MarcWeber
MarcWeber deleted the submit/debug-coercions-as-xml branch December 10, 2014 21:26
ConnorBaker pushed a commit to ConnorBaker/nix that referenced this pull request Jul 25, 2025
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 25, 2026
…caffold

prim_match and prim_split both fetched a compiled regex from the
EvalState regex cache and translated std::regex_error into a uniform
EvalError keyed on the regex source string. Two structurally distinct
post-match assemblies (regex_match vs cregex_iterator) sat between
the open-scaffold and the catch arm, but the scaffold itself was
duplicated verbatim — including the error_space special case for
libstdc++'s regex-state-limit memory exhaustion.

Extract a private withRegex<Body> template helper covering the
regex-fetch + try/catch only; pass the compiled `const std::regex &`
into the body callback. The two consumers' post-match assemblies
stay inline.

The helper takes the RegexCache by reference rather than reaching
through state.regexCache directly: regexCache is a private member of
EvalState, and the existing friend declarations on prim_match /
prim_split (in eval.hh) are unchanged. The friended primops fetch
*state.regexCache and pass it through. A future cleanup that lands a
public EvalState::compileRegex accessor — alongside NixOS#169's broader
EvalState friend-cluster reduction — would let the explicit cache
parameter collapse and the two friend declarations go away.

No behaviour change: error wording, error positions, regex caching
semantics, and the libstdc++-state-limit error_space arm all
preserved exactly.

Refs candidate NixOS#111. See also: NixOS#169 (the friend-cluster cleanup
that will make the explicit cache parameter unnecessary).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 25, 2026
…S#111 NixOS#76 + NixOS#229 doc-fix + NixOS#156 declined)

Sprint 1 targeted single-shard candidates that don't create
cross-shard dependencies. Five candidates evaluated; three
shipped, one already-shipped doc-fix, one declined-with-reason.

Shipped (three):

NixOS#87 (libexpr) — eager/lazy C-binding accessor pair dedup. The
six public symbols (nix_get_list_byidx{,_lazy},
nix_get_attr_byname{,_lazy}, nix_get_attr_byidx{,_lazy}) become
one-line wrappers around three file-static private impl helpers
selecting force=true or force=false. ABI unchanged.
nix_get_attr_byidx_lazy's "(Nix C API contract violation)"
error-message suffix is threaded through the impl as a parameter
rather than collapsed, preserving both error strings exactly.
libexpr commit 374e9db.

NixOS#111 (libexpr) — withRegex<Body> template helper extracting the
prim_match/prim_split regex-fetch + try/catch scaffold. The two
post-match assemblies (regex_match vs cregex_iterator) stay
inline. Helper takes a RegexCache& by reference rather than
reaching through state.regexCache directly, because that member
is private and the existing prim_match/prim_split friend
declarations cover only those two functions; the friended
primops fetch *state.regexCache and pass it through. A future
public EvalState::compileRegex accessor (alongside NixOS#169's
EvalState friend-cluster reduction) would let the explicit
cache parameter collapse and the two friend declarations go
away. Error wording, positions, and the libstdc++-state-limit
error_space arm preserved exactly. libexpr commit 4182720.

NixOS#76 (nix-cli) — walkClosure template helper deduplicating the
dotgraph/graphml BFS scaffold. New file-local
nix-store/closure-walk.hh; both consumers call walkClosure with
their own per-path and per-edge callbacks. Helper kept in
nix-store/ rather than promoted to libstore's store-api.hh per
the candidate's original sketch — that promotion would be a
cross-shard libstore change. Header-only template means no
meson.build edit. Output is byte-for-byte identical pre/post
for both formats. nix-cli commit 705114e.

Already shipped, doc-fix only:

NixOS#229 — parameterised SeenSet<T> on libexpr. Already shipped in
Batch E as commit 76b6808 ("libexpr/print: parameterise
SeenSet by element pointer type (NixOS#229)"). Branch line was
missing from the candidate body — same gap as Pass-1's six
missed Branch lines. Added.

Declined-with-reason:

NixOS#156 (libstore fan-out idiom dedup) — re-read in Sprint 1
showed the "shared" block is ~6 lines before two structurally
different doneFailure overload shapes diverge:
gaveUpOnSubstitution passes BuildError(Failure::DependencyFailed,
msg); resolveDerivation passes (ecFailed, BuildResult::Failure
struct). Extraction would be cosmetic — saves ~10 lines net but
doesn't unlock anything else. Skip-with-reason recorded; re-
evaluate when doneFailure's overloads unify or a third caller
adopts the same shape.

STATUS.md cleanup-branches table:
- libexpr tip moves to 4182720 (was 76b6808)
- nix-cli tip moves to 705114e (was 24ebbcc)
- Sprint-1 candidates appended to both row narratives
Current tip SHAs block also updated.

New "Sprint 1" recently-completed entry. Five other branches
unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Feature request or proposal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants