Skip to content

Extract shared invocation cache storage from ILLink - #135886

Draft
sbomer wants to merge 11 commits into
mainfrom
sbomer/shared-invocation-cache
Draft

sbomer wants to merge 11 commits into
mainfrom
sbomer/shared-invocation-cache

Conversation

@sbomer

@sbomer sbomer commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Extracts ILLink's experimental invocation cache into shared sources, compiled into each consumer without adding a shared DLL. Tasks provide invocation descriptions and prepare their outputs before executing; the shared engine handles content hashing, lookup, restoration, storage, and purge. This intentionally goes beyond a mechanical extraction: the common output contract supports owned directories and file sets, records absent outputs, and uses checksummed manifests. That changes the experimental v1 entry format: existing entries are not reused, but remain purgable. #135446 builds on this infrastructure to add crossgen2 caching.

Replaces the ILLink-specific maintenance package and command with dotnet-build-cache, shared by both caches. Existing users should install that package instead of dotnet-illink-cache and replace dotnet illink-cache purge ... with dotnet build-cache purge --cache illink .... Commands already selecting an explicit directory can use dotnet build-cache purge --cache-directory <path> ... without a cache name. The cache-enablement environment variables are unchanged.

Validated independently on this branch: 287 ILLink/shared-cache tests and 65 maintenance-tool tests passed. Modern .NET and net472 task builds passed; net472 was built but not executed on Linux.

Note

This content was created with assistance from AI.

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 <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
@github-actions github-actions Bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Oct 15, 2026
@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Oct 15, 2026
@azure-pipelines

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

@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
sbomer added this pull request to stack #135895 October 15, 2026 20:58
sbomer and others added 2 commits October 15, 2026 14:24
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
sbomer and others added 2 commits October 16, 2026 09:57
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541
sbomer and others added 4 commits October 21, 2026 11:57
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541

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

Invalid output declarations can trigger cleanup that deletes the configured cache.

3 open issues
What changed in this PR

Extracts ILLink caching into shared sources for reuse by crossgen2, without adding a shared DLL.

Changes:

  • Shares cache configuration, identity, execution, storage, and purge logic.
  • Adds file-set output contracts and manifest checksums.
  • Replaces the ILLink maintenance tool with BuildCache and updates tests, build integration, and documentation.

Builds and tests were not run during this review.

File Description
src/​tools/​illink/​test/​ILLink.Tasks.Tests/​Mock.cs Uses shared key computation.
src/​tools/​illink/​test/​ILLink.Tasks.Tests/​ILLink.Tasks.Tests.csproj Includes shared cache tests.
src/​tools/​illink/​test/​ILLink.Tasks.Tests/​ILLink.Tasks.Tests.cs Updates task-specific cache coverage.
src/​tools/​illink/​test/​ILLink.CacheTool.Tests/​ILLink.CacheTool.Tests.csproj Removes old test project.
src/​tools/​illink/​test/​ILLink.CacheTool.Tests/​CachePurgeTests.cs Relocates purge tests.
src/​tools/​illink/​src/​ILLink.Tasks/​LinkTask.cs Delegates cache lifecycle to shared helpers.
src/​tools/​illink/​src/​ILLink.Tasks/​ILLinkCache.cs Removes task-specific storage implementation.
src/​tools/​illink/​src/​ILLink.Tasks/​ILLink.Tasks.csproj Compiles shared cache sources.
src/​tools/​illink/​src/​ILLink.CacheTool/​README.md Removes old tool documentation.
src/​tools/​illink/​src/​ILLink.CacheTool/​Program.cs Removes old command implementation.
src/​tools/​illink/​src/​ILLink.CacheTool/​ILLink.CacheTool.csproj Removes old tool project.
src/​tools/​illink/​illink.slnx References BuildCache projects.
src/​tools/​BuildCache/​tests/​CachePurgeTests.cs Tests command parsing and cache selection.
src/​tools/​BuildCache/​tests/​BuildCache.Tests.csproj Configures relocated tool tests.
src/​tools/​BuildCache/​src/​Program.cs Implements shared maintenance command.
src/​tools/​BuildCache/​src/​BuildCache.csproj Packages dotnet-build-cache.
src/​tools/​BuildCache/​README.md Documents maintenance and installation.
src/​tasks/​Common/​InvocationCache/​InvocationOutputs.cs Defines output declarations.
src/​tasks/​Common/​InvocationCache/​InvocationInputs.cs Defines input declarations.
src/​tasks/​Common/​InvocationCache/​InvocationDescription.cs Groups invocation identity and outputs.
src/​tasks/​Common/​InvocationCache/​InvocationCachePurge.cs Shares purge implementation.
src/​tasks/​Common/​InvocationCache/​InvocationCacheEntry.cs Shares entry metadata.
src/​tasks/​Common/​InvocationCache/​InvocationCacheConfiguration.cs Defines configuration and default paths.
src/​tasks/​Common/​InvocationCache/​InvocationCache.Outputs.cs Validates and maps outputs.
src/​tasks/​Common/​InvocationCache/​InvocationCache.Identity.cs Computes invocation fingerprints.
src/​tasks/​Common/​InvocationCache/​InvocationCache.cs Implements shared lifecycle and storage.
src/​tasks/​Common/​InvocationCache/​InvocationCache.Configuration.cs Reads cache environment settings.
src/​tasks/​Common/​InvocationCache.Tests/​InvocationCacheTests.cs Tests shared storage and lifecycle.
src/​tasks/​Common/​InvocationCache.Tests/​InvocationCachePurgeTests.cs Tests shared purge behavior.
eng/​Subsets.props Registers BuildCache build subsets.
eng/​pipelines/​coreclr/​templates/​purge-illink-cache.yml Locates renamed maintenance tool.
docs/​tools/​illink/​illink-tasks.md Updates maintenance instructions.
docs/​design/​tools/​illink/​task-cache.md Describes shared cache architecture.

Review effort: Balanced

Comment thread src/tasks/Common/InvocationCache/InvocationCache.cs Outdated
Comment thread src/tasks/Common/InvocationCache/InvocationCache.cs
Comment thread src/tools/BuildCache/src/BuildCache.csproj
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 <223556219+Copilot@users.noreply.github.com>
Copilot-Session: da7cf090-9a92-453d-beb2-f672a9a7b541

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.

🔵 Needs a closer look

Expanded filesystem restoration and incompatible cache encoding warrant maintainer validation across supported platforms; builds and tests were not rerun in this review.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Update API sketch and lifecycle docs for current cache contract

docs/​design/​tools/​illink/​task-cache.md:36

The API sketch and lifecycle paragraph describe an integration that the shared cache no longer exposes. TryCreateFromEnvironment takes InvocationCacheConfiguration; ILLink calls ExecuteCached with an InvocationDescription callback and a parameterless execution callback; restore/store take InvocationOutputs. The shared engine now computes the key from the task's input inventory and context. Update the signatures and ownership explanation together so additional consumers do not follow the obsolete callback contract.

3 resolved since last review

Review effort: Balanced

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.

🔵 Needs a closer look

The expanded cache format and destructive output-restoration contract warrant cross-platform maintainer review; builds and tests were not run in this review.

1 open issue

Review effort: Balanced

Comment on lines +34 to +36
internal static int Execute(InvocationCache? cache, DateTime outputTimestampUtc,
Func<InvocationCacheRequest?> getInvocation, Func<string?, int> execute,
Action? onRestored = null);

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