Repository navigation
Description
Problem Statement
lint (and every command that loads a workspace) reports a warning for a circular import:
lexer.sysml(2,20): warning: Circular import detected: 'Acme_Lexer' imports 'Acme'
Circular imports are explicitly legal in SysML v2 / KerML, so the diagnostic flags a valid, spec-conformant model as suspect. The OMG Pilot Implementation accepts such models silently. The warning also cannot be silenced or promoted (it stays a warning, exit code 0, even with --strict-unresolved), so it is pure noise for users who deliberately use a facade package that public imports its members while the members private import the facade.
Evidence from the specification
- KerML 1.0 §8.2.3.5.1 (Name Resolution Overview): "Circularity is allowed for Imports and Specializations. Therefore, when traversing the graph of these Relationships, an implementation must avoid re-processing a Namespace that has already been visited." The spec asks implementations to tolerate cycles by tracking visited namespaces, not to report them.
- KerML §8.3.2.4.2 (Import),
importedMemberships(excluded : Namespace [0..*]): "The excluded parameter is used to handle the possibility of circular Import Relationships." The sameexcludedparameter appears onNamespaceImport/MembershipImport.importedMemberships(§8.3.2.4.6, §8.3.2.4.4) and onNamespace::visibleMemberships(excluded, isRecursive, includeAll)(§8.3.2.4.5). The metamodel is designed around cyclic import graphs resolving correctly. - OMG example
sysml/src/examples/Import Tests/CircularImport.sysmlin the Pilot Implementation repository (P1public import P2::*, P2public import P1::*, with the comment "The following should not fail."). - Standard library: in the Pilot library (release 2026-09.1)
Systems Library/Parts.sysmlhasprivate import Items::Item;andItems.sysmlhasprivate import Parts::Part;, i.e. the library itself contains an import cycle betweenPartsandItems.
Reproduction
Three files (a facade Acme that publicly imports its members, and members that import the facade back). Taken from the pattern D experiment (experiments/issues/cycle):
acme.sysml
package Acme {
public import Acme_Lexer::*;
public import Acme_Parser::*;
part def AcmeSystem {
part parser : Parser;
}
}
lexer.sysml
package Acme_Lexer {
private import Acme::*;
part def Lexer {
ref part system : AcmeSystem;
}
}
parser.sysml
package Acme_Parser {
private import Acme::*;
part def Parser {
ref part lexer : Lexer;
ref part system : AcmeSystem;
}
}
SysML2Tools (identical on the pinned 0.3.0-beta.4+a8ae1f2 and current main a0d1284):
$ sysml2tools lint acme.sysml lexer.sysml parser.sysml (EXIT=0)
Linting 3 file(s)...
lexer.sysml(2,20): warning: Circular import detected: 'Acme_Lexer' imports 'Acme'
parser.sysml(2,20): warning: Circular import detected: 'Acme_Parser' imports 'Acme'
lint: no errors found.
$ sysml2tools lint --strict-unresolved acme.sysml lexer.sysml parser.sysml (EXIT=0)
lexer.sysml(2,20): warning: Circular import detected: 'Acme_Lexer' imports 'Acme'
parser.sysml(2,20): warning: Circular import detected: 'Acme_Parser' imports 'Acme'
lint: no errors found.
Every reference resolves (no Unresolved reference); the warning is the only output.
OMG Pilot Implementation (release 2026-09.1, jupyter-sysml-kernel-0.63.1, driven headlessly through SysMLInteractive.process(text), the code behind a notebook cell). The three files concatenated into one cell (they must be one cell or loaded as one resource because the cycle spans files):
OK CONCAT[acme.sysml,lexer.sysml,parser.sysml]
(no errors, no warnings; result.hasErrors() == false, formatIssues() empty)
And the OMG example on its own, which SysML2Tools also accepts silently (the detector only looks at top-level packages, so the same construct nested inside one file, P1 ↔ P2, is not reported):
$ sysml2tools lint --strict-unresolved CircularImport.sysml (EXIT=0, no diagnostics)
Pilot: OK CircularImport.sysml (no errors, no warnings)
(The Pilot cannot load the three-file repro one file per cell in either order: the first file's cell fails with Couldn't resolve reference to Namespace 'Acme_Parser' / 'Acme' because the other package is not loaded yet. That is a Pilot limitation of cell-by-cell loading, not a diagnostic about the cycle.)
Where it is emitted
src/DemaConsulting.SysML2Tools.Language/Semantic/Model/ReferenceResolver.csResolveAllcallsDetectCircularImports(importGraph, importSites)(line ~151) afterBuildImportGraph(lines ~270-322).DetectCircularImports/DetectCycles(lines ~336-392) run the DFS and add theDiagnosticSeverity.WarningCircular import detected: '{current}' imports '{neighbor}'(line ~385).BuildImportGraphkeys the graph on top-level package/definition names only, which is why the nested OMG example is never flagged: the diagnostic is inconsistent as well as stricter than the spec.
ExposeScopeResolverhas its own visited set for import cycles ((namespace, recursive, includeAll, filters)tuples). Before removing the diagnostic, verify thatNameResolver's import traversal terminates on cyclic imports independently of this DFS (the repro above and the OMG example resolve fine today, but the existing test only asserts "warning, no infinite loop").- Documentation/requirements/tests that encode the warning and would need updating:
docs/reqstream/sysml2-tools-language/semantic.yaml(~line 90),docs/reqstream/sysml2-tools-language/semantic/model/reference-resolver.yaml(~lines 114, 427),docs/design/sysml2-tools-language.md,docs/design/sysml2-tools-language/semantic/model.md,.../model/reference-resolver.md(~line 582),docs/design/sysml2-tools-tool/lint.md,docs/user_guide/introduction.md(lines ~190, 200),docs/verification/**and the testWorkspaceLoader_LoadAsync_CircularImport_ProducesWarningNoInfiniteLoop, plus.github/standards/sysml2-modeling.md("Import cycles raise a lint warning") and the two self-model workarounds that avoid imports only for this reason (docs/sysml2/model/sysml2-tools-tool/help/help-command.sysml,.../self-test/validation.sysml).
Proposed Solution
Preferred: stop emitting the warning. Keep the visited-set DFS only if something else needs the graph; resolution itself must keep terminating.
Alternative: keep the detector but downgrade it to an opt-in informational diagnostic (for example a --report-import-cycles flag, or an info-severity message that never affects the exit code, with or without --strict-unresolved), off by default.
Either way: update the requirement text, design/verification docs, the user guide table (Circular import; cyclic specialization | warning | 0; the cyclic specialization part is a separate question and can stay), the modeling standard, and replace the test with one asserting a cyclic-import workspace lints with no diagnostics and resolves every reference.
Alternatives Considered
Leave the warning and document lint noise: this forces the workaround recommended in the modeling standard (qualified references instead of imports), which makes facade-style organization (Acme publicly re-exporting its units) awkward even though the spec explicitly supports it.
Benefits
Valid models lint clean, lint output matches the OMG Pilot Implementation, and facade packages (public downward imports plus private upward imports) become a first-class organization pattern for multi-file models.
Priority
Medium - Would improve my workflow
Willingness to Contribute
Yes, I can submit a pull request
Activity