aboutsummaryrefslogtreecommitdiff
path: root/plugins/funind/glob_termops.ml
diff options
context:
space:
mode:
authorMaxime Dénès2020-02-03 18:19:42 +0100
committerMaxime Dénès2020-07-06 11:22:43 +0200
commit0ea2d0ff4ed84e1cc544c958b8f6e98f6ba2e9b6 (patch)
treefbad060c3c2e29e81751dea414c898b5cb0fa22d /plugins/funind/glob_termops.ml
parentcf388fdb679adb88a7e8b3122f65377552d2fb94 (diff)
Primitive persistent arrays
Persistent arrays expose a functional interface but are implemented using an imperative data structure. The OCaml implementation is based on Jean-Christophe Filliâtre's. Co-authored-by: Benjamin Grégoire <Benjamin.Gregoire@inria.fr> Co-authored-by: Gaëtan Gilbert <gaetan.gilbert@skyskimmer.net>
Diffstat (limited to 'plugins/funind/glob_termops.ml')
-rw-r--r--plugins/funind/glob_termops.ml29
1 files changed, 26 insertions, 3 deletions
diff --git a/plugins/funind/glob_termops.ml b/plugins/funind/glob_termops.ml
index 5026120849..8e1331ace9 100644
--- a/plugins/funind/glob_termops.ml
+++ b/plugins/funind/glob_termops.ml
@@ -109,7 +109,13 @@ let change_vars =
| GCast (b, c) ->
GCast
( change_vars mapping b
- , Glob_ops.map_cast_type (change_vars mapping) c ))
+ , Glob_ops.map_cast_type (change_vars mapping) c )
+ | GArray (u, t, def, ty) ->
+ GArray
+ ( u
+ , Array.map (change_vars mapping) t
+ , change_vars mapping def
+ , change_vars mapping ty ))
rt
and change_vars_br mapping ({CAst.loc; v = idl, patl, res} as br) =
let new_mapping = List.fold_right Id.Map.remove idl mapping in
@@ -282,6 +288,12 @@ let rec alpha_rt excluded rt =
GCast (alpha_rt excluded b, Glob_ops.map_cast_type (alpha_rt excluded) c)
| GApp (f, args) ->
GApp (alpha_rt excluded f, List.map (alpha_rt excluded) args)
+ | GArray (u, t, def, ty) ->
+ GArray
+ ( u
+ , Array.map (alpha_rt excluded) t
+ , alpha_rt excluded def
+ , alpha_rt excluded ty )
in
new_rt
@@ -331,7 +343,9 @@ let is_free_in id =
| GHole _ -> false
| GCast (b, (CastConv t | CastVM t | CastNative t)) ->
is_free_in b || is_free_in t | GCast (b, CastCoerce) -> is_free_in b
- | GInt _ | GFloat _ -> false)
+ | GInt _ | GFloat _ -> false
+ | GArray (_u, t, def, ty) ->
+ Array.exists is_free_in t || is_free_in def || is_free_in ty)
x
and is_free_in_br {CAst.v = ids, _, rt} =
(not (Id.List.mem id ids)) && is_free_in rt
@@ -404,6 +418,12 @@ let replace_var_by_term x_id term =
| (GSort _ | GHole _) as rt -> rt
| GInt _ as rt -> rt
| GFloat _ as rt -> rt
+ | GArray (u, t, def, ty) ->
+ GArray
+ ( u
+ , Array.map replace_var_by_pattern t
+ , replace_var_by_pattern def
+ , replace_var_by_pattern ty )
| GCast (b, c) ->
GCast
( replace_var_by_pattern b
@@ -510,7 +530,10 @@ let expand_as =
( sty
, Option.map (expand_as map) po
, List.map (fun (rt, t) -> (expand_as map rt, t)) el
- , List.map (expand_as_br map) brl ))
+ , List.map (expand_as_br map) brl )
+ | GArray (u, t, def, ty) ->
+ GArray
+ (u, Array.map (expand_as map) t, expand_as map def, expand_as map ty))
and expand_as_br map {CAst.loc; v = idl, cpl, rt} =
CAst.make ?loc (idl, cpl, expand_as (List.fold_left add_as map cpl) rt)
in