summaryrefslogtreecommitdiff
path: root/compiler/FunsAnalysis.ml
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/FunsAnalysis.ml')
-rw-r--r--compiler/FunsAnalysis.ml28
1 files changed, 17 insertions, 11 deletions
diff --git a/compiler/FunsAnalysis.ml b/compiler/FunsAnalysis.ml
index 3ba5d35d..9eac3e6f 100644
--- a/compiler/FunsAnalysis.ml
+++ b/compiler/FunsAnalysis.ml
@@ -57,16 +57,16 @@ let analyze_module (m : crate) (funs_map : fun_decl FunDeclId.Map.t)
let stateful = ref false in
let can_diverge = ref false in
let is_rec = ref false in
- let is_builtin_non_fallible_group = ref false in
+ let group_has_builtin_info = ref false in
(* We have some specialized knowledge of some library functions; we don't
have any more custom treatment than this, and these functions can be modeled
suitably in Primitives.fst, rather than special-casing for them all the
way. *)
- let is_builtin_non_fallible (f : fun_decl) : bool =
+ let get_builtin_info (f : fun_decl) : ExtractBuiltin.effect_info option =
let open ExtractBuiltin in
let name = name_to_simple_name f.name in
- SimpleNameSet.mem name builtin_non_fallible_funs_set
+ SimpleNameMap.find_opt name builtin_fun_effects_map
in
(* JP: Why not use a reduce visitor here with a tuple of the values to be
@@ -119,16 +119,21 @@ let analyze_module (m : crate) (funs_map : fun_decl FunDeclId.Map.t)
in
(* Sanity check: global bodies don't contain stateful calls *)
assert ((not f.is_global_decl_body) || not !stateful);
- let is_builtin_non_fallible = is_builtin_non_fallible f in
- is_builtin_non_fallible_group :=
- !is_builtin_non_fallible_group || is_builtin_non_fallible;
+ let builtin_info = get_builtin_info f in
+ let has_builtin_info = builtin_info <> None in
+ group_has_builtin_info := !group_has_builtin_info || has_builtin_info;
match f.body with
| None ->
- obj#may_fail (not is_builtin_non_fallible);
+ let info_can_fail, info_stateful =
+ match builtin_info with
+ | None -> (true, false)
+ | Some { can_fail; stateful } -> (can_fail, stateful)
+ in
+ obj#may_fail info_can_fail;
stateful :=
(not f.is_global_decl_body)
&& use_state
- && not is_builtin_non_fallible
+ && not (has_builtin_info && not info_stateful)
| Some body -> obj#visit_statement () body.body
in
List.iter visit_fun d;
@@ -136,7 +141,7 @@ let analyze_module (m : crate) (funs_map : fun_decl FunDeclId.Map.t)
* groups containing globals contain exactly one declaration *)
let is_global_decl_body = List.exists (fun f -> f.is_global_decl_body) d in
assert ((not is_global_decl_body) || List.length d = 1);
- assert ((not !is_builtin_non_fallible_group) || List.length d = 1);
+ assert ((not !group_has_builtin_info) || List.length d = 1);
(* We ignore on purpose functions that cannot fail and consider they *can*
* fail: the result of the analysis is not used yet to adjust the translation
* so that the functions which syntactically can't fail don't use an error monad.
@@ -144,8 +149,9 @@ let analyze_module (m : crate) (funs_map : fun_decl FunDeclId.Map.t)
* builtin functions which are marked as non-fallible.
* *)
can_fail :=
- ((not is_global_decl_body) && not !is_builtin_non_fallible_group)
- || !can_fail;
+ if is_global_decl_body then !can_fail
+ else if !group_has_builtin_info then !can_fail
+ else true;
{
can_fail = !can_fail;
stateful = !stateful;