Skip to content

Conversation

@Ericson2314
Copy link
Member

Motivation

This probably isn't much of a perf gain, but it does mean we are completely rid of non-length prefixed strings. That allows us to delete some code.

Context

Depends on #14442


Add 👍 to pull requests you find important.

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

@Ericson2314 Ericson2314 requested a review from xokdvium November 10, 2025 06:34
@Ericson2314 Ericson2314 marked this pull request as ready for review November 10, 2025 06:34
@github-actions github-actions bot added new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger c api Nix as a C library with a stable interface labels Nov 10, 2025
@dpulls
Copy link

dpulls bot commented Nov 10, 2025

🎉 All dependencies have been resolved !

.args = {},
.arity = (size_t) arity,
.doc = doc,
.doc = &nix::StringData::make(doc),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a reference to a local temporary StringData which promptly becomes a dangling pointer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is turning a reference into a pointer, and the reference is to a freshly heap-allocated thing, so actually it is fine.

(It errs on the side of leaking without GC, not on the side of the lifetime being too short and getting heap corruption.)

* Optional free-form documentation about the primop.
*/
const char * doc = nullptr;
const StringData * doc = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrimOp is usually not traced, so these StringData would get collected and become a dangling reference.
It could be done by allocating the native primops on the heap or with traceable_allocator.

The C API does allocate them on the GC heap because I needed dynamically allocated ones for NixOps4, but the other, "static" primops will reference garbage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I made these all be statically allocated StringData with the _sds thing.

* Optional free-form documentation about the constant.
*/
const char * doc = nullptr;
const StringData * doc = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

* `null`.
*/
const char * doc;
const StringData & doc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be similar to the RootValue solution so that Doc can be manipulated as an idiomatic C++ object.

Trailing comma helps a lot.
This probably isn't much of a perf gain, but it does mean we are
completely rid of non-length prefixed strings. That allows us to delete
some code.
Now that it isn't just used for `Value`, it doesn't really belong in
there.

Rename `static-string-data.hh` to share the same prefix to keep them
close together when sorting lines, also.
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 new-cli Relating to the "nix" command repl The Read Eval Print Loop, "nix repl" command and debugger

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants