Skip to content

fix(semantics): reflect the concrete metaclass of eight grammar forms - #2142

Merged
HuiJun merged 41 commits into
developfrom
fix/reflect-concrete-metaclasses
Nov 20, 2026
Merged

HuiJun merged 41 commits into
developfrom
fix/reflect-concrete-metaclasses

Conversation

@devin-ai-integration

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

Copy link
Copy Markdown
Contributor

Refs #2244.

What and why

The qvts synthetic atlas asks reflection (Reflection::Elements_<Metaclass>) what each element is, and eight concrete metaclasses answered nothing or their general class. Each now reflects the metaclass its grammar production returns, consistently in the semantic model, the query metamodel (@type), the element-form and query element ids, API JSON and RDF:

Form Before Now
exhibit state s : T; / exhibit s; StateUsage ExhibitStateUsage (classified on develop since #2410)
include use case u : T; / include u; UseCaseUsage IncludeUseCaseUsage (#2410)
library package L; Package LibraryPackage (#2410; standard library package too, still warning library-package)
#M x; (prefix metadata, no kind keyword) ReferenceUsage Usage
KerML succession flow f from a.x to b.y; Flow SuccessionFlow (#2410)
filter @M; no membership ElementFilterMembership owning the condition
calc def K { 1 } (and calc, constraint def, other function-like bodies) no membership ResultExpressionMembership owning the result (a body expression's a.{in q; q} was already owned so)
flow f from p1.x to p2.x; ends under ownedRelationship/ownedEndFeature only the two FlowEnds develop owns natively (#2266, #2369) are also the flow's ownedMember/ownedElement/member, and the element form's @id names each end (<flow>_end0), its ReferenceUsage (_end0_ff) and a chained end's ReferenceSubsetting (_end0_rs), as the query leg already read them

The members a declaration owns without a symbol of its own (filter conditions, body results) are minted once per Model in a memoized side table (synthesizedMembersOf); together with develop's FlowEnds (FlowEndMembers) they are placed at their clause among ownedMembership, ownedMember, member, ownedElement and ownedFeature/feature; the AST is untouched. #2410 landed the LibraryPackage, ExhibitStateUsage, IncludeUseCaseUsage and SuccessionFlow classifications on develop while this PR was open; this head keeps that one implementation (isExhibitedState, isIncludedUseCase, ModInclude) and drops its own duplicate, so against develop it adds the plain Usage, the two memberships and the FlowEnd members, plus the focused tests for all eight. UsageFormMetaclassName is the one entry the query metamodel reads the form-selected usage metaclasses through (event, exhibit, include, prefix metadata), for declarations and library records alike; interface.go records ModExtendedUsage, so the interface format version moves to 25. A message mints no FlowEnds (SysML.xtext MessageEventMember has none).

The synthesized elements carry ids on every surface: the RDF/API JSON exporter mints <filter member>_filter, the symbolfacts element form reads it by node, and the id reader (export.ElementIDs, queryexec.ElementIDOf) records a calc/verification body result's expression parts like a constraint condition's (develop's ConstraintResultMember work had registered only the latter), so element-form @id, query results and the structure differential map them instead of answering empty or [unmapped]. The element form likewise answers an implied flow end, its ReferenceUsage and its ReferenceSubsetting from the slots the conversion mints (end0, end0.ff, end0.rs), mirroring queryexec.

#2244 (chained flow ends failing validateConnectorRelatedFeatures) is fixed on develop by #2266's native FlowEnds; its reproducer self-checks clean on this head too (245 checks, 0 violations, 0 unevaluated).

Related work: #2410 (the four classifications above), #2008 (the SysML SuccessionFlowUsage), #2266 (native FlowEnds, closing #651's flow-end gap; this PR lists those ends as members).

This head also contains #2002 and #2425, which precede it in the merge order because all three move structure_differential_expected.txt; their commits leave this diff once they merge.

Specification basis

SysML.xtext (pilot 2026-09): ExhibitStateUsage, IncludeUseCaseUsage, ExtendedUsage returns SysML::Usage (vs DefaultReferenceUsage returns SysML::ReferenceUsage), ResultExpressionMember, FlowEnd (FlowEndSubsetting), MessageEventMember; KerML.xtext LibraryPackage, SuccessionFlow, ElementFilterMember. KerML 1.1 8.2.4 (ElementFilterMembership), 8.3.4.7.6 (ResultExpressionMembership), 8.3.4.8.4 (FlowEnd, checkFlowEndRedefinition); SysML v2 8.3.6.10, 8.3.17.5, 8.3.21.4.

One row added to docs/project/spec-compliance/02-detailed-semantic-compliance-map/02-calculation.md (✅). The grammar-to-metaclass map is regenerated: the LibraryPackage, ExhibitStateUsage and IncludeUseCaseUsage disagreements are gone.

Known limitations, named here rather than left to discover: a flow's connectorEnd/endFeature still answer the inherited Transfer ends ahead of its own; RDF for a KerML file keeps mapping succession flow to FlowUsage as it maps every KerML feature to its SysML usage kind.

How it was verified

  • New internal/semantic/semantics/reflective_concrete_metaclasses_test.go: one exact-metaclass test per form (declaration and recorded-library paths, explicit and shorthand exhibit/include, library vs plain package, #M x; vs a bare x;, SysML and KerML succession flows, filter/result membership chains and owners, distinct filter identities, a filter condition's scope before resolution).
  • Review round: a namespace with several filter members minted conditions sharing one expression record (one identity for all of them, so the second condition's subtree was never compared), and before document resolution a condition's names resolved in the scope enclosing the namespace rather than its own; each condition now carries its position and resolves in its namespace, with TestElementFilterConditionsKeepDistinctIdentities and TestElementFilterConditionResolvesInItsNamespaceBeforeResolution (the structure differential's tests/testdata root improves in 26 cells, parse/expressions.sysml having five filters).
  • Element ids: elementform/element_identity_test.go (implied flow ends and their ReferenceSubsetting, filter conditions, constraint and calc results), queryexec/flow_end_ids_test.go (filter condition) and queryexec/calc_result_ids_test.go, export/element_ids_reader_test.go and export/element_ids_identity_test.go.
  • TestExtendedDefinitionUsageMetaclass now expects Usage; tests/export/testdata/convert/end_prefix_metadata.golden.ttl moves sysml:ReferenceUsage → sysml:Usage for end #M x (3 lines, the only change).
  • Generated baselines re-recorded with the repository tools only, every movement adjudicated against a fresh develop recording: structure differential (examples/ matched 36647 → 39953; Flow::flowEnd leaves the disagreement list, develop had equal 17 / different 38; Type::ownedEndFeature different 40 → 2; Expression::result equal 3520 → 4105; the relatedFeature movement above), pilot-apijson-diff (typeMismatch 1838 → 1808, presentDifferent 147578 → 147550, pilotMissing 84347 → 84342, improvements only), derived-census (the walk now reaches the FlowEnd, filter-condition and body-result subtrees; the pilot columns do not move), grammar-metaclass map. pilot-differential-baseline.json and training_examples_expected.txt untouched: pilot-diff -check fails on develop itself since fix(check): reject KerML-only declaration keywords in SysML files by default #2275 (three spec-example cells), and that re-record is chore(baselines): re-record the pilot differential for the KerML declaration keyword error #2323's.
  • go build ./... && go vet ./... && gofmt -l . && go test ./... with all six OPENSYSML_REQUIRE_* corpus gates after their download scripts, tests/wasm (REPL 16,305,374 B, engine 11,104,766 B, core 7,488,741 B gzipped, under the budgets), make lint, make docs-counts, go test ./tests/hygiene, go test -C tools ./referee/apijson, pilot-apijson-diff -check, derived-census -check -require-exporter (JDK 21), go test -C tools ./referee/diff, scripts/check-doc-ids.py, scripts/changelog.py check, the comment-length scan; cmd/sysml and tests/codegen re-run alone after a loaded box hit the 10m default.
  • Current head (merges of develop, feat(export): an expression's implied base completes its type and inherited family in the element form #2002 and SWF(bug): fix OwningMembership for a trigger's named payload #2425): go build ./..., go vet ./..., gofmt -l ., make lint, the internal/semantic/..., internal/workspace/libs, internal/frontend/symbolfacts/..., internal/doc/queryexec, internal/translate/export and tests/export packages with the corpus gates, and pilot-apijson-diff -check; the structure differential is re-recorded by tool on the combined tree (one cell beyond this PR's own movement: examples/pilot-corpora OwningMembership::ownedMemberElementId different 32 → 33, where SWF(bug): fix OwningMembership for a trigger's named payload #2425's trigger-payload ownership meets the synthesized memberships). The full-suite and wasm figures above are from the last full local gate, before these merges.
  • By hand: sysml -convert ttl on a probe with all eight forms states the metaclasses above; standard library package still warns; sysml -self-check on the A flow with chained ends (flow from a.b.x to c.d.y) fails validateConnectorRelatedFeatures: the query leg answers no relatedFeature for it #2244 reproducer.

Checklist

  • make test and make lint pass locally
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (see CONTRIBUTING.md)
  • 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 (compliance rows need nothing: the census is counted at docs build)
  • No internal work-item labels (waves, slices, F4, K5) in the body, docs, or changelog

Link to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/a37d687b08a14a4684e597b532b8dd66
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/a37d687b08a14a4684e597b532b8dd66?variant=devin
Requested by: @HuiJun


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

Reflection, the query metamodel, API JSON and RDF now state the metaclass the grammar production returns rather than the kind's general class: exhibit state (ExhibitStateUsage), include use case (IncludeUseCaseUsage), library package (LibraryPackage), a prefix-metadata usage with no kind keyword (Usage, SysML.xtext ExtendedUsage) and KerML succession flow (SuccessionFlow). A namespace's filter conditions are owned through ElementFilterMemberships, a function-like body's result through a ResultExpressionMembership, and a flow's two ends as FlowEnds through EndFeatureMemberships: named source and target by the Transfer end they redefine, each reference-subsetting the feature it attaches to, listed by ownedMembership, ownedMember, ownedFeature and ownedEndFeature. The members live in a memoized side table of the Model.

Regenerates the grammar-to-metaclass map baseline, the structure differential and the pilot API JSON differential (improvements only).

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 Bot and others added 8 commits November 13, 2026 20:28
…te-metaclasses

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

# Conflicts:
#	docs/project/api-json-differential/index.json
#	docs/project/api-json-differential/pilot-examples/Arrowhead Framework Example/AHFNorwayTopics.sysml.json
#	docs/project/api-json-differential/pilot-examples/Cause and Effect Examples/CauseAndEffectExample.sysml.json
#	docs/project/api-json-differential/pilot-examples/Requirements Examples/RequirementDerivationExample.sysml.json
#	docs/project/api-json-differential/pilot-examples/Vehicle Example/SysML v2 Spec Annex A SimpleVehicleModel.sysml.json
#	docs/project/api-json-differential/training/41. Language Extension/User Keyword Example.sysml.json
#	internal/semantic/semantics/reflective_relationships.go
#	internal/semantic/symbols/expression.go
#	internal/translate/export/testdata/structure_differential_expected.txt
…ting; element-form ids for flow ends and filter conditions

A `message` relates events through MessageEventMembers (SysML.xtext), so it mints no
FlowEnds; a FlowEnd owns a ReferenceSubsetting only when its clause names a feature of
a feature (SysML.xtext FlowEndSubsetting). SynthesizedElementID composes a FlowEnd's id at
its end slot, the id reader records a filter condition and a chained flow end's reference
subsetting as the conversion writes them, and the element form reads a condition by node.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
… leg identifies them

The conversion mints a flow's ends at end0/end1 with their EndFeatureMemberships; the
id reader now records them by the feature each from/to clause selects, as it does a
connector's ends, so ElementIDOf reads a FlowEnd, its membership and a chained end's
ReferenceSubsetting as written.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…te-metaclasses

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

# Conflicts:
#	docs/project/api-json-differential/index.json
#	docs/project/api-json-differential/pilot-examples/Vehicle Example/SysML v2 Spec Annex A SimpleVehicleModel.sysml.json
#	docs/project/grammar-metaclass-map-baseline.json
#	internal/frontend/symbolfacts/elementform/element_identity_test.go
#	internal/translate/export/element_ids.go
#	internal/translate/export/testdata/structure_differential_expected.txt
…te-metaclasses

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

# Conflicts:
#	docs/project/api-json-differential/index.json
#	docs/project/api-json-differential/pilot-examples/Vehicle Example/SysML v2 Spec Annex A SimpleVehicleModel.sysml.json
#	internal/frontend/symbolfacts/elementform/element_identity_test.go
#	internal/semantic/metamodel/derived_census_baseline.json
#	internal/semantic/metamodel/derived_census_records.tsv
#	internal/semantic/semantics/annotations.go
#	internal/translate/export/element_ids.go
#	internal/translate/export/kinds.go
#	internal/translate/export/testdata/structure_differential_expected.txt
… it is written as

A calc, verification or other function-like body's closing bare expression is
written as the member stating it (ResultExpressionMembership), so its operands,
parameters and result take ids under that member, as a constraint's condition
already did; the synthesized element id no longer names it at `result`, which
only a body expression's result carries. The structure differential is
re-recorded over the newly compared result-expression subtrees.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…ord severity change

The three spec-example cells that moved (7.13.4/3, 8.4.9.2/3, 8.4.13.6/8) are
the kerml-notation diagnostic now reported as an error (#2275); clean develop
reproduces the same movement. Re-recorded with pilot-diff -update.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 16, 2026 15:56
…ve it in its namespace

A namespace with two `filter` members synthesized conditions that shared one
expression record (owner, role, index 0), so KeyOf and the metamodel's
structure keyed them as one element: reads conflated the two and the second
condition's subtree never compared. Each condition now carries its position
among the namespace's filters, as a flow end carries its end's.

Before the document is resolved, the reflective layer resolved a filter
condition's names in the scope enclosing the namespace, where the walk reads
them in the namespace itself (document.go FilterMember), so a reference bound
an outer namesake or nothing. expressionScopeOf answers the namespace's own
scope for a filter condition.

The structure differential re-records tests/testdata: the five filters of
parse/expressions.sysml now compare one by one, so 26 cells improve and
Expression::result and Feature::featureTarget leave the differing set.

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

@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.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 3 findings. Devin automatically fixed all 3 findings.

Fixed by Devin (3)
  • Explicit extended references become compositions — Confirmed: IsReference is set only by the ref keyword, so the ExtendedUsage exemption in usageIsComposite wrongly kept ref #M x; composite. Removed the exemption; test covers #M x; composite and ref #M y; referential on the declared and recorded paths.
  • Recorded extended usages lose composition — Confirmed: UsageIsComposite's recorded branch rejected the ReferenceUsage kind before recordedUsageIsReferential's ExtendedUsage exception, so EffectiveIsComposite was false for a recorded #M x;. The kind rule now exempts ModExtendedUsage in both places while ref/end/event modifiers still apply; test asserts EffectiveIsComposite on both fixtures.
  • Three-line comment exceeds repository limit — Comment shortened to two lines.

View findings in Devin Review · Follow Devin's work

Devin Review

devin-ai-integration Bot and others added 14 commits November 16, 2026 16:46
…rML-keyword severity change"

This reverts commit 34e5f41.
…te-metaclasses

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

# Conflicts:
#	internal/translate/export/kinds.go
… now reached

A namespace's second and later filter conditions have their own identity
since the filter-identity fix, so the census walk reaches the
FeatureChainExpression of tests/testdata/parse/expressions.sysml's
`filter a.b.c;`: FeatureChainExpression::operator and ::targetFeature on
the testdata root move from 1 to 2 of the pilot's 3.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
develop's native FlowEnds (#2266, #2268, #2369) supersede this branch's
synthesized ones, so the synthesis, its ExpressionFlowEnd role, ids and
tests are dropped; the filter-condition and body-result synthesis stays
and wraps develop's withFlowEndFeature. kinds.go keeps this branch's
ExtendedUsage branch ahead of #2279's narrowed ReferenceUsage test.

Two gaps the merge exposed are fixed at the root: a flow's FlowEnds are
now also its ownedMember/ownedElement/member (withSynthesizedMembers
places FlowEndMembers at their clause) and the element form answers an
implied end, its ReferenceUsage and its ReferenceSubsetting from the
conversion's slots; and a usage declared by prefix metadata alone
(`#M x;`, a plain Usage) is composite by default on the symbol side as
the RDF writer already states it, instead of referential.

Generated artifacts re-recorded by tool only: structure differential
(FlowEnds listed as members, Usage::isReference back to develop's
figures), derived census (elements/implied fall where the duplicate
FlowEnd synthesis went away).

Co-Authored-By: jason.han <hanhuijun@gmail.com>
The calculation row named the branch's superseded flowEndRedefinedEnd and
ExpressionFlowEnd; develop's FlowEndMembers/flowEndFeatureRedefinition own
flow ends now. Drops the test helper the FlowEnd synthesis left unused.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
usageIsComposite exempted every ExtendedUsage from the reference rule, but
IsReference is set only by the ref keyword, so `ref #M x;` reflected as a
composition (SysML v2 8.3.6.10).

Co-Authored-By: jason.han <hanhuijun@gmail.com>
UsageIsComposite rejected a recorded ExtendedUsage by its ReferenceUsage
kind before recordedUsageIsReferential could see it, so EffectiveIsComposite
disagreed with direct reflection; the kind rule now exempts ModExtendedUsage
while the ref/end/event modifiers still apply.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
…elop's owned succession ends

Clean develop reproduces its own baseline; the ten cells move only on the
combined tree, where #2311's owned succession ends are also listed among the
synthesized members this branch adds.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…s owned succession ends

Clean develop reproduces its own census; the pilot-validation rows (and one
pilot-examples, one training row) move only on the combined tree, where the
succession ends #2311 owns are also members this branch synthesizes.

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

# Conflicts:
#	internal/translate/export/testdata/structure_differential_expected.txt
…elop 9d9b320

The merge took develop's copy; this records the combined tree, where this
branch's synthesized memberships, FlowEnd members and ExtendedUsage
composition move the cells develop's baseline cannot see.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
devin-ai-integration Bot and others added 14 commits November 19, 2026 19:54
…d9b320

The cell-wise merge summed both sides' deltas (one cell went negative); the
sixteen rows now hold the measured values of the combined tree.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
element_ids.go keeps this branch's filter-condition and body-result id
registration beside develop's send-argument and guard registration (#2408);
the structure differential takes develop's copy pending its tool re-record.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…elop 052fdb9

The merge took develop's copy; this records the combined tree, where this
branch's synthesized memberships, FlowEnd members and ExtendedUsage
composition raise every root's matched count.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
Develop's #2410 classifies a library package, an exhibited state, an
included use case and a succession flow by their production; this branch
keeps those classifications once, through develop's isExhibitedState,
isIncludedUseCase and ModInclude, and UsageFormMetaclassName (the query
metamodel's entry) now reads them beside the event and ExtendedUsage
forms. ModExhibitedState and ModIncludedUseCase go; ModExtendedUsage stays,
so the interface format version moves to 25. The changelog fragment names
the four forms this branch alone adds.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…elop b5d1dff

The textual merge added #2410's gain to cells this branch had already
raised; the tool records the combined tree's measured values.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
Only the structure differential conflicts; it takes develop's copy pending
its tool re-record on the combined tree.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…elop 13bb942

The merge took develop's copy; this records the combined tree, where this
branch's synthesized memberships, FlowEnd members and ExtendedUsage
composition raise every root's matched count.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
Only the structure differential conflicts; it takes develop's copy pending
its tool re-record on the combined tree.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
…elop 1f208d2 and #2002

The merge took develop's copy; this records the combined tree, where this
branch's synthesized memberships, FlowEnd members and ExtendedUsage
composition raise every root's matched count.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
sysmlMetaclassName keeps #2425's trigger-payload ReferenceUsage rule ahead
of the declaration switch, which this branch reads through
UsageFormMetaclassName.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
One pilot-corpora cell moves on the combined tree (OwningMembership::
ownedMemberElementId, one more differing pair) where #2425's trigger
payload ownership meets this branch's synthesized memberships.

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

This comment was marked as resolved.

devin-ai-integration Bot and others added 2 commits November 20, 2026 08:46
…class row

The row still named ModExhibitedState and ModIncludedUseCase, which went
when this branch adopted develop's isExhibitedState, isIncludedUseCase and
ModInclude; TestComplianceTablesNameLiveGoIdentifiers reads the row again.

Co-Authored-By: jason.han <hanhuijun@gmail.com>
The cell-wise merge kept #2002's derived counts on this branch's larger
element totals; the tool records the measured values of the 80 rows
(our-side columns only, each with at least as many derived as before).

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@HuiJun
HuiJun added this pull request to the merge queue Nov 20, 2026
Merged via the queue into develop with commit 19590f5 Nov 20, 2026
32 checks passed
@HuiJun
HuiJun deleted the fix/reflect-concrete-metaclasses branch November 20, 2026 17:01
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