Skip to content

Resolve layout references by KerML name resolution (same-named definitions) - #84

Merged
Malcolmnixon merged 5 commits into
mainfrom
fix-same-name-defs
Nov 12, 2026
Merged

Malcolmnixon merged 5 commits into
mainfrom
fix-same-name-defs

Conversation

@Malcolmnixon

@Malcolmnixon Malcolmnixon commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Problem

ApiMark has three distinct DocumentationCoverageChecker part defs, one each in ApiMarkCpp, ApiMarkDotNet and ApiMarkVhdl. The General View drew one box wired to all three systems, plus two unconnected duplicates.

The layout strategies re-resolved raw reference text through a first-seen simple-name dictionary that spans the whole workspace. That ignores SysML v2 name resolution:

  • GeneralViewLayoutStrategy.BuildModelEdges / TryResolveQualified
  • InterconnectionViewLayoutStrategy.ResolveByTyping
  • GridViewLayoutStrategy.ResolveSupertypeIndices
  • general-view ResolveOwningBox endpoint mapping

Change (spec basis: KerML 1.1 Beta 2 §8.2.3.5)

  • New public Language unit NameResolver:
    • Local resolution (§8.2.3.5.3): owned, imported and inherited memberships of the namespace. Imports include membership and namespace imports, recursive or not, and filtered imports through a predicate that applies the SysML §7.5.4 filter conditions. Inherited memberships come from a type's general types and exclude private ones. Names, short names and alias memberships all match.
    • Full resolution (§8.2.3.5.4): outward through owning namespaces, then the global namespace.
    • Qualified names (§8.2.3.5.1): the first segment by full resolution, later segments by visible (public-only) resolution.
    • Redefined features (§8.2.3.5.1): resolved against each general type of the owning type.
    • Local namespace per relationship kind (§8.2.3.5.2): for example, a Specialization resolves in the owning namespace of its owning type.
    • Fallback: if all of the above fails, a bare simple-name match is made and flagged, listing every candidate.
  • AstBuilder: captures membership visibility (public by default), import visibility (private by default) and import all, short names, and alias members (SysmlVisibility, SysmlAliasNode).
  • ReferenceResolver: a simple name is looked up in the global namespace only after the enclosing namespaces and imports (§8.2.3.5.4). Previously, a local Base resolved to the standard library's top-level Base package.
  • General, Interconnection and Grid views: the semantic model's resolved typing/supertype is used first, then NameResolver. The bare simple-name fallback now emits a layout warning (Reference 'X' in 'P::Q' … matched 'A::X' by simple name only (ambiguous: …)) instead of silently picking a match. ResolveOwningBox no longer maps already-qualified endpoints by simple name.

Tests

  • Name resolution: owning package first; inherited member; alias and short name; private member via qualified name (doesn't resolve); private vs public import; redefinition target; ambiguous fallback flagged; filtered import.
  • Semantic model: local name shadows the standard library's global Base; visibility, short name and alias are captured.
  • Views:
    • General view wires three same-named definitions to their own systems.
    • General view warns on a simple-name fallback.
    • An unrendered qualified endpoint isn't re-mapped to a same-named box.
    • Interconnection view expands each package's own same-named container.
    • Grid view marks each row against its own package's same-named supertype.

Requirements, design (with spec clauses) and verification docs are updated, including a new NameResolver unit.

Validation

  • ./build.ps1: all tests pass on net8/9/10/11.
  • ./lint.ps1: clean.
  • reqstream --lint --enforce: clean.
  • The ApiMark overview renders three distinct, correctly wired DocumentationCoverageChecker boxes with no fallback warnings.

The General View re-resolved raw type/supertype reference text through a
workspace-wide simple-name dictionary (first-seen wins), so when several
packages each define a same-named part def (e.g. ApiMark's three
DocumentationCoverageChecker defs) every usage was wired to the first
one, leaving the others as unconnected duplicates. The Interconnection
View's ResolveByTyping had the same flaw when expanding nested
containers. ReferenceResolver itself resolves these correctly.

- General View: membership/typing/ref edges use each feature's resolved
  Typing edge; specialization uses the definition's resolved Supertype
  edges; the raw-text fallback now tries the enclosing namespaces
  (innermost first) before the simple-name last resort.
- Interconnection View: ResolveByTyping takes the feature, prefers its
  resolved Typing edge, then lexical scoping, then simple name.
- Regression tests, requirements, design and verification docs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings November 11, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Several moderate layout-resolution issues remain, allowing imported or non-rendered types and same-named definitions to produce incorrect cross-wired edges instead of honoring authoritative semantic targets and lexical scope.

4 open issues
What changed in this PR

This pull request updates General and Interconnection layout strategies to honor semantic type resolution and lexical namespace scoping when multiple packages contain definitions with the same simple name. It adds regression tests and updates the related design, verification, and requirements documentation.

Changes:

  • Prefer resolved typing and supertype targets before namespace-aware and simple-name fallbacks.
  • Resolve interconnection containers and General View relationships within the owning namespace.
  • Add same-named-definition regression tests and traceability updates.
File Description
test/​DemaConsulting.SysML2Tools.Tests/​Semantic/​WorkspaceLoaderTests.cs Verifies that same-named usages resolve to definitions in their owning packages.
test/​DemaConsulting.SysML2Tools.Tests/​Layout/​InterconnectionViewLayoutStrategyTests.cs Verifies that nested containers expand the correct same-named definition.
test/​DemaConsulting.SysML2Tools.Tests/​Layout/​GeneralViewLayoutStrategyTests.cs Verifies that General View composition edges connect each package to its own same-named definition.
src/​DemaConsulting.SysML2Tools.Core/​Layout/​Internal/​InterconnectionViewLayoutStrategy.cs Uses semantic typing targets and namespace-aware lookup for container expansion and root selection.
src/​DemaConsulting.SysML2Tools.Core/​Layout/​Internal/​GeneralViewLayoutStrategy.cs Uses semantic targets and namespace-aware resolution for General View relationship edges.
docs/​verification/​sysml2-tools-language/​semantic/​model/​reference-resolver.md Documents verification coverage for semantic same-name resolution.
docs/​verification/​sysml2-tools-core/​layout/​internal/​interconnection-view-layout-strategy.md Documents verification coverage for same-named container expansion in the Interconnection View.
docs/​verification/​sysml2-tools-core/​layout/​internal/​general-view-layout-strategy.md Documents verification coverage for same-named definition wiring in the General View.
docs/​reqstream/​sysml2-tools-language/​semantic/​model/​reference-resolver.yaml Adds the owning-namespace reference resolution requirement.
docs/​reqstream/​sysml2-tools-language/​semantic/​model.yaml Links the new reference resolution requirement into the semantic model requirements.
docs/​reqstream/​sysml2-tools-core/​layout/​internal/​interconnection-view-layout-strategy.yaml Adds the same-named container expansion requirement.
docs/​reqstream/​sysml2-tools-core/​layout/​internal/​general-view-layout-strategy.yaml Adds the same-named definition wiring requirement.
docs/​reqstream/​sysml2-tools-core/​layout/​internal.yaml Includes the new layout requirements in the internal layout requirements hierarchy.
docs/​design/​sysml2-tools-core/​layout/​internal/​interconnection-view-layout-strategy.md Documents semantic-target-first and namespace-aware container resolution behavior.
docs/​design/​sysml2-tools-core/​layout/​internal/​general-view-layout-strategy.md Documents semantic-target-first and lexical-scope resolution for General View relationships.

Review effort: Lite

- New public Language unit NameResolver: local resolution (owned, imported
  incl. recursive/filtered imports, inherited memberships; names, short
  names, aliases), full resolution outward to the global namespace, visible
  (public-only) resolution for later qualified-name segments, redefined
  features against the owning type's general types, and a flagged
  simple-name fallback.
- AstBuilder captures membership/import visibility, import all, short
  names, and alias members (SysmlVisibility, SysmlAliasNode).
- ReferenceResolver looks a simple name up in the global namespace only
  after enclosing namespaces and imports (local Base no longer resolves to
  the stdlib Base package).
- General, Interconnection and Grid views use the resolved edges first,
  then NameResolver; the bare simple-name fallback now emits a warning.
  ResolveOwningBox no longer maps qualified endpoints by simple name.
- Requirements, design (with spec clauses), verification, tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings November 11, 2026 20:59
@Malcolmnixon Malcolmnixon changed the title Resolve same-named definitions by owning namespace in General/Interconnection views Resolve layout references by KerML name resolution (same-named definitions) Nov 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Malcolm Nixon and others added 2 commits November 11, 2026 22:28
# Conflicts:
#	docs/reqstream/sysml2-tools-core/filtering.yaml
#	docs/reqstream/sysml2-tools-core/filtering/filter-expression-evaluator.yaml
#	docs/reqstream/sysml2-tools-core/layout/internal.yaml
#	docs/reqstream/sysml2-tools-core/layout/internal/general-view-layout-strategy.yaml
#	docs/reqstream/sysml2-tools-core/layout/internal/interconnection-view-layout-strategy.yaml
#	docs/reqstream/sysml2-tools-language/semantic/model.yaml
#	docs/reqstream/sysml2-tools-language/semantic/model/ast-builder.yaml
#	docs/reqstream/sysml2-tools-language/semantic/model/reference-resolver.yaml
#	docs/verification/sysml2-tools-core/filtering/filter-expression-evaluator.md
#	docs/verification/sysml2-tools-core/layout/internal/general-view-layout-strategy.md
#	docs/verification/sysml2-tools-core/layout/internal/interconnection-view-layout-strategy.md
#	docs/verification/sysml2-tools-language/semantic/model/ast-builder.md
#	docs/verification/sysml2-tools-language/semantic/model/sysml-node.md
#	src/DemaConsulting.SysML2Tools.Core/Layout/Internal/InterconnectionViewLayoutStrategy.cs
#	test/DemaConsulting.SysML2Tools.Tests/Filtering/FilterExpressionEvaluatorTests.cs
#	test/DemaConsulting.SysML2Tools.Tests/Semantic/WorkspaceLoaderTests.cs
…isibility

- ReferenceResolver resolves a simple name through a local member's short
  name or a local alias before outer or global names (KerML 8.2.3.5.2).
- GeneralView redefinition and subsetting lookups use the flagged
  simple-name fallback, and the fallback warning is recorded even when
  the match is outside the rendered scope.
- Aliases take their member visibility.
- NameResolver.GeneralTypes merges resolved edges with raw resolution of
  unresolved supertypes; filtered recursive imports keep searching after
  a rejected candidate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings November 12, 2026 03:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

…ody, layout re-check

- A membership import of an alias brings in the alias's short name.
- Visibility and short-name capture applies to KerML type, action, state,
  and requirement bodies, never taking a nested member's prefix.
- Layouts re-check semantic typing/supertype targets with NameResolver;
  a different KerML resolution wins.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A critical active finding shows semantic resolution can still create Typing/Supertype edges to private or out-of-scope targets, allowing references to cross namespace visibility boundaries.

1 open issue
7 resolved since last review

Review effort: Lite

@Malcolmnixon
Malcolmnixon merged commit 36a3690 into main Nov 12, 2026
10 checks passed
@Malcolmnixon
Malcolmnixon deleted the fix-same-name-defs branch November 12, 2026 14:18
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.

2 participants