Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Bindlib by de Bruijn indices #843

Open
wants to merge 102 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
3810bb5
add Term.Db constructor
fblanqui Feb 4, 2022
2dfeb71
remove Bindlib from terms (but not rhs)
fblanqui Feb 8, 2022
3434aac
change definition of Term.dtree to rule Tree_type.dtree
fblanqui Feb 8, 2022
49ec8ab
remove Bindlib on rhs
fblanqui Feb 14, 2022
7efc5db
remove TEnv
fblanqui Feb 14, 2022
084ef7a
remove bindlib from dependencies
fblanqui Feb 14, 2022
b522ac7
remove mkfree
fblanqui Feb 14, 2022
23c7397
remove new_mvar and do not export new_var
fblanqui Feb 14, 2022
6730df0
remove box type
fblanqui Feb 14, 2022
170ca77
remove bind_mvar3
fblanqui Feb 14, 2022
28e2508
Env: rename to_tbox into to_terms
fblanqui Feb 14, 2022
02ec00b
remove fresh_box
fblanqui Feb 14, 2022
3a8d502
cli: Term.* -> CLT.*
fblanqui Feb 14, 2022
74aefe9
remove bctxt
fblanqui Feb 14, 2022
d7b6f00
dune-project: use cmdliner <= 1.0.4
fblanqui Feb 14, 2022
b93ccfd
lambdapi.opam: use cmdliner <= 1.0.4
fblanqui Feb 14, 2022
8ff86cd
remove module Bindlib
fblanqui Feb 15, 2022
83b1ec9
renamings: tvar -> var, tbinder -> binder, tmbinder -> mbinder
fblanqui Feb 15, 2022
3376e30
call mk_Appl in subst, and reorganize code in term
fblanqui Feb 15, 2022
2decd3e
rename mk_Impl into mk_Arro
fblanqui Feb 15, 2022
6b5e980
scope: remove useless call to is_closed
fblanqui Feb 15, 2022
6fff025
fix comment
fblanqui Feb 15, 2022
18e5cd5
optimize link/unlink/reset by exposing binder
fblanqui Feb 15, 2022
4a51e1c
remove constraints on bound variable identifiers
fblanqui Feb 15, 2022
dbecfe9
fix reset_term
fblanqui Feb 18, 2022
3d6e948
record if a variable is bound
fblanqui Feb 18, 2022
d46bcab
details
fblanqui Feb 18, 2022
5f073ca
details
fblanqui Feb 18, 2022
fe9d807
detail
fblanqui Feb 18, 2022
cfb0ee0
Merge remote-tracking branch 'lp/master' into db
fblanqui Feb 22, 2022
2b584d3
Merge remote-tracking branch 'lp/master' into db
fblanqui Feb 22, 2022
a369ed3
Merge remote-tracking branch 'lp/master' into db
fblanqui Feb 23, 2022
83e0998
Merge remote-tracking branch 'lp/master' into db
fblanqui Feb 24, 2022
110eaf7
Merge remote-tracking branch 'lp/master' into db
fblanqui Mar 17, 2022
0488ad9
Merge remote-tracking branch 'lp/master' into db
fblanqui Mar 29, 2022
cf4aaef
Merge remote-tracking branch 'lp/master' into db
fblanqui May 9, 2022
e4167af
Merge remote-tracking branch 'lp/master' into db
fblanqui May 12, 2022
ead55ce
Merge remote-tracking branch 'lp/master' into db
fblanqui May 18, 2022
60c75b8
Merge remote-tracking branch 'lp/master' into db
fblanqui May 19, 2022
eb2c957
Merge remote-tracking branch 'lp/master' into db
fblanqui Jul 12, 2022
3bde217
Merge remote-tracking branch 'lp/master' into db
fblanqui Jul 12, 2022
e5d646c
Merge remote-tracking branch 'lp/master' into db
fblanqui Jul 12, 2022
ff0f98e
Merge remote-tracking branch 'lp/master' into db
fblanqui Jul 28, 2022
813ae2f
Merge remote-tracking branch 'lp/master' into db
fblanqui Jul 29, 2022
d5a25a5
Merge remote-tracking branch 'lp/master' into db
fblanqui Aug 4, 2022
6bf38b9
Merge remote-tracking branch 'lp/master' into db
fblanqui Sep 6, 2022
9cc5937
Merge remote-tracking branch 'lp/master' into db
fblanqui Sep 12, 2022
b6eeaa3
Merge remote-tracking branch 'lp/master' into db
fblanqui Sep 12, 2022
65ba575
Merge remote-tracking branch 'lp/master' into db
fblanqui Sep 28, 2022
bbc1477
Merge remote-tracking branch 'lp/master' into db
fblanqui Sep 28, 2022
4085120
Merge remote-tracking branch 'lp/master' into db
fblanqui Dec 28, 2022
4d8ea21
Merge remote-tracking branch 'lp/master' into db
fblanqui Dec 28, 2022
d4ef7ad
Merge remote-tracking branch 'lp/master' into db
fblanqui Dec 28, 2022
7eeb49f
Merge remote-tracking branch 'lp/master' into db
fblanqui Dec 30, 2022
30cd837
Merge remote-tracking branch 'lp/master' into db
fblanqui Dec 30, 2022
5329381
Merge remote-tracking branch 'lp/master' into db
fblanqui Dec 30, 2022
f72ba2f
Merge remote-tracking branch 'lp/master' into db
fblanqui Dec 30, 2022
cc114b0
Merge remote-tracking branch 'lp/master' into db
fblanqui Dec 31, 2022
804fc06
tests/regressions: update expected output of hrs and xtc
fblanqui Dec 31, 2022
7862dd8
fix dk export
fblanqui Dec 31, 2022
7a69b75
Merge remote-tracking branch 'lp/master' into db
fblanqui Jan 2, 2023
eb228eb
Merge remote-tracking branch 'lp/master' into db
fblanqui Jan 11, 2023
7073352
Merge remote-tracking branch 'lp/master' into db
fblanqui Jan 29, 2023
b8980f4
Merge remote-tracking branch 'lp/master' into db
fblanqui Jan 31, 2023
57d5686
Merge remote-tracking branch 'lp/master' into db
fblanqui Feb 27, 2023
3807cd1
Merge remote-tracking branch 'lp/master' into db
fblanqui Mar 12, 2023
a34cc45
Merge remote-tracking branch 'lp/master' into db
fblanqui Mar 17, 2023
858f1f3
Merge remote-tracking branch 'lp/master' into db
fblanqui Mar 30, 2023
9790ee6
Merge remote-tracking branch 'lp/master' into db
fblanqui Apr 4, 2023
4f651f3
Merge remote-tracking branch 'lp/master' into db
fblanqui Apr 14, 2023
7cbc2cd
Merge remote-tracking branch 'lp/master' into db
fblanqui Apr 14, 2023
a2491c2
Merge remote-tracking branch 'lp/master' into db
fblanqui Jun 9, 2023
6babc67
add tests/OK/991.lp
fblanqui Jun 9, 2023
d0b7dde
Merge remote-tracking branch 'lp/master' into db
fblanqui Jun 12, 2023
e762e86
Merge remote-tracking branch 'lp/master' into db
fblanqui Jul 28, 2023
0b16862
Merge remote-tracking branch 'lp/master' into db
fblanqui Jul 28, 2023
68f62de
update doc
fblanqui Jul 29, 2023
f137ca2
Merge remote-tracking branch 'lp/master' into db
fblanqui Jul 31, 2023
3a27af9
Merge remote-tracking branch 'lp/master' into db
fblanqui Aug 1, 2023
50a9075
Merge remote-tracking branch 'lp/master' into db
fblanqui Aug 1, 2023
457a368
Merge remote-tracking branch 'lp/master' into db
fblanqui Sep 15, 2023
e7ce853
Merge remote-tracking branch 'lp/master' into db
fblanqui Oct 25, 2023
0db4750
Merge remote-tracking branch 'dk/master' into db
fblanqui Nov 7, 2023
4a3df34
Merge remote-tracking branch 'dk/master' into db
fblanqui Nov 11, 2023
24a54e8
Merge remote-tracking branch 'dk/master' into db
fblanqui Dec 19, 2023
c74325b
enforce locally nameless convention (never deal with terms containing…
barras Jan 26, 2024
2eb6850
Enforce locally nameless convention (Bruno)
fblanqui Feb 22, 2024
d987930
spaces
fblanqui Feb 22, 2024
6094505
Merge remote-tracking branch 'dk/master' into db
fblanqui Feb 22, 2024
07b05ea
Merge remote-tracking branch 'dk/master' into db
fblanqui Feb 28, 2024
dad144c
Merge remote-tracking branch 'dk/master' into db
fblanqui Mar 1, 2024
2890ad1
exclude 991 in tests/export_raw_dk.sh
fblanqui Mar 1, 2024
b00961f
Merge remote-tracking branch 'dk/master' into db
fblanqui Mar 19, 2024
7dd3baa
remove tests related to identifier restrictions due to bindlib
fblanqui Mar 29, 2024
641a46c
Merge remote-tracking branch 'dk/master' into db
fblanqui Mar 29, 2024
4f260a9
Merge remote-tracking branch 'dk/master' into db
fblanqui Apr 23, 2024
fa42a15
Merge remote-tracking branch 'dk/master' into db
fblanqui Apr 30, 2024
f58c24f
Merge remote-tracking branch 'dk/master' into db
fblanqui May 3, 2024
4b4bcf7
Merge remote-tracking branch 'dk/master' into db
fblanqui Jun 24, 2024
6e123bd
Merge remote-tracking branch 'dk/master' into db
fblanqui Jun 24, 2024
7757b36
Merge remote-tracking branch 'dk/master' into db
fblanqui Aug 30, 2024
bdba910
Merge remote-tracking branch 'dk/master' into db
fblanqui Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions doc/terms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ An identifier can be:
**Remark:** for any regular identifier ``i``, ``{|i|}`` and ``i`` are
identified.

**Remark:** Escaped identifiers or regular identifiers ending with a
non-negative integer with leading zeros cannot be used for bound
variable names.

**Convention:** identifiers starting with an uppercase letter denote
types (e.g. ``Nat``, ``List``), and identifiers starting with a
lowercase letter denote constructors, functions and proofs
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ systems: Dedukti, Coq, HRS, CPF.")
(menhir (>= 20200624))
(sedlex (>= 3.2))
(alcotest :with-test)
(alt-ergo :with-test)
(dedukti (and :with-test (>= 2.7)))
(bindlib (>= 5.0.1))
(timed (>= 1.0))
Expand Down
1 change: 1 addition & 0 deletions lambdapi.opam
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ depends: [
"menhir" {>= "20200624"}
"sedlex" {>= "3.2"}
"alcotest" {with-test}
"alt-ergo" {with-test}
"dedukti" {with-test & >= "2.7"}
"bindlib" {>= "6.0.0"}
"timed" {>= "1.0"}
Expand Down
4 changes: 3 additions & 1 deletion src/cli/init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ open Common open Error
open Format
open Parsing

module CLT = Cmdliner.Term

let write_file : string -> (formatter -> unit) -> unit = fun fn pp ->
let oc = open_out fn in
let ppf = formatter_of_out_channel oc in
Expand Down Expand Up @@ -54,7 +56,7 @@ let run : Path.t -> unit = fun root_path ->
in
Error.handle_exceptions run

let root_path : Path.t Term.t =
let root_path : Path.t CLT.t =
let doc =
"Defines the root path of the package. It is the module path under which \
the package will be registered and installed (if desired), and it will \
Expand Down
8 changes: 5 additions & 3 deletions src/cli/install.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ open Cmdliner
open Common open Library open Error
open Parsing

module CLT = Cmdliner.Term

let run_command : bool -> string -> unit = fun dry_run cmd ->
if dry_run then Console.out 1 "%s" cmd else
match Sys.command cmd with
Expand Down Expand Up @@ -88,22 +90,22 @@ let run_uninstall : Config.t -> bool -> string -> unit =
in
Error.handle_exceptions run

let dry_run : bool Term.t =
let dry_run : bool CLT.t =
let doc =
"Do not install anything, only print the command that would be executed \
if the option was not given."
in
Arg.(value & flag & info ["dry-run"] ~doc)

let pkg_file : string Term.t =
let pkg_file : string CLT.t =
let doc =
Printf.sprintf
"Path to the package configuration file $(b,%s) corresponding to the \
package that should be uninstalled." Package.pkg_file
in
Arg.(required & pos 0 (some non_dir_file) None & info [] ~docv:"FILE" ~doc)

let files : string list Term.t =
let files : string list CLT.t =
let doc =
Printf.sprintf
"Source file with the [%s] extension (or with the [%s] extension when \
Expand Down
4 changes: 4 additions & 0 deletions src/common/debug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ module D = struct
out ppf "]"
end

let hashtbl : 'a pp -> 'b pp -> ('a, 'b) Hashtbl.t pp = fun key elt ->
let tbl ppf = Hashtbl.iter (fun k v -> out ppf "%a,%a; " key k elt v) in
fun ppf -> out ppf "[%a]" tbl

let map : (('key -> 'elt -> unit) -> 'map -> unit)
-> 'key pp -> string -> 'elt pp -> string -> 'map pp =
fun iter key sep1 elt sep2 ppf m ->
Expand Down
8 changes: 8 additions & 0 deletions src/common/logger.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,11 @@ let reset_loggers ?(default=Stdlib.(! default_loggers)) () =
(** [log_summary ()] gives the keys and descriptions for logging options. *)
let log_summary () =
List.map (fun d -> (d.logger_key, d.logger_desc)) Stdlib.(!loggers)

(** [set_debug_in b c f x] sets [c] logger to [b] for evaluating [f x]. *)
let set_debug_in : bool -> char -> ('a -> 'b) -> 'a -> 'b = fun b c f x ->
let is_activated = String.contains (get_activated_loggers()) in
let v = is_activated c in
let s = String.make 1 c in
set_debug b s;
try let r = f x in set_debug v s; r with e -> set_debug v s; raise e
3 changes: 3 additions & 0 deletions src/common/logger.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ val reset_loggers : ?default:string -> unit -> unit

(** [log_summary ()] gives the keys and descriptions for logging options. *)
val log_summary : unit -> (char * string) list

(** [set_debug_in b c f x] sets [c] logger to [b] for evaluating [f x]. *)
val set_debug_in : bool -> char -> ('a -> 'b) -> 'a -> 'b
17 changes: 5 additions & 12 deletions src/core/coercion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ let _ =
(* Add the rule [coerce $A $A $t ↪ $t] (but we don't have access to
the parser here) *)
let rule =
let lhs =
[ mk_Patt (Some 0, "A", [||])
; mk_Patt (Some 0, "A", [||])
; mk_Patt (Some 1, "t", [||]) ]
in
let vars = [|new_tevar "A"; new_tevar "t"|] in
let rhs = _TEnv (_TE_Vari vars.(1)) [||] in
let rhs = Bindlib.(bind_mvar vars rhs |> unbox) in
let arity = 3 in
let arities = [|0; 0|] in
{ lhs; rhs; arity; arities; vars; xvars_nb = 0; rule_pos = None }
let a = mk_Patt (Some 0, "A", [||])
and t = mk_Patt (Some 1, "t", [||]) in
let lhs = [a; a; t] and arities = [|0; 0|] in
{ lhs; rhs=t; arity=3; arities; vars_nb=2; xvars_nb = 0; rule_pos = None }
in
Sign.add_rule Ghost.sign coerce rule
Sign.add_rule Ghost.sign (coerce, rule)
50 changes: 17 additions & 33 deletions src/core/ctxt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,50 @@ open Timed
(** [type_of x ctx] returns the type of [x] in the context [ctx] when it
appears in it, and
@raise [Not_found] otherwise. *)
let type_of : tvar -> ctxt -> term = fun x ctx ->
let (_,a,_) = List.find (fun (y,_,_) -> Bindlib.eq_vars x y) ctx in a
let type_of : var -> ctxt -> term = fun x ctx ->
let (_,a,_) = List.find (fun (y,_,_) -> eq_vars x y) ctx in a

(** [def_of x ctx] returns the definition of [x] in the context [ctx] if it
appears, and [None] otherwise *)
let rec def_of : tvar -> ctxt -> ctxt * term option = fun x c ->
let rec def_of : var -> ctxt -> ctxt * term option = fun x c ->
match c with
| [] -> [], None
| (y,_,d)::c -> if Bindlib.eq_vars x y then c,d else def_of x c
| (y,_,d)::c -> if eq_vars x y then c,d else def_of x c

(** [mem x ctx] tells whether variable [x] is mapped in the context [ctx]. *)
let mem : tvar -> ctxt -> bool = fun x ->
List.exists (fun (y,_,_) -> Bindlib.eq_vars x y)
let mem : var -> ctxt -> bool = fun x ->
List.exists (fun (y,_,_) -> eq_vars x y)

(** [to_prod ctx t] builds a product by abstracting over the context [ctx], in
the term [t]. It returns the number of products as well. *)
let to_prod : ctxt -> term -> term * int = fun ctx t ->
let f (t,c) (x,a,v) =
let b = Bindlib.bind_var x t in
let b = bind_var x t in
match v with
| None -> _Prod (lift a) b, c + 1
| Some v -> _LLet (lift a) (lift v) b, c
| None -> mk_Prod (a, b), c + 1
| Some v -> mk_LLet (a, v, b), c
in
let t, c = List.fold_left f (lift t, 0) ctx in
Bindlib.unbox t, c

(** [to_prod_box bctx t] is similar to [to_prod bctx t] but operates on boxed
contexts and terms. *)
let to_prod_box : bctxt -> tbox -> tbox * int = fun bctx t ->
let f (t, c) (x, a) =
let b = Bindlib.bind_var x t in
(_Prod a b, c + 1)
in
List.fold_left f (t, 0) bctx

(** [box_context ctx] lifts context [ctx] to a boxed context. *)
let box_context : ctxt -> bctxt =
List.filter_map
(fun (x, t, u) -> if u = None then Some (x, lift t) else None)
List.fold_left f (t, 0) ctx

(** [to_abst ctx t] builds a sequence of abstractions over the context [ctx],
in the term [t]. *)
let to_abst : ctxt -> term -> term = fun ctx t ->
let f t (x, a, _) = _Abst (lift a) (Bindlib.bind_var x t) in
Bindlib.unbox (List.fold_left f (lift t) ctx)
let f t (x, a, _) = mk_Abst (a, bind_var x t) in
List.fold_left f t ctx

(** [to_let ctx t] adds the defined variables of [ctx] on top of [t]. *)
let to_let : ctxt -> term -> term = fun ctx t ->
let f t = function
| _, _, None -> t
| x, a, Some u -> _LLet (lift a) (lift u) (Bindlib.bind_var x t)
| x, a, Some u -> mk_LLet (a, u, bind_var x t)
in
Bindlib.unbox (List.fold_left f (lift t) ctx)
List.fold_left f t ctx

(** [sub ctx vs] returns the sub-context of [ctx] made of the variables of
[vs]. *)
let sub : ctxt -> tvar array -> ctxt = fun ctx vs ->
let sub : ctxt -> var array -> ctxt = fun ctx vs ->
let f ((x,_,_) as hyp) ctx =
if Array.exists (Bindlib.eq_vars x) vs then hyp::ctx else ctx
if Array.exists (eq_vars x) vs then hyp::ctx else ctx
in
List.fold_right f ctx []

Expand All @@ -79,9 +64,8 @@ let rec unfold : ctxt -> term -> term = fun ctx t ->
begin
match !(m.meta_value) with
| None -> t
| Some(b) -> unfold ctx (Bindlib.msubst b ts)
| Some(b) -> unfold ctx (msubst b ts)
end
| TEnv(TE_Some(b), ts) -> unfold ctx (Bindlib.msubst b ts)
| TRef(r) ->
begin
match !r with
Expand Down
2 changes: 1 addition & 1 deletion src/core/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
(public_name lambdapi.core)
(synopsis "LambdaPi interactive theorem prover [core]")
(modules :standard)
(libraries lambdapi.common lambdapi.lplib pratter bindlib why3 unix))
(libraries lambdapi.common lambdapi.lplib pratter why3 unix))
Loading
Loading