Commit graph

16527 commits

Author SHA1 Message Date
eldritch horrors f5754dc90a libexpr: move eval memory allocation to own struct
Change-Id: I9d472c9606fe66fdc1cb7cb9dcf6d1b6b46c6686
2024-11-28 15:12:22 +00:00
eldritch horrors cb8262e11c libexpr: remove EvalState::rootPath
this belongs to lazy trees, which we neither have nor intend to have.
we will keep SourcePath as that may come in handy at some later date.

Change-Id: I44b8f1dd6c435d7486c393fabdcd272766b2b56b
2024-11-28 15:12:22 +00:00
eldritch horrors 3593f5555e libexpr: handle debug trace frames as parent pointer list
this also fixes a debugger bug where leaving the debugger does not clean
up old debugger state completely. in such cases the fake frame withFrame
created was left behind after the corresponding caller frame was unwound

Change-Id: I45adcd116276b03b2f87076518c9eae6fe844e06
2024-11-28 15:12:22 +00:00
eldritch horrors 985afeeb4d libexpr: allocate debug state only when debugger is active
Change-Id: Id30f388264c5d1e472e3bdce5078db3914f3b475
2024-11-28 15:08:35 +00:00
eldritch horrors 35cb0cb28b libutil: make enumerate iter deref non-const
there's no need for this. no concept requires unary deref to be const.

Change-Id: I4e4592c5917382ad2dcc70e5d3f12662614b2fd1
2024-11-28 14:49:23 +00:00
eldritch horrors 5892ed2731 libutil: make generators iterable
range-for on generators sounds like a pretty good thing, right?

Change-Id: Ibed5e038c8dc50c918cf7c1f1aa70d822fb3efa2
2024-11-27 02:09:08 +01:00
eldritch horrors 89a0ddc108 libcmd: don't enter debugger immediately on nix repl --debugger
checking whether a repl hook is set does not tell whether it's running,
which in turn means we will enter a debug repl even when not debugging.
this is not very useful when we have no debug frames to inspect at all,
as commonly happens when starting a new repl with --debugger specified.

Change-Id: I7065dc4ec29743bdd53ed99c29d6592e2ceea89c
2024-11-27 02:09:08 +01:00
eldritch horrors 9554a1ae29 libexpr: remove dead code
Change-Id: Ife3a23822102b6038401e4944777392836039472
2024-11-27 02:09:08 +01:00
eldritch horrors 003883306d libexpr: move debug repl state into own struct
just to keep debug-related state closer together. eventually this will
also allow us to not allocate debugger state altogether unless needed.

Change-Id: Id83fea75d96d0ecbe21683cb1b57dd5b11b13535
2024-11-27 02:09:08 +01:00
eldritch horrors e635db77e3 libexpr: only runDebugRepl with EvalErrors
only break ever passed a non-EvalError, and even that was erroneous.

Change-Id: I03bb74d7fc449d9bab1e7d8e774389d2381ab457
2024-11-27 02:09:08 +01:00
eldritch horrors 7af000ddff libexpr: move symbols into own struct
not all of these are even used by eval itself. notably sWith wasn't used
at all, sEpsilon was only used by the eval cache one layer up, and other
attributes are used in places even further away from eval itself. we can
keep this commingling for now, but eventually we should clean it up too.

Change-Id: I5684ac614361bf008e04472130c6c02082b4c2d7
2024-11-27 02:09:08 +01:00
eldritch horrors f017f9ddd3 libexpr: extract some global constants from EvalState
these do not rely on the GC being initialized. there's no reason for
them to not be statics, shared between all eval states in a process.

Change-Id: Ib9675f3945d3a0a7097d6c85096adcbd6f441d83
2024-11-27 02:09:08 +01:00
eldritch horrors 650809f66e drop unnecessary EvalState shared pointers
currently ref<>s are used to share eval states between whatever created
that state and the various repl instances. repls however do not own any
eval states, not even partially. they only provide interactive use of a
previously allocated state that is owned by something else, notably for
debug repls which are run from *within* an evaluation which may already
be wrapped by another repl instance. presumably this was originally set
up like this to guarantee memory safety, even though it's never needed.

Change-Id: I29a2cd1d4245c077f9270452a0873d4c47448729
2024-11-27 02:09:08 +01:00
eldritch horrors f5cddcfc09 libcmd: make Repl instances proper scopes
there's no reason to ever *own* a repl instance. everything either wants
to run a repl and receive the result of that run, or run a repl and then
totally ignore the result. allowing non-transient repl instances doesn't
do anything useful for us, unless making ownership analysis hard counts.

this also fixes a bug in which a repl could ignore the store it was told
to use during construction, using the one returned by openStore instead.
this never showed up in lix because openStore() was always passed anyway

Change-Id: If2b1ad24ab74377340199b36af1dd629d7ce3f25
2024-11-27 02:09:08 +01:00
eldritch horrors 66f6dbda32 libstore: remove an unused function
Change-Id: If5e24046409f3c1d444e558306a98f3eba5845f4
2024-11-20 14:17:02 +00:00
eldritch horrors a911b44a31 libstore: break up QueryMissingContext::doPath
std::visit makes coroutines nearly impossible to use correctly.

Change-Id: I085c08b595a5d4a43208eb97f023aa00b48bff45
2024-11-20 14:17:02 +00:00
eldritch horrors 74d820e5e8 libstore: move Store::queryMissing into a fresh struct
we want to get rid of all these local lambdas, they make coroutines impossible.

Change-Id: I94336f0844e9cdb0aa27788d0ee5f99925f24e0c
2024-11-20 14:17:02 +00:00
eldritch horrors 9cf91b7385 cli infra: modernize legacy command interface
give legacy commands their program name and c++-converted argv directly
instead of passing on the (argc, argv) pair untouched. all are required
to process these things, and all of them do it in exactly the same way.
we can also remove a few old helpers only used to make this less awful.

Change-Id: I4ecd02343bca0cf85faf6fe043031d4f64c5f29c
2024-11-20 14:17:02 +00:00
eldritch horrors c4a077d0b8 libcmd: drop non-default ctors virtual inheritance
it's a trap. it's always a trap. non-default ctors of virtual base
classes must be called with the same parameters every time or very
surprising things will happen. good luck if you virtually derive a
class more than once with different ctor arguments. that'll break.

Change-Id: I1345963e69e98f37c3cbd070bae164d89eade455
2024-11-20 14:17:02 +00:00
eldritch horrors ac74dc3a2b treewide: drop trivial leaf virtual inheritance
this does nothing on classes that are never used as base classes and
have only a single base class of their own. all of these classes are
also made final to prove that they are indeed in this category. once
we need to derive any of them we can erase their `final` specifiers.

Change-Id: I4bd8e50a58815227392b5a5a762fda4542d15bae
2024-11-20 14:17:02 +00:00
eldritch horrors 34e592ea6a libcmd, nix: drop NixMultiCommand
there are no uses of plain MultiCommand as a base class *except* in
NixArgs, which is the only one that does not implement run(). there
is not much of a reason not to implement a run member there though,
so let's just do that and get rid of this weird intermediate class.

Change-Id: Ie84e3acd071b43bc186a2bac87646cbfb3aff845
2024-11-20 14:17:02 +00:00
eldritch horrors 95a9a4cece libstore: don't derive store classes from their configs
the very slight speedup in config setting access is not worth the
maintenance overhead of conflating concers like this. the virtual
inheritance scheme used for configs requires too much duplication
of base class constructor arguments to be worth doing. perhaps we
should get rid of all virtual inheritance of data-membered bases?

Change-Id: I4acf5ceaedb4ed7476efe1114c2e065ec72d2c6d
2024-11-20 14:59:40 +01:00
eldritch horrors b0d7a81613 fix tooling after include reorganization
clangd broke because it can't look through symlinks. compile_commands
manipulation does not fix it, clangd configuration does not fix it, a
vfs overlay does not fix it, and while a combination of those can fix
it with a bind mount in place that's just too cursed to even consider

clangd bug: https://github.com/llvm/llvm-project/issues/116877

Change-Id: I8e3e8489548eb3a7aa65ac9d12a5ec8abf814aec
2024-11-19 22:55:32 +00:00
jade f116608a20 Merge "libstore: abort all curl transfers on interrupt" into main 2024-11-19 05:03:47 +00:00
jade 0bec915522 Merge "unnamed threads: Obliterate" into main 2024-11-19 05:02:48 +00:00
jade 519957bd59 unnamed threads: Obliterate
Ever read gdb output and you just kinda get a headache because you have
to infer what a thread is by reading the stack trace? It's not hard, but
we could also just never have to do that again, which is also not hard.

Sample:

(gdb) info thr
  Id   Target Id                    Frame
* 1    LWP 3719283 "nix-daemon"     0x00007e558587da0f in accept ()
   from target:/nix/store/c10zhkbp6jmyh0xc5kd123ga8yy2p4hk-glibc-2.39-52/lib/libc.so.6
  2    LWP 3719284 "signal handler" 0x00007e55857b2bea in sigtimedwait ()
   from target:/nix/store/c10zhkbp6jmyh0xc5kd123ga8yy2p4hk-glibc-2.39-52/lib/libc.so.6

The API design for this is forced by the macOS pthread_setname_np only
being able to change the current thread's name, but if we just conform
everything to that, it works everywhere.

Change-Id: I2b1d6ed41e3c94170cb0b4e73ad66f239ebd9c88
2024-11-18 18:53:40 -08:00
jade 950c213ddf Merge "feat: better warning for common SSL errors" into main 2024-11-19 02:48:24 +00:00
eldritch horrors 16bed313c6 libstore: abort all curl transfers on interrupt
give the transfer progress callback a chance to register all transfers
as aborted when an interrupt event occurs. checkInterrupt() will throw
an Interrupted exception if an interrupt signal was caught, which will
immediately break out of the curl loop. it isn't even necessary within
the curl main loop as curl guarantees to call progress callbacks about
once per second (or more often), and we already abort transfers from a
progress update if a signal was caught. this may delay shutdown a bit,
but "about one second" as should not be noticeable in most situations.

fixes #577

Change-Id: Ida4e72732562bdf6560e4f182ecdcdb663c6dda5
2024-11-19 02:49:41 +01:00
jade 33e832ba5a Merge "manual: Make link to install page clickable" into main 2024-11-19 01:47:03 +00:00
Tom Bereknyei 6334e91b2f feat: better warning for common SSL errors
(cherry picked from commit 3e5bf903413f420c1f997e4b55140761172b8434)
Upstream-PR: https://github.com/NixOS/nix/pull/11246
Change-Id: Iccd92721bbcd92604a4b0e5c845242bdf3dd0f66
2024-11-18 16:49:35 -08:00
jade fbdb177b31 manual: Make link to install page clickable
Closes: https://github.com/lix-project/lix/pull/11

Thanks to xsova for suggesting this.

Change-Id: I5958fa4438f4b83d928e8f309aab9a33fb4cbedd
2024-11-18 16:32:20 -08:00
jade 6a9b66357e pkg-config: add the base lix include-dir as an include-dir
This allows <lix/*> includes to work from external projects not taking
Lix as a buildInput with Nix, but just using pkg-config.

Change-Id: I5b24fd0981344b013beaf406c16988dad17f0edb
2024-11-18 12:31:41 -08:00
jade 13f54451e6 meson: remove the ability to use unqualified includes from inside Lix
These are still supported externally with pkg-config, but this commit
ensures they no longer build internally.

Change-Id: I2fa38f85e43b18f1f1dbcfdb0367de8f192aca2c
2024-11-18 12:31:41 -08:00
jade 103cd44a04 Include rearrangement: rest
Change-Id: If9b5502ff348d358d7007b885e26e98a0d228f39
2024-11-18 12:31:19 -08:00
jade eeaa72b62b Include rearrangement: libexpr
Change-Id: Ib230a3021d544d3ab1376542b73ea1df1a220a3c
2024-11-18 12:22:39 -08:00
jade 94ca95714e Include rearrangement: libstore
Change-Id: I27c83510d9053bb8bdd7eda9ad3a4b77d633056a
2024-11-18 12:22:39 -08:00
jade df0e1993b7 Include rearrangement: libutil
Change-Id: Ibf4ee57e430ce1cd175f994d1db7964c8407ffa7
2024-11-18 12:22:39 -08:00
jade b62cc7b361 meson: prepare for include rearrangement
Context: we have include paths that are "types.hh" and similarly common
names. We currently have these compatibly available as
"lix/libutil/types.hh" externally but *not yet internally*. This is
because we don't have any way for the src directory to appear as
`"lix/"` from inside of Lix: the lix/ include directory is created by
the install process.

The goal of this whole thing is to make it clearer which component of
Lix that files are a part of, which should hopefully help at least a
little bit to new developers. One disadvantage of un-mixing these is
that it will cause some API changes if we ever move a file between
libraries, but that is not very common, and we don't care that much
about external API users.

This was planned for a while and is why we have a FixIncludes check to
begin with.

Personally I don't see a great benefit in rearranging our source code,
and in fact, it would probably be counterproductive:
- Moving the includes into a separate `include/` directory would just
  make developers have to deal with more directories, when we can
  already generate the desired layout through the build process.
- This would also decouple the .cc and .hh files which currently
  conventionally have each others' definitions and declarations
  respectively, right next to each other, making it easier for them to
  feel decoupled and diverge.

Content: Add ../include as an include directory so that lix/ in include
paths will resolve to src/ within Lix itself, just as it does externally
today. This prepares for a further series of commits applying the actual
change to each library one-by-one by accepting both include versions at
once.

This could have been done with ../ and a symlink called lix, but we
would like to not accept libexpr/foo.hh internally for it would be
broken externally, so we need an otherwise empty directory for the
include.

Change-Id: Ideac17faadae2bcea2dffbab34eb27c582ede399
2024-11-18 12:22:39 -08:00
eldritch horrors c859d03013 libfetchers: remove scheme static initializers
provide a initLibFetchers function instead that runs them explicitly.

Change-Id: Ida532e6ff18b72fdc21c9f98df7aceda6713e5df
2024-11-15 16:15:11 +01:00
eldritch horrors 8088927b90 libexpr: initGC -> initLibExpr
we'll put more stuff in there shortly. unfortunately.

Change-Id: I74be957469c3dcd5157f999e2cf23b1c668426d8
2024-11-15 16:15:11 +01:00
eldritch horrors 3dba1d341a libstore: remove TransferItem::phase
transferComplete has outlived its usefulness, and the other two phases
can be a boolean flag telling us whether we're still receiving headers

Change-Id: Ia943f95dcf0ce8ee2cc6d0f44ddf13151aef4346
2024-11-15 16:15:11 +01:00
eldritch horrors 3b1298efce libstore: simplify TransferSource::read
things can be much simpler if the read loop knows whether the transfer
is done or not. this information is available, let's pass it back down

Change-Id: Idb99afeb06a0d7a0999c3f4a1c6ce5adeab5f054
2024-11-15 16:15:11 +01:00
eldritch horrors b22f2bc8e9 libstore: use http for exceptionAbortsDownload tests
file:// urls are no longer handled by curl itself, and this is supposed
to test the curl wrapper. use http to force the wrapper to be involved.

Change-Id: Ib13087db07b3b2f1ae44ce8e3ec7a96d935b1bab
2024-11-15 16:15:11 +01:00
eldritch horrors 986a98d32f libstore: remove curlFileTransfer reference from transfers
they don't need these any more if we consider unpausing and cancelling
of transfers a cooperative affair between transfers and the curl_multi
handler. we can also remove an enable_shared_from_this base class now.

Change-Id: Iefa380df60c0cada53719cdaa500bab953892319
2024-11-15 16:15:11 +01:00
eldritch horrors 4ba19f68fb libstore: improve curl wrapper resource handling
wrap all curl pointers in unique pointers for move correctness. the
destructor of TransferItem can go away completely since it does not
do anything special any more: memory bookkeeping is done using raii
wrappers, and its effects on the transfer state are not observable.
only TransferSource inspects the result, and even it does not check
for transfer results in its own destructor (only during transfers).

Change-Id: Ibb58484703854d5d5425e7c63cf2985d93920e97
2024-11-15 16:15:11 +01:00
eldritch horrors 43777939eb libstore: simplify download buffer handling
keep the download buffer in TransferItem. keep only *one* download
buffer (not one for success returns and one for failures). we also
remove the asynchronous callbacks since they are no longer needed.

Change-Id: I9b1c1e4c59d5333602aea1c36e477c481eaaf98e
2024-11-12 14:01:57 +01:00
eldritch horrors 7d7e16ecec libstore: use curl-builtin read callback
when no custom READFUNCTION is set curl will fall back to using its
READDATA as a FILE pointer and calling fread on it to retrieve data
to send to the peer. we can wrap our upload data in a FILE pointer.
doing so also allows for upload retries, but we don't do that here.

Change-Id: I0509f936229dd978e89135862dacc8a3937cd4de
2024-11-12 14:01:57 +01:00
eldritch horrors 5be7956592 libstore: move remaining retry state out of TransferItem
Change-Id: Ie2c22722bdda18027017e12d10e16931a694743e
2024-11-12 14:01:57 +01:00
Emilia Bopp 8a9094303b Merge "libutil: fix non-ASCII chars in URL encoding" into main 2024-11-11 14:08:37 +00:00
Emilia Bopp a378c61948 libutil: fix non-ASCII chars in URL encoding
Due to the cast to (unsigned int), the encoding appended broken
bytes padding. This is fixed here with a bitmask.

Fixes: #562
Change-Id: I0c93bd2b8c2f82df208d4693b7254544e3121dc3
2024-11-11 14:26:03 +01:00