get output by label and input returns null for nodes that are not in an ancestor-descendant-relationship
I'm having a problem with the generator and I suspect it may have something to do with the order of the micro-steps which I don't fully understand, although I read the User Guide section about the generator algorithm.
I have a concept, let's call it ConceptA
and its reduction rule looks something like this:
concept ConceptA --> <T callA($LABEL$ MyLabel [someCall($COPY_SRC$[condition])], $COPY_SRC$[exprB]) T>
inheritors false
condition <always>
As you can see, a mapping label is attached that maps the instance of ConceptA to some output.
Now the problem is the following: The second COPY_SRC
, the one which has the dummy text exprB
under it, is not under the label macro and copies some input src to its place. This input is of another concept, let's call it ConceptB
. ConceptB
has of course its own reduction rule, but also a weaving rule. The purpose of this weaving rule is to weave additional arguments into the call expression whose dummy function name is someCall
in the example above (so the extra arguments should go next to the node labeled condition
in the example above). In this case, the returned sequence of the foreach of the weave-each of the weaving rule is an empty sequence, so no additional arguments should be weaved in in this particular case. But the query to retrieve the context for the weaving rule is executed nonetheless, which should be fine. The code for this query looks essentially something like this:
genContext.get output MyLabel for (node.ancestor<concept = ConceptA>)
But this returns null
for some reason. And so I get an exception:
java.lang.IllegalStateException: @NotNull method jetbrains/mps/generator/impl/interpreted/TemplateWeavingRuleInterpreted.getContextNode must not return null
I expected this to work and not return null
. I expected that the reduction rule for the ConceptA
instance is applied including the attachment of the mapping label, and only in the next micro-step are all the rules for the subnodes executed that got inserted via COPY_SRC
. But now that I get this exception, I wonder if this assumption is wrong. Maybe the weaving rule for the ConceptB
instance and the label attachment are executed in parallel since they are not in an ancestor-descendant-relationship in the AST. Can somebody tell me if this should work or if the execution is indeed parallelized and therefore the search for the output by mapping label is unreliable?
Please sign in to leave a comment.
I would say that in general getting IllegalStateException at runtime is a bug, either a missing design-time check or an error in the generator. I would encourage you to create a small reproducer if possible and submit a bug report to youtrack.jetbrains.com.
Interesting note, but unfortunately this does not really address my fundamental problem.
The exception is very simple to reproduce, just deliberately return null in the context query of a weaving rule and make sure the weaving rule is executed. You can use the example 7 from the generator sample project for that, just replace the content of a weaving rule's context query with
null;
.My problem is not really the fact that an exception is thrown. It makes sense to me that an exception is thrown when the context query returns
null
, since you cannot weave a node intonull
. My problem is the fact thatnull
is returned in the first place. The code that returnsnull
is the call to “get output by label and input”, which essentialy boils down to something like this:So my problem is the fact that the part of the output of a node can not be found using the mapping label, although I think the mapping label should have been attached. I would like to know how I can find the output in this case, maybe I have to split the generation steps somehow?