Skip to content

Commit 549948d

Browse files
authored
Merge pull request #17 from egraphs-good/fix-scheduler-scope
Fix scheduler's scope
2 parents 255b67a + 952f446 commit 549948d

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

src/scheduling.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl ScheduleState {
7676
if self.schedulers.iter().any(|(n, _)| n == name) {
7777
return Err(egglog::Error::ParseError(ParseError(
7878
span.clone(),
79-
"Scheduler name already exists".into(),
79+
format!("Scheduler {name} already exists"),
8080
)));
8181
}
8282
let scheduler =
@@ -136,22 +136,22 @@ impl ScheduleState {
136136
Ok(run_report)
137137
}
138138
"saturate" => {
139-
new_scope!(|| {
140-
let mut report = RunReport::default();
141-
loop {
139+
let mut report = RunReport::default();
140+
loop {
141+
let iter_report = new_scope!(|| {
142142
let mut iter_report = RunReport::default();
143143
for expr in exprs {
144144
let res = self.run(egraph, expr)?;
145145
iter_report.union(res);
146146
}
147-
if !iter_report.updated {
148-
break;
149-
}
150-
report.union(iter_report);
147+
Ok(iter_report)
148+
})?;
149+
if !iter_report.updated {
150+
break;
151151
}
152-
153-
Ok(report)
154-
})
152+
report.union(iter_report);
153+
}
154+
Ok(report)
155155
}
156156
"seq" => {
157157
new_scope!(|| {
@@ -165,22 +165,25 @@ impl ScheduleState {
165165
})
166166
}
167167
"repeat" => {
168-
new_scope!(|| {
169-
match exprs.as_slice() {
170-
[Expr::Lit(_span, Literal::Int(n)), rest @ ..] => {
171-
let mut report = RunReport::default();
172-
for _ in 0..*n {
168+
match exprs.as_slice() {
169+
[Expr::Lit(_span, Literal::Int(n)), rest @ ..] => {
170+
let mut report = RunReport::default();
171+
for _ in 0..*n {
172+
let sub_report = new_scope!(|| {
173+
let mut report = RunReport::default();
173174
// Recursively run the rest of the expressions
174175
for expr in rest {
175176
let res = self.run(egraph, expr)?;
176177
report.union(res);
177178
}
178-
}
179-
Ok(report)
179+
Ok(report)
180+
})?;
181+
report.union(sub_report);
180182
}
181-
_ => err(),
183+
Ok(report)
182184
}
183-
})
185+
_ => err(),
186+
}
184187
}
185188
_ => Err(egglog::Error::ParseError(ParseError(
186189
span.clone(),

tests/repro-scheduler-scopes.egg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
;; scheduler declaration inside repeat
2+
(run-schedule
3+
(repeat 10
4+
(let-scheduler bo (back-off))
5+
(run-with bo)))
6+
7+
;; scheduler declaration inside saturate
8+
(relation R (i64 ))
9+
(R 1)
10+
(rule ((R x) (< x 10)) ((R (+ x 1))))
11+
(run-schedule
12+
(saturate
13+
(let-scheduler bo (back-off))
14+
(run-with bo)))
15+
(print-size)

0 commit comments

Comments
 (0)