Repository navigation
cmake: function-visibility.txt, which callers must see which callees' bodies - #398
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>
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>
|
Updated after #290: I merged main in (a731ab3), then dropped two entries (6ba3369). UpdateBadBuildingGibbet and UpdateBadBuildingStretchingRack now reach 100% with or without updateBuildingSignpostCounter's body, so those two edges are gone, and the list has 85 entries and 125 edges. Their "must not see addBuildingToTargetableBuildings" rows still hold on the new code: with that body they drop to 0.8539 and 0.7407. #399 builds its wrappers from this list, so it only needed the new head (61ef05f). The description has the updated numbers. |
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>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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>
|
Hi @kotijekriv , I merged your other branch. Is this one still relevant? |
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>
|
Thanks for merging #399. This one is down to a single line now: I merged main into it, so against main it only adds the edge UpdateTrebuchet → If you'd rather not keep a PR open for one line, I can move it into #453 and close this one. Either way works for us. |
Update (2026-11-21), after #399: #399 brought this manifest onto main (02fab42) as it stood at 20176fe, so everything described below is on main already. main is now merged into this branch (3e959f2), and against main this PR adds only one edge: UpdateTrebuchet →
GameSynchronyState::isAIPlayer(its update note is below; UpdateTrebuchet is in #453).Adds
cmake/function-visibility.txt, the list gynt asked for on Discord: for each caller, the functions whose bodies it has to see when it is compiled.means UpdateCamel has to be compiled in a unit that also holds those two bodies. Whether a callee needs something itself is its own entry. Names are fully qualified the way the definitions are written. Entries are sorted by the caller's address, and each entry's callees by theirs. There are 85 entries with 125 edges, and in every one of them the callee is at a lower address than its caller. Nothing else changes: the file is not read by the build yet.
Update after #290: #290 rewrote UpdateBadBuildingGibbet and UpdateBadBuildingStretchingRack so that they reach 100% without
/GL. On mainea63a49d9both measure 1.0000 with and without updateBuildingSignpostCounter's body, so their two edges are gone (87 entries and 127 edges before). Their "must not see" rows for addBuildingToTargetableBuildings still hold on the new code and are re-measured below: 1.0000 alone, 0.8539 (Gibbet) and 0.7407 (StretchingRack) with it.Update (2026-11-21), for #378: #378 puts
UnitsState/selectionContainsOnlyArabAssassins.cppon the/GLlist.BuildingsState::canUnitReachBuildingPerimeter(on main at 100%) calls that function and must not see its body: the pair is in the "Must not see" table below (0.7731 alone, 0.5738 with it). Nothing had to be added to the list for it. Its entry is already here, withgetBuildingHeightForBuildingID, the one callee it must see. With #399's option on, that puts it into a wrapper of three files built without/GL. Real builds, reccmp, raw:canUnitReachBuildingPerimeter3458fea34,/GLe81059741,/GL/GLlineTwo limits. The list isn't read by the default build, so there only the
/GLlist decides. And an entry without callee lines changes nothing, because the generator groups only files that an entry joins.Update (2026-11-21), for UpdateTrebuchet: one edge more, UpdateTrebuchet →
GameSynchronyState::isAIPlayer. Without it UpdateTrebuchet measures 0.9132 with its other two callees; with it 0.9818. The original calls it at 0x0056A05B and 0x0056A124 and does not re-read the unit slot behind either call.One edge is gone: UpdateMerchant →
activateTraderState. It was measured on a 93.8% draft, the weaker kind of evidence named under "Known gaps". UpdateMerchant has since landed on main at 100% (#409), and that version must not see the body. On main3458fea34it reads 100.0 under/GL(activateTraderState.cppisn't on the/GLlist), 90.0 in a wrapper build with the old line and 100.0 without it. It was the only one of 150 functions (the/GLlist plus every file this list names) whose raw number differed between/GLand the wrappers.How each edge was measured
Every edge comes from
tools/compiler-internals/tu_merge.py, not from reading the code. For a caller and one or more callees, it compiles the caller as committed and with the callees' bodies pasted into its file (bundled MSVC 2005,/FA, no/GL). Each result is diffed against the original withquick_diff.py --name CALLER. Every function and struct resolver was switched on./GLlist lets every listed file see every other.Trees measured:
677469cd2cmake/compiler-flags-gl.txtreimpl/units-B-development(our Map::Units branch, contains main)reimpl/units-A-development(our other Map::Units branch)The list was then checked against main
3458fea34: every name from main resolves there. 22 names are not on main yet. 21 are Map::Units Update functions (UpdateMerchant landed with #409): they were measured on our local branchesreimpl/units-B-developmentandreimpl/units-A-development(UpdateCamel is also on the localreimpl/units-B-round2-100), and gynt'sreimpl/map-units-updatefunctionshas drafts of all of them. The 22nd isUnitsState::changeDestinationByAmountfrom #378. A generator would skip them until they land. If you'd rather keep only what is on main, they are easy to take out.Highlights
/GLboth are on the list, so Dairy can't avoid it, which is why it is at 93.9 today./GLbatch already found./GLworkshop functions (UpdateArmorersWorkshop and friends) need updateVisuallyActiveState. That matches gl-conundrum.md.Measured gains left out of the file
Twelve callees raised their caller's score but cannot be same-file edges, so they are not in the file:
So the building Update functions gain from seeing playSFXAtLocation's body, although by the address layout it cannot have been in their file. I haven't found the reason yet.
Some kept edges span huge distances: UpdateInnkeeper (0x540EC0) → getBuildingResourceAmountByUid (0x409330), and UpdatePikeman/UpdateMaceman →
ViewportRenderState::xyAreValidat 0x401000. They contradict no other measurement, so they stay. Innkeeper's is confirmed by a build (below). A third, UpdateMerchant → activateTraderState, was removed (update of 2026-11-21).Known gaps
cmake/compiler-flags-gl.txton main has six lines for four files that don't exist:takeScreenshot.cpp,determineBuildingPlacementRotation.cpp, andexecuteDefaultCastleAIV.cppandfindAppropriateGridLocationForBuilding.cpp(twice each).The
staticideaDeclaring the Update functions
staticchanges nothing. A static function can't go intoMACRO_FUNCTION_RESOLVERas it stands (MSVC 2005 error C2970: an internal-linkage function as a template argument). So the test swapped the resolver's argument for0and kept the function alive with an external function pointer, the way a dispatch table would.static/GLcalleesstatic/GLlist; the file lists 6)Does a wrapper build reproduce
/GL?Yes, so far. #399 builds on this PR and adds the generator gynt suggested:
cmake/function-visibility-units.pyand an option,-DOPENSHC_FUNCTION_VISIBILITY_UNITS=ON, off by default. It groups each caller with its callees (one group per connected set, since a function is defined once), writes one wrapper.cppper group that#includes the members, and builds the wrappers instead of the members, without/GL.Built with the file as first posted (87 entries, before the updates above) on our Map::Units development branch, which contains main and its
/GLlist: 24 wrappers holding 124 files, no build failures, and it links. Against the/GLbuild of the same code, 2,247 of 2,254 functions are identical, 7 are better and none is worse. All 2,107 functions at 100% stay at 100%./GL/GLThis PR is only the list; the build doesn't read it.
The measurements
Single-callee rows: the caller alone, then with that one callee pasted in before it ("callee first") and after it ("callee after"). Scores are quick_diff ratios; % is each function's status.
Must not see (69 pairs)
ea63a49d9ea63a49d9Hurt alone, needed together with the caller's other callees (10 pairs)
Gained, one callee at a time (143 pairs, including the 12 left out above)
The leave-one-out rounds of the 55 callers and the 259 pairs with no effect don't fit here; I can post them as a comment.
🤖 Generated with Claude Code