Skip to content

Commit efde658

Browse files
committed
Update OCaml
1 parent f0240e8 commit efde658

File tree

14 files changed

+151
-29
lines changed

14 files changed

+151
-29
lines changed

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.165"
3+
let supported_charon_version = "0.1.166"

charon-ml/src/PrintGAst.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ let call_to_string (env : 'a fmt_env) (indent : string) (call : call) : string =
2828
let dest = place_to_string env call.dest in
2929
indent ^ dest ^ " := move " ^ func ^ args
3030

31-
let assertion_to_string (env : 'a fmt_env) (indent : string) (a : assertion) :
32-
string =
31+
let assertion_to_string (env : 'a fmt_env) (a : assertion) : string =
3332
let cond = operand_to_string env a.cond in
34-
if a.expected then indent ^ "assert(" ^ cond ^ ")"
35-
else indent ^ "assert(¬" ^ cond ^ ")"
33+
if a.expected then "assert(" ^ cond ^ ")" else "assert(¬" ^ cond ^ ")"
34+
35+
let abort_kind_to_string (env : 'a fmt_env) (a : abort_kind) : string =
36+
match a with
37+
| Panic None -> "panic"
38+
| Panic (Some name) -> "panic(" ^ name_to_string env name ^ ")"
39+
| UndefinedBehavior -> "undefined_behavior"
40+
| UnwindTerminate -> "unwind_terminate"
3641

3742
(** Small helper *)
3843
let fun_sig_with_name_to_string (env : 'a fmt_env) (indent : string)

charon-ml/src/PrintLlbcAst.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ module Ast = struct
3737
indent ^ "storage_dead " ^ local_id_to_string env var_id
3838
| Deinit p -> indent ^ "deinit " ^ place_to_string env p
3939
| Drop (p, _, _) -> indent ^ "drop " ^ place_to_string env p
40-
| Assert a -> assertion_to_string env indent a
40+
| Assert (asrt, abort_kind) ->
41+
indent
42+
^ assertion_to_string env asrt
43+
^ " else "
44+
^ abort_kind_to_string env abort_kind
4145
| Call call -> call_to_string env indent call
4246
| Abort (Panic _) -> indent ^ "panic"
4347
| Abort UndefinedBehavior -> indent ^ "undefined_behavior"

charon-ml/src/PrintUllbcAst.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ module Ast = struct
2727
indent ^ "set_discriminant(" ^ place_to_string env p ^ ", "
2828
^ variant_id_to_pretty_string variant_id
2929
^ ")"
30-
| Assert a -> assertion_to_string env indent a
30+
| Assert (asrt, abort_kind) ->
31+
indent
32+
^ assertion_to_string env asrt
33+
^ " else "
34+
^ abort_kind_to_string env abort_kind
3135
| StorageLive var_id ->
3236
indent ^ "storage_live " ^ local_id_to_string env var_id
3337
| StorageDead var_id ->
@@ -75,6 +79,11 @@ module Ast = struct
7579
| Drop (_, p, _, tgt, unwind) ->
7680
indent ^ "drop " ^ place_to_string env p ^ " -> "
7781
^ block_id_to_string tgt ^ "(unwind:" ^ block_id_to_string unwind ^ ")"
82+
| TAssert (asrt, tgt, unwind) ->
83+
indent
84+
^ assertion_to_string env asrt
85+
^ " -> " ^ block_id_to_string tgt ^ "(unwind:"
86+
^ block_id_to_string unwind ^ ")"
7887
| Abort _ -> indent ^ "panic"
7988
| Return -> indent ^ "return"
8089
| UnwindResume -> indent ^ "unwind_continue"

charon-ml/src/generated/Generated_GAst.ml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ type fn_ptr_kind = Types.fn_ptr_kind [@@deriving show, ord]
2323
type fun_decl_id = Types.fun_decl_id [@@deriving show, ord]
2424

2525
(** (U)LLBC is a language with side-effects: a statement may abort in a way that
26-
isn't tracked by control-flow. The two kinds of abort are:
27-
- Panic (may unwind or not depending on compilation setting);
28-
- Undefined behavior: *)
26+
isn't tracked by control-flow. The three kinds of abort are:
27+
- Panic
28+
- Undefined behavior (caused by an "assume")
29+
- Unwind termination *)
2930
type abort_kind =
30-
| Panic of name option (** A built-in panicking function. *)
31+
| Panic of name option
32+
(** A built-in panicking function, or a panic due to a failed built-in
33+
check (e.g. for out-of-bounds accesses). *)
3134
| UndefinedBehavior (** Undefined behavior in the rust abstract machine. *)
3235
| UnwindTerminate
33-
(** Unwind had to stop for Abi reasons or because cleanup code panicked
36+
(** Unwind had to stop for ABI reasons or because cleanup code panicked
3437
again. *)
3538

3639
(** Check the value of an operand and abort if the value is not expected. This
@@ -47,9 +50,33 @@ and assertion = {
4750
expected : bool;
4851
(** The value that the operand should evaluate to for the assert to
4952
succeed. *)
50-
on_failure : abort_kind; (** What kind of abort happens on assert failure. *)
53+
check_kind : builtin_assert_kind option;
54+
(** The kind of check performed by this assert. This is only used for
55+
error reporting, as the check is actually performed by the
56+
instructions preceding the assert. *)
5157
}
5258

59+
(** The kind of a built-in assertion, which may panic and unwind. These are
60+
removed by [reconstruct_fallible_operations] because they're implicit in the
61+
semantics of (U)LLBC. This kind should only be used for error-reporting
62+
purposes, as the check itself is performed in the instructions preceding the
63+
assert. *)
64+
and builtin_assert_kind =
65+
| BoundsCheck of operand * operand
66+
(** Fields:
67+
- [len]
68+
- [index] *)
69+
| Overflow of binop * operand * operand
70+
| OverflowNeg of operand
71+
| DivisionByZero of operand
72+
| RemainderByZero of operand
73+
| MisalignedPointerDereference of operand * operand
74+
(** Fields:
75+
- [required]
76+
- [found] *)
77+
| NullPointerDereference
78+
| InvalidEnumConstruction of operand
79+
5380
and call = { func : fn_operand; args : operand list; dest : place }
5481
and copy_non_overlapping = { src : operand; dst : operand; count : operand }
5582

charon-ml/src/generated/Generated_GAstOfJson.ml

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ and assertion_of_json (ctx : of_json_ctx) (js : json) :
117117
combine_error_msgs js __FUNCTION__
118118
(match js with
119119
| `Assoc
120-
[ ("cond", cond); ("expected", expected); ("on_failure", on_failure) ]
120+
[ ("cond", cond); ("expected", expected); ("check_kind", check_kind) ]
121121
->
122122
let* cond = operand_of_json ctx cond in
123123
let* expected = bool_of_json ctx expected in
124-
let* on_failure = abort_kind_of_json ctx on_failure in
125-
Ok ({ cond; expected; on_failure } : assertion)
124+
let* check_kind =
125+
option_of_json builtin_assert_kind_of_json ctx check_kind
126+
in
127+
Ok ({ cond; expected; check_kind } : assertion)
126128
| _ -> Error "")
127129

128130
and attr_info_of_json (ctx : of_json_ctx) (js : json) :
@@ -250,6 +252,44 @@ and borrow_kind_of_json (ctx : of_json_ctx) (js : json) :
250252
| `String "UniqueImmutable" -> Ok BUniqueImmutable
251253
| _ -> Error "")
252254

255+
and builtin_assert_kind_of_json (ctx : of_json_ctx) (js : json) :
256+
(builtin_assert_kind, string) result =
257+
combine_error_msgs js __FUNCTION__
258+
(match js with
259+
| `Assoc [ ("BoundsCheck", `Assoc [ ("len", len); ("index", index) ]) ] ->
260+
let* len = operand_of_json ctx len in
261+
let* index = operand_of_json ctx index in
262+
Ok (BoundsCheck (len, index))
263+
| `Assoc [ ("Overflow", `List [ x_0; x_1; x_2 ]) ] ->
264+
let* x_0 = binop_of_json ctx x_0 in
265+
let* x_1 = operand_of_json ctx x_1 in
266+
let* x_2 = operand_of_json ctx x_2 in
267+
Ok (Overflow (x_0, x_1, x_2))
268+
| `Assoc [ ("OverflowNeg", overflow_neg) ] ->
269+
let* overflow_neg = operand_of_json ctx overflow_neg in
270+
Ok (OverflowNeg overflow_neg)
271+
| `Assoc [ ("DivisionByZero", division_by_zero) ] ->
272+
let* division_by_zero = operand_of_json ctx division_by_zero in
273+
Ok (DivisionByZero division_by_zero)
274+
| `Assoc [ ("RemainderByZero", remainder_by_zero) ] ->
275+
let* remainder_by_zero = operand_of_json ctx remainder_by_zero in
276+
Ok (RemainderByZero remainder_by_zero)
277+
| `Assoc
278+
[
279+
( "MisalignedPointerDereference",
280+
`Assoc [ ("required", required); ("found", found) ] );
281+
] ->
282+
let* required = operand_of_json ctx required in
283+
let* found = operand_of_json ctx found in
284+
Ok (MisalignedPointerDereference (required, found))
285+
| `String "NullPointerDereference" -> Ok NullPointerDereference
286+
| `Assoc [ ("InvalidEnumConstruction", invalid_enum_construction) ] ->
287+
let* invalid_enum_construction =
288+
operand_of_json ctx invalid_enum_construction
289+
in
290+
Ok (InvalidEnumConstruction invalid_enum_construction)
291+
| _ -> Error "")
292+
253293
and builtin_fun_id_of_json (ctx : of_json_ctx) (js : json) :
254294
(builtin_fun_id, string) result =
255295
combine_error_msgs js __FUNCTION__

charon-ml/src/generated/Generated_LlbcAst.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ and statement_kind =
5050
or a conditional call that should only happen if the place has not
5151
been moved out of. See the docs of [DropKind] for more details; to get
5252
precise drops use [--precise-drops]. *)
53-
| Assert of assertion
53+
| Assert of assertion * abort_kind
54+
(** Fields:
55+
- [assert]
56+
- [on_failure] *)
5457
| Call of call
5558
| Abort of abort_kind
5659
(** Panic also handles "unreachable". We keep the name of the panicking

charon-ml/src/generated/Generated_LlbcOfJson.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ and statement_kind_of_json (ctx : of_json_ctx) (js : json) :
7272
let* x_1 = trait_ref_of_json ctx x_1 in
7373
let* x_2 = drop_kind_of_json ctx x_2 in
7474
Ok (Drop (x_0, x_1, x_2))
75-
| `Assoc [ ("Assert", assert_) ] ->
75+
| `Assoc
76+
[
77+
("Assert", `Assoc [ ("assert", assert_); ("on_failure", on_failure) ]);
78+
] ->
7679
let* assert_ = assertion_of_json ctx assert_ in
77-
Ok (Assert assert_)
80+
let* on_failure = abort_kind_of_json ctx on_failure in
81+
Ok (Assert (assert_, on_failure))
7882
| `Assoc [ ("Call", call) ] ->
7983
let* call = call_of_json ctx call in
8084
Ok (Call call)

charon-ml/src/generated/Generated_UllbcAst.ml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ and statement_kind =
3535
the function's body, in which case it is implicitly deallocated at the
3636
end of the function. *)
3737
| Deinit of place
38-
| Assert of assertion
39-
(** A runtime check for a condition. This can be either:
40-
- Emitted for bounds/overflow/etc checks if
41-
[--reconstruct-fallible-operations] is not set;
42-
- Reconstructed from [if b { panic() }] if [--reconstruct-assets] is
43-
set. *)
38+
| Assert of assertion * abort_kind
39+
(** A non-diverging runtime check for a condition. This can be either:
40+
- Emitted for inlined "assumes" (which cause UB on failure)
41+
- Reconstructed from [if b { panic() }] if [--reconstruct-asserts] is
42+
set. This statement comes with the effect that happens when the
43+
check fails (rather than representing it as an unwinding edge).
44+
45+
Fields:
46+
- [assert]
47+
- [on_failure] *)
4448
| Nop (** Does nothing. Useful for passes. *)
4549

4650
and switch =
@@ -107,6 +111,14 @@ and terminator_kind =
107111
- [tref]
108112
- [target]
109113
- [on_unwind] *)
114+
| TAssert of assertion * block_id * block_id
115+
(** Assert that the given condition holds, and if not, unwind to the given
116+
block. This is used for bounds checks, overflow checks, etc.
117+
118+
Fields:
119+
- [assert]
120+
- [target]
121+
- [on_unwind] *)
110122
| Abort of abort_kind (** Handles panics and impossible cases. *)
111123
| Return
112124
| UnwindResume

charon-ml/src/generated/Generated_UllbcOfJson.ml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@ and statement_kind_of_json (ctx : of_json_ctx) (js : json) :
6363
| `Assoc [ ("Deinit", deinit) ] ->
6464
let* deinit = place_of_json ctx deinit in
6565
Ok (Deinit deinit)
66-
| `Assoc [ ("Assert", assert_) ] ->
66+
| `Assoc
67+
[
68+
("Assert", `Assoc [ ("assert", assert_); ("on_failure", on_failure) ]);
69+
] ->
6770
let* assert_ = assertion_of_json ctx assert_ in
68-
Ok (Assert assert_)
71+
let* on_failure = abort_kind_of_json ctx on_failure in
72+
Ok (Assert (assert_, on_failure))
6973
| `String "Nop" -> Ok Nop
7074
| _ -> Error "")
7175

@@ -141,6 +145,18 @@ and terminator_kind_of_json (ctx : of_json_ctx) (js : json) :
141145
let* target = block_id_of_json ctx target in
142146
let* on_unwind = block_id_of_json ctx on_unwind in
143147
Ok (Drop (kind, place, tref, target, on_unwind))
148+
| `Assoc
149+
[
150+
( "Assert",
151+
`Assoc
152+
[
153+
("assert", assert_); ("target", target); ("on_unwind", on_unwind);
154+
] );
155+
] ->
156+
let* assert_ = assertion_of_json ctx assert_ in
157+
let* target = block_id_of_json ctx target in
158+
let* on_unwind = block_id_of_json ctx on_unwind in
159+
Ok (TAssert (assert_, target, on_unwind))
144160
| `Assoc [ ("Abort", abort) ] ->
145161
let* abort = abort_kind_of_json ctx abort in
146162
Ok (Abort abort)

0 commit comments

Comments
 (0)