Commit graph

17833 commits

Author SHA1 Message Date
Silvan Mosberger
a6dccae223 Fix non-deterministic parser printing
In _very_ rare cases (I had about 7 cases out of 32200 files!),
the order of how inherit-from bindings are printed when using
`nix-instantiate --parse` gets messed up.

The cause of this seems to be because the std::map the bindings are
placed in is keyed on a _pointer_, which then uses an
[implementation-defined strict total order](https://en.cppreference.com/w/cpp/language/operator_comparison#Pointer_total_order).

The fix here is to key the bindings on their displacement instead,
which maintains the same order as they appear in the file.

Unfortunately I wasn't able to make a reproducible test for this in the
source, there's something about the local environment that makes it
unreproducible for me.

However I was able to make a reproducible test in a Nix build on a Nix
version from a very recent master:

    nix build github:infinisil/non-det-nix-parsing-repro

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2024-07-19 00:42:00 +02:00
John Ericson
463256b9e8
Merge pull request #11122 from L-as/fix-ub
Fix ub
2024-07-16 18:51:17 -04:00
Las Safin
a1f3f103bc
Check if drv is initialized in DerivationGoal::waiteeDone
It might not be set, in which case we shouldn't do anything.
Surprisingly, this somehow did not cause segfaults before?

Caught by UBSan.
2024-07-16 22:01:39 +00:00
Las Safin
5b6a21acc5
Avoid casting function pointer in libutil test support
Casting function pointers seems to be almost always UB.
See https://stackoverflow.com/questions/559581/casting-a-function-pointer-to-another-type

Fixed by doing the casting of `void*` to `std::string*` inside the function instead.

Caught by UBSan.
2024-07-16 22:01:34 +00:00
Robert Hensing
8f22245fdf
Merge pull request #11119 from philiptaron/attrbute
builtins.genericClosure: fix documentation typo
2024-07-16 23:54:59 +02:00
Philip Taron
0a1a116f4b
builtins.genericClosure: fix documentation typo 2024-07-16 13:51:52 -07:00
Eelco Dolstra
9300f855fc
Merge pull request #11114 from DeterminateSystems/fix-warning
Pos::getSnippetUpTo(): Fix warning
2024-07-16 17:24:43 +02:00
Eelco Dolstra
3d8fa9f668 Pos::getSnippetUpTo(): Fix warning 2024-07-16 16:34:13 +02:00
Eelco Dolstra
9c6678da0e
Merge pull request #11092 from DeterminateSystems/hash-SourcePath
Use std::unordered_map for the EvalState caches
2024-07-16 11:06:43 +02:00
John Ericson
4bbadba83a
Merge pull request #11108 from obsidiansystems/remote-store-constructors
Ensure we can construct remote store configs in isolation
2024-07-15 22:51:22 -04:00
Robert Hensing
03326d606f
Merge pull request #11110 from GoldsteinE/fix-repl-tests
tests/functional/repl.sh: fail test on wrong stdout
2024-07-16 00:23:42 +02:00
John Ericson
808082ea03 Ensure we can construct remote store configs in isolation
Progress towards #10766

I thought that #10768 achieved, but when I went to use this stuff (in
Hydra), turns out it did not. (Those `using FooConfig;` lines were not
working --- they are so finicky!) This PR gets the job done, and adds
some trivial unit tests to make sure I did what I intended.

I had to add add a header to expose `SSHStoreConfig`, after which the
preexisting `ssh-store-config.*` were very confusingly named files, so I
renamed them to `common-ssh-store-config.hh` to match the type defined
therein.
2024-07-15 17:32:49 -04:00
Las Safin
846869da0e
Make goals use C++20 coroutines (#11005)
undefined
2024-07-15 16:49:15 -04:00
Goldstein
1bec90e3c4
tests/functional/repl.sh: fail test on wrong stdout
Previous test implementation assumed that grep supports newlines
in patterns. It doesn't, so tests spuriously passed, even though
some tests outputs were broken.

This patches output (and expected output) before grepping,
so there're no newlines in pattern.
2024-07-15 23:11:26 +03:00
Robert Hensing
c6b5503190
Merge pull request #11072 from NixOS/doc-comments
Doc comments
2024-07-15 21:00:42 +02:00
Robert Hensing
61a4d3d45c getSnippetUpTo: Return optional
This makes it possible to certain discern failures from empty
snippets, which I think is an ok review comment.

Maybe it should do so for swapped column indexes too, but I'm not
sure.

I don't think it matters in the grand scheme. We don't even have
a real use case for `nullopt` now anyway.

Since we don't have a use case, I'm not applying this logic to
higher level functions yet.
2024-07-15 20:10:45 +02:00
Robert Hensing
03d33703ef Revert "Use HintFmt for doc comments"
Unfortunately these don't render correctly, because they go into the
markdown renderer, instead of the terminal.

```
nix-repl> :doc lib.version
Attribute '[35;1mversion[0m'

    … defined at [35;1m/home/user/h/nixpkgs/lib/default.nix:73:40[0m
```

We could switch that to go direct to the terminal, but then we should
do the same for the primops, to get a consistent look.

Reverting for now.

This reverts commit 3413e0338cbee1c7734d5cb614b5325e51815cde.
2024-07-15 19:56:40 +02:00
Robert Hensing
ce31a0457f Use HintFmt for doc comments 2024-07-15 19:56:40 +02:00
Robert Hensing
6a125e65d0 Revert "Doc comments: use std::unordered_map"
hash<SourcePath> isn't implemented yet, and I can't cherry-pick
a bug-free commit yet.

This reverts commit 95529f31e3bbda99111c5ce98a33484dc6e7a462.
2024-07-15 19:56:40 +02:00
Robert Hensing
ac89df815d libcmd/repl.cc: Explain evalString call and defend 2024-07-15 19:56:40 +02:00
Robert Hensing
21817473e8 Doc comments: use std::unordered_map
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
2024-07-15 19:56:40 +02:00
Robert Hensing
131b6ccc71 nixexpr.hh: Avoid the warning and pragmas 2024-07-15 19:56:40 +02:00
Robert Hensing
6bbd493d49 libcmd/repl-interacter: INT_MAX -> numeric_limits 2024-07-15 19:56:40 +02:00
Robert Hensing
8a855296f5 tests/function/repl: Characterise the missing doc comment behavior 2024-07-15 19:56:40 +02:00
Robert Hensing
71cb8bf509 libexpr: Rename "column" fields to offset
... because that's what they are.
2024-07-15 19:56:40 +02:00
Robert Hensing
77e9f9ee82 libexpr: Get rid of unused line tracking fields 2024-07-15 19:56:40 +02:00
Robert Hensing
f9243eca75 tests/functional/repl.sh: Work around GHA failure 2024-07-15 19:56:40 +02:00
Robert Hensing
cef11b23e8 Add missing .sh in _NIX_TEST_ACCEPT=1 message 2024-07-15 19:56:40 +02:00
Robert Hensing
d4f576b0b2 nix repl: Render docs for attributes 2024-07-15 19:56:40 +02:00
Robert Hensing
491b9cf415 Refactor: extract DocComment::getInnerText(PosTable) 2024-07-15 19:56:40 +02:00
Robert Hensing
e68234c4f9 libexpr: Rearrange lexer files so that yylex_init_extra can be found 2024-07-15 19:56:40 +02:00
Robert Hensing
7fae378835 Track doc comments and render them in :doc 2024-07-15 19:56:40 +02:00
Robert Hensing
e5af7cbeb9 libutil: Add Pos::getSnippetUpTo(Pos) 2024-07-15 18:41:11 +02:00
Robert Hensing
63f520fd00 doc/testing: Typo 2024-07-15 18:41:11 +02:00
Eelco Dolstra
550b3479cf Include the accessor in the SourcePath hash 2024-07-15 15:46:30 +02:00
Robert Hensing
9d7397c4ba
Merge pull request #11093 from NixOS/fix-concatStringsSep
Fix C++ `concatStringsSep`
2024-07-14 13:11:29 +02:00
Robert Hensing
7e604f716c concatStrings: Give compiler access to definition for inlining
... at call sites that are may be in the hot path.

I do not know how clever the compiler gets at these sites.
My primary concern is to not regress performance and I am confident
that this achieves it the easy way.
2024-07-14 12:20:45 +02:00
Robert Hensing
97e01107ec dropEmptyInitThenConcatStringsSep -> concatStringSep: empty separator
When the separator is empty, no difference is observable.

Note that concatStringsSep has centralized definitions. This adds the
required definitions. Alternatively, `strings-inline.hh` could be
included at call sites.
2024-07-14 12:10:39 +02:00
Robert Hensing
d40fdb5711 dropEmptyInitThenConcatStringsSep: Update doc and deprecate 2024-07-14 11:50:20 +02:00
Robert Hensing
1c97718146 dropEmptyInitThenConcatStringsSep: Allow it to drop items again
It's usually harmless, if it occurs at all.
2024-07-13 03:06:24 +02:00
Robert Hensing
6b2c277c36 dropEmptyInitThenConcatStringsSep -> concatStringSep: sigs are not empty
... but if they are, I'd like to see at least a hint of it so that
I'd know to fix it.
2024-07-13 03:06:24 +02:00
Robert Hensing
76b2d5ef3d dropEmptyInitThenConcatStringsSep -> concatStringSep: PATH handling
It's still wrong, but one step closer to correct.
Not that anyone should use "" or "." in their PATH, but that is not
for us to intervene.
2024-07-13 03:06:24 +02:00
Robert Hensing
9ca42d5da2 dropEmptyInitThenConcatStringsSep -> concatStringSep: setting value was already harmed
Considering that `value` was probably parsed with tokenizeString
prior, it's unlikely to contain empty strings, and we have no
reason to remove them either.
2024-07-13 03:06:24 +02:00
Robert Hensing
4029426ca8 dropEmptyInitThenConcatStringsSep -> concatStringSep: tokens from tokenizeString are not empty 2024-07-13 03:06:24 +02:00
Robert Hensing
0fe3525223 illegal configuration line -> syntax error in configuration line
The law has nothing to do with this, although I do feel like a
badass when I mess with the config.
I'm a conf artist.
2024-07-13 03:06:24 +02:00
Robert Hensing
cf3c5cd189 dropEmptyInitThenConcatStringsSep -> concatStringSep: showVersions version is not empty 2024-07-13 03:06:24 +02:00
Robert Hensing
d9043021df dropEmptyInitThenConcatStringsSep -> concatStringSep: break nix help "" "" "" build
Garbage in, error out. Experimental CLI. Zero derivations given.
2024-07-13 03:06:24 +02:00
Robert Hensing
062672b022 dropEmptyInitThenConcatStringsSep -> concatStringSep: CLI commands are not empty 2024-07-13 03:06:24 +02:00
Robert Hensing
0480bfe50b dropEmptyInitThenConcatStringsSep -> concatStringSep: do not drop attributes with empty names
Empty attributes are probably not well supported, but the least we
could do is leave a hint.
Attribute path rendering and parsing should be done according to
Nix expression syntax in my opinion.
2024-07-13 03:06:24 +02:00
Robert Hensing
4b34feb4c2 dropEmptyInitThenConcatStringsSep -> concatStringSep: system string should not be empty 2024-07-13 03:06:24 +02:00