Swapping a configuration's dependency keeps objects compiled against the old one's headers: no unit's staleness check looks at its compile command #51
Labels
No labels
bug
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Build#51
Loading…
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?
Summary
Whether a C++ unit is compiled again is decided from file times alone: its source, the newest artifact of the configuration's external dependencies, the prerequisites in its own dependency file and the BMIs it imports. The command it was compiled with is never compared. A configuration gets a build directory of its own only for what
VariantId()hashes, andVariantId()does not hashcfg.dependencies. The compile command does take from each dependency its directory, everyincludedirectory under it (-I) and its PCM directory (-fprebuilt-module-path).So a configuration built on another dependency in the same build directory keeps every object that is still newer than its source, the BMIs it imports and what its dependency file lists, which names the old dependency's headers. Where a header of the same name says something else in the new dependency, the program is linked from objects compiled against the old one, and nothing is printed.
The link does compare its command: it is recorded with the objects it reads in
<output>.linkand run again when either differs. Since 6.4.2 a source's scan does too (CurrentScan), so after such a swap the module graph is read for the new dependency while the objects stay as they were compiled for the old one.Line numbers refer to
578a1da(6.4.2). Reproduced with 6.4.1 (the stable Flatpak) and with578a1dabuilt natively.Reproduce
tests/SourceScan/fixture/switchhas two libraries,onandoff, each with aswitch.hthat definesWITH_EXTRA, 1 inonand 0 inoff. The app'smain.cppincludes<switch.h>; underWITH_EXTRAit imports the app's own moduleExtraand returns 40, otherwise it returns 2. Copy that directory, add theproject.cppbelow, which builds the app on the librarySWITCH_LIBnames, and run the program after each build:The second build, with
578a1da:main.cppis scanned again, because its command changed, and is not compiled. With 6.4.1 the second build ends in[7/7] Linking scan-offand[8/8] Linking scan-switch, and its program exits 40 as well.project.cpp
Where
implementations/Crafter.Build-Implementation.cpp:16,Implementation::Check: an object is stale when it is missing or not newer than its.cpp,sourceFloorand the newest prerequisite of its dependency file (:22), or than a BMI it imports.implementations/Crafter.Build-Interface.cpp:57and:121,ModulePartition::CheckandModule::Check: the same rule for a BMI and its.pcm.d.implementations/Crafter.Build-Clang.cpp:1590: a C source's object, by its source and its dependency file alone.interfaces/Crafter.Build-Clang.cppm:690,VariantId(): type, debug, sysroot, defines, compile flags, the wasm variant and baseline flags, the std PCM key, project args and the toolchain. Not the dependencies.implementations/Crafter.Build-Clang.cpp:725-744, inGetCompileCommand: what each dependency, and each of its own dependencies, adds to the command.implementations/Crafter.Build-Clang.cpp:2019-2030: the link's record of its command and objects.:306,CurrentScan: a scan holds only for the command it was taken with.Proposal
Do for each unit what the link and the scan already do: keep the command it was compiled with beside its object or BMI, and count it stale when the command differs. That takes in every input of the command, not only the dependencies, and leaves
VariantId()as it is. Hashing the dependencies intoVariantId()instead would give each set of dependencies a build directory of its own, with a full build after every swap, and would still miss whatever else reaches the command without being hashed.Not looked at
External dependencies (
cfg.externalDependencies), whose include flags reach the command in the same way and are not hashed either; CUDA sources; whether anything else reaches the command without being inVariantId().