Skip to content

Harden source generation and diagnostics - #24

Merged
RejectKid merged 1 commit into
masterfrom
harden-source-generator
Jul 22, 2026
Merged

Harden source generation and diagnostics#24
RejectKid merged 1 commit into
masterfrom
harden-source-generator

Conversation

@RejectKid

Copy link
Copy Markdown
Owner

What changed

  • isolate source generation into one deterministic file per bit object so malformed declarations cannot suppress unrelated output
  • classify backing fields from Roslyn symbols, including nullable byte[], and emit escaped, fully qualified identifiers and framework/library references
  • make raw byte* behavior explicit: checked mode reports BITSKIT009, while unsafe mode generates direct pointer access
  • validate invalid options, unsupported backing types, names, collisions, widths, fixed layouts, and modifier combinations with BITSKIT007BITSKIT014
  • tolerate malformed attributes and support compatible attributes derived from BitFieldAttribute
  • document the generator guarantees, diagnostics, and raw-pointer contract

Why

The generator previously depended on display strings and generated all bit objects as one output. Legal nullable/keyword/shadowing cases could produce invalid C#, a malformed declaration could affect unrelated objects, and raw pointers were wrapped as zero-length checked spans. These changes make generated output deterministic, symbol-correct, isolated, and diagnosable.

Validation

  • dotnet build BitsKit.sln -c Release --no-restore
  • dotnet test BitsKit.sln -c Release --no-build (4,616 tests on both .NET 8 and .NET 10)
  • dotnet pack BitsKit/BitsKit.csproj -c Release --no-build
  • benchmark discovery on .NET 10 via --list flat

Regression coverage includes nullable arrays, unsafe raw pointers, keyword identifiers, consumer types shadowing framework names, same-named objects in separate namespaces, invalid-object and invalid-field isolation, derived attributes, and all new diagnostics.

@RejectKid
RejectKid marked this pull request as ready for review July 22, 2026 21:02
@RejectKid
RejectKid merged commit c98ea8b into master Jul 22, 2026
7 checks passed
@RejectKid
RejectKid deleted the harden-source-generator branch July 22, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant