Skip to content
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

feat: implement the generic map functions from the WDL standardy library. #257

Merged
merged 7 commits into from
Nov 22, 2024

Conversation

peterhuene
Copy link
Collaborator

@peterhuene peterhuene commented Nov 21, 2024

This PR implements the following WDL standard library functions:

  • as_pairs
  • as_map
  • keys
  • contains_key
  • values
  • collect_by_key

It also corrects a few issues discovered during testing:

  • Map values in wdl-engine should accept None for a key.
  • Common type calculation now supports discovering common types between the
    compound types containing Union and None as inner types, e.g.
    Array[String] | Array[None] -> Array[String?]
  • The "required primitive type" constraint has been removed as every place the
    constraint was used should allow for optional primitive types as well;
    consequently, the AnyPrimitiveTypeConstraint was renamed to simply
    PrimitiveTypeConstraint.
  • The common type calculation now favors the "left-hand side" of the
    calculation rather than the right, making it more intuitive to use. For
    example, a calculation of File | String is now File rather than
    String.

Added test cases to existing functions that accept maps with optional primitive keys.

Before submitting this PR, please make sure:

  • You have added a few sentences describing the PR here.
  • You have added yourself or the appropriate individual as the assignee.
  • You have added at least one relevant code reviewer to the PR.
  • Your code builds clean without any errors or warnings.
  • You have added tests (when appropriate).
  • You have updated the README or other documentation to account for these
    changes (when appropriate).
  • You have added an entry to the relevant CHANGELOG.md (see
    "keep a changelog" for more information).
  • Your commit messages follow the conventional commit style.

This commit implements the `as_pairs` function from the WDL standard library.
This commit implements the `as_map` function from the WDL standard library.
This commit implements the `keys` function from the WDL standard library.
This commit implements the `contains_key` function from the WDL standard
library.

It also corrects a few issues discovered during testing:

* Map values in `wdl-engine` should accept `None` for a key.
* Common type calculation now supports discovering common types between the
  compound types containing `Union` and `None` as inner types, e.g.
  `Array[String] | Array[None] -> Array[String?]`
* The "required primitive type" constraint has been removed as every place the
  constraint was used should allow for optional primitive types as well;
  consequently, the `AnyPrimitiveTypeConstraint` was renamed to simply
  `PrimitiveTypeConstraint`.
* The common type calculation now favors the "left-hand side" of the
  calculation rather than the right, making it more intuitive to use. For
  example, a calculation of `File | String` is now `File` rather than
  `String`.

Added test cases to existing functions that accept maps with optional primitive
keys.
This commit implements the `values` function from the WDL standard library.
This commit implements the `collect_by_key` function from the WDL standard
library.
.unwrap();
assert!(value.unwrap_boolean());

let value = eval_v1_expr(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also test baz after this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that I better understand, what would be the expression to test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do test ['bar', 'baz'] further below (should be true), if that's what you mean.

Otherwise, a test for ['baz'] would be the same as a test for ['qux'] here (neither are keys of the Foo struct); I can change the test to use baz instead, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge this as-is and put up a follow-up PR if warranted after discussion.

@peterhuene peterhuene merged commit 0fe42e1 into stjude-rust-labs:main Nov 22, 2024
16 checks passed
@peterhuene peterhuene deleted the stdlib branch November 22, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants