Configuration and Runtime Flags
Config Gate
Bound Work
A numeric limit can gate how much input a program accepts before it stops accumulating work.
Program
Play the program to choose a limit and watch the accepted count change.
limit_gate_config.rs
Replay: real traced execution (multi-file project)
fn main() {
let limit = 2;
let mut accepted = 0;
for value in [3, 8, 13] {
if value <= limit * 5 {
accepted += 1;
}
}
println!("limit={limit} accepted={accepted}");
}
fn main() {
let limit = 1;
let mut accepted = 0;
for value in [3, 8, 13] {
if value <= limit * 5 {
accepted += 1;
}
}
println!("limit={limit} accepted={accepted}");
}
fn main() {
let limit = 3;
let mut accepted = 0;
for value in [3, 8, 13] {
if value <= limit * 5 {
accepted += 1;
}
}
println!("limit={limit} accepted={accepted}");
}
limit ← 2, accepted ← 0
1fn main() {2 let limi→ 2t = 2; //@limit=2, 1, 33 let mut accepte→ 0d = 0;4 for value in [3, 8, 13] {for value in [3, 8, 13]
pass 1 of 33let mut accepted = 0;4for valu3e in [3, 8, 13] {5 if value <= limit * 5 {All 3 passes — pass 1 is the card above pass valuelimitaccepted1 3 2 0 → 1 2 8 2 1 → 2 3 13 — — accepted ← 1
pass 1 of 24for value in [3, 8, 13] {5 if valu3e <= limi2t * 5 {6 accepte→ 1d += 1;7 }accepted ← 2
pass 2 of 24for value in [3, 8, 13] {5 if valu8e <= limi2t * 5 {6 accepte→ 2d += 1;7 }println!("limit={limit} accepted={accepted}");
8 }9 println!("limit={limit} accepted={accepted}");10}outputlimit=2 accepted=2
limit ← 1, accepted ← 0
1fn main() {2 let limi→ 1t = 1;3 let mut accepte→ 0d = 0;4 for value in [3, 8, 13] {for value in [3, 8, 13]
pass 1 of 33let mut accepted = 0;4for valu3e in [3, 8, 13] {5 if value <= limit * 5 {All 3 passes — pass 1 is the card above pass valuelimitaccepted1 3 1 0 → 1 2 8 — — 3 13 — — accepted ← 1
4for value in [3, 8, 13] {5 if valu3e <= limi1t * 5 {6 accepte→ 1d += 1;7 }println!("limit={limit} accepted={accepted}");
8 }9 println!("limit={limit} accepted={accepted}");10}outputlimit=1 accepted=1
limit ← 3, accepted ← 0
1fn main() {2 let limi→ 3t = 3;3 let mut accepte→ 0d = 0;4 for value in [3, 8, 13] {for value in [3, 8, 13]
pass 1 of 33let mut accepted = 0;4for valu3e in [3, 8, 13] {5 if value <= limit * 5 {All 3 passes — pass 1 is the card above pass value1 3 2 8 3 13 accepted ← 1
pass 1 of 34for value in [3, 8, 13] {5 if valu3e <= limi3t * 5 {6 accepte→ 1d += 1;7 }All 3 passes — pass 1 is the card above pass valueaccepted1 3 0 → 1 2 8 1 → 2 3 13 2 → 3 println!("limit={limit} accepted={accepted}");
8 }9 println!("limit={limit} accepted={accepted}");10}outputlimit=3 accepted=3
Follow the Gate
limitstarts at2.- The gate is
value <= limit * 5, so the cutoff is10. acceptedstarts at0.- Values
3and8pass the gate, soacceptedbecomes2. - Value
13is above10, so the program printslimit=2 accepted=2. | limit | cutofflimit * 5| accepted values | output | | ---: | ---: | --- | --- | | 1 | 5 | 3 | limit=1 accepted=1 | | 2 | 10 | 3, 8 | limit=2 accepted=2 | | 3 | 15 | 3, 8, 13 | limit=3 accepted=3 |
limit
`limit` is runtime configuration that changes the acceptance threshold.
gate
The `if` condition accepts only values below the configured threshold.
accumulator
`accepted` records how much input passed the gate.
Exercise: limit_gate_config.rs
Reproduce limit=2 accepted=2, then use limit 1 and 3 to predict limit=1 accepted=1 and limit=3 accepted=3.