Skip to content

Commit a5443ed

Browse files
authored
Merge pull request #1590 from Nadrieril/reconstruct-empty-box-drops
Reconstruct box deinitialization
2 parents 64f03b2 + 5b373b0 commit a5443ed

21 files changed

Lines changed: 246 additions & 89 deletions

‎.envrc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
watch_file ./charon/rust-toolchain
2+
watch_file nix/*.nix
23
use flake

‎charon-ml/src/CharonVersion.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(* This is an automatically generated file, generated from `charon/Cargo.toml`. *)
22
(* To re-generate this file, rune `make` in the root directory *)
3-
let supported_charon_version = "0.1.308"
3+
let supported_charon_version = "0.1.309"

‎charon-ml/src/PrintFmt.ml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,11 @@ module Llbc = struct
22652265
fn_ptr (place_to_string env p)
22662266
(pp_unwind_block env indent indent_incr)
22672267
on_unwind
2268+
| DropEmptyBox (p, on_unwind) ->
2269+
Format.fprintf fmt "%sdrop_empty_box %s%a" indent
2270+
(place_to_string env p)
2271+
(pp_unwind_block env indent indent_incr)
2272+
on_unwind
22682273
| Assert (asrt, on_failure, on_unwind) ->
22692274
Format.fprintf fmt "%s%a else %a%a" indent (pp_print_assertion env) asrt
22702275
(pp_print_abort_kind env) on_failure
@@ -2477,6 +2482,10 @@ module Ullbc = struct
24772482
(pp_fn_ptr env) fn_ptr (place_to_string env p)
24782483
(block_id_to_string tgt)
24792484
(block_id_to_string unwind)
2485+
| DropEmptyBox (p, tgt, unwind) ->
2486+
Format.fprintf fmt "%sdrop_empty_box %s -> %s (unwind: %s)" indent
2487+
(place_to_string env p) (block_id_to_string tgt)
2488+
(block_id_to_string unwind)
24802489
| TAssert (asrt, tgt, unwind) ->
24812490
Format.fprintf fmt "%sassert %a -> %s (unwind: %s)" indent
24822491
(pp_print_assertion env) asrt (block_id_to_string tgt)

‎charon-ml/src/generated/Generated_LlbcAst.ml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ and statement_kind =
6767
- [fn_ptr]: Reference to the [drop_glue] code to call on drop.
6868
- [kind]
6969
- [on_unwind] *)
70+
| DropEmptyBox of place * block
71+
(** Deallocate a [Box] whose pointee has already been moved out/dropped.
72+
73+
Resugared when it appears in elaborated/optimized MIR, if
74+
[--treat-box-as-builtin] is set and [--desugar-drops] isn't.
75+
76+
Fields:
77+
- [place]
78+
- [on_unwind] *)
7079
| Assert of assertion * abort_kind * block
7180
(** Fields:
7281
- [assert]

‎charon-ml/src/generated/Generated_OfJson.ml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,18 @@ module Ullbc = struct
20352035
let* target = block_id_of_json ctx target in
20362036
let* on_unwind = block_id_of_json ctx on_unwind in
20372037
Ok (Drop (kind, place, fn_ptr, target, on_unwind))
2038+
| `Assoc
2039+
[
2040+
( "DropEmptyBox",
2041+
`Assoc
2042+
[
2043+
("place", place); ("target", target); ("on_unwind", on_unwind);
2044+
] );
2045+
] ->
2046+
let* place = place_of_json ctx place in
2047+
let* target = block_id_of_json ctx target in
2048+
let* on_unwind = block_id_of_json ctx on_unwind in
2049+
Ok (DropEmptyBox (place, target, on_unwind))
20382050
| `Assoc
20392051
[
20402052
( "InlineAsm",
@@ -2180,6 +2192,14 @@ module Llbc = struct
21802192
let* kind = drop_kind_of_json ctx kind in
21812193
let* on_unwind = block_of_json ctx on_unwind in
21822194
Ok (Drop (place, fn_ptr, kind, on_unwind))
2195+
| `Assoc
2196+
[
2197+
( "DropEmptyBox",
2198+
`Assoc [ ("place", place); ("on_unwind", on_unwind) ] );
2199+
] ->
2200+
let* place = place_of_json ctx place in
2201+
let* on_unwind = block_of_json ctx on_unwind in
2202+
Ok (DropEmptyBox (place, on_unwind))
21832203
| `Assoc
21842204
[
21852205
( "Assert",

‎charon-ml/src/generated/Generated_OfPostcard.ml‎

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,11 @@ module Ullbc = struct
17201720
let* on_unwind = block_id_of_postcard ctx st in
17211721
Ok (Drop (kind, place, fn_ptr, target, on_unwind))
17221722
| 4 ->
1723+
let* place = place_of_postcard ctx st in
1724+
let* target = block_id_of_postcard ctx st in
1725+
let* on_unwind = block_id_of_postcard ctx st in
1726+
Ok (DropEmptyBox (place, target, on_unwind))
1727+
| 5 ->
17231728
let* asm = inline_asm_of_postcard ctx st in
17241729
let* fallthrough = option_of_postcard block_id_of_postcard ctx st in
17251730
let* labels =
@@ -1728,19 +1733,19 @@ module Ullbc = struct
17281733
in
17291734
let* on_unwind = block_id_of_postcard ctx st in
17301735
Ok (InlineAsm (asm, fallthrough, labels, on_unwind))
1731-
| 5 ->
1736+
| 6 ->
17321737
let* assert_ = assertion_of_postcard ctx st in
17331738
let* target = block_id_of_postcard ctx st in
17341739
let* on_unwind = block_id_of_postcard ctx st in
17351740
Ok (TAssert (assert_, target, on_unwind))
1736-
| 6 ->
1741+
| 7 ->
17371742
let* name = name_of_postcard ctx st in
17381743
let* on_unwind = block_id_of_postcard ctx st in
17391744
Ok (Panic (name, on_unwind))
1740-
| 7 -> Ok UnwindTerminate
1741-
| 8 -> Ok UnwindResume
1742-
| 9 -> Ok Return
1743-
| 10 -> Ok UndefinedBehavior
1745+
| 8 -> Ok UnwindTerminate
1746+
| 9 -> Ok UnwindResume
1747+
| 10 -> Ok Return
1748+
| 11 -> Ok UndefinedBehavior
17441749
| _ -> Error ("unknown enum variant tag: " ^ string_of_int __tag))
17451750

17461751
and unwind_kind_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
@@ -1818,11 +1823,15 @@ module Llbc = struct
18181823
let* on_unwind = block_of_postcard ctx st in
18191824
Ok (Drop (place, fn_ptr, kind, on_unwind))
18201825
| 7 ->
1826+
let* place = place_of_postcard ctx st in
1827+
let* on_unwind = block_of_postcard ctx st in
1828+
Ok (DropEmptyBox (place, on_unwind))
1829+
| 8 ->
18211830
let* assert_ = assertion_of_postcard ctx st in
18221831
let* on_failure = abort_kind_of_postcard ctx st in
18231832
let* on_unwind = block_of_postcard ctx st in
18241833
Ok (Assert (assert_, on_failure, on_unwind))
1825-
| 8 ->
1834+
| 9 ->
18261835
let* asm = inline_asm_of_postcard ctx st in
18271836
let* fallthrough = option_of_postcard block_of_postcard ctx st in
18281837
let* labels =
@@ -1831,36 +1840,36 @@ module Llbc = struct
18311840
in
18321841
let* on_unwind = block_of_postcard ctx st in
18331842
Ok (InlineAsm (asm, fallthrough, labels, on_unwind))
1834-
| 9 ->
1843+
| 10 ->
18351844
let* call = call_of_postcard ctx st in
18361845
let* dest = place_of_postcard ctx st in
18371846
let* on_unwind = block_of_postcard ctx st in
18381847
Ok (Call (call, dest, on_unwind))
1839-
| 10 ->
1848+
| 11 ->
18401849
let* data = switch_data_of_postcard ctx st in
18411850
let* branches =
18421851
index_vec_of_postcard branch_id_of_postcard block_of_postcard ctx
18431852
st
18441853
in
18451854
Ok (Switch (data, branches))
1846-
| 11 ->
1855+
| 12 ->
18471856
let* _0 = block_of_postcard ctx st in
18481857
Ok (Loop _0)
1849-
| 12 ->
1858+
| 13 ->
18501859
let* _0 = usize_of_postcard ctx st in
18511860
Ok (Break _0)
1852-
| 13 ->
1861+
| 14 ->
18531862
let* _0 = usize_of_postcard ctx st in
18541863
Ok (Continue _0)
1855-
| 14 ->
1864+
| 15 ->
18561865
let* name = name_of_postcard ctx st in
18571866
let* on_unwind = block_of_postcard ctx st in
18581867
Ok (Panic (name, on_unwind))
1859-
| 15 -> Ok UnwindTerminate
1860-
| 16 -> Ok UnwindResume
1861-
| 17 -> Ok Return
1862-
| 18 -> Ok UndefinedBehavior
1863-
| 19 -> Ok Nop
1868+
| 16 -> Ok UnwindTerminate
1869+
| 17 -> Ok UnwindResume
1870+
| 18 -> Ok Return
1871+
| 19 -> Ok UndefinedBehavior
1872+
| 20 -> Ok Nop
18641873
| _ -> Error ("unknown enum variant tag: " ^ string_of_int __tag))
18651874
end
18661875

‎charon-ml/src/generated/Generated_UllbcAst.ml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ and terminator_kind =
9898
- [fn_ptr]: Reference to the [drop_glue] code to call on drop.
9999
- [target]
100100
- [on_unwind] *)
101+
| DropEmptyBox of place * block_id * block_id
102+
(** Deallocate a [Box] whose pointee has already been moved out/dropped.
103+
104+
Resugared when it appears in elaborated/optimized MIR, if
105+
[--treat-box-as-builtin] is set and [--desugar-drops] isn't.
106+
107+
Fields:
108+
- [place]
109+
- [target]
110+
- [on_unwind] *)
101111
| InlineAsm of inline_asm * block_id option * block_id list * block_id
102112
(** An inline assembly block.
103113

‎charon/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎charon/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tracing = { version = "0.1", features = ["max_level_trace"] }
2626

2727
[package]
2828
name = "charon"
29-
version = "0.1.308"
29+
version = "0.1.309"
3030
authors.workspace = true
3131
edition.workspace = true
3232
license.workspace = true

‎charon/src/ast/bodies/safety.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ impl HasSafety for llbc_ast::Statement {
338338
place.write_safety(krate).or_else(|| rvalue.safety(krate))
339339
}
340340
StatementKind::SetDiscriminant(place, _) => place.write_safety(krate),
341-
StatementKind::PlaceMention(place) | StatementKind::Drop { place, .. } => {
342-
place.read_safety(krate)
343-
}
341+
StatementKind::PlaceMention(place)
342+
| StatementKind::Drop { place, .. }
343+
| StatementKind::DropEmptyBox { place, .. } => place.read_safety(krate),
344344
StatementKind::Borrowck(st) => st.safety(krate),
345345
StatementKind::Assert {
346346
assert, on_failure, ..
@@ -398,7 +398,9 @@ impl HasSafety for ullbc_ast::Terminator {
398398
TerminatorKind::Call { call, dest, .. } => {
399399
call.safety(krate).or_else(|| dest.write_safety(krate))
400400
}
401-
TerminatorKind::Drop { place, .. } => place.read_safety(krate),
401+
TerminatorKind::Drop { place, .. } | TerminatorKind::DropEmptyBox { place, .. } => {
402+
place.read_safety(krate)
403+
}
402404
TerminatorKind::Assert { assert, .. } => assert.cond.safety(krate),
403405
TerminatorKind::InlineAsm { asm, .. } => asm.kind.is_asm().into(),
404406
TerminatorKind::UndefinedBehavior => Safety::Unsafe,

0 commit comments

Comments
 (0)