Repository navigation
Conversation
- Revised productions for textual notation shorthand TransitionUsages to add EmptyTransitionSourceMember at the beginning. - Revised all TransitionUsage productions to have TransitionLinkMember at the end. - Removed adding these as additional members in the TransitionUsageAdapter. - Revised computation of UsageUtil.getSourceFeatureOf(transition).
Currently contains one test method testTransitionShorthandNotation, which checks that, when a transition is parsed from the shorthand notation, and then moved programmatically in the model, it retains its already computed source and target values. The test passes.
| findFirst().orElse(null); | ||
| if (sourceFeatureMembership != null && sourceFeatureMembership.getMemberElement() == null) { | ||
| Feature source = UsageUtil.getPreviousFeature(transition); | ||
| sourceFeatureMembership.setMemberElement(source); |
There was a problem hiding this comment.
This is still a mutation that can be called from a getter:
getSource / sourceFeature
→ UsageUtil.getSourceFeatureOf
→ TransitionUsageAdapter.computeSource
→ membership.setMemberElement(source)
There was a problem hiding this comment.
This is a trade-off. However, it is essentially the same level of mutation as resolving a proxy, which happens all the time in MF getters. Indeed, I was thinking of possibly using a proxy instead of a null for the un-transformed source member, but I think this would be hard to get to work with the Xtext (which we still need to do). Also, the source feature resolution is entirely reference, so there is no change to the AST composition (like there was before).
That said, I am not sure it is necessary that getSource returns the correct value before transformation. I set it up that way because the code for getSourceFeatureOf previously had a call to addAdditionalMembers, to ensure the source feature was computed. I would need to do some research to determine whether this is still necessary.
There was a problem hiding this comment.
I was able to remove the mutation by getSource and getSourceFeature and still get all tests to pass, though it took a bit more changes than I had expected.
|
|
||
| // Note: Needs to come before clearing and recomputation of inheritance cache. | ||
| //checkTransitionUsageSuccessionBindingConnector | ||
| computeTransitionLinkConnectors(); |
There was a problem hiding this comment.
Moving this computation into doTransform raises a lifecycle question for long-lived editable models.
After a transition has been transformed, reconnecting its source changes the source reference, but the previously computed binding still refers to the old source.
The inherited binding-enumeration methods only return the stored candidates, and calling ElementUtil.transform again skips doTransform on an already-transformed adapter.
Our prototype refreshed the transition binding candidates when they were requested, replacing candidates whose endpoints had changed. This also allowed reconstruction after clearing the binding lists or replacing the adapter.
What operation should an editor use to refresh these candidates after an edit or cleanup, without requiring a global transformation and neither a global cash invalidation? Could we add a regression test covering a source reconnection followed by binding enumeration?
There was a problem hiding this comment.
This computation was always in doTransform, because Namespace.doTransform calls addAdditionalMembers. It was just moved out of TransitionUsageAdapter.addAdditionalMembers (which is a goal of this PR) directly into doTransform.
Also, the point you are making is not specific to this PR. It is really just a variant of the "when to clear caches?" question. For example, the shorthand for SuccessionAsUsage requires the same lexical source search as the shorthand for TransitionUsage (indeed, the source and target for a TransitionUsage really get set in its nested succession).
Now, these shorthands are really intended for use in the textual notation. They are not available in the graphical notation. When a segment of a textual notation is re-parsed, then new abstract syntax objects are created for the resulting parse subtree, with new adapters ready for a new round of transformation.
But, if you want to get this same effect without re-parsing an element subtree, you could use ElementUtil.clean(Element), which removes the current adapter object from an element. Then, the next time the adapter for that element is retrieved, a new one is created that is untransformed. (This also effectively drops any caches implemented in the adapter.)
If, instead, you want to have a specific method for clearing the isTransformed flag or an option to not set this flag, that would not be very hard to add. But it should probably have its own issue separate from (and more generally than) what is being addressed in this PR.
| findFirst().orElse(null); | ||
| Membership sourceFeatureMembership = computeSourceFeatureMembershipOf(transition); | ||
| if (sourceFeatureMembership != null) { | ||
| Feature sourceFeature = FeatureUtil.getBasicFeatureOf((Feature)sourceFeatureMembership.getMemberElement()); |
There was a problem hiding this comment.
This changes the returned feature for a chained source. Previously, the basic feature was used to check whether the source represented an ActionUsage, but the method returned the original feature referenced by the membership.
For first off.nested, the previous implementation returned the chain, whereas this implementation returns its final feature, nested.
Is this change intentional for the contract of sourceFeature()? The final getSource() getter already normalizes its result, so these two APIs should be checked separately. Could we add a test covering the source membership, sourceFeature() and getSource() for a chained source?
There was a problem hiding this comment.
This is a mistake. I'll fix it. Thanks for the catch.
|
|
||
| ownedMembers.remove(transition); | ||
| ownedMembers.add(transition); | ||
| ElementUtil.transform(transition); |
There was a problem hiding this comment.
Does this call actually execute doTransform again? ElementAdapter.transform() skips it when the adapter is already marked as transformed.
The endpoint-stability assertions are useful, but this call does not appear to exercise a second transformation. Could we clarify the test comment and add separate coverage for the intended binding-refresh lifecycle after a programmatic edit?
There was a problem hiding this comment.
Well, I was kind of thinking that the idempotency of transform was part of the point here. However, I agree the test would be stronger if an ElementUtil.clean(transition) call is added, so that the transformation really has to run again. I have confirmed that the test still passes with this modification.
- Added tests for longhand transitions with and without a feature chain as source. (Test with source feature chain fails.) - Updated testTransitionShorthandNotation to clean element before transforming again.
|
|
||
| /** | ||
| * This flag records if the source or target of a SuccessionAsUsage that is the succession of a TransitionUsage | ||
| * have been set correctly. If not, a recomputation of implicit general types later my resolve the problem. |
There was a problem hiding this comment.
Yes, this is a mistype. I corrected it by amending the head commit and doing a force push. This is a case in which it really didn't seem worth devoting a commit to a one character correction!
| * This flag records if the source or target of a SuccessionAsUsage that is the succession of a TransitionUsage | ||
| * have been set correctly. If not, a recomputation of implicit general types later my resolve the problem. | ||
| */ | ||
| protected boolean isRecomputeImplicitGeneralTypes = false; |
There was a problem hiding this comment.
Adding this flag may complicated a long-lived editable model. See my general comment review.
There was a problem hiding this comment.
The field isRecomputeImplicitGeneralTypes is not persistent state. It is simply a way to communicate between the methods addDefaultGeneralType and computeImplicitGeneralType on how isComputeImplicitGeneralTypes (inherited from TypeAdapter) needs to be set. This is necessary, because isComputeImplicitGeneralTypes is set to false after the call from TypeAdapter.computeImplicitGeneralType() to addDefaultGeneralType(). I tried moving this set to before the call, but this resulted in a few test failures (one KerML test involving metadata and a couple virtual container tests).
However, I will admit that it is rather poor style to implement this kind of local communication between methods using a class field. So I have re-implemented it without this field by splitting the part of TypeAdapter.computeImplicitGeneralType() the makes the call to addDefaultGeneralType() and sets isComputeImplicitGeneralTypes to false into a separately overridable method (see below). This shows that no new persistent state is required for the proposed implementation.
What is persistent state, though, is the TypeAdapter.isComputeImplicitGeneralTypes flag, which already existed before this PR. I tried removing this flag, but that resulted in two to three times worse performance on the batch parse/transform/validate performance tests. So the flag is necessary for the current Xtext-based pilot implementation.
While not clearly delineated in the code (this is one of the older parts of the codebase), the isComputeImplicitGeneralTypes flag basically singles the caching of the implicit general types. So this flag should be handled together with caching in other adapters. But this is beyond the scope of the present PR. The important thing is that the implementation proposed here doesn't make the caching situation any worse.
|
Hi Ed, Thank you for addressing the review comments. Removing source completion from the getters, preserving chained sources and strengthening the transformation test are useful improvements. Regarding the new isRecomputeImplicitGeneralTypes field in ReferenceUsageAdapter, I understand the problem it solves: an endpoint may be queried before the transition’s shorthand source has been established, and that incomplete computation must not prevent a later attempt from finding the source. My concern is about its lifecycle in a long-lived editable model. The flag handles “the source is not available yet”, but it does not appear to handle “the source was successfully computed and has subsequently changed”. For example: After processing this model, the succession’s source end has an implicit reference subsetting to off. If a graphical command reconnects the transition source to on, the retry flag is already false. Re-enabling computation alone would not seem sufficient either, since the existing implicit reference subsetting prevents a replacement from being added. I checked the proposed ElementUtil.clean(transition) approach. It only removes the adapter from the transition itself; it does not reset adapters on its owned elements. Cleaning and transforming the transition can therefore rebuild its binding candidates while leaving the succession source end’s previously computed implicit reference subsetting unchanged. Calling transformAll after cleaning only the transition would not necessarily resolve this: the owned elements retain their adapters and their isTransformed flags. Also, if implied relationships have already been materialized, removing adapters does not remove those relationships. The updated movement test is useful, but it preserves the source, so the results retained by the succession ends remain valid. It does not exercise a reconnection after a successful initial computation. I take your point that this belongs to the broader invalidation question and is not entirely introduced by this PR. However, this additional flag illustrates the difficulty we encountered in ST6RI-969: stored candidates, computation control and the completeness of previous results are managed together across the adapter hierarchy. Clients cannot reliably refresh one result without understanding the state held by several related adapters. I am not suggesting that adapters should never contain state, or that this flag should be removed without an equivalent mechanism. Could we document the intended lifecycle and add a test that:
We can address the general lifecycle in a separate issue, but identifying and testing the required invalidation scope here would give downstream applications a concrete integration contract. Longer term, I would prefer to represent result completeness explicitly and separate request-local evaluation state from optional persistent caching. That direction does not depend on adopting the proposed rule engine. |
- Updated UsageUtil.getSourceFeatureOf() so it no longer calls TransitionUsageAdapter.computeSource(). - Updated ReferenceUsageAdapter so implied SuccessionAsUsage related features can be recomputed later if null now.
TypeAdapter now provides an overridable method "addImplicitGeneralTypes" with an parameter for setting the value of "isComputeImplicitTypes".
- Add cleanAll methods to ElementUtil. - Updated test to use cleanAll and transformAll in second step.
|
In the last couple of commits, I have implemented the following:
|
As necessary: - Adds Membership with no member element as the first ownedRelationship of the TranstionUsage. - Adds an empty transitionLinkFeature.
|
@adaussy |
|
This PR has been moved to the 2026-11 milestone. |
This PR continues the line of changes in previous PRs #814 (ST6RI-947), #818 (ST6RI-979) and #822 (ST6RI-981) to separate model preparation from model queries.
Background
Previously, the various textual notations for transitions were all parsed into a
TransitionUsagewithout a requiredtransitionLinkfeature. This was physically inserted into the abstract syntax tree (AST) later by overriding the methodaddAdditionalMembersin classTransitionUsageAdapter. Further, the shorthand transition notation in which thesourceis determined lexically (e.g, of the form "then...") was parsed into aTransitionUsagewithout the initial owned membership that usually determines the transitionsource. Thesourcewas determined later, also as part of theaddAdditionalMembersfunctionality.Normally,
addAdditionalMembersis called fromNamespace::doTransformas part of the semantic transformation of a model. However, it was also possible to callTransactionUsage.getSource()before a full transformation was done, in which case the implementation calledTransitionUsageAdapter.addAdditionalMemberson-demand. This coupled model queries with structural model mutations and adapter initialization. Such couplings are being systematically removed from the implementation.For example, consider following model, with a transition that explicitly declares both the source and target states:
A transition declaration in this form was parsed as referencing it's
sourcestate using an alias membership and containing a succession whose target feature was the transition target. Transforming the transition then resulted in an implied reference subsetting from the source end of the contained succession to the alias member, establishing that member as the succession source feature. The methodTransitionUsage.getSourcereturned the alias member reference to the transition source state.Now consider a version of this model that uses the implied-source shorthand notaion. In this shorthand, the source state is not explicitly denoted in the transaction, but is determined as the lexically nearest previous state before the transition.
This was parsed similarly to the previous version of the model, but without an alias membership for the source state. The correct source state was computed during transformation and an alias membership referencing this state was physically added to the
TransitionUsage. At this point, theTransitionUsagein the AST has the same form as when parsed from the full notation.So, during semantic transformation of the model, calling
TransitionUsageAdapter.transformincluded an initial call toTransitionUsageAdapter.addAdditionalMembers. The methodTransitionUsageAdapter.addAdditionalMembersdid two things:computeSource, which added a source alias membership to theTransitionUsageif it had been missing.computeTransitionLinkConnectors, which (among other things) added atransitionLinkFeatureto theTransitionUsageas necessary.The property getter
getSourceon theTransitionUsagewas also implemented to calladdAdditionalMemberson theTransitionUsagebefore actually getting the source element. This ensured that aTransitionUsageparsed from the shorthand notation actually had its source added to the parse tree, so it could be returned by the getter, in the case that the getter was called beforetransform. However, in this case, thegetSourcequery could result in the physical mutations to the parsed model as described above.Considerations
In the previous PRs mentioned at the beginning of this description, the general approach was to move functionality from the adapter class for an element to the post-processor class for the element. This is not the approach taken for the present PR for two reasons:
TreeIterator), so some elements may get skipped.sourceof a shorthandTransitionUsageis not parser-specific and, therefore, should stay in the adapter.Changes
TransitionUsagenotation. For the shorthand, thisMembershipis parsed with a nullmemberElement.transitionLinkFeatureto all the productions that produceTransitionUsages.Membershipfor thesourcefeature and adding thetransitionLinkFeaturefrom theTransitionUsageAdapter, but left other processing. This includes (incomputeSource) finding thesourcefor a shorthandTransitionUsageparsed with an initialMembershipwith a nullmemberElementand setting thememberElementto this source value.computeSourceandcomputeTransitionLinkConnectionsfromaddAdditionalMemberstodoTransform.UsageUtil.getSourceFeatureOf(Transition)to remove the call toaddAdditionalMembers. This means that the source of aTransitionUsageparsed from the shorthand notation remains null until theTransitionUsageis tansformed.Tests
Added
org.omg.sysml.interactive.tests.TransitionUsageTest:testTransitionSource– Tests that the source (and target) of a longhand transition declaration are computed correctly.testTransitionSourceWithFeatureChain- Tests that the source feature and source of a transition usage are computed correctly when the source is a feature chain.testTransitionShorthandNotation– Tests:TransitionUsageparsed from the shorthand notation has itssourceset correctly.TransitionUsageparsed from the shorthand notation, thatTransitionUsagecan change position in the abstract syntax tree for a model, and it's source feature won't change.testSuccessionInTransitionUsage– Tests: