Skip to content

Commit 15c30f1

Browse files
authored
Merge pull request #1593 from Nadrieril/mutable-locals
Track the mutability of locals
2 parents 2bceb7c + 6cc2b5f commit 15c30f1

497 files changed

Lines changed: 8640 additions & 8617 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.311"
3+
let supported_charon_version = "0.1.312"

‎charon-ml/src/PrintFmt.ml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,8 @@ let pp_locals (env : fmt_env) (indent : string) (fmt : Format.formatter)
19041904
| None -> ""
19051905
| Some place -> "; drop flag for " ^ place_to_string env place
19061906
in
1907-
Format.fprintf fmt "%slet %s: %s; // %s%s" indent
1907+
Format.fprintf fmt "%slet %s%s: %s; // %s%s" indent
1908+
(if var.is_mutable then "mut " else "")
19081909
(local_id_to_string env var.index)
19091910
(ty_to_string env var.local_ty)
19101911
kind drop_flag_for

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ and local = {
346346
through desugaring. *)
347347
span : span; (** Span of the variable declaration. *)
348348
local_ty : ty; (** The variable type *)
349+
is_mutable : bool;
350+
(** Whether this local was declared [mut]. Anonymous locals are always
351+
mutable. *)
349352
drop_flag_for : place option;
350353
(** If this local is a drop flag, this is the place whose initialization
351354
state it tracks. *)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3763,14 +3763,16 @@ and local_of_json (ctx : of_json_ctx) (js : json) : (local, string) result =
37633763
("name", name);
37643764
("span", span);
37653765
("ty", ty);
3766+
("mutable", mutable_);
37663767
("drop_flag_for", drop_flag_for);
37673768
] ->
37683769
let* index = local_id_of_json ctx index in
37693770
let* name = option_of_json string_of_json ctx name in
37703771
let* span = span_of_json ctx span in
37713772
let* local_ty = ty_of_json ctx ty in
3773+
let* is_mutable = bool_of_json ctx mutable_ in
37723774
let* drop_flag_for = option_of_json place_of_json ctx drop_flag_for in
3773-
Ok ({ index; name; span; local_ty; drop_flag_for } : local)
3775+
Ok ({ index; name; span; local_ty; is_mutable; drop_flag_for } : local)
37743776
| _ -> Error "")
37753777

37763778
and locals_of_json (ctx : of_json_ctx) (js : json) : (locals, string) result =

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3093,8 +3093,9 @@ and local_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
30933093
let* name = option_of_postcard string_of_postcard ctx st in
30943094
let* span = span_of_postcard ctx st in
30953095
let* local_ty = ty_of_postcard ctx st in
3096+
let* is_mutable = bool_of_postcard ctx st in
30963097
let* drop_flag_for = option_of_postcard place_of_postcard ctx st in
3097-
Ok ({ index; name; span; local_ty; drop_flag_for } : local))
3098+
Ok ({ index; name; span; local_ty; is_mutable; drop_flag_for } : local))
30983099

30993100
and locals_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
31003101
(locals, string) result =

‎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.311"
29+
version = "0.1.312"
3030
authors.workspace = true
3131
edition.workspace = true
3232
license.workspace = true

‎charon/src/ast/bodies.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ pub struct Local {
116116
/// The variable type
117117
#[cfg_attr(feature = "charon_on_charon", charon::rename("local_ty"))]
118118
pub ty: Ty,
119+
/// Whether this local was declared `mut`. Anonymous locals are always mutable.
120+
#[cfg_attr(feature = "charon_on_charon", charon::rename("is_mutable"))]
121+
pub mutable: bool,
119122
/// If this local is a drop flag, this is the place whose initialization state it tracks.
120123
pub drop_flag_for: Option<Place>,
121124
}
@@ -358,6 +361,7 @@ impl Locals {
358361
name,
359362
span: Span::dummy(),
360363
ty: ty.clone(),
364+
mutable: true,
361365
drop_flag_for: None,
362366
});
363367
Place::new(local_id, ty)

‎charon/src/bin/charon-driver/translate/translate_bodies.rs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,20 @@ impl<'tcx> BodyTransCtx<'tcx, '_, '_> {
609609
self.locals_map.get(&local.index()).copied()
610610
}
611611

612-
pub(crate) fn push_var(&mut self, rid: mir::Local, ty: Ty, name: Option<String>, span: Span) {
612+
pub(crate) fn push_var(
613+
&mut self,
614+
rid: mir::Local,
615+
ty: Ty,
616+
name: Option<String>,
617+
span: Span,
618+
mutable: bool,
619+
) {
613620
let local_id = self.locals.locals.push_with(|index| Local {
614621
index,
615622
name,
616623
span,
617624
ty,
625+
mutable,
618626
drop_flag_for: None,
619627
});
620628
self.locals_map.insert(rid.as_usize(), local_id);
@@ -632,7 +640,7 @@ impl<'tcx> BodyTransCtx<'tcx, '_, '_> {
632640
let ty = self.translate_rustc_ty(span, &var.ty)?;
633641

634642
// Add the variable to the environment
635-
self.push_var(index, ty, name, span);
643+
self.push_var(index, ty, name, span, var.mutability.is_mut());
636644
}
637645

638646
Ok(())

‎charon/src/bin/generate-asts/generate_ml/util.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn make_ocaml_ident(name: &str) -> String {
2020
| "include"
2121
| "let"
2222
| "method"
23+
| "mutable"
2324
| "open"
2425
| "rec"
2526
| "struct"

0 commit comments

Comments
 (0)