Skip to content

Commit 8a543c7

Browse files
committed
Fix issues, refactor dedent, update worflow to use astral actions
1 parent 1141fae commit 8a543c7

File tree

7 files changed

+181
-183
lines changed

7 files changed

+181
-183
lines changed
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
=====CONTENT=====
2+
23
.. guideline:: test ga
3-
:id: gui_FWr4O8NFxpgr
4-
:category: advisory
5-
:status: draft
6-
:release: 1.1.1-1.1.1
7-
:fls: fls_fsdjkfslkdfj
8-
:decidability: decidable
9-
:scope: crate
10-
:tags: test,gatest,ga
11-
12-
hehehehe
13-
14-
.. rationale::
15-
:id: rat_y8xxrKQIfr7y
16-
:status: draft
17-
18-
test ga
19-
20-
.. non_compliant_example::
21-
:id: non_compl_ex_4cQT1M3psxLs
22-
:status: draft
23-
24-
test ga
25-
26-
.. code-block:: rust
27-
28-
dfhsdfkjshdfskdjhftest ga
29-
30-
.. compliant_example::
31-
:id: compl_ex_zrLFcPlviRu5
32-
:status: draft
33-
34-
test ga
35-
36-
.. code-block:: rust
37-
4+
:id: gui_LzfV28IVG7qO
5+
:category: advisory
6+
:status: draft
7+
:release: 1.1.1-1.1.1
8+
:fls: fls_fsdjkfslkdfj
9+
:decidability: decidable
10+
:scope: crate
11+
:tags: test,gatest,ga
12+
13+
hehehehe
14+
15+
.. rationale::
16+
:id: rat_nPL2Cv7VBdqG
17+
:status: draft
18+
19+
test ga
20+
21+
.. non_compliant_example::
22+
:id: non_compl_ex_Bv7HMs0AVNlH
23+
:status: draft
24+
3825
test ga
3926

27+
.. code-block:: rust
28+
29+
dfhsdfkjshdfskdjhftest ga
30+
31+
.. compliant_example::
32+
:id: compl_ex_H5Z7OsxZX3Ig
33+
:status: draft
34+
35+
test ga
36+
37+
.. code-block:: rust
38+
39+
test ga
40+
4041
=====CONTENT=END=====
41-
Saved guideline to src/coding-guidelines/concurrency.rst
Lines changed: 84 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,88 @@
11
=====CONTENT=====
2+
23
.. guideline:: Recursive function are not allowed
3-
:id: gui_llfYnmAucaJQ
4-
:category: required
5-
:status: draft
6-
:release: 1.3.0-latest
7-
:fls: fls_vjgkg8kfi93
8-
:decidability: undecidable
9-
:scope: system
10-
:tags: increase-human-error
11-
12-
Any function shall not call itself directly or indirectly
13-
14-
.. rationale::
15-
:id: rat_bbk57IUR7pjD
16-
:status: draft
17-
18-
Recursive functions can easily cause stack overflows, which may result in exceptions or, in some cases, undefined behavior (typically some embedded systems). Although the Rust compiler supports [tail call optimization](https://en.wikipedia.org/wiki/Tail_call), this optimization is not guaranteed and depends on the specific implementation and function structure. There is an [open RFC to guarantee tail call optimization in the Rust compiler](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md), but this feature has not yet been stabilized. Until tail call optimization is guaranteed and stabilized, developers should avoid using recursive functions to prevent potential stack overflows and ensure program reliability.
19-
20-
.. non_compliant_example::
21-
:id: non_compl_ex_bEG9g2wgnCci
22-
:status: draft
23-
24-
The below function `concat_strings` is not complaint because it call itself and depending on depth of data provided as input it could generate an stack overflow exception or undefine behavior.
25-
THIS LINE WAS ADDED IN PURPOSE TO TEST SNAPSHOT TESTING???
26-
27-
.. code-block:: rust
28-
29-
// Recursive enum to represent a string or a list of `MyEnum`
30-
enum MyEnum {
31-
Str(String),
32-
List(Vec<MyEnum>),
33-
}
34-
35-
// Concatenates strings from a nested structure of `MyEnum` using recursion.
36-
fn concat_strings(input: &[MyEnum]) -> String {
37-
let mut result = String::new();
38-
for item in input {
39-
match item {
40-
MyEnum::Str(s) => result.push_str(s),
41-
MyEnum::List(list) => result.push_str(&concat_strings(list)),
42-
}
43-
}
44-
result
45-
}
46-
47-
.. compliant_example::
48-
:id: compl_ex_j9sv9nZWk1Eo
49-
:status: draft
50-
51-
The following code implements the same functionality using iteration instead of recursion. The `stack` variable is used to maintain the processing context at each step of the loop. This approach provides explicit control over memory usage. If the stack grows beyond a predefined limit due to the structure or size of the input, the function returns an error rather than risking a stack overflow or out-of-memory exception. This ensures more predictable and robust behavior in resource-constrained environments.
52-
53-
.. code-block:: rust
54-
55-
// Recursive enum to represent a string or a list of `MyEnum`
56-
enum MyEnum {
57-
Str(String),
58-
List(Vec<MyEnum>),
59-
}
60-
61-
/// Concatenates strings from a nested structure of `MyEnum` without using recursion.
62-
/// Returns an error if the stack size exceeds `MAX_STACK_SIZE`.
63-
fn concat_strings_non_recursive(input: &[MyEnum]) -> Result<String, &'static str> {
64-
const MAX_STACK_SIZE: usize = 1000;
65-
let mut result = String::new();
66-
let mut stack = Vec::new();
67-
68-
// Add all items to the stack
69-
stack.extend(input.iter());
70-
71-
while let Some(item) = stack.pop() {
72-
match item {
73-
MyEnum::Str(s) => result.insert_str(0, s),
74-
MyEnum::List(list) => {
75-
// Add list items to the stack
76-
for sub_item in list.iter() {
77-
stack.push(sub_item);
78-
if stack.len() > MAX_STACK_SIZE {
79-
return Err("Too big structure");
80-
}
81-
}
82-
}
83-
}
84-
}
85-
Ok(result)
86-
}
4+
:id: gui_1EDWRNKjs6It
5+
:category: required
6+
:status: draft
7+
:release: 1.3.0-latest
8+
:fls: fls_vjgkg8kfi93
9+
:decidability: undecidable
10+
:scope: system
11+
:tags: reduce-human-error
12+
13+
Any function shall not call itself directly or indirectly
14+
15+
.. rationale::
16+
:id: rat_Hbn0yLGzVdDK
17+
:status: draft
18+
19+
Recursive functions can easily cause stack overflows, which may result in exceptions or, in some cases, undefined behavior (typically some embedded systems). Although the Rust compiler supports [tail call optimization](https://en.wikipedia.org/wiki/Tail_call), this optimization is not guaranteed and depends on the specific implementation and function structure. There is an [open RFC to guarantee tail call optimization in the Rust compiler](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md), but this feature has not yet been stabilized. Until tail call optimization is guaranteed and stabilized, developers should avoid using recursive functions to prevent potential stack overflows and ensure program reliability.
20+
21+
.. non_compliant_example::
22+
:id: non_compl_ex_eRmcumqqmMaZ
23+
:status: draft
24+
25+
The below function `concat_strings` is not complaint because it call itself and depending on depth of data provided as input it could generate an stack overflow exception or undefine behavior.
26+
27+
.. code-block:: rust
28+
29+
// Recursive enum to represent a string or a list of `MyEnum`
30+
enum MyEnum {
31+
Str(String),
32+
List(Vec<MyEnum>),
33+
}
34+
35+
// Concatenates strings from a nested structure of `MyEnum` using recursion.
36+
fn concat_strings(input: &[MyEnum]) -> String {
37+
let mut result = String::new();
38+
for item in input {
39+
match item {
40+
MyEnum::Str(s) => result.push_str(s),
41+
MyEnum::List(list) => result.push_str(&concat_strings(list)),
42+
}
43+
}
44+
result
45+
}
46+
47+
.. compliant_example::
48+
:id: compl_ex_t6Hy8E2YlneV
49+
:status: draft
50+
51+
The following code implements the same functionality using iteration instead of recursion. The `stack` variable is used to maintain the processing context at each step of the loop. This approach provides explicit control over memory usage. If the stack grows beyond a predefined limit due to the structure or size of the input, the function returns an error rather than risking a stack overflow or out-of-memory exception. This ensures more predictable and robust behavior in resource-constrained environments.
52+
53+
.. code-block:: rust
54+
55+
// Recursive enum to represent a string or a list of `MyEnum`
56+
enum MyEnum {
57+
Str(String),
58+
List(Vec<MyEnum>),
59+
}
60+
61+
/// Concatenates strings from a nested structure of `MyEnum` without using recursion.
62+
/// Returns an error if the stack size exceeds `MAX_STACK_SIZE`.
63+
fn concat_strings_non_recursive(input: &[MyEnum]) -> Result<String, &'static str> {
64+
const MAX_STACK_SIZE: usize = 1000;
65+
let mut result = String::new();
66+
let mut stack = Vec::new();
67+
68+
// Add all items to the stack
69+
stack.extend(input.iter());
70+
71+
while let Some(item) = stack.pop() {
72+
match item {
73+
MyEnum::Str(s) => result.insert_str(0, s),
74+
MyEnum::List(list) => {
75+
// Add list items to the stack
76+
for sub_item in list.iter() {
77+
stack.push(sub_item);
78+
if stack.len() > MAX_STACK_SIZE {
79+
return Err("Too big structure");
80+
}
81+
}
82+
}
83+
}
84+
}
85+
Ok(result)
86+
}
8787

8888
=====CONTENT=END=====
89-
Saved guideline to src/coding-guidelines/associated-items.rst

.github/workflows/auto-pr-on-issue.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ jobs:
1818
- name: Checkout code
1919
uses: actions/checkout@v4
2020

21-
# TODO: make this step a reusable composite workflow.
2221
- name: Install uv
23-
run: |
24-
curl -LsSf https://astral.sh/uv/install.sh | sh
25-
export PATH="/root/.cargo/bin:$PATH"
26-
uv --version
22+
uses: astral-sh/setup-uv@v6
2723

2824
- name: Set up Git
2925
run: |

.github/workflows/build-guidelines.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ jobs:
2525
- name: Checkout repository
2626
uses: actions/checkout@v3
2727
- name: Install uv
28-
run: |
29-
curl -LsSf https://astral.sh/uv/install.sh | sh
30-
export PATH="/root/.cargo/bin:$PATH"
31-
uv --version
28+
uses: astral-sh/setup-uv@v6
3229
- name: Build documentation
3330
run: |
3431
mkdir -p build
@@ -86,4 +83,4 @@ jobs:
8683
run: cargo install typos-cli
8784
- name: Check for typos
8885
run: typos
89-
86+

.github/workflows/snapshot-ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ jobs:
1616
uses: actions/checkout@v4
1717

1818
- name: Install uv
19-
shell: bash
20-
run: |
21-
curl -LsSf https://astral.sh/uv/install.sh | sh
22-
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
19+
uses: astral-sh/setup-uv@v6
2320

2421
- name: Run snapshot tests
2522
run: |

generate_guideline_templates.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import argparse
66
import string
77
import random
8+
from textwrap import dedent, indent
89

910
# Configuration
1011
CHARS = string.ascii_letters + string.digits
@@ -63,44 +64,47 @@ def guideline_rst_template(
6364
def norm(value: str) -> str:
6465
return value.strip().lower()
6566

66-
guideline_text = f""".. guideline:: {guideline_title.strip()}
67-
:id: {guideline_id}
68-
:category: {norm(category)}
69-
:status: {norm(status)}
70-
:release: {norm(release_begin)}-{release_end.strip()}
71-
:fls: {norm(fls_id)}
72-
:decidability: {norm(decidability)}
73-
:scope: {norm(scope)}
74-
:tags: {",".join(tags.strip().split())}
75-
76-
{amplification.strip()}
77-
78-
.. rationale::
79-
:id: {rationale_id}
80-
:status: {norm(status)}
81-
82-
{rationale.strip()}
83-
84-
.. non_compliant_example::
85-
:id: {non_compliant_example_id}
86-
:status: {norm(status)}
87-
88-
{non_compliant_ex_prose.strip()}
89-
90-
.. code-block:: rust
91-
92-
{non_compliant_ex.strip()}
93-
94-
.. compliant_example::
95-
:id: {compliant_example_id}
96-
:status: {norm(status)}
97-
98-
{compliant_example_prose.strip()}
99-
100-
.. code-block:: rust
101-
102-
{compliant_example.strip()}
103-
"""
67+
indented_compliant_ex= indent(compliant_example.strip(), " " * 13)
68+
indented_non_compliant_ex= indent(non_compliant_ex.strip(), " " * 13)
69+
guideline_text = dedent(f"""
70+
.. guideline:: {guideline_title.strip()}
71+
:id: {guideline_id}
72+
:category: {norm(category)}
73+
:status: {norm(status)}
74+
:release: {norm(release_begin)}-{release_end.strip()}
75+
:fls: {norm(fls_id)}
76+
:decidability: {norm(decidability)}
77+
:scope: {norm(scope)}
78+
:tags: {",".join(tags.strip().split())}
79+
80+
{amplification.strip()}
81+
82+
.. rationale::
83+
:id: {rationale_id}
84+
:status: {norm(status)}
85+
86+
{rationale.strip()}
87+
88+
.. non_compliant_example::
89+
:id: {non_compliant_example_id}
90+
:status: {norm(status)}
91+
92+
{non_compliant_ex_prose.strip()}
93+
94+
.. code-block:: rust
95+
96+
{indented_non_compliant_ex.strip()}
97+
98+
.. compliant_example::
99+
:id: {compliant_example_id}
100+
:status: {norm(status)}
101+
102+
{compliant_example_prose.strip()}
103+
104+
.. code-block:: rust
105+
106+
{indented_compliant_ex.strip()}
107+
""")
104108

105109
return guideline_text
106110
def generate_id(prefix):

0 commit comments

Comments
 (0)