# Lane PSY of run mg9: dScMg3DEsp_c, the "Psyche Out!" minigame.
#
# actor id 0x185 (scene 389), spawn symbol dScMg3DEsp_c_classInit (0x020ea1f0,
# 0x90), SpawnInfo 0x0213c78c, vtable _ZTV12dScMg3DEsp_c. Every one of those
# was read out of the ROM by this lane rather than taken from the brief:
# scanning extracted/overlays/overlay_0006.bin (base 0x020bfec0) for the
# doubled-id word 0x01850185 returns EXACTLY ONE hit, at 0x0213c790, which puts
# the record at 0x0213c78c with the factory in the word before it:
#
#     0213c78c  f0 a1 0e 02   0x020ea1f0   the factory
#               85 01 85 01   389, 389     the id, twice
#
# ---- THE CLASS NAME COMES OUT OF THE ROM'S OWN type_info -------------------
#
# port/mg_fanout_costs.txt section 14's chain, which is stronger than a src
# spelling because a per-TU placeholder can be wrong and a relocation cannot.
# The word IMMEDIATELY BEFORE a class's vtable points at its type_info, and
# that record's second word is the name:
#
#     relocs.txt  from:0x0213c8c0 kind:load to:0x0213c7c8 module:overlay(6)
#     relocs.txt  from:0x0213c7cc kind:load to:0x0213c7d4 module:overlay(6)
#
# and 0x0213c7d4 reads "12dScMg3DEsp_c" in the overlay image. The type_info's
# THIRD word is the base's, from:0x0213c7d0 to:0x0213bc64, whose own name at
# 0x0213bd00 reads "19dScMgSingle3DBase_c" and whose base is ov004's
# 0x020bbf6c. So the hierarchy is stated by the ROM twice over before a line of
# code is read.
#
# ---- THE HIERARCHY IS THREE DEEP, AND THE CODE SAYS SO IN BOTH DIRECTIONS --
#
#     Scene -> dScMgBase_c         data_ov004_020bc0c0  36  (the framework's)
#           -> dScMgSingle3DBase_c _ZTV19dScMgSingle3DBase_c  36  ovr 8, mark 6
#           -> dScMg3DEsp_c        _ZTV12dScMg3DEsp_c  36  ovr 14, mark 12, nosrc 0
#
# port/mg_fanout_costs.txt section 3's row for 0x185 lists one vtable and says
# nothing about an intermediate base, which is the same gap run mg6 lane MEM
# found for 0x16b and section 13's CORRECTION 1 warns will fire again. It fires
# here. Both edges are read off code:
#
#   src/d_s_mg3_d_esp.cpp (the factory) calls _ZN11dScMgBase_cC2Ev(o),
#   writes _ZTV19dScMgSingle3DBase_c into o[0], constructs the Particle::SysTracker
#   at +0x471c, writes _ZTV12dScMg3DEsp_c over it, then constructs two Models
#   at +0x4f38 and +0x4f88, _ZN15dMg3DEspModel_cC1Ev(+0x4fd8) and a
#   TextureTransformer at +0x51f4. Object size 0x5558.
#
#   src/_ZN12dScMg3DEsp_cD0Ev.cpp (slot 17, D0) unwinds them in the OPPOSITE order:
#   0x0213c8c4 first, the four sub-objects down, then 0x0213e448, then
#   Particle::SysTracker::~SysTracker(+0x471c), _ZN11dScMgBase_cD2Ev and
#   Memory::Deallocate. src/_ZN12dScMg3DEsp_cD1Ev.cpp (slot 16, D2) does the same
#   without the Deallocate.
#
# So SIX of this class's fourteen overrides -- slots 2, 5, 7, 10, 26 and 33 --
# are the MIDDLE base's bodies, exactly the same six as 0x16b, and a seat that
# filled one derived table would leave six raw DS words in a table the factory
# installs.
#
# THIS IS THE THIRD CLASS UNDER THAT MIDDLE TABLE and hal/scene_mg_memory2.cpp
# section 3 predicted it: "If a THIRD class under this base is ever seated,
# promoting kSingle3DFaces to an exported seam ... is the right move." This
# lane does NOT take that move, and says why in hal/scene_mg_psycheout.cpp
# section 3 rather than leaving it implied: promoting the array means editing
# hal/scene_mg_flower.cpp and hal/scene_mg_memory2.cpp, which are two other
# lanes' files, in a fan-out where nine other lanes are cutting against the
# same base. The per-file copy is the shape both existing seats use, it is
# measured safe, and this row is appended after both of theirs so neither
# witness moves.
#
# ---- THE WIDTH IS 36, CHECKED FIVE WAYS ------------------------------------
#
# port/mg_fanout_costs.txt section 11 measured that twelve of twenty-nine
# widths in that file's own section 3 table were phantoms and that a 37-slot
# fill writes a host thunk over live ROM data belonging to another class. All
# three of its checks, plus a fourth this lane adds:
#
#   1. SPAN. config/arm9/overlays/ov006/symbols.txt puts the next symbol after
#      _ZTV12dScMg3DEsp_c at data_ov006_0213c954, exactly 0x90 = 36 words on,
#      so a 37th slot cannot exist inside the table.
#   2. TERMINAL SLOT. Slot 35 holds 0x020ad660, the word every dScMgBase_c-
#      derived table holds there.
#   3. WHAT THE WORD PAST IT IS. Index 36 reads 0x0000000a -- decimal ten, not
#      an address in any module -- and it is the FIRST WORD of the next config
#      symbol, data_ov006_0213c954, whose second word is 0x00000003.
#   4. RELOCATION COUNT. config/arm9/overlays/ov006/relocs.txt has exactly 36
#      relocations inside the 36-word span from 0x0213c8c4, and STILL 36 inside
#      a 37-word span from the same address. A vtable slot is a relocated code
#      pointer, so word 36 carrying none means it cannot be one. Check 3 says
#      what the word is and check 4 says what it is not, from a different file.
#
#   5. RELOCATION STRIDE. Run mg9 lane LKY's check, which needs no config
#      symbol and no judgment at all: a vtable's relocations run at a 4-byte
#      stride for exactly the table width and then jump. From 0x0213c8c4 the
#      stride is 4 for THIRTY-FIVE consecutive steps -- 36 relocated words --
#      and the step after 0x0213c950 is TWELVE, to 0x0213c95c. Five checks,
#      four files (symbols.txt, the overlay image, relocs.txt twice over) and
#      one answer.
#
#      NOTHING IN THIS FILE MAY CONTAIN AN UNBALANCED SQUARE BRACKET, and this
#      paragraph is where the first draft had two of them. CMake reads a slice
#      with file(STRINGS), and an unmatched opening square bracket makes that
#      reader swallow EVERY FOLLOWING LINE into a single list element -- so
#      every path below it silently leaves the build. The failure does not look
#      like a slice failure: the hal and unmatched files still compile, and the
#      link then reports a wall of LNK2019s that reads exactly like an unclosed
#      closure. Measured on this tree with cmake -P: a four-line file whose
#      second line opens a square bracket and never closes it comes back as TWO
#      elements, and the same file with the bracket closed comes back as four.
#      A scan of every slice in the tree finds this the only one that ever had
#      the defect.
#
#      AND A SECOND READER TRAP IN THE SAME FILE, which this header did not
#      carry until the mg9 reviewer noticed it was only ever written down in a
#      commit message. CMake's foreach skips a line only when it STARTS with a
#      '#', so a TRAILING INLINE COMMENT on a src line does not get stripped:
#      the path becomes "src/_ZN12dScMg3DEsp_c13InitResourcesEv.cpp      # slot 0 ..." and
#      resolves to nothing. That kills one path per commented line rather than
#      the whole tail, so it is quieter than the bracket, and it produced this
#      lane's very first LNK2019 wall. Every annotation in this file therefore
#      sits on its OWN line above the path it describes. No other slice in the
#      tree uses inline comments, which is why the convention was invisible
#      until it was broken.
#
# The middle table's own width was re-read the same way rather than cited from
# port/slice_mem.txt or port/slice_flw.txt: 0x0213e448 -> data_ov006_0213e4d8
# is 0x90 = 36 words, slot 35 is 0x020ad660, and index 36 is 0x050a0a0f.
#
# ---- FOURTEEN OVERRIDES, TWELVE MARKERS, ZERO WITHOUT A SOURCE -------------
#
# Read out of the overlay image against dScMgBase_c's table at 0x020bc0c0 in
# extracted/overlays/overlay_0004.bin (base 0x020ad660):
#
#   OWN, eight     slots 0, 3, 6, 9, 16, 17, 18, 20
#   MIDDLE, six    slots 2, 5, 7, 10, 26, 33
#   UNMARKED, two  slot 16 (_ZN12dScMg3DEsp_cD1Ev) and slot 33
#                  (_ZN19dScMgSingle3DBase_c9Virtual84Ev); the other twelve carry the
#                  "recovered from vtable slot identity" marker
#   nosrc          ZERO. All fourteen resolve to a real src TU.
#
# ALL TWELVE MARKERS WERE ADJUDICATED AGAINST THE ROM BY THIS LANE, with the
# instruction-plus-pool arithmetic on every one, and appended to
# port/tools/inferred_stub_adjudicated.txt. Five of the twelve are the middle
# base's and already carried rows from run link60 lane MGB and run mg6 lane
# MEM; they were re-derived rather than inherited, and this lane's rows agree
# with theirs.
#
# ---- THE STATE MACHINE IS SEVEN TABLES AND THREE LEVELS DEEP ---------------
#
# port/unmatched/Mg3DEsp_StateDispatch.cpp is the derivation: twenty-two pairs
# out of src/__sinit_ov006_02130a08.c read assignment by assignment, twenty-two
# DISTINCT code words, every adjustment zero, every table with exactly two
# relocations (the constructor's and its dispatcher's pool) so none is orphaned,
# and every arity hand-read off the ROM rather than taken from src. Seven
# dispatching TUs are host-copied and are OUT of this slice; TWO of the seven
# are the open-coded-int third shape that neither the link nor a `::*` sweep can
# see, and one of those two is reached only through the other.
#
# ---- ZERO PER-SOURCE RENAMES, AND THE REASON IS THE REUSABLE PART ----------
#
# THIS SLICE CARRIES NO -D ROW AT ALL. An earlier draft of this section said
# "ONE PER-SOURCE RENAME, AND IT IS NOT OPTIONAL" and ended "port/
# CMakeLists.txt carries the two -D rows", and BOTH SENTENCES WERE FALSE: no -D
# row for this class exists, port/CMakeLists.txt's own block says so in its
# heading ("NO PER-SOURCE -D ROW FOR THIS CLASS, AND THE REASON IS REUSABLE"),
# and the wave-1 list below this contradicted it a hundred lines further down.
# It survived because it was written before the repair was attempted and never
# revisited after the attempt failed. It is corrected here rather than deleted,
# because a later lane looking for the per-source-rename precedent would look
# at exactly this heading and take the wrong lesson from it.
#
# WHAT ACTUALLY HAPPENED. src/_ZN12dScMg3DEsp_c16CleanupResourcesEv.cpp (slot 3, CleanupResources)
# releases two SharedFilePtrs spelled G0 and G1 -- shared placeholder names for
# globals that exist in no config. hal/cxx_aliases.cpp binds bare G0 to
# _data_020a0eac (the game heap) and bare G1 to _data_ov002_0210e05c, and BOTH
# ARE WRONG FOR THIS TU. The body's own literal pool says what they are, read
# out of the overlay image at 0x020e9d14 and 0x020e9d18: 0x02141e9c and
# 0x02141e74, which are two of the eleven SharedFilePtrs
# __sinit_ov006_02130a08 constructs (file ids 0x1ef and 0x202).
#
# THE STANDING -D REPAIR CANNOT REACH THIS ONE, which is the finding. It works
# when the placeholder is declared in the TU and the target is not declared
# anywhere the TU can see. G1 AND ITS TARGET ARE BOTH IN include/decl_common.h
# -- line 396 is `extern int G1[];` and line 3041 is
# `extern void*data_ov006_02141e74;` -- so -DG1=data_ov006_02141e74 rewrites
# line 396 into a redefinition of line 3041 with a different type of
# indirection. Measured, not predicted: error C2372. A lane reaching for the -D
# repair should CHECK decl_common.h FOR THE TARGET FIRST; if it is there, the
# repair is a host copy. This one is
# port/unmatched/Mg3DEsp_Cleanup.cpp, and src/_ZN12dScMg3DEsp_c16CleanupResourcesEv.cpp is out of
# the list below.
#
# A scan of every TU in this slice for the shared placeholder names (VT, VT0,
# HEAP, G0, G1, G2, R0, R1, R2) returns this ONE file and no other.
#
# func_020beb68 in src/_ZN12dScMg3DEsp_c13OnYoshiTryEatEi.cpp needs NO row: it is
# data_ov004_020beb68 under a name that exists in no config, and
# port/unmatched/MgCoin_Faces.cpp already aliases it.
#
# ---- HOW THIS LIST WAS DERIVED ---------------------------------------------
#
# The delta only. port/slice_mg1.txt already carries the ov004 framework, the
# thirty-five overlay constructors (including this class's,
# src/__sinit_ov006_02130a08.c) and the arm9 waves under them, and
# port/slice_flw.txt and port/slice_mem.txt already carry all six of the middle
# base's bodies. CMake appends every list to the same targets and dedupes
# identical absolute paths, so nothing here is compiled twice and nothing
# already sliced is repeated.
#
# Seeded from the class's own code -- the eight own override bodies, the
# factory and the twenty routed state bodies -- and then closed by the link,
# wave by wave. Each wave is marked below.

# ---- wave 1: the class's own code -----------------------------------------

# the factory
src/d_s_mg3_d_esp.cpp

# the eight own overrides, less slot 6.
# SLOT 6 IS NOT HERE ON PURPOSE. src/_ZN12dScMg3DEsp_c8BehaviorEv.cpp is the Behavior
# and it is a pointer-to-member dispatcher declared inside extern "C", which is
# one of the two shapes a link cannot see. port/mg_fanout_costs.txt section
# 14's practical rule is to read the src before wiring slot 6 by name; this is
# the class that rule is for. port/unmatched/Mg3DEsp_StateDispatch.cpp has it.
# slot 0  InitResources, 0x380
src/_ZN12dScMg3DEsp_c13InitResourcesEv.cpp
# SLOT 3 IS NOT HERE ON PURPOSE EITHER. src/_ZN12dScMg3DEsp_c16CleanupResourcesEv.cpp releases two
# SharedFilePtrs spelled as the shared placeholders G0 and G1, and the standing
# per-source -D repair CANNOT be used: G1 and its target are BOTH declared in
# include/decl_common.h (lines 396 and 3041), so the define turns one of them
# into a redefinition with a different type of indirection. Host-copied in
# port/unmatched/Mg3DEsp_Cleanup.cpp, which carries the derivation.
# slot 9  Render, 0xe4
src/_ZN12dScMg3DEsp_c6RenderEv.cpp
# slot 16 D2, unmarked
src/_ZN12dScMg3DEsp_cD1Ev.cpp
# slot 17 D0
# RETIRED at SLICE1: body now in src/_ZN12dScMg3DEsp_cD1Ev.cpp. MSVC folds the ROM destructor variants into one symbol, so only one of a class two per-function destructor TUs can be compiled.
#src/_ZN12dScMg3DEsp_cD0Ev.cpp
# slot 18 state reset -- READS ITS ARGUMENT
src/_ZN12dScMg3DEsp_c13OnYoshiTryEatEi.cpp
# slot 20
src/_ZN12dScMg3DEsp_c9Virtual50Ev.cpp

# the twenty routed state bodies, less the two that are also dispatchers
# (func_ov006_020e9b70 and func_ov006_020e8830, both host-copied).
# f2c 0
src/func_ov006_020e9bbc.c
# f2c 2
src/func_ov006_020e989c.cpp
# fac 0
src/func_ov006_020e97b0.c
# fac 1
src/func_ov006_020e96f4.cpp
# fac 2
src/func_ov006_020e968c.c
# fac 3
src/func_ov006_020e9670.c
# f5c 0
src/func_ov006_020e9318.c
# f5c 1
src/func_ov006_020e91a0.c
# f5c 2
src/func_ov006_020e8f14.c
# f74 0
src/func_ov006_020e8cb0.c
# f74 1
src/func_ov006_020e8c74.c
# f74 2
src/func_ov006_020e8bd0.cpp
# f1c 0
src/func_ov006_020e8928.c
# f8c 0
src/func_ov006_020e8728.c
# f8c 1
src/func_ov006_020e85f0.c
# f8c 2
src/func_ov006_020e84b8.c
# f8c 3
src/func_ov006_020e83bc.c
# f44 0
src/func_ov006_020e82c8.c
# f44 1
src/func_ov006_020e8214.c
# f44 2
src/func_ov006_020e81e0.c

# ---- wave 2: the closure the first link named ------------------------------
#
# Nineteen unresolved externals over three targets, line for line the same set
# on all three. Eighteen are ov006 bodies this class's own code calls, and one
# is arm9. THE arm9 ONE IS LISTED, against port/slice_mg1.txt's general rule
# that the arm9 half comes back through /OPT:REF: func_020179b4 had no other
# caller in the build, so /OPT:REF had already dropped it, which is the same
# exception curling's wave 2 hit for twenty of them.
#
# ONE OF THE NINETEEN IS NOT HERE. _ZN15dMg3DEspModel_c8BehaviorEv is the per-frame tick of
# the sub-object at this+0x4fd8, and a `::*` sweep over these additions BEFORE
# they were wired found that it dispatches a member pointer held in an OBJECT
# FIELD. It is the EIGHTH dispatcher in a class the cost file budgets five for,
# and no link could ever have named the defect: the type is local to the TU, so
# no global is emitted and no symbol can fail. Host-copied in
# port/unmatched/Mg3DEsp_FieldPmf.cpp, which carries the derivation, the four
# routed addresses and the six source pairs.
src/_ZN15dMg3DEspModel_cC1Ev.cpp
src/_ZN15dMg3DEspModel_c13InitResourcesEv.cpp
src/func_ov006_020e8aac.c
src/func_ov006_020e81a4.c
src/func_ov006_020e8354.c
src/func_ov006_020e8b18.c
src/func_ov006_020e8e10.cpp
src/_ZN15dMg3DEspModel_cD1Ev.cpp
src/func_ov006_020e984c.c
src/func_ov006_020e95a4.c
src/func_ov006_020e95e4.c
src/func_ov006_020e93e8.c
src/func_ov006_020e8d7c.c
src/func_020179b4.c
#
# THE FOUR WRITERS OF THE FIELD, which are ordinary slice lines and are only
# grouped here because they are what makes the field's six source pairs make
# sense.
#
# THE OTHER READER IS NOT HERE, AND THE REASON IS A SECOND DEFECT.
# _ZN15dMg3DEspModel_c6RenderEv is the RENDER half of the same idle test and does NOT
# dispatch the field, so it needed no host copy for THAT -- but it dispatches
# the sub-object's ModelAnim at +0xc through a six-virtual local shadow, which
# is ROM numbering, and hal/cxxname_bridge.cpp deliberately does not dual-fill
# _ZTV9ModelAnim slot 5 because that slot is a real Virtual18. It is the TU
# that file's ModelAnim2 block says "trap-by-Virtual18 will name it if such a
# TU ever appears" about. Host-copied in
# port/unmatched/Mg3DEsp_ModelAnimRender_020e7b44.cpp; found by run mg9's
# mandatory element-vtable check, not by a fault.
src/func_ov006_020e7d7c.c
src/func_ov006_020e7e74.c
src/_ZN15dMg3DEspModel_c5ResetEv.cpp
#
# ---- wave 2b: the four field states, which arrive with the dispatch --------
#
# Named by the address switch in port/unmatched/Mg3DEsp_FieldPmf.cpp and by
# nothing else, exactly as run link60 lane MG2 measured for curling ("state
# bodies added to the slice: 0 predicted, 4 measured -- they arrive with the
# dispatch, not with the closure"). Every one has a src TU and every adjustment
# word is zero. func_ov006_020e7fac is the idle body the two sentinels name.
src/func_ov006_020e7cc0.cpp
src/func_ov006_020e7de8.c
src/func_ov006_020e7f04.cpp
src/func_ov006_020e7fac.c

# ---- wave 3: the second wave's own closure ---------------------------------
#
# Twenty-seven unresolved externals: eleven ov006 bodies, fourteen ordinary
# /alternatename rows and two more shadow-class destructors. All sixteen faces
# are in port/unmatched/Mg3DEsp_Faces.cpp. Every one of the eleven was swept for
# `::*`, for the //cpp marker and for the shared placeholder names before it was
# listed; all eleven come back clean, so this class's dispatcher count stays at
# eight.
src/_ZN17dMg3DEspAnimSet_c8BehaviorEv.cpp
src/_ZN17dMg3DEspAnimSet_cC1Ev.cpp
src/_ZN17dMg3DEspAnimSet_c13InitResourcesEv.cpp
src/_ZN15dMg3DEspModel_c14ResetTransformEv.cpp
src/_ZN17dMg3DEspAnimSet_cD1Ev.cpp
# src/_ZN17dMg3DEspAnimSet_c6RenderEv.cpp IS OUT: the SECOND shadow-class Render dispatch
# on a plain ModelAnim, and the one that was measured as a fault rather than
# read. Host-copied in port/unmatched/Mg3DEsp_ModelAnimRender_020e777c.cpp,
# whose header carries the nine-dispatch sweep of the whole class code block
# that says these two are the only broken sites.
src/func_ov006_020e7940.c
src/func_ov006_020e794c.c
src/func_ov006_020e792c.c
src/_ZN17dMg3DEspAnimSet_c5ResetEv.cpp
# the fifth writer of the field at the sub-object's +0x210, and the only one
# that spells the eight-byte pair as a `double`
src/func_ov006_020e7f5c.cpp
