Skip to content

Split Emit into generic C# fragments and Semantics-specific constants #183

Closed

Description

@matt-edmondson

Problem

Semantics.SourceGenerators/Emit.cs mixes two unrelated kinds of constant behind one internal static class:

Generic C# vocabulary — reusable by any generator:

internal const string Public = "public";
internal const string Static = "static";
internal const string SummaryOpen = "/// <summary>";
internal const string SummaryClose = "/// </summary>";
internal const string ValueParameter = "value";
internal const string RightParameter = "right";

Semantics-specific policy — meaningless anywhere else:

internal const string DiagnosticCategory = "Semantics.SourceGenerators";
internal const string PhysicsOperatorSuppression =
    "System.Diagnostics.CodeAnalysis.SuppressMessage(\"Usage\", \"CA2225:...\", Justification = \"Physics quantity operator\")";

As long as they share a file, the generic half cannot be extracted without dragging the physics half along.

Proposal

  • Move the C# keyword and doc-delimiter constants into the shared code-generation package as a public CSharpKeywords (or similar). Note that SummaryOpen/SummaryClose become redundant if the structured doc-comment model lands (Model XML documentation comments as structured data CodeBlocker#86) — prefer deleting them over moving them.
  • Keep DiagnosticCategory and PhysicsOperatorSuppression here, renamed to something that says what they are (SemanticsDiagnostics.Category, SemanticsAttributes.PhysicsOperatorSuppression).
  • ValueParameter / RightParameter are conventions of this generator's emission style, not of C#. Keep them here too.
  • While in the file: PhysicsOperatorSuppression is a hand-escaped attribute string. If the template model grows structured attribute support (Close the correctness and coverage gaps in the C# template object model CodeBlocker#85, item 6), build it from that instead of from a string literal.

Acceptance criteria

  • No Semantics-specific constant remains in whatever type is extracted.
  • Committed generator output unchanged (verify-generated stays green).

Context

Part of #181. Small, but it is a prerequisite for the extraction being a clean lift rather than a copy-and-prune.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions