Skip to content

Enable root-relative ILLink task cache sharing - #135320

Open
sbomer wants to merge 42 commits into
mainfrom
sbomer/illink-cache-worktree-sharing
Open

sbomer wants to merge 42 commits into
mainfrom
sbomer/illink-cache-worktree-sharing

Conversation

@sbomer

@sbomer sbomer commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Builds on #135886 to share eligible ILLink task cache entries across worktrees with equivalent layouts. Map declared source roots into stable cache identities while retaining full content hashing, and run single-root invocations from that root with structured relative arguments rather than rewriting raw command strings. Use the shared invocation cache for storage and restoration.

Caching remains opt-in, with compiler and symbol-preservation defaults unchanged. Unsupported inputs run uncached with their original arguments and working directory. This branch retains the already-merged resolver fix from #136249 because the current base predates it.

Validated both task targets, 355 task/shared-cache tests, 1,307 linker tests (30 existing skips), and 65 cache-maintenance tests on Linux. Real enclosing-root and disjoint-root cache hits matched uncached DLL/PDB bytes, including concurrent writers and SDK mapping probes. Windows/macOS execution and full runtime builds were not run.

Note

This pull request description was created with assistance from GitHub Copilot.

@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Oct 7, 2026
@azure-pipelines

azure-pipelines Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Untracked assembly-resolution paths and Windows drive-root rewriting can produce unsound cache keys.

Review effort: Balanced
Findings: 2 High severity

Open (2)
What changed in this PR

Adds root-relative ILLink cache identities so equivalent worktrees can share eligible cached outputs.

Changes:

  • Maps source-root paths into stable cache keys and relative invocations.
  • Expands cache eligibility checks and input hashing.
  • Adds target wiring, documentation, and extensive tests.
File Description
LinkTask.cs Implements path mapping and cache validation.
Microsoft.NET.ILLink.targets Forwards SDK source roots.
Mock.cs Captures cache invocation details.
ILLink.Tasks.Tests.cs Tests sharing, eligibility, and fallback behavior.
eng/​illink.targets Defines the runtime repository source root.
sfx-finish.proj Forwards source roots for framework trimming.
oob-trim.proj Forwards source roots for OOB trimming.
illink-tasks.md Documents task behavior and configuration.
task-cache.md Updates cache design decisions.

@github-actions github-actions Bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Oct 7, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

sbomer and others added 11 commits October 15, 2026 11:52
Keep ILLink configuration and input identity in the task while sharing entry validation, publication, directory restoration, and usage metadata. Preserve v1 serialization, mutex names, diagnostics, and purge semantics. Compile shared sources into consumers without adding a runtime assembly.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Reference the shared invocation cache entry metadata directly from the purge tool and tests.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Keep ILLink configuration and task tests in ILLink, and exercise storage with a tool-independent fixture.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Share opt-in parsing, cache-directory resolution, diagnostics, and construction while keeping ILLink eligibility and input identity in its task. Move configuration tests alongside the shared storage tests and preserve ILLink configuration behavior.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Share entry enumeration, last-used handling, deletion, diagnostics, and summary reporting with explicit layout and tool labels. Keep the ILLink CLI and idle-cache requirement unchanged. Move engine tests into shared sources and cover independent layouts while retaining CLI tests in the tool project.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Move restore-or-execute orchestration and successful-result storage into the shared cache sources. Keep ILLink eligibility, key computation and output preparation in task callbacks, preserving the existing directory-only v1 storage contract.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Describe inputs, context, and outputs independently of cache policy and compute content identities in the shared layer. Resolve cache configuration lazily and keep output preparation in normal tool execution, with cache-owned restoration on hits.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol

Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Preserve runtime library ExtraArgs input discovery in DescribeInvocation, including readable XML inputs and assembly search-directory inventories. Adapt bypass returns and diagnostic assertions to the extracted invocation-description contract.

Assisted-by: GitHub Copilot CLI:gpt-6.1-sol

Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Move the ILLink cache CLI into a standalone dotnet-build-cache tool. Support named ILLink and crossgen2 caches with explicit-directory, environment, and shared platform-default resolution, independently of task enablement. Update build, test, CI, and usage wiring and align tool-file identity coverage with explicit absence markers.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Use only the explicit cache directory in CI commands and the matching example. Explain that a cache name does not validate directory ownership when an explicit directory is supplied.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
Let output validation exceptions propagate instead of falling back to normal execution, preserving the existing protection against overlapping cache and output directories. Cover rejected declarations and ILLink output cleanup with regression tests.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
@sbomer
sbomer changed the base branch from main to sbomer/illink-reject-path-shaped-resolution October 21, 2026 21:48
@sbomer
sbomer added this pull request to stack #136310 October 22, 2026 17:49
Base automatically changed from sbomer/illink-reject-path-shaped-resolution to main October 22, 2026 20:57
sbomer and others added 3 commits November 11, 2026 12:39
Record input roles while generating execution arguments and logical cache context. Capture normalized file identities in InvocationDescription and extract source-root mapping from LinkTask. Remove override detection and assembly-name/module preflight restrictions; defer hashless linked-resource tracking.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Resolve physical input and output locations through a reversible path map instead of retaining parallel path and identity inventories.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Preserve root-relative invocation construction and reversible path identities while integrating CachedToolTask diagnostic capture and replay.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
sbomer and others added 14 commits November 12, 2026 10:54
Record arguments once and render execution and cache context from the same structured list, preserving original spelling on normalization fallback. Replace the abstract path map with a concrete shared SourceRootPathMap and retain linker-specific symbol checks in ILLink.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Reuse prepared paths in argument rendering, input discovery, output preparation and cache descriptions. Preserve original argument spelling for fallback and retain relative execution without deterministic mappings.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Store canonical full paths for file access and map distinct paths once during key construction, including structured argument context. Pass known paths to ILLink as full paths without changing its working directory. Retain cross-root sharing and reject overlapping logical namespaces.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Remove the invocation builder and rendering callbacks, retaining plain physical path records until cache key computation. Drop working-directory identity and redundant path normalization, and allow nested physical roots with independent logical prefixes.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Record task settings and item metadata directly instead of retaining command-line fragments. Keep ordered physical path inputs separate from the content inventory, mapping them only during key construction, and remove InvocationArgument.IsPath.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Construct cache descriptions directly from task parameters, resolving physical paths only for cache file access. Remove inline cache bookkeeping and argument rewriting, preserve the original response-building flow and raw extra arguments, and expose the content inventory as an unordered read-only collection.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Register supported extra arguments directly in the cache description, restore feature and substitution settings, and retain input/context collections without intermediate copies. Keep original tool argument construction unchanged.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Restore conservative assembly inventory, defer cache-only preparation until extra arguments pass, and remove unrelated execution and formatting changes. Cover early bypass and ignored input dependencies.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
Restore byte-only satellite inventory and limit symbol checks to emission. Preserve portable PDB paths without inspecting existing document or CodeView paths, and simplify physical invocation path handling.

Assisted-by: Copilot:gpt-6.1-sol
Co-authored-by: Copilot <[email protected]>
Copilot-Session: af970add-1797-4965-9c32-5230b3bf3400
…mbol preservation are absent

Avoid bypassing the ILLink cache when SourceRoots lack logical MappedPath prefixes, have conflicting logical mappings, or when portable PDBs are emitted without PreserveSymbolPaths. In these cases, include physical paths in the cache key so entries still store and hit at the same locations without being shared across worktrees.

Assisted-by: Copilot:gemini-4-neon
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 63f42165-ce0c-4ed8-8526-5f1e29a55b24
Verify via reflection that every public declared parameter on ILLink is covered by the cache key or explicitly bypasses caching, and that mutating each parameter changes the generated tool arguments (except SourceRoots) and cache key accordingly.

Assisted-by: Copilot:gemini-4-neon
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 63f42165-ce0c-4ed8-8526-5f1e29a55b24
Map external XML and assembly-location diagnostic origins using --pathmap
when logical SourceRoots are provided, so linker diagnostics are
path-independent and can be cached and replayed verbatim across worktrees.

Assisted-by: GitHub-Copilot-CLI:gemini-4-neon
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 63f42165-ce0c-4ed8-8526-5f1e29a55b24
…implification-temp

# Conflicts:
#	src/tools/illink/src/ILLink.Tasks/LinkTask.cs
#	src/tools/illink/test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs
@sbomer
sbomer requested a balanced review from Copilot November 24, 2026 22:48
@sbomer
sbomer requested review from a team and jtschuster November 24, 2026 22:53
@sbomer
sbomer marked this pull request as ready for review November 24, 2026 22:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical flaws can turn invalid descriptor paths into successful cache hits, replay incorrect XML diagnostic origins or stale symbol paths, and corrupt linker arguments for source roots containing quotes even with caching disabled.

4 open issues

Review effort: Balanced

Comment on lines +304 to +305
var paths = new SourceRootPathMap(SourceRoots);
pathDependentReason = paths.HasLogicalRoots ? null : "no SourceRoots have logical MappedPath prefixes.";
}
foreach (ITaskItem reference in ReferenceAssemblyPaths ?? Array.Empty<ITaskItem>())
{
if (!AddAssembly(AddPath(nameof(ReferenceAssemblyPaths), reference.ItemSpec), checkOutputSymbols: false))
Comment on lines +485 to +487
path = Path.GetFullPath(path);
if (path.Length > Path.GetPathRoot(path).Length)
path = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
@@ -44,22 +44,26 @@ public abstract class ProcessLinkerXmlBase
protected readonly LinkContext _context;

protected ProcessLinkerXmlBase(LinkContext context, Stream documentStream, string xmlDocumentLocation)
: this(context, documentStream, context.MapPath(xmlDocumentLocation), resource: null)
- Move LinkContext.AddPathMap/MapPath outside #if !ILTRIM so ILTrim.Core compiles.
- Normalize alternate directory separators in SourceRootPathMap.Map for Windows paths.
- Match LinkTask.Quote trailing-backslash trimming in ILLink.Tasks.Tests assertions.
- Reject quoted SourceRoots before --pathmap emission, verify effective skip action before waiving reference symbol checks, preserve trailing separators on file paths during cache input discovery, and resolve external XML paths before mapping diagnostic origins.

Assisted-by: Copilot:gemini-4-neon
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 63f42165-ce0c-4ed8-8526-5f1e29a55b24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

External linked-resource changes can now restore stale DLLs from the cache, and method-based diagnostics still expose physical source paths instead of applying path mapping.

6 open issues

Review effort: Balanced

throw new BadImageFormatException("Input PE image has no managed metadata.", path);
MetadataReader metadata = pe.GetMetadataReader();
foreach (AssemblyFileHandle handle in metadata.AssemblyFiles)
foreach (AssemblyReferenceHandle reference in metadata.AssemblyReferences)
!GetStringParam(token, out string? logicalPath))
return -1;

context.AddPathMap(physicalPath, logicalPath);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants