Repository navigation
cmake: optional wrapper units built from function-visibility.txt - #399
Merged
TheRedDaemon merged 9 commits intoNov 21, 2026
Merged
TheRedDaemon merged 9 commits into
TheRedDaemon merged 9 commits into
Conversation
… bodies
One entry per caller, with the callees whose bodies it must see when it is
compiled, fully qualified as the definitions are written:
OpenSHC::funcA
OpenSHC::funcB
87 entries, 127 edges, sorted by the caller's address. Every edge is a
tu_merge.py measurement: pasting the callee into the caller's unit raises the
caller's quick_diff ratio, and for callers with several callees a leave-one-out
over the full set decided which are needed together. In all 127 the callee is
at a lower address than its caller.
Twelve measured gains are left out because they cannot be same-file edges:
in seven the callee is at a higher address than its caller, and the other
five would put a callee into a unit with callers that measure worse when they
see it.
23 names are not on main yet. 22 are Map::Units Update callers: they were
measured on our local branches reimpl/units-B-development and
reimpl/units-A-development (UpdateCamel is also on the local
reimpl/units-B-round2-100), and gynt's reimpl/map-units-updatefunctions has
drafts of all 22. The 23rd is UnitsState::changeDestinationByAmount from sourcehold#378.
A generator skips names it cannot find. The measurements are in the PR
description.
Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With -DOPENSHC_FUNCTION_VISIBILITY_UNITS=ON, configure runs cmake/function-visibility-units.py. It groups every caller of cmake/function-visibility.txt with the callees whose bodies it must see (one group per connected set, since a function is defined once) and writes one wrapper .cpp per group that #includes the members. The wrappers replace their members in the build, and the members leave the /GL list; the wrappers are built without /GL. Off by default; nothing changes without the option. Groups are formed over files, so a .cpp that defines several listed functions is included once. A group whose members define the same internal-linkage name (a file-scope static or anything in an anonymous namespace) is not wrapped, and its files build as before. Manifest names with no .cpp in the build are skipped and listed at configure time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tCounter's body sourcehold#290 rewrote UpdateBadBuildingGibbet and UpdateBadBuildingStretchingRack so that they reach 100% without /GL. On main (ea63a49), tu_merge.py gives both 1.0000 in all three layouts: the caller alone, the callee's body pasted before it, and pasted after it (45 of 45 and 41 of 41 instructions). Seeing updateBuildingSignpostCounter no longer helps either of them, so their two entries go. The callee keeps its other two callers, UpdateBadBuildingGallows and UpdateBadBuildingDungeon. The manifest now has 85 entries and 125 edges. On main's sources the wrapper generator from sourcehold#399 makes 24 units holding 91 source files (93 before), with no internal-name clashes and the same 23 names not on main yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lity-wrappers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 13, 2026
Merged
Reimplement 5 UI functions from gynt's drafts and #318/#327/#328, with one header commit (100%)
#410
Merged
The entry for UpdateMerchant listed GameStateStructures::activateTraderState. That edge was measured on a 93.8% draft of UpdateMerchant. The function has since landed on main at 100% (sourcehold#409), and it reaches that under /GL without the body: activateTraderState.cpp is not on the /GL list. With the body in its unit the caller keeps the unit slot in esi across the call, where the original reads it again, so the original's caller did not know it. Measured on main 3458fea with sourcehold#399's wrapper build (-DOPENSHC_FUNCTION_VISIBILITY_UNITS=ON), reccmp, raw: UpdateMerchant reads 100.0 under /GL, 90.0 with the wrappers before this change and 100.0 after it. It was the only one of the 150 functions in that build (main's /GL list plus every file the manifest names) whose raw number differed between /GL and the wrappers, and none differs now. The manifest now has 85 entries and 124 edges. On main's sources the generator makes 24 units holding 92 source files (93 before). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…lity-wrappers Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…lity-wrappers Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
kotijekriv
marked this pull request as ready for review
November 21, 2026 00:31
This was referenced Nov 21, 2026
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 21, 2026
UpdateTrebuchet (0x00569410) calls GameSynchronyState::isAIPlayer twice, at 0x0056A05B and 0x0056A124. Behind each call the original pushes ebx, the unit slot it read from 0xEE0FC8, without reading the slot again (0x0056A068, 0x0056A12D); behind the next call, to 0x00465F20, it reads it again (0x0056A06F, 0x0056A134). So the original's caller knew that isAIPlayer writes no memory, which it can know only from the body. Measured with tu_merge.py on main 3458fea (in a clone with two UI commits on top, nothing under Map or Synchrony) plus worker C's UpdateTrebuchet.cpp (6757ed1, at 100% under /GL), every struct and function resolver on, quick_diff ratio of the caller: caller alone 0.5440 isAIPlayer, hasUnitReachedDestination, deselectUnit 0.9818 hasUnitReachedDestination, deselectUnit 0.9132 isAIPlayer alone 0.5587 (callees first and caller first read the same in each row). Leaving isAIPlayer out lowers the score, so it is needed together with the other two. isAIPlayer (0x004010B0) is at a lower address than its caller, and it goes first in the entry, whose callees are sorted by address. The manifest now has 85 entries and 125 edges. On main's sources the generator from sourcehold#399 makes the same 24 units holding 92 source files, file for file, since UpdateTrebuchet is not on main. With that UpdateTrebuchet.cpp in the build, isAIPlayer.cpp joins its unit (24 units holding 95 source files, 94 without the line); no other file in that unit calls isAIPlayer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheRedDaemon
approved these changes
Nov 21, 2026
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 21, 2026
The manifest itself is on main since sourcehold#399 (02fab42); this branch keeps one more edge, UpdateTrebuchet -> GameSynchronyState::isAIPlayer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 21, 2026
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional way to build the units that
cmake/function-visibility.txtdescribes, instead of relying on/GL. It builds on #398, the manifest, so its diff holds #398's commits too: please review #398 first. Off by default: without the option, nothing changes.What it does
At configure time,
cmake/function-visibility-units.pyreads the manifest and groups every caller with the callees whose bodies it must see. A function can be defined only once, so everything joined by entries ends up in one group. For each group it writes one wrapper.cppinto the build folder:CMakeLists.txt then builds the wrappers in place of their members. The members come off the
/GLlist, and the wrappers themselves are built without/GL. The source tree is not touched..cppis included twice: groups are formed over files, not functions, so a file that defines several listed functions lands in exactly one wrapper.static, or anything in an anonymous namespace) would not compile in one unit. Such a group is not wrapped: its files build as before, and the clash is printed at configure time. The check reads the source line by line rather than parsing it, so a brace inside a string or a comment could hide a static from it. A clash it misses fails loudly (C2084). Todaysrc/OpenSHChas one file-scope static and no anonymous namespaces..cppin the build defines are skipped, and configure prints how many and which. On main today that is the 22 names cmake: function-visibility.txt, which callers must see which callees' bodies #398 lists.find_package(Python3)). Under a preset that replacesPATH, CMake may not find it; pass-DPython3_EXECUTABLE=<path to python.exe>then.Does it reproduce
/GL?Measured on our Map::Units branch (
reimpl/units-B-development, which contains main677469cd2, so main's whole/GLlist is in it). One full build used/GLas today, one used this option with the manifest from #398. Both had every resolver switched on, and all files compiled. reccmp:/GLThe seven that got better:
/GLUpdateDairyFarmer is the case
/GLcan't express: it must not see getResourceCountThatCanBeDeposited, but addResourceToGranary must, and under/GLevery listed file sees every other. Every function that is 100% under/GLstays 100%, including UpdateCamel, UpdateLady, UpdateFireEater, UpdateInnkeeper and all the main/GLcallers. UpdateHorseArcher_DoShooting and UpdateSiegeTent need no unit-mates, so they are not in a wrapper, and they stay 100% as well.On main
3458fea34it was built and measured too (update of 2026-11-21 below): 24 wrappers holding 92 files, and none of the 150 functions that can differ reads a different raw number than under/GL.Things worth a look
ViewportRenderState::xyAreValid. Almost every Map::Units Update function needs checkIfCitizenUnitIsAliveBasedOnState or hasUnitReachedDestination, which chains them all together. The two far edges still listed below pull in the rest. On main alone the largest wrapper is 18 files (the building-menu render functions).tools/compiler-internals/gl-conundrum.md(section 4), each of these pairs has a boundary between them, so they can't share a file./GLfiles outside every group. With the option on, 45 files on the/GLlist are in no group and keep/GL, while the files they were in one/GLmodule with leave it. Four of the 45 don't exist on main (stale lines incompiler-flags-gl.txt, listed in cmake: function-visibility.txt, which callers must see which callees' bodies #398). The rest had no measured edge: nothing they call changed their score. None of them got worse in the build above. The rule: once a callee is in a wrapper, every caller that must see it needs an entry. On main with this manifest no such caller is left out: nothing outside the wrappers reads lower (update of 2026-11-21). It did happen once, with a hand-made manifest on our branch (update of 2026-11-20).#includethe members by absolute path, so moving the source tree needs a reconfigure, which happens anyway.Update (2026-11-20): measured again, with #378's functions and a fuller manifest
A second measurement, on a different tree and with more files in the wrappers. With the option on, 327 of the 363 functions in the build read 100%, against 323 under
/GL, and no function that reads 100% under/GLreads lower. Three unit updates reach 100% that/GLcan only get there by breaking six functions on main.What was measured
3458fea34), Reimplement 47 UnitsState functions at 100% and restyle 28 more #378's heade81059741and this PR's head61ef05f74. It depends on Reimplement 47 UnitsState functions at 100% and restyle 28 more #378: the unit updates need bodies that Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 adds or puts on the/GLlist (setupUnitSharingTileIDs,changeDestinationByAmount,sitDownIfStanding,standUpIfSeated)./GLlist plus that branch's unit updates. That is 363 functions (201 in Map::Units, 77 in Map::Buildings, the rest spread over UI, IO, Game and a few others). The function resolver of every function in the list and the data resolvers were on./GLas today, one with-DOPENSHC_FUNCTION_VISIBILITY_UNITS=ONand the manifest described below. All numbers are reccmp's raw percentage.Result
12 of the 363 functions read differently between the two builds:
/GLBuildingsState::canUnitReachBuildingPerimeterUnits::UpdateBakerUnits::UpdateHunterUnits::UpdateDairyFarmerUnits::UpdateWoodcutterUnits::UpdateBlacksmithUnits::UpdateBrewerUnits::UpdateSlaveUnits::UpdateAppleFarmerWindowAndDirectDraw::takeScreenshot(unfinished)Units::UpdateCatapultUI::Rendering::InitBlendFilterArraysUnk/GL./GLreads lower with the wrappers.UpdateCatapultis the only function that reads lower, by 0.3. It is not a missing entry: all 14/GLfiles in its call closure are in its wrapper, and a/GLbuild of only Catapult and those 14 files reads the same 86.5. The 86.8 shows up only when the whole list is one/GLmodule, so it comes from something outside its own calls.InitBlendFilterArraysUnkkeeps its raw number; only the normalised one differs. It is a callee in two entries the manifest already had.The manifest that was used
It was made by rule, not from measured edges: every Map::Units source on the
/GLlist gets an entry with each/GLcallee it calls, except callees underMap/Buildings. The manifest of this PR is kept as it is. That gives 127 entries and 516 lines, where this PR has 209 lines. It is an upper bound: measured edges would be fewer.The generator needed no change. It wrote 28 wrappers holding 186 of the sources. The largest has 94 files: 35 unit updates, 43 UnitsState functions, 2 files from Map::Buildings and 9 others. It compiled and linked first try.
These lines are not added to this PR. They name functions that only #378 has, and unit updates that aren't on main yet. They can follow once those are in.
A first, hand-measured manifest was tried before the rule: 26 lines, with entries for
UpdateBakerandUpdateHunterand the callees they must see. It already put the three units at 100.0, but three other functions fell from 100.0:UnitsState::deleteUnit(98.7),UpdateOx(86.8) andUpdateGhost(49.3). Each calls a function that had moved into a wrapper while the caller stayed outside. So the caveat under "/GLfiles outside every group" is real: once a callee is wrapped, every caller that must see it needs an entry. With entries for them, all three read 100.0 again.What it means
/GLcan't. The unit updates must not see four BuildingsState bodies that other callers need:updateBuildingSignpostCounter,getResourceCountThatCanBeDeposited,getStorageBuildingForResourceTypeAndAmountandaddResourceToStockpile. Under/GLevery listed file sees every other, soUpdateBaker,UpdateHunterandUpdateDairyFarmerread 93.2, 96.3 and 93.9. Taking the four off the/GLlist puts those three at 100.0, but six functions on main fall with it:addResourceToGranary100 → 76.3,getStorageBuildingForResourceTypeAndAmount100 → 58.8,getResourceSpace100 → 88.9,addResourceToStockpile100 → 97.9,UpdateBadBuildingDungeon100 → 96.4,UpdateBadBuildingGallows100 → 94.1. With the wrappers the three units and the six main functions all read 100.0: the four bodies sit in three small wrappers with the callers that need them, and the units' wrapper doesn't hold them.canUnitReachBuildingPerimeter(on main) reads 60.1 in the/GLbuild of this merge, because Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 putsUnitsState/selectionContainsOnlyArabAssassins.cppon the/GLlist and the caller then sees a body the original didn't see. A second/GLbuild without that one line reads 100.0, and it is the only one of the 363 functions that differs between those two builds. In its own wrapper the function doesn't see that body either, and reads 100.0./GLbuilds of the same sources between 43 and 86. Other builds ran on the same PC at times, so take it as an indication, not a benchmark.Still open
UpdateWoodcutterandUpdateBlacksmithstop one instruction short, at 99.2 and 98.9, under/GLand with the wrappers alike. BehindBuildingsState::getBuildingResourceAmountByUidthe original loadsecxagain but doesn't read the unit slot again: it knows what the callee writes, but has no register record for it. Neither/GLnor a wrapper can state that. In a local test with that one definition markedinlineand included from its class header, both units read 100.0, and main's two callers (UpdateIronMine,UpdateInnkeeper) stay at 100.0. That touches a generated header, so it is a separate question; the write-up is ready./GLmodule givesUpdateCatapultbeyond its own callees is not known. The function is at 86%, so nothing at 100% depends on it./GL?".Update (2026-11-21): built and measured on main
Builds of main, alone and with #378, with the option off and on. The build list is the
/GLlist plus every file the manifest names: every other file has the same compile command in both modes. reccmp, raw./GL3458fea34+ this PRe81059741+ this PRcompile_commands.jsonof main + this PR is identical to main's./GLand the wrappers. That needed one fix in cmake: function-visibility.txt, which callers must see which callees' bodies #398's list: UpdateMerchant listedactivateTraderState, an edge measured on a draft. The 100% version from Reimplement 4 Map::Units functions and RenderAnimatedTutorialFloatOverlay, with UnitState names (100%) #409 must not see that body, and read 90.0 with it. The 2026-11-20 build didn't catch it becauseactivateTraderState.cppwasn't in that build list, so the name was skipped. This time the list holds every file the manifest names.canUnitReachBuildingPerimeterreads 60.1 under/GLand 100.0 with the wrappers, with no new entry (see cmake: function-visibility.txt, which callers must see which callees' bodies #398).computeLadderClimbPath96.9 → 100.0 andrecomputeUnitStandingHeight98.8 → 100.0. Neither has an entry: probably a body they must not see left the/GLmodule; not looked into yet, and seen in this build list only.🤖 Generated with Claude Code