Skip to content

fix: CodeAnnotations builds its attribute constructions on use, not in static fields - #102

Merged
CaffeinatedCoder merged 1 commit into
release/2.3.0from
fix/code-annotations-statics
Oct 28, 2026
Merged

CaffeinatedCoder merged 1 commit into
release/2.3.0from
fix/code-annotations-statics

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #90

Problem

CodeAnnotations kept seven Metalama AttributeConstruction objects in static readonly fields. Such an object belongs to one compilation, and a static field outlives it. At design time the IDE keeps Metalama's process across edits, so every compilation that filled the fields stays reachable: a limited memory leak. Gaël Fraiteur of Metalama found it reviewing the project (discussion 2305).

Change

  • CodeAnnotations: each of the seven is a static property with an expression body now, which builds the construction where it is used. The 78 call sites (AddAttribute(CodeAnnotations.CompilerGenerated) and the like) are unchanged.
  • CompileTimeStaticStateTests (conventions): every static field of .Generators, and every static auto-property with storage, holds an allowlisted durable type: strings, Type, DiagnosticDefinition, and arrays, lists and tuples of those. [Template] members are skipped, since Metalama introduces them into the target.

Metalama's own detector for the pattern (metalama/Metalama#2307) is still open, so the build cannot use it yet.

Tests

  • With the seven fields restored, the new test fails and names all seven. A fixture test pins what counts as storage (fields, auto-properties, nested tuples) and what does not (expression-bodied properties, [Template] fields, constants, instance fields).
  • The generated code is unchanged: the generated-surface snapshot and the woven probes pass. Full suite: 18,214 passed.
  • Input class: static storage in compile-time code. The test walks every source of .Generators. The other static storage there is durable, so there was no sibling to fix.

🤖 Generated with Claude Code

…n static fields

CodeAnnotations held seven AttributeConstruction objects in static readonly fields. An
AttributeConstruction belongs to one compilation, and a static field outlives it: at design time,
where the IDE keeps Metalama's process across edits, every compilation that filled the fields stays
reachable. Gael Fraiteur of Metalama found it reviewing the project (metalama/Metalama discussion
2305); metalama/Metalama#2307 will detect the pattern, and is still open.

Each is a static property with an expression body now, so the 78 call sites
(AddAttribute(CodeAnnotations.CompilerGenerated) and the like) are unchanged, and so is the generated
code: the generated-surface snapshot and the woven probes pass as before.

CompileTimeStaticStateTests (conventions) holds every static field of .Generators, and every static
auto-property with storage, to an allowlist of durable types: strings, Type, DiagnosticDefinition,
and arrays, lists and tuples of those. [Template] members are introduced into the target and hold
nothing. With the seven fields restored it fails, naming all seven.

Input class: static storage in compile-time code. The test walks every source of .Generators; the
other static storage there (the DiagnosticDefinitions, TypedConversionMethods, GeneratedMemberNames)
is durable, so there was no sibling to fix.

Defect class CRP: what it costs is memory over an IDE session, with no effect on what is generated.

Closes #90

Defect-Class: CRP
Found-By: OR
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 2.3.0 milestone Oct 28, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working severity/medium Inconsistency or failure in a narrow scenario package/generators Affects CodoMetis.TypeKit.Generators labels Oct 28, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 1f47368 into release/2.3.0 Oct 28, 2026
14 of 15 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/code-annotations-statics branch October 28, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working package/generators Affects CodoMetis.TypeKit.Generators severity/medium Inconsistency or failure in a narrow scenario

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant