Skip to content

refactor(semantic): split the model's most involved derivations into one helper per concern - #2153

Open
devin-ai-integration[bot] wants to merge 5 commits into
developfrom
refactor/sonar-semantic
Open

devin-ai-integration[bot] wants to merge 5 commits into
developfrom
refactor/sonar-semantic

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What and why

SonarCloud's analysis of develop flags seven constructs in internal/semantic for cognitive complexity over 30 (go:S3776) and one switch with 37 branches (go:S1479). Each is addressed at the root by extracting one named helper per nested concern; nothing is suppressed, no rule or sonar-project.properties moved, and every evaluation order, early return and derived answer is unchanged.

internal/semantic/metamodel/structure_parameters.go (three go:S3776 findings)

  • structureBehaviorGenerals: the walk over the implied base features' behavior types moves into structureImpliedBaseBehaviors; the nested-subsetting exception and the uniqueStructureElements fold stay where they were.
  • structureParameterTable: the symbol-backed table becomes structureSymbolParameters, the owned-feature scan (direction, result role, first-result-wins) becomes structureOwnedParameters, and the claiming of a general's parameters by redefinition clause, position-with-direction, or result role becomes structureClaimedParameters. The recursion, the visiting cycle guard and the inherited-parameter append loop remain in the method.
  • structureImplicitParameterRedefinitions: the owning-type reading with its Behavior/Step test becomes structureBehaviorOwner (keeping the three distinct outcomes: unknown, not behavior-like, behavior-like), and the per-general result-or-positional lookup becomes structureParameterAt.

internal/semantic/semantics/annotations.go (go:S1479)

  • ReflectiveElements' feature switch drops from 37 to 27 branches. Ten data-like cases move to three helpers that run, in the switch's former position, right after sendElements: featureChainElements (ownedFeatureChaining, featureTarget, crossFeature, chainingFeature; the crossed-chain reading is its own crossFeatureElements), typeOperandElements (unioningType, intersectingType, differencingType, keyed to the Model method each reads) and expressionElements (argument, referent, function, referencedElement). Each helper reports handled so an unhandled feature still falls through to the remaining switch — including a non-Feature's ownedFeatureChaining, which the switch previously let fall to the trailing derivations.

internal/semantic/semantics/nested.go (go:S3776)

  • familyNestedFQN becomes the composition of familyRoleNestedFQN (the keyword-stated roles, composite or not) and familyCompositeNestedFQN (the kind-only composite rules), with the role rules still consulted first and the composite rules still gated on u.Composite.

internal/semantic/semantics/redefinition.go (go:S3776)

  • implicitParameterTargets: reading the direction and result role from a recorded symbol's facts or the usage's AST, and the skipExplicit refusal, move into parameterDirectionOf; the owner, position and general walk is untouched.

internal/semantic/semantics/reflective_relationships.go (go:S3776)

  • implicitRelationshipElements: the per-metaclass source/target end answers (specific, general, owningType, owningClassifier, owningFeature and relationshipEndFeature) move into implicitRelationshipEndElements, keeping the earlier implicit-form dispatch and the empty-versus-underived distinctions.

How it was verified

  • go build ./... && go vet ./... && test -z "$(gofmt -l .)" && make lint pass.
  • go test ./internal/semantic/..., go test ./tests/corpus -run 'TestTrainingExamples|TestPilotCorpora' (after ./scripts/download-training-examples.sh and ./scripts/download-pilot-corpora.sh), make test-quick SHARDS="model export", go test ./tests/hygiene, python3 scripts/check-doc-ids.py and python3 scripts/changelog.py check pass; no ratchet, baseline or golden moved.
  • go run -C tools ./cmd/pilot-apijson-diff -check reproduces docs/project/api-json-differential/ unchanged.

Checklist

  • make test and make lint pass locally
  • Tests added or updated for the change (pure refactor; the existing suites cover every touched derivation)
  • Documentation extended where it already covers the surface (no documented surface changes)
  • Changelog entry added as changes/unreleased/<slug>.<section>.md, not as an edit to CHANGELOG.md
  • baselines regenerated and make docs-counts run if a gate count moved (none moved)
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog
    Requested by: @HuiJun

🟢 Devin Review found nothing to fix · View findings

Devin Review

…one helper per concern

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@HuiJun
HuiJun added this pull request to the merge queue Nov 12, 2026
@devin-ai-integration
devin-ai-integration Bot removed this pull request from the merge queue due to a manual request Nov 12, 2026

This branch has not been deployed

No deployments
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