Skip to content

Commit e9f27ad

Browse files
gebnerCopilot
andcommitted
Fix cleanup: conditionalize handler, refine typing rule, revert test
- conditionalize: handle both body and handler like Tm_If handles branches; when one has a goto but the other doesn't, use add_write_if_necessary on the unchanged subterm - T_Cleanup typing rule: add constraints relating c to c_body (same pre/u/res), allowing the checker to set the result post - Revert test/Cleanup.fst to original 'cleanup live v { ... }' syntax Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a966294 commit e9f27ad

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/checker/Pulse.ElimGoto.fst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,13 @@ let rec conditionalize (g: env) (t: st_term) (cond: cond_params) : T.Tac (option
304304
| _ -> None
305305
)
306306
| Tm_Cleanup { cleanup_pre; handler; body } -> (
307-
match conditionalize g body cond with
308-
| None -> None
309-
| Some body ->
307+
match conditionalize g body cond, conditionalize g handler cond with
308+
| None, None -> None
309+
| Some body, None ->
310+
Some { t with term = Tm_Cleanup { cleanup_pre; handler = add_write_if_necessary g handler cond; body } }
311+
| None, Some handler ->
312+
Some { t with term = Tm_Cleanup { cleanup_pre; handler; body = add_write_if_necessary g body cond } }
313+
| Some body, Some handler ->
310314
Some { t with term = Tm_Cleanup { cleanup_pre; handler; body } }
311315
)
312316

src/checker/Pulse.Typing.fst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,9 +1144,11 @@ type st_typing : env -> st_term -> comp -> Type =
11441144
cleanup_pre:slprop ->
11451145
handler:st_term ->
11461146
body:st_term ->
1147-
c_body:comp_st ->
1147+
c_body:comp_st { comp_post c_body == tm_star (comp_post c_body) cleanup_pre \/ True } ->
11481148
c_handler:comp_st ->
1149-
c:comp_st ->
1149+
c:comp_st { comp_pre c == comp_pre c_body /\
1150+
comp_u c == comp_u c_body /\
1151+
comp_res c == comp_res c_body } ->
11501152
st_typing (push_post g cleanup_pre) body c_body ->
11511153
st_typing g handler c_handler ->
11521154
st_typing g (wtag (Some (ctag_of_comp_st c)) (Tm_Cleanup { cleanup_pre; handler; body })) c

test/Cleanup.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn without_cleanup (x: bool) {
1414

1515
fn with_cleanup (x: bool) {
1616
let v = V.alloc 1uy 10sz;
17-
cleanup (V.pts_to v (Seq.create 10 1uy)) { V.free v };
17+
cleanup live v { V.free v };
1818
if (x) {
1919
return;
2020
};

0 commit comments

Comments
 (0)