#45 Enable AOT/trim analyzers and source-generate key regex - #58
Merged
Merged
Conversation
Enable `IsAotCompatible` on the core and hybrid packages; both build clean with zero IL2xxx/IL3xxx warnings under `-p TreatWarningsAsErrors=true` on net8.0 and net10.0, including the generic NatsHybridCacheSerializer<T> path. Convert the `RegexOptions.Compiled` key-validation regex in NatsExtensions to a source-generated `[GeneratedRegex]` partial method (pattern semantics preserved) so it does not fall back to the interpreter under AOT. Enabling the analyzers pulls in the SDK-implicit, build-time-only `Microsoft.NET.ILLink.Tasks` package, so the NuGet lock files are regenerated (that one package is the only delta; PrivateAssets, never flows to consumers). Add unit tests covering the key-validation regex accept/reject behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Matthew DeVenny <matt@codecargo.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR advances issue #45’s AOT/trimming compatibility work by enabling AOT/trim analyzers for the core and hybrid packages, replacing the runtime-compiled key-validation regex with a source-generated regex, and adding unit coverage to ensure key-validation behavior remains unchanged.
Changes:
- Enabled AOT/trim analyzer behavior via
<IsAotCompatible>true</IsAotCompatible>in bothNatsDistributedCacheandNatsHybridCacheExtensions. - Replaced the
RegexOptions.Compiledkey-validation regex field with a[GeneratedRegex]source-generated regex inNatsExtensions. - Added unit tests to validate accepted/rejected key behavior and regenerated RID-specific NuGet lockfiles.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Extensions/NatsExtensionsKeyValidationTests.cs | Adds unit tests asserting key-validation accept/reject behavior via TryPutWithTtlAsync. |
| src/NatsDistributedCache/NatsExtensions.cs | Converts key-validation regex to source-generated [GeneratedRegex] and updates call site. |
| src/NatsDistributedCache/NatsDistributedCache.csproj | Enables AOT compatibility/analyzer behavior for the core package. |
| src/NatsHybridCacheExtensions/NatsHybridCacheExtensions.csproj | Enables AOT compatibility/analyzer behavior for the hybrid extensions package. |
| src/NatsDistributedCache/packages.win-x64.lock.json | Lockfile regen to include Microsoft.NET.ILLink.Tasks (SDK/analyzer-induced). |
| src/NatsDistributedCache/packages.linux-x64.lock.json | Lockfile regen to include Microsoft.NET.ILLink.Tasks (SDK/analyzer-induced). |
| src/NatsDistributedCache/packages.linux-arm64.lock.json | Lockfile regen to include Microsoft.NET.ILLink.Tasks (SDK/analyzer-induced). |
| src/NatsDistributedCache/packages.osx-arm64.lock.json | Lockfile regen to include Microsoft.NET.ILLink.Tasks (SDK/analyzer-induced). |
| src/NatsHybridCacheExtensions/packages.win-x64.lock.json | Lockfile regen to include Microsoft.NET.ILLink.Tasks (SDK/analyzer-induced). |
| src/NatsHybridCacheExtensions/packages.linux-x64.lock.json | Lockfile regen to include Microsoft.NET.ILLink.Tasks (SDK/analyzer-induced). |
| src/NatsHybridCacheExtensions/packages.linux-arm64.lock.json | Lockfile regen to include Microsoft.NET.ILLink.Tasks (SDK/analyzer-induced). |
| src/NatsHybridCacheExtensions/packages.osx-arm64.lock.json | Lockfile regen to include Microsoft.NET.ILLink.Tasks (SDK/analyzer-induced). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The ILLink.Tasks version in the lock files floats with the SDK/runtime patch level. Regenerate against the current .NET 8/10 SDK so the entries match what CI resolves (10.0.10 / 8.0.29), fixing the "NuGet lock files are out of date" drift check. Only Microsoft.NET.ILLink.Tasks changes; no other packages. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Matthew DeVenny <matt@codecargo.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #45 (AOT / trimming compatibility). One of three independent PRs splitting that issue.
What
<IsAotCompatible>true</IsAotCompatible>on the core (NatsDistributedCache) and hybrid (NatsHybridCacheExtensions) packages.RegexOptions.Compiledkey-validation regex inNatsExtensionsto a source-generated[GeneratedRegex]partial method (pattern semantics preserved exactly,\A…\zanchors and/ = .chars kept).Notes
-p TreatWarningsAsErrors=true— including the genericNatsHybridCacheSerializer<T>/serializerRegistry.GetSerializer<T>()path, so no[RequiresUnreferencedCode]/[RequiresDynamicCode]forwarding was needed.RegexOptions.Compiledis not flagged by the IL analyzers, but it degrades under AOT (Reflection.Emit → interpreter fallback); the conversion is proactive hardening.Microsoft.NET.ILLink.Taskspackage that enabling the analyzers pulls in. It hasPrivateAssetsand never flows to package consumers. Regenerating is required because the repo enforcesRestoreLockedMode=true+ a CI drift check.Testing
dotnet build -p TreatWarningsAsErrors=true: 0 warnings / 0 errors, net8.0 + net10.0.🤖 Generated with Claude Code