Feature resolution depends on the order of specializations (redefines vs. subsets) Environment

  • Syside 0.11.0 (CLI syside 0.11.0 18800c5, Python package syside==0.11.0)
  • macOS (Apple Silicon)

Summary
A usage has two specializations: it redefines one feature and subsets another. A nested feature it inherits is redefined with a value along only one of the two paths. Syside’s evaluator returns the redefined value or the unvalued original depending on which specialization is written first. KerML semantics don’t depend on the order of a feature’s specializations, so both orderings should give the same result.

package F16 {
    part def ChildContext {
        part child_bb { attribute setting defined by ScalarValues::Real [1]; }
        part child_gb subsets child_bb { attribute redefines setting = 3.2; }
        part child_wb subsets child_gb;
    }
    part def ParentContext {
        part childContext defined by ChildContext [1];
        part parent_gb { part role subsets childContext.child_bb [1]; }
        part parent_wb subsets parent_gb {
            // Variant A: redefines first
            part redefines role subsets childContext.child_wb;
        }
        part plainVia_wb subsets childContext.child_wb;
    }
    part ctx defined by ParentContext {
        attribute viaWbRole defined by ScalarValues::Real = parent_wb.role.setting;
        attribute viaChildWb defined by ScalarValues::Real = childContext.child_wb.setting;
        attribute viaPlain defined by ScalarValues::Real = plainVia_wb.setting;
    }
}

Variant B replaces the line marked “Variant A” with the same relationships written in the other order:

            part role subsets childContext.child_wb redefines ParentContext::parent_gb::role;

Evaluation script

import syside, sys
model = syside.load_model([sys.argv[1]])[0]
c = syside.Compiler(); lib = syside.Environment.get_default().lib
ctx = next(x for x in model.nodes(syside.PartUsage) if x.name == "ctx")
for n in ("viaWbRole", "viaChildWb", "viaPlain"):
    v = next(x for x in ctx.owned_features.collect() if x.name == n)
    print(n, "=", c.evaluate_feature(feature=v, scope=ctx, stdlib=lib, experimental_quantities=True)[0])

Observed

Variant A (redefines first) Variant B (subsets first)
syside check All checks passed All checks passed
viaWbRole F16::ChildContext::child_bb::setting (unvalued) 3.2
viaChildWb 3.2 3.2
viaPlain 3.2 3.2

The heritage of parent_wb.role lists its specializations in source order: [Redefinition, Subsetting] in A, [Subsetting, Redefinition] in B.

Expected
viaWbRole evaluates to 3.2 in both variants. parent_wb.role subsets child_wb, which specializes child_gb, which redefines setting with 3.2. The path through the redefined parent_gb::role leads to child_bb::setting, which is the same feature that child_gb redefines. So there is a single effective feature, and its value is 3.2 whatever the order in which the generals are written.

Apparent cause
Feature resolution seems to follow the first general in declaration order, and to stop at child_bb::setting without checking whether another general (reached through the subsetting) provides a redefinition of that feature.

Impact
This construction is idiomatic in recursive black-, gray- and whitebox architectures. An integrating-level whitebox constituent redefines the graybox constituent, which subsets the child’s blackbox, and subsets the child’s whitebox. With the natural part redefines X subsets Y ordering, the integrating level silently reads the child’s unvalued blackbox declaration instead of the design values the child’s graybox commits. No diagnostic is raised, so analyses and verification that read child design values get wrong or unresolved results.

Workaround
Write the subsets relationship before the redefines relationship. This requires naming the feature and qualifying the redefined feature (Variant B).

Related observation, possibly the same root cause
inherited_memberships and inherited_features in the Python API return no members inherited through a chained subsetting (subsets a.b), although name resolution and evaluation do follow such chains. For example, after part chained subsets ctx.x;, chained.a evaluates correctly while inherited_memberships is empty.

This is a known issue. Ideally, the solution would cover everything from name resolution to evaluation without significantly penalizing performance, e.g.something similar to a Python MRO. Syside stops search on the first match rather than continuing for a potentially better match, consistent with name resolution. The latter search method has significant performance overhead in name resolution that I would not be surprised if recursively forking name resolution to worker threads would be faster — it is that bad.

Technically, specialization order does matter:

As evidenced by ordered inherited members. However, the specification does not say what the order is, or rather it is implied by OCL constraints which are often extremely inefficient when implemented verbatim.

Fixed for the next release.