miniwdl
miniwdl copied to clipboard
shortcut for evaluating member access of a struct literal?
Context: https://github.com/common-workflow-lab/wdl-cwl-translator/pull/188#pullrequestreview-88654613
It would be nice if there was a method on WDL.Expr.Get
from a fully WDL.load()
ed WDL.Tree.Document
to determine if it can be evaluated into a single static value.
https://github.com/common-workflow-lab/wdl-cwl-translator/blob/90c9c3e710e9b8395dcada0929013861537553a5/wdl2cwl/tests/wdl_files/literal_struct.wdl#L15
command <<<
echo ~{three.one} ~{three.two} ~{six.one} ~{six.two}
>>>
three
is a literal struct, so I don't think its value can change and short of trying to execute the entire WDL.Tree.Task
I don't see how to use the miniwdl methods to determine the result of the lookups
Thanks!
@mr-c hmm...can you help me understand the general applicability of such a method?
If the referenced expressions are anything but literal constants, then naturally evaluating the Get
has to entail building up the necessary environment by evaluating the declarations in turn (that is running the task to some extent).
If they are all literal constants, then a shortcut is possible in principle, but what's common/important about that case as to warrant a special method?
@mlin Sure. In this case it involves literal constants, yep.
The resulting conversion to a CWL Expression (a Javascript/ECMAScript 5.1 expression) is a bit verbose
https://github.com/common-workflow-lab/wdl-cwl-translator/pull/188/files#diff-80ca6af97f83dc40e9f835c30f0d6fad04710ad6d3271c0999b958a7ea383745R10
echo $({ "one": "four", "two": "five" }.one) $({ "one": "four", "two": "five" }.two) $(inputs.six.one) $(inputs.six.two)
If there was a function to easily evaluate the member access, then the translator could have produced
echo four five $(inputs.six.one) $(inputs.six.two)
In summary, it would be nice to have a function that could evaluate any "simple" WDL expression from a parsed WDL document.
A "simple" expression is one that does not make use of identifiers or any function that takes a File input or returns a File output; i.e. it is an expression that can be evaluated unambiguously without any knowledge of the runtime context. An execution engine may choose to replace simple expressions with their literal values.
From https://github.com/openwdl/wdl/blob/main/versions/1.1/SPEC.md#expressions
@mr-c I think we're agreed that an evaluator shortcut is possible and beneficial if the identifiers/Gets pertain only to literal constants. I'm still a little unclear -- and forgive me for pressing -- on: where do such cases arise with such frequency or importance as to justify a special static-analysis optimization? (Given that they're evaluated correctly without such an optimization, even if 'a bit verbose'.) I'm having a hard time inferring this from the toy example, which however I assume is based on something else in the wild -- that's what I'm getting at.
I read the quoted defn of "simple" expression as excluding use of identifiers at all.
@mr-c I think we're agreed that an evaluator shortcut is possible and beneficial if the identifiers/Gets pertain only to literal constants.
:+1:
I'm still a little unclear -- and forgive me for pressing -- on: where do such cases arise with such frequency or importance as to justify a special static-analysis optimization? (Given that they're evaluated correctly without such an optimization, even if 'a bit verbose'.) I'm having a hard time inferring this from the toy example, which however I assume is based on something else in the wild -- that's what I'm getting at.
Oh, I don't know how frequent this is.
Just seemed like something that should be possible, but wasn't obvious to me as to how to achieve.
There is no urgency or priority from me, as it doesn't block translating WDL to CWL.
I read the quoted defn of "simple" expression as excluding use of identifiers at all.
Ah, I see that now. I read it as including identifiers that didn't refer to File
constants. Now I see that I had that wrong. Therefore I revise my request: for a shortcut to evaluate the result of simple expressions and expressions that include identifiers that recursively are simple expressions and where there are no File
literals anywhere.
Maybe a nice starter project for an intern or student worker.