Skip to content

Commit 664b72d

Browse files
committed
Support assumed functions in Rust mutability inference
1 parent 7e5a7da commit 664b72d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/AstToMiniRust.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,8 +1400,13 @@ let translate_decl env (d: Ast.decl): MiniRust.decl option =
14001400
let meta = translate_meta flags in
14011401
Some (MiniRust.Constant { name; typ; body; meta })
14021402

1403-
| DExternal _ ->
1404-
None
1403+
| DExternal (_, _, _, _, lid, _, _) ->
1404+
let name, parameters, return_type =
1405+
match lookup_decl env lid with
1406+
| name, Function (_, parameters, return_type) -> name, parameters, return_type
1407+
| _ -> failwith " impossible"
1408+
in
1409+
Some (MiniRust.Assumed { name; parameters; return_type })
14051410

14061411
| DType (lid, flags, _, _, decl) ->
14071412
let name = lookup_type env lid in

lib/OptimizeMiniRust.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ let infer_function (env: env) valuation (d: decl): decl =
669669
the traversal does not add or remove any bindings, but only increases the
670670
mutability, we can do a direct replacement instead of a more complex merge *)
671671
Function { f with body; parameters }
672+
(* Assumed functions already have their mutability specified, we skip them *)
673+
| Assumed _ -> d
672674
| _ ->
673675
assert false
674676

@@ -1021,6 +1023,8 @@ let infer_mut_borrows files =
10211023
List.filter_map (function
10221024
| Function { parameters; name; _ } ->
10231025
Some (name, List.map (fun (p: MiniRust.binding) -> p.typ) parameters)
1026+
| Assumed { name; parameters; _ } ->
1027+
Some (name, parameters)
10241028
| _ ->
10251029
None
10261030
) decls) files))
@@ -1044,6 +1048,7 @@ let infer_mut_borrows files =
10441048
else
10451049
match infer_function env valuation (NameMap.find name definitions) with
10461050
| Function { parameters; _ } -> distill (List.map (fun (b: MiniRust.binding) -> b.typ) parameters)
1051+
| Assumed { parameters; _ } -> distill parameters
10471052
| _ -> failwith "impossible"
10481053
in
10491054

0 commit comments

Comments
 (0)