-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Struct literal Revisit - Revisit #297
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
versions/development/SPEC.md
Outdated
Person( ... ) | ||
``` | ||
|
||
Arugments placed within the parethesis are key-value pairs, where the key is the name of one of the struct declarations, and the value is the value to set the argument to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found one more 😛
Arugments placed within the parethesis are key-value pairs, where the key is the name of one of the struct declarations, and the value is the value to set the argument to. | |
Arguments placed within the parethesis are key-value pairs, where the key is the name of one of the struct declarations, and the value is the value to set the argument to. |
Can you construct Struct literals in the output? Something like: task output_struct_collection {
input {
String firstName = "Peter"
}
output {
Person harry = Person(name="Harry", age=5+7)
Person constructed = Person(name=firstName, age=88)
}
} As far as I can see, the documentation doesn't address this. |
@illusional I am actually not sure if that is supported at the moment by any of the implementations. To me it would be good eventually to get to the point where constructing struct literals in the output is supported, however it will require a bit of work from the workflow engine. I would be interested to know from others if they this for now this should be allowed or labelled as future support |
I agree that I don't think it's currently possible. I think I think it'd be a good idea in the future. |
@geoffjentry as it is not explicitly stated in the spec whether we allow this or not, do you think it would be safe to assume that it is not allowed, or do you think we need to expressly forbid it for the time? |
I'd double check with @cjllanwarne and @mlin that I haven't misspoken but if indeed it's not supported we should explicitly disallow it |
I don't quite see the argument to forbid using the new struct literal syntax in output sections. Cromwell doesn't support it there, but nor does it implement the new literal syntax anywhere, right? |
I think initialisation in the output would be a useful feature of the language, and not just because I'm biased, is there a way it can be supported? |
@illusional anything can be passed via vote, but to be folded in requires implementation. I can't speak for @mlin but from the perspective of Cromwell it's more likely to see implementation of things which require less work (disclaimer: I don't actually know how hard it'd be to implement ... @cjllanwarne ?) |
If I'm not mistaken, currently cromwell does allow for the initialization of structs in the output section using the (in develop removed) output {
IndexedBamFile outputBam = object {
file: bamFile,
index: bamIndex
}
} |
With the new syntax we may want some new constraints on name collisions between struct types and standard library function names (#307), eg my empty |
Could someone familiar with Hermes comment on whether the above & related cases complicate language parsing? @cjllanwarne @geoffjentry |
|
I had a go at implementing this in the grammar - I had a few thoughts:
|
versions/development/SPEC.md
Outdated
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of empty lines...?
@cjllanwarne thanks for taking a stab at this. In regards to the struct literals in the output section, it appears that the general consensus is that this is already supported and there should be no strict reason to disallow it. If this is the case, I will go ahead and add an example to demonstrate this. As for the naming collisions, this definitely will represent a problem. Engine functions should be considered key words in my opinion. This has the added side effect of course of making the addition of an engine function a breaking change that must wait for a major version release. But I think this is okay and would be accepted by the community. Therefore there should be no collisions within a I am also now concerned about complicating the A few suggestions:
|
After looking at the example, I think I personally lean towards using |
One cheesy trick is to formally constrain struct type names to start with an uppercase letter, while function names start with a lowercase letter. 🧀 🧀 🧀 I also quite like Pat's #3 keeping the existing |
@mlin the one concern I had about repurpossing the object literal syntax was that it might get confused with other types of blocks, either by users or at a grammar level. But if you do not see any issues arising from that, it might be our easiest way forward |
FWIW from a grammar point of view, if we had a defined set of
|
FWIW2: I also kind of like "Idea 3: repurpose the old |
@cjllanwarne @mlin the benefit to option 3 imo, is that it would help for users to migrate away from objects, since it would be quite easier. @geoffjentry @illusional @DavyCats any specific thoughts on this before I try implementing something |
Great discussion, folks. From the perspective of community support wrt capitalization, I’m very much for promoting conventions and against enforcing them with requirements. Case is a tricky thing and can easily cause unwarranted difficulty, especially for people from cultures whose language does not include a concept of case. |
I like the overall idea, and I do not have an opinion on syntactic details. It looks quite reasonable and understandable to me. So 👍 and lots of thanks to @patmagee and everyone involved in this discussion. |
It looks like general discussion has died down for this PR in its current iteration. I am going to give it 1 more day for any last minute opinions, and then put it to a vote |
👍 |
4 similar comments
👍 |
👍 |
👍 |
👍 |
Voting passes 4-0 |
New struct literal syntax similar to the old `object` syntax, but replaces the `object` keyword with the intended struct type name. This allows earlier static typechecking of the struct members, where before we waited until coercing the object to a struct decl. (The `object` syntax remains valid.) Some tedious surgery was involved to make declared struct types available to `Expr` typechecking logic, where before they'd only been needed in `Tree`. #113 openwdl/wdl#297
The new style struct literals are implemented in miniwdl v0.9.0 for I think we can merge this if @patmagee would like to rebase on main and unless Cromwell team has any late-breaking concerns (cc @cjllanwarne) |
assigned parameters. Struct literal notation attempts to be more declarative to help engine implementations apply the proper | ||
type conversions to nested structs, as well as remove any ambiguity over what the object being constructed represents. | ||
|
||
A `Struct Literal` declaration is similar to a map literal except it is preceded by a reference to the struct name. For example, the basic syntax for the `Person` struct would look like the following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/map/object/
This is implemented in wdlTools |
This is in v1.1 and will be propagated to development. |
I have fixed the identified typos. @DavyCats @cjllanwarne @mlin @geoffjentry please feel free to scrutinize this before it goes to voting again!