Skip to content

Operator deduplication may miss commutative or symmetric Dot/Cross variants #57

@matt-edmondson

Description

@matt-edmondson

Summary

Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs deduplicates emitted operators using simple string keys (e.g. "Dot:{selfType}:{otherType}:{resultType}", "Mul:{a}:{b}"). These keys are not symmetric across operand order, so the generator can emit:

  • both A * B and B * A for commutative multiplications
  • a Dot(B) on A and another Dot(A) on B whose generated bodies represent the same scalar product

The result is duplicate definitions or — worse — slightly inconsistent ones if metadata changes between sweeps.

Evidence

  • QuantitiesGenerator.cs:153-161 and :245-278 build the dedup keys directly from operand order.
  • Self-divide is handled as a special case (:161) but no equivalent commutative normalisation exists for cross-dimensional ops.

Suggested next step

  • Normalise operand order in dedup keys (e.g. sort the operand type names alphabetically when the relationship is declared commutative).
  • Add a generator-level invariant test that compiles a small fixture and asserts no duplicate methods/operators per generated type.

Area / Severity

SourceGenerators · incomplete

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions