Potential bug with resolveTemp() [message #1839624] |
Wed, 24 March 2021 18:13 |
Yves BERNARD Messages: 146 Registered: July 2014 |
Senior Member |
|
|
Hi all,
I get a strange issue. Let's assume that I write the followings rules:
unique lazy rule rule_for_A {
from
src: MM1!A
to
tgt: MM2!X
}
rule rule_for_Bv1 {
from
src: MM1!B
to
tgt: MM2!Y (
a_set <- Set{thisModule.rule_for_A(src.a)},
one_a <- thisModule.resolveTemp(src.a, 'rule_forA', 'tgt')
)
}
rule rule_for_Bv2 {
from
src: MM1!B
to
tgt: MM2!Y (
one_a <- thisModule.resolveTemp(src.a, 'rule_forA', 'tgt'),
a_set <- Set{thisModule.rule_for_A(src.a)}
)
}
Of course, I can only have one of the two "rules for B" in my transformation. The point is that I didn't get the same result with two versions. In the transformation I'm writing, the rules written like the v1 (i.e. resolveTemp *after* the call to the lazy rule) work fine while the ones written like the v2 (i.e. resolveTemp *before* the call to the lazy rule) generate a runtime error.
Did I missed something or is it actually a (known?) bug?
Thanks,
Yves
Yves
[Updated on: Wed, 24 March 2021 18:15] Report message to a moderator
|
|
|
Re: Potential bug with resolveTemp() [message #1839628 is a reply to message #1839624] |
Wed, 24 March 2021 20:00 |
|
This is a limitation of how lazy rules work: resolveTemp() does not trigger any rules. Only invoking the lazy rule does that. Therefore, resolveTemp() cannot find 'tgt' before the unique lazy rule is executed.
Normally, if you only need the default "to" element of a unique lazy rule, you just invoke the rule again on the same input. Instead of creating new output elements every time it is invoked, it will return the same (unique) output for a given (unique) input.
The special version of resolveTemp() with three parameters has been added in EMFTVM to be able to also access other output elements of a unique lazy rule, apart from the first one. However, it "leaks" the implementation detail of whether or not a unique lazy rule has been invoked before. A relatively clean way to insulate against this, is to invoke the unique lazy rule you depend on within the "using" clause of a rule:
unique lazy rule rule_for_A {
from
src : MM1!A
to
tgt : MM2!X,
tgt2 : MM2!Y
}
rule rule_for_Bv2 {
from
src : MM1!B
using {
tgt : MM2!X = thisModule.rule_for_A(src.a);
}
to
tgt : MM2!Y (
one_a <- thisModule.resolveTemp(src.a, 'rule_forA', 'tgt2'),
a_set <- Set{tgt}
)
}
Cheers,
Dennis
|
|
|
Powered by
FUDForum. Page generated in 0.02010 seconds