-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Description
OperationBodySyntax currently exposes (Try)GetGenericBody helpers for recovering a GenericOperationBodySyntax view from syntax.
This pushes a semantic concern into the syntax layer and encourages downstream code to recover structure by probing syntax shapes directly. It also duplicates knowledge that already exists at the semantic level, where bound operations already expose the relevant pieces of a generic body: operands, successors, regions, attributes, and the trailing type signature.
Proposed Change
Remove OperationBodySyntax.GetGenericBody() and OperationBodySyntax.TryGetGenericBody(...).
Instead, add a method or property on Semantics.Operation that synthesizes a GenericOperationBodySyntax from the operation’s semantic properties.
Then migrate GenericSyntaxBuilder to use this new semantic entry point rather than extracting a generic body from OperationBodySyntax.
Motivation
This change improves layering and makes the API direction clearer:
- syntax should represent what was parsed, not provide recovery helpers for semantic projections
- generic-body reconstruction belongs with bound operations, which already expose the constituent data
- consumers should depend on semantic structure when they want a generic representation
- this reduces reliance on syntax-shape probing and prepares the API for removing older generic-body convenience paths
Expected Design Direction
Instead of code reaching into syntax like this:
var genericBody = operation.Syntax.Body.GetGenericBody();
the semantic layer should provide an explicit way to obtain a synthesized generic body, for example:
var genericBody = operation.GenericBody;
or:
var genericBody = operation.ToGenericBodySyntax();
The exact shape of the API can be decided during implementation, but the new entry point should live on Semantics.Operation, not on OperationBodySyntax.
Scope
- Remove
OperationBodySyntax.GetGenericBody() - Remove
OperationBodySyntax.TryGetGenericBody(...) - Add a method or property to
Semantics.Operationthat synthesizesGenericOperationBodySyntaxfrom:- operand values
- successor references
- regions
- attributes
- trailing type signature information
- Migrate
GenericSyntaxBuilderto use the newSemantics.OperationAPI - Update any other internal call sites that currently rely on syntax-layer generic-body extraction
Benefits
- Improves separation of concerns between syntax and semantics
- Makes generic-body reconstruction an explicit semantic operation
- Reduces fragile syntax probing APIs
- Gives
GenericSyntaxBuildera cleaner dependency on bound operations rather than parse-shape recovery - Helps move the codebase toward a more coherent long-term API surface
Notes
- The synthesized generic body should preserve the formatting and token structure needed by
GenericSyntaxBuilder - Consider naming carefully so the new API clearly communicates that it is synthesizing a generic syntax representation rather than exposing parsed syntax directly
- Audit for any remaining code that treats syntax as the primary source of generic-body structure when semantic information is already available