Skip to content

Commit a7ea250

Browse files
authored
Merge pull request #738 from ppedrot/module-abstract-type
Adapt w.r.t. rocq-prover/rocq#19995.
2 parents 185416f + 9c7a171 commit a7ea250

File tree

2 files changed

+52
-26
lines changed

2 files changed

+52
-26
lines changed

src/coq_elpi_HOAS.ml

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3698,6 +3698,34 @@ type module_item =
36983698
| Functor of Names.ModPath.t * Names.ModPath.t list
36993699
| FunctorType of Names.ModPath.t * Names.ModPath.t list
37003700

3701+
[%%if coq = "8.20" || coq = "9.0"]
3702+
type 'a generic_module_body = 'a Declarations.generic_module_body
3703+
let module_view m = (m.Declarations.mod_mp, m.Declarations.mod_type)
3704+
let mod_type m = m.Declarations.mod_type
3705+
let mod_mp m = m.Declarations.mod_mp
3706+
3707+
let rec functor_params x =
3708+
let open Declarations in
3709+
match x with
3710+
| MoreFunctor(_,{ mod_type_alg = Some (MENoFunctor (MEident mod_mp)) },rest) -> mod_mp :: functor_params rest
3711+
| _ -> [] (* XXX non trivial functors, eg P : X with type a = nat, are badly described (no params) *)
3712+
[%%else]
3713+
type 'a generic_module_body = 'a Mod_declarations.generic_module_body
3714+
let module_view m = (Mod_declarations.mod_mp m, Mod_declarations.mod_type m)
3715+
let mod_type = Mod_declarations.mod_type
3716+
let mod_mp = Mod_declarations.mod_mp
3717+
3718+
let rec functor_params x =
3719+
let open Declarations in
3720+
match x with
3721+
| MoreFunctor (_, mtb, rest) ->
3722+
begin match Mod_declarations.mod_type_alg mtb with
3723+
| Some (MENoFunctor (MEident mod_mp)) -> mod_mp :: functor_params rest
3724+
| _ -> [] (* XXX *)
3725+
end
3726+
| _ -> [] (* XXX non trivial functors, eg P : X with type a = nat, are badly described (no params) *)
3727+
[%%endif]
3728+
37013729
let rec in_elpi_module_item ~depth path state (name, item) =
37023730
let open Declarations in
37033731
match item with
@@ -3706,31 +3734,24 @@ let rec in_elpi_module_item ~depth path state (name, item) =
37063734
| SFBmind { mind_packets } ->
37073735
CList.init (Array.length mind_packets) (fun i -> Gref (GlobRef.IndRef (MutInd.make2 path name,i)))
37083736
| SFBrules _ -> nYI "rewrite rules"
3709-
| SFBmodule ({ mod_mp; mod_type = NoFunctor _ } as b) -> [Module (mod_mp,in_elpi_module ~depth state b) ]
3710-
| SFBmodule { mod_mp; mod_type = MoreFunctor _ as l } -> [Functor(mod_mp,functor_params l)]
3711-
| SFBmodtype { mod_mp; mod_type = NoFunctor _ } -> [ModuleType mod_mp]
3712-
| SFBmodtype { mod_mp; mod_type = MoreFunctor _ as l } -> [FunctorType (mod_mp,functor_params l)]
3713-
3714-
and functor_params x =
3715-
let open Declarations in
3716-
match x with
3717-
| MoreFunctor(_,{ mod_type_alg = Some (MENoFunctor (MEident mod_mp)) },rest) -> mod_mp :: functor_params rest
3718-
| _ -> [] (* XXX non trivial functors, eg P : X with type a = nat, are badly described (no params) *)
3737+
| SFBmodule b ->
3738+
begin match module_view b with
3739+
| mod_mp, NoFunctor _ -> [Module (mod_mp,in_elpi_module ~depth state b) ]
3740+
| mod_mp, (MoreFunctor _ as l) -> [Functor(mod_mp,functor_params l)]
3741+
end
3742+
| SFBmodtype m ->
3743+
begin match module_view m with
3744+
| mod_mp, NoFunctor _ -> [ModuleType mod_mp]
3745+
| mod_mp, (MoreFunctor _ as l) -> [FunctorType (mod_mp,functor_params l)]
3746+
end
37193747

3720-
and in_elpi_module : 'a. depth:int -> API.Data.state -> 'a Declarations.generic_module_body -> module_item list =
3721-
fun ~depth state { Declarations.
3722-
mod_mp; (* Names.module_path *)
3723-
mod_expr; (* Declarations.module_implementation *)
3724-
mod_type; (* Declarations.module_signature *)
3725-
mod_type_alg; (* Declarations.module_expression option *)
3726-
mod_delta; (* Mod_subst.delta_resolver *)
3727-
mod_retroknowledge; (* Retroknowledge.action list *)
3728-
} ->
3729-
match mod_type with
3748+
and in_elpi_module : 'a. depth:int -> API.Data.state -> 'a generic_module_body -> module_item list =
3749+
fun ~depth state mb ->
3750+
match mod_type mb with
37303751
| Declarations.MoreFunctor _ -> nYI "functors"
37313752
| Declarations.NoFunctor contents ->
37323753
let l =
3733-
CList.map (in_elpi_module_item ~depth mod_mp state) contents in
3754+
CList.map (in_elpi_module_item ~depth (mod_mp mb) state) contents in
37343755
CList.flatten l
37353756

37363757
let rec in_elpi_modty_item (name, item) = match item with
@@ -3742,16 +3763,16 @@ let rec in_elpi_modty_item (name, item) = match item with
37423763
| Declarations.SFBmodule mb -> in_elpi_modty mb
37433764
| Declarations.SFBmodtype _ -> []
37443765

3745-
and in_elpi_modty : 'a.'a Declarations.generic_module_body -> string list =
3746-
fun { Declarations.mod_type; (* Declarations.modty_signature *) } ->
3747-
match mod_type with
3766+
and in_elpi_modty : 'a.'a generic_module_body -> string list =
3767+
fun mb ->
3768+
match mod_type mb with
37483769
| Declarations.MoreFunctor _ -> nYI "functors"
37493770
| Declarations.NoFunctor contents ->
37503771
CList.flatten (CList.map in_elpi_modty_item contents)
37513772

3752-
let in_elpi_module ~depth s (x : Declarations.module_body) = in_elpi_module ~depth s x
3773+
let in_elpi_module ~depth s x = in_elpi_module ~depth s x
37533774

3754-
let in_elpi_module_type (x : Declarations.module_type_body) = in_elpi_modty x
3775+
let in_elpi_module_type x = in_elpi_modty x
37553776

37563777
(* ********************************* }}} ********************************** *)
37573778

src/coq_elpi_HOAS.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,13 @@ type module_item =
268268
| Functor of Names.ModPath.t * Names.ModPath.t list
269269
| FunctorType of Names.ModPath.t * Names.ModPath.t list
270270

271+
[%%if coq = "8.20" || coq = "9.0"]
271272
val in_elpi_module : depth:int -> State.t -> Declarations.module_body -> module_item list
272273
val in_elpi_module_type : Declarations.module_type_body -> string list
274+
[%%else]
275+
val in_elpi_module : depth:int -> State.t -> Mod_declarations.module_body -> module_item list
276+
val in_elpi_module_type : Mod_declarations.module_type_body -> string list
277+
[%%endif]
273278

274279
val coercion_status : coercion_status Conversion.t
275280
type record_field_att =

0 commit comments

Comments
 (0)