Skip to content

Commit 2bc288a

Browse files
committed
Update 'loop-recognition'
1 parent c4d6380 commit 2bc288a

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

content/posts/2025/loop-recognition.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title = "Revisiting Loop Recognition in C++... in Rust"
33
description = "Cargo Cult Programming"
44
date = 2025-05-27
5+
updated = 2025-05-28
56
draft = false
67
+++
78

@@ -44,7 +45,19 @@ With all that out of the way, let's Rewrite It In Rust.
4445

4546
# The Algorithm (The It)
4647

47-
The original paper uses an implementation of a loop recognition algorithm as a benchmark. Each implementation largely followed the pseudocode of the algorithm while utilizing the most basic idioms of the language when applicable. This raises the question of what is considered Idiomatic Rust.
48+
The original paper uses an implementation of a loop recognition algorithm as a benchmark. The description of the algorithm in the original paper was brief, only referencing the relevant papers[^havlak] [^tarjan] and providing an exact copy of the pseudocode.
49+
50+
[^havlak]: Havlak, Paul. (1997). Nesting of Reducible and Irreducible Loops. ACM Trans. Program. Lang. Syst.. 19. 557-567. [10.1145/262004.262005](https://dl.acm.org/doi/10.1145/262004.262005).
51+
52+
[^tarjan]: Tarjan, Robert. (1973). Testing Flow Graph Reducibility. Journal of Computer and System Sciences. 9. 96-107. [10.1145/800125.804040](https://dl.acm.org/doi/10.1145/800125.804040).
53+
54+
What the algorithm actually does is irrelevant to this experiment. The reasons for choosing this algorithm over others is describe in the original paper. But since I was asked to actually describe loop recognition, I will make an attempt.[^better]
55+
56+
[^better]: You are better off reading the Havlak paper.
57+
58+
Control-Flow Graphs are concerned with representing programs as traditional graphs. Each node in the graph, known as a Basic Block, corresponds with any number of statements executed in sequence without branching. An edge then describes the flow from one block of statements to the next which may or may not involve a branch. Havlak describes a loop as "Intuitively... a chunk of code whose execution may repeat without the repetition of any surrounding code." or more precisely as a subgraph of [strongly connected components](https://en.wikipedia.org/wiki/Strongly_connected_component). A *reducible* loop then is defined as one of these subgraphs with only one entry point, making an *irreducible* loop one with multiple entry points. The loop recognition algorithm is concerned with building a tree of these loop subgraphs and determining whether the loop is reducible or irreducible.
59+
60+
Each implementation of the algorithm, according to the paper, largely followed the pseudocode of the algorithm while utilizing the most basic idioms of the language when applicable. This raises the question of what is considered Idiomatic Rust.
4861

4962
## Idiomatic Rust
5063

0 commit comments

Comments
 (0)