Skip to content

Commit 1c4aedb

Browse files
authored
Merge pull request #1528 from Nadrieril/instantiate-fnptrs
Instantiate fn pointer higher-kinded regions
2 parents 20406cb + 4e6f6f5 commit 1c4aedb

37 files changed

Lines changed: 183 additions & 71 deletions

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

‎charon-ml/src/PrintFmt.ml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,12 @@ let pp_fn_operand (env : fmt_env) (fmt : Format.formatter) (op : fn_operand) :
16561656
unit =
16571657
match op with
16581658
| FnOpRegular func -> pp_fn_ptr env fmt func
1659-
| FnOpDynamic op -> Format.fprintf fmt "(%a)" (pp_operand env) op
1659+
| FnOpDynamic (op, regions) ->
1660+
Format.fprintf fmt "(%a)" (pp_operand env) op;
1661+
if regions <> [] then
1662+
Format.fprintf fmt "<%a>"
1663+
(pp_sep_list ", " pp_string)
1664+
(List.map (region_to_string env) regions)
16601665

16611666
let pp_call (env : fmt_env) (indent : string) (fmt : Format.formatter)
16621667
(call : call) : unit =

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ and error = { span : span; msg : string }
258258
and fn_operand =
259259
| FnOpRegular of fn_ptr
260260
(** Regular case: call to a top-level function, trait method, etc. *)
261-
| FnOpDynamic of operand (** Use of a function pointer. *)
261+
| FnOpDynamic of operand * region list
262+
(** Call through a function pointer, instantiated with the given regions.
263+
*)
262264

263265
(** Where a given function came from. *)
264266
and fun_source =

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,10 @@ and fn_operand_of_json (ctx : of_json_ctx) (js : json) :
781781
| `Assoc [ ("Regular", _0) ] ->
782782
let* _0 = fn_ptr_of_json ctx _0 in
783783
Ok (FnOpRegular _0)
784-
| `Assoc [ ("Dynamic", _0) ] ->
784+
| `Assoc [ ("Dynamic", `List [ _0; _1 ]) ] ->
785785
let* _0 = operand_of_json ctx _0 in
786-
Ok (FnOpDynamic _0)
786+
let* _1 = index_vec_of_json region_id_of_json region_of_json ctx _1 in
787+
Ok (FnOpDynamic (_0, _1))
787788
| _ -> Error "")
788789

789790
and fn_ptr_of_json (ctx : of_json_ctx) (js : json) : (fn_ptr, string) result =

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,10 @@ and fn_operand_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
721721
Ok (FnOpRegular _0)
722722
| 1 ->
723723
let* _0 = operand_of_postcard ctx st in
724-
Ok (FnOpDynamic _0)
724+
let* _1 =
725+
index_vec_of_postcard region_id_of_postcard region_of_postcard ctx st
726+
in
727+
Ok (FnOpDynamic (_0, _1))
725728
| _ -> Error ("unknown enum variant tag: " ^ string_of_int __tag))
726729

727730
and fn_ptr_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :

‎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
@@ -27,7 +27,7 @@ tracing = { version = "0.1", features = ["max_level_trace"] }
2727

2828
[package]
2929
name = "charon"
30-
version = "0.1.288"
30+
version = "0.1.289"
3131
authors.workspace = true
3232
edition.workspace = true
3333
license.workspace = true

‎charon/src/ast/bodies.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ pub struct SwitchData {
175175
pub enum FnOperand {
176176
/// Regular case: call to a top-level function, trait method, etc.
177177
Regular(FnPtr),
178-
/// Use of a function pointer.
179-
Dynamic(Operand),
178+
/// Call through a function pointer, instantiated with the given regions.
179+
Dynamic(Operand, RegionArgs),
180180
}
181181

182182
#[derive(Debug, Clone, PartialEq, Eq)]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl HasSafety for Call {
263263
};
264264
callee_safety
265265
.or_else(|| match &self.func {
266-
FnOperand::Dynamic(op) => op.safety(krate),
266+
FnOperand::Dynamic(op, _) => op.safety(krate),
267267
FnOperand::Regular(_) => Safety::Safe,
268268
})
269269
.or_else(|| self.args.safety(krate))
@@ -298,7 +298,7 @@ impl HasSafety for FnOperand {
298298
}
299299
}
300300
},
301-
FnOperand::Dynamic(op) => op.ty().kind().as_fn_ptr().unwrap().safety(krate),
301+
FnOperand::Dynamic(op, _) => op.ty().kind().as_fn_ptr().unwrap().safety(krate),
302302
}
303303
}
304304
}

‎charon/src/ast/type_level.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub use type_info::*;
1919
pub use types::*;
2020
pub use vars::*;
2121

22+
/// A set of region arguments, typically meant to instantiate a `RegionBinder`.
23+
pub type RegionArgs = IndexVec<RegionId, Region>;
24+
2225
/// A set of generic arguments.
2326
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2427
#[derive(SerializeState, DeserializeState, Drive, DriveMut, DriveTwo)]

0 commit comments

Comments
 (0)