Skip to content

Commit 149d2a1

Browse files
authored
Merge pull request #1578 from Nadrieril/cleanup
Improve the AST for typechecking purposes
2 parents 7bd38d6 + f87da80 commit 149d2a1

81 files changed

Lines changed: 2085 additions & 822 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎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.302"
3+
let supported_charon_version = "0.1.303"

‎charon-ml/src/ExpressionsUtils.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let binop_can_fail : binop -> bool = function
1313
| Mul OWrap
1414
| Shl OWrap
1515
| Shr OWrap
16-
| AddChecked | SubChecked | MulChecked | Cmp -> false
16+
| Cmp -> false
1717
| Div _ | Rem _ | Add _ | Sub _ | Mul _ | Shl _ | Shr _ -> true
1818

1919
let mk_unit_const : constant_expr = { kind = CAdt (None, []); ty = mk_unit_ty }

‎charon-ml/src/PrintFmt.ml‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ and pp_constant_expr (env : fmt_env) (fmt : Format.formatter)
624624
end
625625
| CArray fields ->
626626
Format.fprintf fmt "[%a]" (pp_sep_list ", " (pp_constant_expr env)) fields
627+
| CRepeat (value, count, _) ->
628+
Format.fprintf fmt "[%a; %a]" (pp_constant_expr env) value
629+
(pp_constant_expr env) count
627630
| CGlobal gref -> pp_global_decl_ref env fmt gref
628631
| CPtrNoProvenance n -> Format.fprintf fmt "no-provenance %s" (Z.to_string n)
629632
| CExternSymbol name -> Format.fprintf fmt "&raw const <extern:%s>" name
@@ -651,7 +654,8 @@ and pp_cast_kind (env : fmt_env) (fmt : Format.formatter) (cast : cast_kind) :
651654
unit =
652655
match cast with
653656
| CastScalar tgt -> Format.fprintf fmt "cast<%a>" pp_scalar_type tgt
654-
| CastPtrExposeProvenance -> Format.pp_print_string fmt "cast_expose"
657+
| CastPtrExposeProvenance tgt ->
658+
Format.fprintf fmt "cast_expose<%a>" pp_integer_type tgt
655659
| CastPtrWithExposedProvenance tgt ->
656660
Format.fprintf fmt "cast_with_exposed<%a>" (pp_ty env) tgt
657661
| CastFnDefToFnPtr -> Format.pp_print_string fmt "fn_def_to_fn_ptr"
@@ -1638,9 +1642,6 @@ and pp_binop (fmt : Format.formatter) (binop : binop) : unit =
16381642
| Mul om -> Format.fprintf fmt "%a.*" pp_overflow_mode om
16391643
| Shl om -> Format.fprintf fmt "%a.<<" pp_overflow_mode om
16401644
| Shr om -> Format.fprintf fmt "%a.>>" pp_overflow_mode om
1641-
| AddChecked -> pp_string fmt "checked.+"
1642-
| SubChecked -> pp_string fmt "checked.-"
1643-
| MulChecked -> pp_string fmt "checked.*"
16441645
| Cmp -> pp_string fmt "cmp"
16451646

16461647
and pp_operand (env : fmt_env) (fmt : Format.formatter) (op : operand) : unit =
@@ -1743,11 +1744,9 @@ and pp_rvalue (env : fmt_env) (fmt : Format.formatter) (rv : rvalue) : unit =
17431744
(pp_operand env) op2
17441745
| Discriminant p ->
17451746
Format.fprintf fmt "@discriminant(%s)" (place_to_string env p)
1746-
| Len (place, _, _) ->
1747-
Format.fprintf fmt "len(%s)" (place_to_string env place)
1748-
| Repeat (v, _, len, _) ->
1747+
| Repeat (v, count, _, _) ->
17491748
Format.fprintf fmt "[%s; %s]" (operand_to_string env v)
1750-
(constant_expr_to_string env len)
1749+
(constant_expr_to_string env count)
17511750
| Aggregate (akind, ops) -> pp_aggregate env akind fmt ops
17521751

17531752
let pp_fn_operand (env : fmt_env) (fmt : Format.formatter) (op : fn_operand) :
@@ -1763,8 +1762,7 @@ let pp_fn_operand (env : fmt_env) (fmt : Format.formatter) (op : fn_operand) :
17631762

17641763
let pp_call (env : fmt_env) (indent : string) (fmt : Format.formatter)
17651764
(call : call) : unit =
1766-
Format.fprintf fmt "%s%a = %a(%a)" indent (pp_place env) call.dest
1767-
(pp_fn_operand env) call.func
1765+
Format.fprintf fmt "%s%a(%a)" indent (pp_fn_operand env) call.func
17681766
(pp_sep_list ", " (pp_operand env))
17691767
call.args
17701768

@@ -2306,8 +2304,9 @@ module Llbc = struct
23062304
labels;
23072305
Format.fprintf fmt "\n%s}" indent;
23082306
pp_unwind_block env indent indent_incr fmt on_unwind
2309-
| Call (call, on_unwind) ->
2310-
Format.fprintf fmt "%a%a" (pp_print_call env indent) call
2307+
| Call (call, dest, on_unwind) ->
2308+
Format.fprintf fmt "%s%a = %a%a" indent (pp_place env) dest
2309+
(pp_print_call env "") call
23112310
(pp_unwind_block env indent indent_incr)
23122311
on_unwind
23132312
| Panic (name, on_unwind) ->
@@ -2479,9 +2478,9 @@ module Ullbc = struct
24792478
match st with
24802479
| Goto bid -> Format.fprintf fmt "%sgoto %s" indent (block_id_to_string bid)
24812480
| Switch (data, branches) -> pp_switch env indent fmt data branches
2482-
| Call (call, tgt, unwind) ->
2483-
Format.fprintf fmt "%a -> %s (unwind: %s)" (pp_print_call env indent)
2484-
call (block_id_to_string tgt)
2481+
| Call (call, dest, tgt, unwind) ->
2482+
Format.fprintf fmt "%s%a = %a -> %s (unwind: %s)" indent (pp_place env)
2483+
dest (pp_print_call env "") call (block_id_to_string tgt)
24852484
(block_id_to_string unwind)
24862485
| Drop (kind, p, fn_ptr, tgt, unwind) ->
24872486
let kind =

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

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ and binop =
6969
| Mul of overflow_mode
7070
| Div of overflow_mode
7171
| Rem of overflow_mode
72-
| AddChecked
73-
(** Returns [(result, did_overflow)], where [result] is the result of the
74-
operation with wrapping semantics, and [did_overflow] is a boolean
75-
that indicates whether the operation overflowed. This operation does
76-
not fail. *)
77-
| SubChecked (** Like [AddChecked]. *)
78-
| MulChecked (** Like [AddChecked]. *)
7972
| Shl of overflow_mode
8073
(** Fails if the shift is bigger than the bit-size of the type. *)
8174
| Shr of overflow_mode
@@ -258,25 +251,15 @@ and rvalue =
258251
259252
Remark: in case of closures, the aggregated value groups the closure
260253
id together with its state. *)
261-
| Len of place * ty * constant_expr option
262-
(** Length of a place of type [[T]] or [[T; N]]. This applies to the place
263-
itself, not to a pointer value. This is inserted by rustc in a single
264-
case: slice patterns.
265-
{@rust[
266-
fn slice_pattern_4(x: &[()]) {
267-
match x {
268-
[_named] => (),
269-
_ => (),
270-
}
271-
}
272-
]} *)
273-
| Repeat of operand * ty * constant_expr * trait_ref option
254+
| Repeat of operand * constant_expr * trait_ref * trait_ref option
274255
(** [Repeat(x, n)] creates an array containing [n] copies of [x].
275256
276-
We translate this to a function call for LLBC. The last field is the
277-
proof that the repeated value is [Copy]. This proof can be absent when
278-
the operand is a constant, which Rust permits to be repeated without
279-
[Copy]. *)
257+
Fields:
258+
- [operand]
259+
- [count]
260+
- [elem_is_copy]: Proof that the element type is [Copy].
261+
- [elem_is_sized]: Proof that the element type is [Sized]; absent with
262+
[--hide-marker-traits]. *)
280263

281264
(** Unary operation *)
282265
and unop =

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,7 @@ and builtin_assert_kind =
200200
| ResumedAfterPanic
201201
| ResumedAfterDrop
202202

203-
and call = {
204-
func : fn_operand;
205-
args : operand list;
206-
dest : place;
207-
safety : call_safety;
208-
}
203+
and call = { func : fn_operand; args : operand list; safety : call_safety }
209204

210205
(** Whether we statically know something about the safety of this call, that
211206
takes precedence over the safety of the callee's signature. *)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ and statement_kind =
8181
jumping. Absent for [naked_asm!] and [noreturn].
8282
- [labels]: Targets of [[AsmOperand::Label]] operands.
8383
- [on_unwind]: Action to be taken if the inline assembly unwinds. *)
84-
| Call of call * block
84+
| Call of call * place * block
8585
(** Fields:
8686
- [call]
87+
- [dest]
8788
- [on_unwind] *)
8889
| Switch of switch_data * block list
8990
(** Fields:

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

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,6 @@ and binop_of_json (ctx : of_json_ctx) (js : json) : (binop, string) result =
299299
| `Assoc [ ("Rem", _0) ] ->
300300
let* _0 = overflow_mode_of_json ctx _0 in
301301
Ok (Rem _0)
302-
| `String "AddChecked" -> Ok AddChecked
303-
| `String "SubChecked" -> Ok SubChecked
304-
| `String "MulChecked" -> Ok MulChecked
305302
| `Assoc [ ("Shl", _0) ] ->
306303
let* _0 = overflow_mode_of_json ctx _0 in
307304
Ok (Shl _0)
@@ -502,14 +499,11 @@ and byte_of_json (ctx : of_json_ctx) (js : json) : (byte, string) result =
502499
and call_of_json (ctx : of_json_ctx) (js : json) : (call, string) result =
503500
combine_error_msgs js __FUNCTION__
504501
(match js with
505-
| `Assoc
506-
[ ("func", func); ("args", args); ("dest", dest); ("safety", safety) ]
507-
->
502+
| `Assoc [ ("func", func); ("args", args); ("safety", safety) ] ->
508503
let* func = fn_operand_of_json ctx func in
509504
let* args = list_of_json operand_of_json ctx args in
510-
let* dest = place_of_json ctx dest in
511505
let* safety = call_safety_of_json ctx safety in
512-
Ok ({ func; args; dest; safety } : call)
506+
Ok ({ func; args; safety } : call)
513507
| _ -> Error "")
514508

515509
and call_safety_of_json (ctx : of_json_ctx) (js : json) :
@@ -531,7 +525,9 @@ and cast_kind_of_json (ctx : of_json_ctx) (js : json) :
531525
| `Assoc [ ("RawPtr", _0) ] ->
532526
let* _0 = ty_of_json ctx _0 in
533527
Ok (CastRawPtr _0)
534-
| `String "PtrExposeProvenance" -> Ok CastPtrExposeProvenance
528+
| `Assoc [ ("PtrExposeProvenance", _0) ] ->
529+
let* _0 = integer_type_of_json ctx _0 in
530+
Ok (CastPtrExposeProvenance _0)
535531
| `Assoc [ ("PtrWithExposedProvenance", _0) ] ->
536532
let* _0 = ty_of_json ctx _0 in
537533
Ok (CastPtrWithExposedProvenance _0)
@@ -705,6 +701,22 @@ and constant_expr_kind_of_json (ctx : of_json_ctx) (js : json) :
705701
let* _0 = type_decl_ref_of_json ctx _0 in
706702
let* _1 = variant_id_of_json ctx _1 in
707703
Ok (CDiscriminant (_0, _1))
704+
| `Assoc
705+
[
706+
( "Repeat",
707+
`Assoc
708+
[
709+
("value", value);
710+
("count", count);
711+
("value_is_sized", value_is_sized);
712+
] );
713+
] ->
714+
let* value = constant_expr_of_json ctx value in
715+
let* count = constant_expr_of_json ctx count in
716+
let* value_is_sized =
717+
option_of_json trait_ref_of_json ctx value_is_sized
718+
in
719+
Ok (CRepeat (value, count, value_is_sized))
708720
| `Assoc [ ("SizeOf", _0) ] ->
709721
let* _0 = ty_of_json ctx _0 in
710722
Ok (CSizeOf _0)
@@ -1444,17 +1456,24 @@ and rvalue_of_json (ctx : of_json_ctx) (js : json) : (rvalue, string) result =
14441456
let* _0 = aggregate_kind_of_json ctx _0 in
14451457
let* _1 = list_of_json operand_of_json ctx _1 in
14461458
Ok (Aggregate (_0, _1))
1447-
| `Assoc [ ("Len", `List [ _0; _1; _2 ]) ] ->
1448-
let* _0 = place_of_json ctx _0 in
1449-
let* _1 = ty_of_json ctx _1 in
1450-
let* _2 = option_of_json constant_expr_of_json ctx _2 in
1451-
Ok (Len (_0, _1, _2))
1452-
| `Assoc [ ("Repeat", `List [ _0; _1; _2; _3 ]) ] ->
1453-
let* _0 = operand_of_json ctx _0 in
1454-
let* _1 = ty_of_json ctx _1 in
1455-
let* _2 = constant_expr_of_json ctx _2 in
1456-
let* _3 = option_of_json trait_ref_of_json ctx _3 in
1457-
Ok (Repeat (_0, _1, _2, _3))
1459+
| `Assoc
1460+
[
1461+
( "Repeat",
1462+
`Assoc
1463+
[
1464+
("operand", operand);
1465+
("count", count);
1466+
("elem_is_copy", elem_is_copy);
1467+
("elem_is_sized", elem_is_sized);
1468+
] );
1469+
] ->
1470+
let* operand = operand_of_json ctx operand in
1471+
let* count = constant_expr_of_json ctx count in
1472+
let* elem_is_copy = trait_ref_of_json ctx elem_is_copy in
1473+
let* elem_is_sized =
1474+
option_of_json trait_ref_of_json ctx elem_is_sized
1475+
in
1476+
Ok (Repeat (operand, count, elem_is_copy, elem_is_sized))
14581477
| _ -> Error "")
14591478

14601479
and scalar_type_of_json (ctx : of_json_ctx) (js : json) :
@@ -2007,13 +2026,18 @@ module Ullbc = struct
20072026
[
20082027
( "Call",
20092028
`Assoc
2010-
[ ("call", call); ("target", target); ("on_unwind", on_unwind) ]
2011-
);
2029+
[
2030+
("call", call);
2031+
("dest", dest);
2032+
("target", target);
2033+
("on_unwind", on_unwind);
2034+
] );
20122035
] ->
20132036
let* call = call_of_json ctx call in
2037+
let* dest = place_of_json ctx dest in
20142038
let* target = block_id_of_json ctx target in
20152039
let* on_unwind = block_id_of_json ctx on_unwind in
2016-
Ok (Call (call, target, on_unwind))
2040+
Ok (Call (call, dest, target, on_unwind))
20172041
| `Assoc
20182042
[
20192043
( "Drop",
@@ -2209,11 +2233,16 @@ module Llbc = struct
22092233
in
22102234
let* on_unwind = block_of_json ctx on_unwind in
22112235
Ok (InlineAsm (asm, fallthrough, labels, on_unwind))
2212-
| `Assoc [ ("Call", `Assoc [ ("call", call); ("on_unwind", on_unwind) ]) ]
2213-
->
2236+
| `Assoc
2237+
[
2238+
( "Call",
2239+
`Assoc
2240+
[ ("call", call); ("dest", dest); ("on_unwind", on_unwind) ] );
2241+
] ->
22142242
let* call = call_of_json ctx call in
2243+
let* dest = place_of_json ctx dest in
22152244
let* on_unwind = block_of_json ctx on_unwind in
2216-
Ok (Call (call, on_unwind))
2245+
Ok (Call (call, dest, on_unwind))
22172246
| `Assoc [ ("Switch", `Assoc [ ("data", data); ("branches", branches) ]) ]
22182247
->
22192248
let* data = switch_data_of_json ctx data in

0 commit comments

Comments
 (0)