Repository navigation
chore: Read the sources a compiled assembly was built from out of its PDB document table - #3275
Conversation
…cument table Snapshot capture asks Unity for every compilation assembly on the main thread, which is the one step it cannot move off the main thread. A PDB already lists every source the compiler was given, so these parts let a later change build the same list from the dll and PDB instead: - HotReloadPdbDocumentTable reads every document row, including sources without a method body, after matching the PDB to the dll's build. - HotReloadCompiledSourceMap maps the urls to Unity asset paths for both url forms (pathmapped "./" and absolute), packages whose folder differs from their name, packages outside the project and Virtual Players. - HotReloadSnapshotPackageRoots reads the package roots with the same immutability rule the capture uses. A cross-check test compares the result with Unity's sourceFiles for every compiled assembly of this project. Nothing calls the parts in production yet.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The current hot-reload capture behavior is unchanged. No actionable issue identified here prevents merging after normal checks. Pre-merge checks |
|
Summary
CompilationPipeline.GetAssemblies(), plus a test that cross-checks the two lists on every compiled assembly of this project.User Impact
What
HotReloadPdbDocumentTable.Read(dll, pdb): matches the PDB to the dll's build by the CodeView GUID (throwsInvalidOperationExceptionotherwise), then returns every row of the PDB's document table in table order. UnlikeHotReloadPdbDocumentIndex.ReadDocuments, it includes sources without a method body (empty, comment-only or declaration-only files), which no sequence point refers to.HotReloadCompiledSourceMap.FromDocuments(...): maps document urls to the asset paths Unity lists insourceFiles, plus whether the assembly belongs to an immutable package (decided by the first mapped source, the same rule asShouldSkipImmutablePackageSources). It handles:./-relative urls (assemblies compiled with a pathmap) and absolute urls (assemblies without one, and packages outside the project), including Windows drive-letter urls on any platform;LocalPkg2is not insideLocalPkg), de-duplication, and dropping generated documents, non-C# documents and project files outside Assets and package roots.HotReloadSnapshotPackageRoots.ReadCurrent(): the registered package roots with the capture's immutability rule (Embedded and Local are editable). Kept separate fromScriptPackageRootsso the type pause points share does not change.HotReloadPdbDocumentIndex.ReadCodeViewGuidandToHashAlgorithmgo fromprivate statictointernal staticso the table reader reuses them. No other change to existing files.Assets/Tests/Editor/HotReload/Fixtures/PdbDocumentTable/.Cross-check result
HotReloadCompiledSourceCrossCheckTests.FromDocuments_MatchesTheSourceFilesUnityListsForEveryCompiledAssemblypasses on this repository's development project (Unity 2022.3.62f3, macOS): for all 112 compiled assemblies with sources, a dll and a PDB, the immutability matchesShouldSkipImmutablePackageSources(sourceFiles), and for the editable ones the asset path set equalssourceFiles.StopwatcharoundReadonly).Verification
Run one class at a time with
uloop run-tests --filter-type class:HotReloadCompiledSourceMapTests: 23 passed (one test per row of the input table; 17 failed against a stub before the implementation).HotReloadPdbDocumentTableTests: 2 passed (both failed against a stub).HotReloadCompiledSourceCrossCheckTests: 2 passed. With theAssets/mapping disabled as a mutation, both failed and the cross-check listed the 17 Assets-side assemblies whose lists differed.HotReloadPdbDocumentIndexTests(existing): 26 passed after the visibility change.scripts/check-file-length.sh: no file over the limit.