Remove reliance on static initializers for registration #359
Labels
No labels
Affects/CppNix
Affects/Nightly
Affects/Only nightly
Affects/Stable
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/lix ci
Area/nix-eval-jobs
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/repl/debugger
Area/store
awaiting
author
awaiting
contributors
bug
Context
contributors
Context
drive-by
Context
maintainers
Context
RFD
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
Feature/S3
imported
Language/Bash
Language/C++
Language/NixLang
Language/Python
Language/Rust
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
Topic/Large Scale Installations
ux
No project
No assignees
6 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lix-project/lix#359
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
A few places in Lix rely on static initializers to register various ops or backends. This is generally a bad idea: static initializers have undefined execution ordering which can vary across builds or even sometimes across runs, they break inter-module dependency analysis which can lead to really weird behavior with static .a builds, they break a whole bunch of static analysis / unused code detection, etc.
They also happen to be global and impossible to be made not-global, which could impair plans for a better liblix.
Let's instead switch to explicit registration of those ops / backends / ... as part of an "init" function/method. This will keep them as global for now - this proposed change is neutral on that dimension. The old
Register*structs used for static initializer registration will be kept in the short term as__attribute__((deprecated))for plugin compatibility, but this might be revisited if we decide not to care about plugin source compatibility.Known places to update:
cl/1905)cl/2812)cl/1385)plugin-filessetting documentation (cl/2826)primops.cc#42primops.cc#42primops.cc#42The beginning for
RegisterPrimOpremoval is at https://gerrit.lix.systems/c/lix/+/1342Of the cases I've listed, I think
GlobalConfig::Registerwill likely be the thorniest. It's being used across shared libraries, which means it's really not trivial to invert the dependency without introducing loops. Most likely it will need a fairly major refactor of the initialization API for all the sub libs in Lix.The other ones seem self contained to a single shared module so they should be easier.
cl/1385should take care ofRegisterStoreImplementationThis issue was mentioned on Gerrit on the following CLs:
RegisterLegacyCommand")CommandRegistry")Removed
RegisterLegacyCommandin https://gerrit.lix.systems/c/lix/+/1905nix --versionevaluates configuration #519Removed
RegisterCommandincl/2812Last couple should be pretty small
Working on plugin-files.
edit:
cl/2826plugin-filesinitialization,nix_plugin_entry#740GlobalConfig::Registerrequires a large rearchitecture of the entire system due to how fucked our config handling is: main calls initNix calls initStore which loads the configuration file, so all config registrations must happen beforeinitNix. since this is pretty much the first thing that happens at all we're well and truly fucked about this one.RegisterPrimOpis not nearly as bad, but it requires plugins to expose aninit_libexprhook or something of the sort, which we currently do not have (but @raito needs for the flake extraction).