Repository navigation
fix: static readonly fields of immutable types are not static state (0.3.1) - #6
Merged
Merged
Conversation
…0.3.1) A snippet or include with a static readonly lookup table (string, primitive, enum, read-only / immutable collection of those) loaded a fresh assembly on every run under a host that cannot unload (Mono/Unity), leaking one assembly per run until the next domain reload. StaticState.Has now ignores readonly fields of immutable declared types. Arrays and mutable element types stay state. Contract 3.5 documents the rule; version 0.3.1 (Python unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ions, one-line docs Skipped: snippet-declared readonly structs as immutable (behaviour change, out of scope); foreach instead of All (no measurable gain). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… is not immutable, live-state caveat in 3.5 - A snippet type implementing / deriving a read-only or immutable collection type can keep state in its instance: then no view type counts as immutable (compiler-generated types excluded). - IntPtr / UIntPtr point at mutable native memory: state. - Spec 3.5: initializers reading live host state keep their first value on Mono; host objects behind a read-only type. - Tests: getter-only mutable auto-property, IntPtr, a snippet-implemented IReadOnlyList. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Problem
In 0.3.0
StaticState.Hastreated every non-const static field as state,static readonlyincluded. A snippet or include with astatic readonlylookup table therefore loaded a fresh assembly on every run on a host that cannot unload (Mono / Unity): one leaked assembly per run until the next domain reload.Fix
static readonlyfield (or getter-only static auto-property) is not state when its declared type is immutable: string, primitives other thanIntPtr/UIntPtr, enums, decimal, DateTime, DateTimeOffset, TimeSpan, Guid, nullables of these, and read-only / immutable collections (IReadOnly*,ReadOnlyCollection/Dictionary,System.Collections.Immutable.*) of immutable elements.spec/contract.md§3.5 documents the rule and its consequences (an initializer reading live host state keeps its first value on Mono). Changelog v0.3.1.__version__ = "0.3.0"):python/code_exechas no diff.Tests
StatefulSnippetsNeverSeeAnotherRunsStatics: 11 new cases (5 stateless lookup tables, 6 stateful readonly variants). Plant checks: disabling the exemption turns all 5 stateless cases red; exempting every readonly field turns the 3 mutable-readonly cases red; trusting views turns the snippet-implementedIReadOnlyListcase red.scripts/test-all.shwith Roslyn 3.8.0 + 5.9.0 (net8/net10, C# 9 SourceConsumer, pack + PackageConsumer, Python) green; net48 green (116).Implement stages
Nullable.GetUnderlyingType,!IsNestedfor immutable collections, shorter docs.🤖 Generated with Claude Code