From d9d7abe8a93d37b0487ad4351266a49163c78dc9 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Tue, 20 Aug 2024 08:07:18 -0400 Subject: [PATCH 1/3] Implement short-circuit evaluation for `group.include.all`. --- doc/src/release-notes.md | 1 + src/project.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/src/release-notes.md b/doc/src/release-notes.md index 763f23e..5092f6a 100644 --- a/doc/src/release-notes.md +++ b/doc/src/release-notes.md @@ -18,6 +18,7 @@ * `clean` now cleans all caches by default. * Submit jobs with `--constraint="scratch"` by default on Delta. * Submit jobs with `--constraint="nvme"` by default on Frontier. +* `group.include.all` now employs short circuit evaluation. *Fixed:* diff --git a/src/project.rs b/src/project.rs index 50f82f7..a3dcc41 100644 --- a/src/project.rs +++ b/src/project.rs @@ -211,7 +211,7 @@ impl Project { Error::JSONPointerNotFound(name.clone(), include.clone()) })?; - if expr::evaluate_json_comparison(comparison, actual, expected) + if !expr::evaluate_json_comparison(comparison, actual, expected) .ok_or_else(|| { Error::CannotCompareInclude( actual.clone(), @@ -220,8 +220,9 @@ impl Project { ) })? { - matches += 1; + break; } + matches += 1; } Ok(matches == conditions.len()) } From 43df2b3808f28b2abe710c2b377a677bd36792ca Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Tue, 20 Aug 2024 08:51:22 -0400 Subject: [PATCH 2/3] Update documentation. --- doc/src/workflow/action/group.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/src/workflow/action/group.md b/doc/src/workflow/action/group.md index 40a414b..1aad2ac 100644 --- a/doc/src/workflow/action/group.md +++ b/doc/src/workflow/action/group.md @@ -23,15 +23,18 @@ groups of directories included in a given action. ## include `action.group.include`: **array** of **tables** - Define a set of selectors, *any* of -which may be true for a directory to be included in this group. +which may be `true` for a directory to be included in this group. Each selector is a **table** with only one of the following keys: * `condition`: An array of three elements: The *JSON pointer*, *the operator*, and the *operand*. The [JSON pointer](../../guide/concepts/json-pointers.md) references a specific portion of the directory's value. The operator may be `"<"`, `"<="`, - `"=="`, `">="`, or `">"`. -* `all`: Array of conditions (see above). All conditions must be true for this selector - to be true. + `"=="`, `">="`, or `">"`. Both operands **must** have the same data type. The element + referenced by each JSON pointer must be present in the value of **every** directory. +* `all`: Array of conditions (see above). All conditions must be `true` for this selector + to be `true`. `all` is evaluated with short-circuit logic. When an element in `all` + evaluates to `false`, the JSON pointers in the remaining elements are not evaluated + and are not required to be present. For example, select all directories where a value is in the given range: ```toml @@ -54,10 +57,7 @@ Compare by array: condition = ["/array", "==", [1, "string", 14.0] ``` -Both operands **must** have the same data type. The element referenced by JSON pointer -must be present in the value of **every** directory. -When you omit `include`, **row** includes **all** directories in the workspace. > Note: **Row** compares arrays *lexicographically*. @@ -66,6 +66,8 @@ JSON Objects (also known as maps or dictionaries) are not comparable. You must u pointers to specific keys in objects. +When you omit `include`, **row** includes **all** directories in the workspace. + ## sort_by `action.group.sort_by`: **array** of **strings** - An array of @@ -122,7 +124,7 @@ would split into the groups: When omitted, there is no maximum group size. -When `maximum_size` is set **and** `split_by_sort_key` is `true`, **row** first splits +When both `maximum_size` **and** `split_by_sort_key` are `true`, **row** first splits by the sort key, then splits the resulting groups according to `maximum_size`. ## submit_whole From d9538a858b9ddd9f7b4d10f658cd93089311fd03 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Tue, 20 Aug 2024 15:27:02 -0400 Subject: [PATCH 3/3] Remove extra newlines. --- doc/src/workflow/action/group.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/src/workflow/action/group.md b/doc/src/workflow/action/group.md index 1aad2ac..5b7c7fb 100644 --- a/doc/src/workflow/action/group.md +++ b/doc/src/workflow/action/group.md @@ -57,8 +57,6 @@ Compare by array: condition = ["/array", "==", [1, "string", 14.0] ``` - - > Note: **Row** compares arrays *lexicographically*.